~gary/charms/precise/juju-gui/run-without-ppa

« back to all changes in this revision

Viewing changes to hooks/config-changed

  • Committer: Nicola Larosa
  • Date: 2013-01-04 17:13:20 UTC
  • mfrom: (18.2.15 juju-gui)
  • Revision ID: nicola.larosa@canonical.com-20130104171320-wt22g2mk1gid03w9
Setup encrypted conn. to the API environment

Pass the same certificate and private key used by nginx to the
API environment, so that the websocket connection can use WSS.

R=frankban, gary.poster
CC=
https://codereview.appspot.com/7007045

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
    added_or_changed = diff.added_or_changed
43
43
    juju_api_port = config.get('juju-api-port')
44
 
    staging = config.get('staging')
 
44
    in_staging = config.get('staging')
45
45
 
46
46
    # The juju_gui_source_changed and juju_api_branch_changed variables
47
47
    # control whether we restart the GUI and the API, respectively, at the
62
62
    # Handle changes to SSL certificates.
63
63
    ssl_properties = set(
64
64
        ['ssl-cert-path', 'ssl-cert-contents', 'ssl-key-contents'])
65
 
    if added_or_changed & ssl_properties:
 
65
    ssl_changed = added_or_changed & ssl_properties
 
66
    if ssl_changed:
66
67
        save_or_create_certificates(
67
68
            config['ssl-cert-path'], config.get('ssl-cert-contents'),
68
69
            config.get('ssl-key-contents'))
69
70
 
70
71
    # Handle changes to the improv server configuration.
71
 
    if staging:
 
72
    if in_staging:
72
73
        staging_properties = set(
73
74
            ['staging', 'staging-environment', 'juju-api-port'])
74
75
        staging_changed = added_or_changed & staging_properties
75
 
        if staging_changed or juju_api_branch_changed:
 
76
        if staging_changed or ssl_changed or juju_api_branch_changed:
76
77
            if 'staging' in added_or_changed:
77
78
                # 'staging' went from False to True, so the agent server is
78
79
                # running and must be stopped.
85
86
            service_control(current_api, STOP)
86
87
            # Now the improv server can be cleanly started.
87
88
            log('Starting or restarting staging.')
88
 
            start_improv(juju_api_port, config.get('staging-environment'))
 
89
            start_improv(juju_api_port, config.get('staging-environment'),
 
90
                         config['ssl-cert-path'])
89
91
    else:
90
92
        agent_properties = set(['juju-api-port', 'staging'])
91
93
        agent_changed = added_or_changed & agent_properties
92
 
        if agent_changed or juju_api_branch_changed:
 
94
        if agent_changed or ssl_changed or juju_api_branch_changed:
93
95
            if 'staging' in added_or_changed:
94
96
                # If 'staging' transitions to False we need to stop the backend
95
97
                # and start the agent.
100
102
                current_api = AGENT
101
103
            service_control(current_api, STOP)
102
104
            log('Starting or restarting Juju API agent.')
103
 
            start_agent(juju_api_port)
 
105
            start_agent(juju_api_port, config['ssl-cert-path'])
104
106
 
105
107
    # Handle changes to the juju-gui configuration.
106
108
    gui_properties = set(
107
109
        ['juju-gui-console-enabled', 'juju-api-port', 'staging'])
108
110
    gui_changed = added_or_changed & gui_properties
109
 
    ssl_cert_path_changed = 'ssl-cert-path' in added_or_changed
110
 
    if gui_changed or juju_gui_source_changed or ssl_cert_path_changed:
 
111
    if gui_changed or ssl_changed or juju_gui_source_changed:
111
112
        with su('root'):
112
113
            service_control(GUI, STOP)
113
114
        console_enabled = config.get('juju-gui-console-enabled')
114
115
        ssl_cert_path = config['ssl-cert-path']
115
 
        start_gui(juju_api_port, console_enabled, staging, ssl_cert_path)
 
116
        start_gui(juju_api_port, console_enabled, in_staging, ssl_cert_path)
116
117
 
117
118
 
118
119
def main():