Merge lp:~stub/charms/precise/postgresql-psql/devel into lp:charms/postgresql-psql

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 18
Proposed branch: lp:~stub/charms/precise/postgresql-psql/devel
Merge into: lp:charms/postgresql-psql
Diff against target: 45 lines (+22/-5)
2 files modified
config.yaml (+6/-0)
hooks/hooks.py (+16/-5)
To merge this branch: bzr merge lp:~stub/charms/precise/postgresql-psql/devel
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+199938@code.launchpad.net

Description of the change

The PostgreSQL charm had an (until now) undocumented 'roles' parameter on the relation. This parameter specifies a list of roles that PostgreSQL should grant a newly created user.

This branch adds support for setting this parameter on the psql service.

To post a comment you must log in.
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
1=== modified file 'config.yaml'
2--- config.yaml 2013-05-07 07:01:22 +0000
3+++ config.yaml 2013-12-23 10:26:33 +0000
4@@ -5,3 +5,9 @@
5 description: |
6 Database to connect 'db' relationships to, overriding the
7 generated default database name.
8+ roles:
9+ default: ""
10+ type: string
11+ description: |
12+ Comma separated list of roles for PostgreSQL to grant to the database
13+ user.
14
15=== modified file 'hooks/hooks.py'
16--- hooks/hooks.py 2013-08-23 11:43:56 +0000
17+++ hooks/hooks.py 2013-12-23 10:26:33 +0000
18@@ -57,11 +57,22 @@
19
20 for _, relid, unit, relation in all_relations(relation_types=['db']):
21 log("{} {} {!r}".format(relid, unit, relation), DEBUG)
22- if config['database'] and relation['database'] != config['database']:
23- log("Overriding generated database {} with {}".format(
24- relation['database'], config['database']), INFO)
25- hookenv.relation_set(relid, database=config['database'])
26- elif 'user' in relation:
27+
28+ def_str = '<DEFAULT>'
29+ if config['database'] != relation.get('database', ''):
30+ log("Switching from database {} to {}".format(
31+ relation.get('database', '') or def_str,
32+ config['database'] or def_str), INFO)
33+
34+ if config['roles'] != relation.get('roles', ''):
35+ log("Updating granted roles from {} to {}".format(
36+ relation.get('roles', '') or def_str,
37+ config['roles'] or def_str))
38+
39+ hookenv.relation_set(
40+ relid, database=config['database'], roles=config['roles'])
41+
42+ if 'user' in relation:
43 rebuild_relation(relid, unit, relation)
44
45 for _, relid, unit, relation in all_relations(relation_types=['db-admin']):

Subscribers

People subscribed via source and target branches