Merge lp:~abentley/charms/precise/juju-reports/external-oauth into lp:~juju-qa/charms/precise/juju-reports/trunk

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 35
Proposed branch: lp:~abentley/charms/precise/juju-reports/external-oauth
Merge into: lp:~juju-qa/charms/precise/juju-reports/trunk
Diff against target: 76 lines (+30/-2)
3 files modified
config.yaml (+4/-0)
hooks/common.py (+24/-2)
hooks/install (+2/-0)
To merge this branch: bzr merge lp:~abentley/charms/precise/juju-reports/external-oauth
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+225824@code.launchpad.net

Commit message

Provide OAauth credentials from config var.

Description of the change

This branch changes the charm to supply OAuth credentials from the lp-oauth config variable.

The file is only updated if it does not match the desired value, so that the Makefile is not triggered unduly.

As a driveby, the Launchpad Code SSH key is added to the ubuntu user, just as it already was for root. This makes initial startup more automated.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

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 2014-06-19 19:58:55 +0000
3+++ config.yaml 2014-07-07 13:22:09 +0000
4@@ -20,6 +20,10 @@
5 type: string
6 default: ""
7 description: "SSH key for accessing private code on launchpad."
8+ lp-oauth:
9+ type: string
10+ default: ""
11+ description: "OAuth credentials for accessing private data on Launchapd."
12 dist-clean:
13 type: boolean
14 default: true
15
16=== modified file 'hooks/common.py'
17--- hooks/common.py 2014-06-19 19:58:55 +0000
18+++ hooks/common.py 2014-07-07 13:22:09 +0000
19@@ -184,6 +184,24 @@
20 hookenv.relation_set(relation_id, relation_settings)
21
22
23+def update_file(path, new_contents):
24+ """Write file only if the contents are changed."""
25+ try:
26+ file_context = open(path, 'r')
27+ except IOError as e:
28+ if e.errno == errno.ENOENT:
29+ old_contents = None
30+ else:
31+ raise
32+ else:
33+ with file_context as fileobj:
34+ old_contents = fileobj.read()
35+ if old_contents == new_contents:
36+ return
37+ with open(path, 'w') as fileobj:
38+ fileobj.write(new_contents)
39+
40+
41 def update_from_config():
42 ini = get_ini()
43 mongo_url = get_mongo_url()
44@@ -195,13 +213,17 @@
45 hookenv.log('Incomplete config: source')
46 return
47 update_source(config['source'], config['revno'])
48+ oauth_path = os.path.join(PROJECT_DIR, 'jujureports/lp_credentials.txt')
49+ update_file(oauth_path, config['lp-oauth'] + '\n')
50 install_production(config['dist-clean'], config['develop-install'])
51 if mongo_url == '':
52 hookenv.log('No mongodb set up.')
53 return
54 ini = install_ini(mongo_url)
55- if config['lp-key'] == '':
56- hookenv.log('Not setting up cron because lp-key not set.')
57+ for key in ['lp-key', 'lp-oauth']:
58+ if config[key] == '':
59+ hookenv.log('Not setting up cron because {} not set.'.format(key))
60+ break
61 else:
62 install_cronjob(config['cron-interval'], config['error-email'])
63 start()
64
65=== modified file 'hooks/install'
66--- hooks/install 2014-06-06 14:16:14 +0000
67+++ hooks/install 2014-07-07 13:22:09 +0000
68@@ -25,6 +25,8 @@
69
70 # Make sure launchpad is a known host so ssh isn't prompted to accept it.
71 cat templates/known_hosts >> /root/.ssh/known_hosts
72+cat templates/known_hosts >> /home/ubuntu/.ssh/known_hosts
73+chown ubuntu:ubuntu /home/ubuntu/.ssh/known_hosts
74
75 # Get the code.
76 cd $project_dir

Subscribers

People subscribed via source and target branches

to all changes: