Prepare runner-only provisioning for approved editor secrets
Validate / validate (push) Successful in 3m46s
Validate / validate (push) Successful in 3m46s
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""Runner-only: persist optional Actions editor secrets without logging values."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
values = {key: os.environ.get(key, '') for key in
|
||||
('EDITOR_TOTP_SECRET', 'EDITOR_SESSION_SECRET', 'EDITOR_ORIGIN')}
|
||||
# Missing Actions configuration preserves the current server configuration.
|
||||
if values['EDITOR_TOTP_SECRET'] and values['EDITOR_SESSION_SECRET']:
|
||||
if not re.fullmatch(r'[A-Z2-7]{32,}', values['EDITOR_TOTP_SECRET']):
|
||||
raise SystemExit('Invalid editor authenticator configuration')
|
||||
if not re.fullmatch(r'[A-Za-z0-9_-]{32,}', values['EDITOR_SESSION_SECRET']):
|
||||
raise SystemExit('Invalid editor session configuration')
|
||||
if not values['EDITOR_ORIGIN']:
|
||||
raise SystemExit('Editor origin is required when provisioning secrets')
|
||||
if not re.fullmatch(r'https?://[A-Za-z0-9.:-]+', values['EDITOR_ORIGIN']):
|
||||
raise SystemExit('Invalid editor origin')
|
||||
lines = [line for line in path.read_text().splitlines()
|
||||
if not any(line.startswith(key + '=') for key in values)]
|
||||
lines += [f'{key}={value}' for key, value in values.items()]
|
||||
fd, temp = tempfile.mkstemp(dir=path.parent, prefix='.editor-env-')
|
||||
try:
|
||||
with os.fdopen(fd, 'w') as output:
|
||||
output.write('\n'.join(lines) + '\n')
|
||||
os.chmod(temp, 0o600)
|
||||
os.replace(temp, path)
|
||||
finally:
|
||||
if os.path.exists(temp):
|
||||
os.unlink(temp)
|
||||
Reference in New Issue
Block a user