@@ -35,10 +35,14 @@ def qa_database(path):
|
||||
passfile, cert = [path.parent / name for name in ('qa.pgpass', 'rds-ca.pem')]
|
||||
qa_env.private_file(passfile)
|
||||
qa_env.private_file(cert)
|
||||
expected = f"{db['host']}:{db['port']}:{db['database']}:{db['user']}:"
|
||||
endpoint = f"{db['host']}:{db['port']}:"
|
||||
expected = f"{endpoint}{db['database']}:{db['user']}:"
|
||||
entries = [line for line in passfile.read_text().splitlines() if line and not line.startswith('#')]
|
||||
cd.require(len(entries) == 1 and entries[0].startswith(expected), 'pgpass must authorize exactly the dedicated QA database')
|
||||
password = re.sub(r'\\(.)', r'\1', entries[0][len(expected):])
|
||||
qa_entry = re.compile(re.escape(endpoint) + r'kg_qa_[a-z0-9_]{1,56}:kg_qa_[a-z0-9_]{1,56}:(?:[^:\\]|\\.)+')
|
||||
cd.require(all(qa_entry.fullmatch(line) for line in entries), 'pgpass must contain only exact QA entries at the configured endpoint')
|
||||
matching = [line for line in entries if line.startswith(expected)]
|
||||
cd.require(len(matching) == 1, 'pgpass must contain exactly one entry for the configured QA database and role')
|
||||
password = re.sub(r'\\(.)', r'\1', matching[0][len(expected):])
|
||||
cd.require(bool(password), 'dedicated QA database password missing')
|
||||
url = (f"postgresql://{db['user']}:{quote(password, safe='')}@{db['host']}:{db['port']}/{db['database']}"
|
||||
'?sslmode=verify-full&sslrootcert=/run/qa/rds-ca.pem')
|
||||
|
||||
Reference in New Issue
Block a user