Merge ~cjwatson/launchpad:charm-admin-superuser-any-dbname into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: a2fde21d337b95ccc8ab701cd818d8d8ae6c30e5
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:charm-admin-superuser-any-dbname
Merge into: launchpad:master
Diff against target: 28 lines (+9/-1)
1 file modified
charm/launchpad-admin/reactive/launchpad-admin.py (+9/-1)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+439149@code.launchpad.net

Commit message

charm: Use admin database password for any database name

Description of the change

This seems to work in practice (at least when relating directly to the `postgresql` charm rather than via a proxy), and it makes it a lot easier to handle database creation.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charm/launchpad-admin/reactive/launchpad-admin.py b/charm/launchpad-admin/reactive/launchpad-admin.py
2index 0a31116..6dad256 100644
3--- a/charm/launchpad-admin/reactive/launchpad-admin.py
4+++ b/charm/launchpad-admin/reactive/launchpad-admin.py
5@@ -16,6 +16,12 @@ from ols import base, postgres
6 from psycopg2.extensions import make_dsn, parse_dsn
7
8
9+def any_dbname(dsn):
10+ parsed_dsn = parse_dsn(dsn)
11+ parsed_dsn["dbname"] = "*"
12+ return make_dsn(**parsed_dsn)
13+
14+
15 def strip_password(dsn):
16 parsed_dsn = parse_dsn(dsn)
17 parsed_dsn.pop("password", None)
18@@ -34,7 +40,9 @@ def configure(db, db_admin, session_db):
19 db_primary, _ = postgres.get_db_uris(db)
20 db_admin_primary, _ = postgres.get_db_uris(db_admin)
21 session_db_primary, _ = postgres.get_db_uris(session_db)
22- update_pgpass(db_admin_primary)
23+ # We assume that this admin user works for any database on this host,
24+ # which seems to be true in practice.
25+ update_pgpass(any_dbname(db_admin_primary))
26 update_pgpass(session_db_primary)
27 config["db_primary"] = strip_password(db_primary)
28 config["db_admin_primary"] = strip_password(db_admin_primary)

Subscribers

People subscribed via source and target branches

to status/vote changes: