Sanitized single-commit public mirror of recipe-maintainer. - Removed test-ssh/.testenv (live creds); added test-ssh/.testenv.example placeholders. - Removed plans/ and planned-updates/ (deployment-planning docs) so no client/ deployment domains appear in the public repo. - All other secret stores were already gitignored. - docs.coopcloud.tech retained as a submodule (public upstream).
85 lines
3.0 KiB
Python
Executable File
85 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Create a test admin account on Bluesky PDS."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
|
from utils.tests.helpers import run, resolve_domain
|
|
|
|
|
|
def run_in_container(domain, cmd):
|
|
"""Run a command inside the app container via abra."""
|
|
result = run(
|
|
f'''script -qefc "abra app run {domain} app --no-tty -- sh -c '{cmd}' 2>&1" /dev/null''',
|
|
check=False, timeout=120,
|
|
)
|
|
return result.stdout
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--domain', default=os.environ.get('TEST_DOMAIN'))
|
|
args = parser.parse_args()
|
|
domain = args.domain or resolve_domain('bluesky-pds')
|
|
|
|
test_handle = f"testadmin.{domain}"
|
|
test_email = f"testadmin@{domain}"
|
|
# Generate a random password
|
|
import secrets
|
|
test_password = f"manual-test-{secrets.token_hex(8)}"
|
|
pds_host = "http://localhost:3000"
|
|
admin_pw_flag = "--admin-password \\$(cat /run/secrets/pds_admin_password)"
|
|
pds_flag = f"--pds-host {pds_host}"
|
|
creds_file = os.path.join(os.path.dirname(__file__), '..', f'test-account-{domain}.json')
|
|
|
|
# Check if the account already exists
|
|
print("Checking for existing test account ...")
|
|
account_list = run_in_container(domain, f"goat pds admin account list {admin_pw_flag} {pds_flag} 2>&1")
|
|
|
|
for did in re.findall(r'did:plc:\w+', account_list):
|
|
info = run_in_container(domain, f"goat pds admin account info {did} {admin_pw_flag} {pds_flag} 2>&1")
|
|
if f'"handle": "{test_handle}"' in info:
|
|
print(f"Test account already exists ({did}, handle: {test_handle}).")
|
|
print("To recreate, delete it first:")
|
|
print(f" abra app run {domain} app -- goat pds admin account delete {did} --admin-password \\$(cat /run/secrets/pds_admin_password) --pds-host {pds_host}")
|
|
return
|
|
|
|
# Create the account
|
|
print(f"Creating test account ({test_handle}) ...")
|
|
create_output = run_in_container(
|
|
domain,
|
|
f"goat pds admin account create {admin_pw_flag} {pds_flag} --handle {test_handle} --email {test_email} --password '{test_password}' 2>&1",
|
|
)
|
|
|
|
test_did_match = re.search(r'did:plc:\w+', create_output)
|
|
if not test_did_match:
|
|
print("FAIL: Could not create test account")
|
|
print(f"Output: {create_output}")
|
|
sys.exit(1)
|
|
test_did = test_did_match.group()
|
|
|
|
# Save credentials
|
|
creds = {
|
|
"handle": test_handle,
|
|
"email": test_email,
|
|
"password": test_password,
|
|
"did": test_did,
|
|
"pds": f"https://{domain}",
|
|
}
|
|
with open(creds_file, 'w') as f:
|
|
json.dump(creds, f, indent=2)
|
|
f.write('\n')
|
|
|
|
print(f"Account created and credentials saved to {creds_file}")
|
|
print(f" Handle: {test_handle}")
|
|
print(f" Email: {test_email}")
|
|
print(f" DID: {test_did}")
|
|
print(f" Password: {test_password}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|