Merge lp:~stub/charms/precise/postgresql/bug-1187508-allowed-hosts into lp:charms/postgresql

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 57
Proposed branch: lp:~stub/charms/precise/postgresql/bug-1187508-allowed-hosts
Merge into: lp:charms/postgresql
Prerequisite: lp:~stub/charms/precise/postgresql/charm-helpers
Diff against target: 52 lines (+13/-0)
2 files modified
README.markdown (+4/-0)
hooks/hooks.py (+9/-0)
To merge this branch: bzr merge lp:~stub/charms/precise/postgresql/bug-1187508-allowed-hosts
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+174771@code.launchpad.net

Description of the change

This is a resubmission of https://code.launchpad.net/~davidpbritton/charms/precise/postgresql/trunk/+merge/171906, conflicts resolved and suggestions implemented.

This is to address Bug #1187508, where a client charm has no way of knowing if the credentials it has will actually work for it yet.

Simple change to set and export an "allowed-units" relation setting. This will show if you can connect to the database or not. Since the relations run asynchronously, there is no way to determine this otherwise. If your host is in the allowed_host setting, your client IP has been added to the hba conf file.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :
Revision history for this message
David Britton (dpb) wrote :

Stub: looks great! thanks for re-implementing.

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.markdown'
--- README.markdown 2013-04-10 13:54:05 +0000
+++ README.markdown 2013-07-15 14:23:49 +0000
@@ -118,6 +118,8 @@
118- `user`: a regular user authorized to read the database118- `user`: a regular user authorized to read the database
119- `password`: the password for `user`119- `password`: the password for `user`
120- `state`: 'standalone', 'master' or 'hot standby'.120- `state`: 'standalone', 'master' or 'hot standby'.
121- `allowed-units`: space separated list of allowed clients (unit name).
122 You should check this to determine if you can connect to the database yet.
121123
122## During db-admin-relation-changed124## During db-admin-relation-changed
123125
@@ -128,3 +130,5 @@
128- `user`: a created super user130- `user`: a created super user
129- `password`: the password for `user`131- `password`: the password for `user`
130- `state`: 'standalone', 'master' or 'hot standby'132- `state`: 'standalone', 'master' or 'hot standby'
133- `allowed-units`: space separated list of allowed clients (unit name).
134 You should check this to determine if you can connect to the database yet.
131135
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2013-07-08 10:52:59 +0000
+++ hooks/hooks.py 2013-07-15 14:23:49 +0000
@@ -440,6 +440,7 @@
440 # It's not an IP address.440 # It's not an IP address.
441 return addr441 return addr
442442
443 allowed_units = set()
443 relation_data = []444 relation_data = []
444 relids = hookenv.relation_ids('db') + hookenv.relation_ids('db-admin')445 relids = hookenv.relation_ids('db') + hookenv.relation_ids('db-admin')
445 for relid in relids:446 for relid in relids:
@@ -477,6 +478,7 @@
477 raise RuntimeError(478 raise RuntimeError(
478 'Unknown relation type {}'.format(repr(relid)))479 'Unknown relation type {}'.format(repr(relid)))
479480
481 allowed_units.add(unit)
480 relation['private-address'] = munge_address(482 relation['private-address'] = munge_address(
481 relation['private-address'])483 relation['private-address'])
482 relation_data.append(relation)484 relation_data.append(relation)
@@ -523,6 +525,13 @@
523 owner="postgres", group="postgres", perms=0600)525 owner="postgres", group="postgres", perms=0600)
524 postgresql_reload()526 postgresql_reload()
525527
528 # Loop through all db relations, making sure each knows what are the list
529 # of allowed hosts that were just added. lp:#1187508
530 # We sort the list to ensure stability, probably unnecessarily.
531 for relid in hookenv.relation_ids('db') + hookenv.relation_ids('db-admin'):
532 hookenv.relation_set(
533 relid, {"allowed-units": " ".join(unit_sorted(allowed_units))})
534
526535
527def install_postgresql_crontab(postgresql_ident):536def install_postgresql_crontab(postgresql_ident):
528 '''Create the postgres user's crontab'''537 '''Create the postgres user's crontab'''

Subscribers

People subscribed via source and target branches