~tvansteenburgh/charms/precise/apache2/fix-tests

« back to all changes in this revision

Viewing changes to hooks/hooks.py

[ahasenack] If the config key "servername" is empty, fill it in with the public-address of the unit to match what the documentation says.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    open_port,
17
17
    close_port,
18
18
    log,
19
 
    config as config_get,
 
19
    config as orig_config_get,
20
20
    relations_of_type,
 
21
    unit_get
21
22
)
22
23
from charmhelpers.contrib.charmsupport import nrpe
23
24
 
137
138
###############################################################################
138
139
# Hook functions
139
140
###############################################################################
 
141
def config_get(scope=None):
 
142
    """
 
143
    Wrapper around charm helper's config_get to replace an empty servername
 
144
    with the public-address.
 
145
    """
 
146
    result = orig_config_get(scope)
 
147
    if scope == "servername" and len(result) == 0:
 
148
        result = unit_get("public-address")
 
149
    elif type(result) is dict and "servername" in result.keys():
 
150
        result["servername"] = unit_get("public-address")
 
151
    return result
 
152
 
140
153
def install_hook():
141
154
    if not os.path.exists(default_apache2_service_config_dir):
142
155
        os.mkdir(default_apache2_service_config_dir, 0600)
405
418
        # ssl_cert is SELFSIGNED so generate self-signed certificate for use.
406
419
        if config_data['ssl_cert'] and config_data['ssl_cert'] == "SELFSIGNED":
407
420
            os.environ['OPENSSL_CN'] = config_data['servername']
408
 
            os.environ['OPENSSL_PUBLIC'] = run(["unit-get", "public-address"]).rstrip()
409
 
            os.environ['OPENSSL_PRIVATE'] = run(["unit-get", "private-address"]).rstrip()
 
421
            os.environ['OPENSSL_PUBLIC'] = unit_get("public-address")
 
422
            os.environ['OPENSSL_PRIVATE'] = unit_get("private-address")
410
423
            run(['openssl', 'req', '-new', '-x509', '-nodes', '-config',
411
424
                 os.path.join(os.environ['CHARM_DIR'], 'data', 'openssl.cnf'),
412
425
                 '-keyout', key_file, '-out', cert_file])