~cprov/charms/trusty/core-image-publisher/glanceclient-builddeps

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/hahelpers/apache.py

  • Committer: Celso Providelo
  • Date: 2015-03-25 04:13:43 UTC
  • Revision ID: celso.providelo@canonical.com-20150325041343-jw05jaz6jscs3c8f
fork of core-image-watcher

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014-2015 Canonical Limited.
 
2
#
 
3
# This file is part of charm-helpers.
 
4
#
 
5
# charm-helpers is free software: you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License version 3 as
 
7
# published by the Free Software Foundation.
 
8
#
 
9
# charm-helpers is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public License
 
15
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
#
 
18
# Copyright 2012 Canonical Ltd.
 
19
#
 
20
# This file is sourced from lp:openstack-charm-helpers
 
21
#
 
22
# Authors:
 
23
#  James Page <james.page@ubuntu.com>
 
24
#  Adam Gandelman <adamg@ubuntu.com>
 
25
#
 
26
 
 
27
import subprocess
 
28
 
 
29
from charmhelpers.core.hookenv import (
 
30
    config as config_get,
 
31
    relation_get,
 
32
    relation_ids,
 
33
    related_units as relation_list,
 
34
    log,
 
35
    INFO,
 
36
)
 
37
 
 
38
 
 
39
def get_cert(cn=None):
 
40
    # TODO: deal with multiple https endpoints via charm config
 
41
    cert = config_get('ssl_cert')
 
42
    key = config_get('ssl_key')
 
43
    if not (cert and key):
 
44
        log("Inspecting identity-service relations for SSL certificate.",
 
45
            level=INFO)
 
46
        cert = key = None
 
47
        if cn:
 
48
            ssl_cert_attr = 'ssl_cert_{}'.format(cn)
 
49
            ssl_key_attr = 'ssl_key_{}'.format(cn)
 
50
        else:
 
51
            ssl_cert_attr = 'ssl_cert'
 
52
            ssl_key_attr = 'ssl_key'
 
53
        for r_id in relation_ids('identity-service'):
 
54
            for unit in relation_list(r_id):
 
55
                if not cert:
 
56
                    cert = relation_get(ssl_cert_attr,
 
57
                                        rid=r_id, unit=unit)
 
58
                if not key:
 
59
                    key = relation_get(ssl_key_attr,
 
60
                                       rid=r_id, unit=unit)
 
61
    return (cert, key)
 
62
 
 
63
 
 
64
def get_ca_cert():
 
65
    ca_cert = config_get('ssl_ca')
 
66
    if ca_cert is None:
 
67
        log("Inspecting identity-service relations for CA SSL certificate.",
 
68
            level=INFO)
 
69
        for r_id in relation_ids('identity-service'):
 
70
            for unit in relation_list(r_id):
 
71
                if ca_cert is None:
 
72
                    ca_cert = relation_get('ca_cert',
 
73
                                           rid=r_id, unit=unit)
 
74
    return ca_cert
 
75
 
 
76
 
 
77
def install_ca_cert(ca_cert):
 
78
    if ca_cert:
 
79
        with open('/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt',
 
80
                  'w') as crt:
 
81
            crt.write(ca_cert)
 
82
        subprocess.check_call(['update-ca-certificates', '--fresh'])