def test_unit_get(self): # unit_get is used to retrieve individual configuration elements mock_config = {'key': 'value'} # Monkey-patch shelltoolbox.command to avoid having to call out # to unit-get. self._patch_command(lambda *args: mock_config[args[0]]) self.assertEqual(mock_config['key'], charmhelpers.unit_get('key'))
def write_gui_config( console_enabled, login_help, readonly, in_staging, charmworld_url, build_dir, secure=True, sandbox=False, default_viewmode='sidebar', show_get_juju_button=False, config_js_path=None, ga_key='', password=None): """Generate the GUI configuration file.""" log('Generating the Juju GUI configuration file.') is_legacy_juju = legacy_juju() user = '******' if is_legacy_juju else 'user-admin' # Normalize empty string passwords to None. password = password if password else None if password is None and ((is_legacy_juju and in_staging) or sandbox): password = '******' api_backend = 'python' if (is_legacy_juju and not sandbox) else 'go' if secure: protocol = 'wss' else: log('Running in insecure mode! Port 80 will serve unencrypted.') protocol = 'ws' context = { 'raw_protocol': protocol, 'address': unit_get('public-address'), 'console_enabled': json.dumps(console_enabled), 'login_help': json.dumps(login_help), 'password': json.dumps(password), 'api_backend': json.dumps(api_backend), 'readonly': json.dumps(readonly), 'user': json.dumps(user), 'protocol': json.dumps(protocol), 'sandbox': json.dumps(sandbox), 'charmworld_url': json.dumps(charmworld_url), 'ga_key': json.dumps(ga_key), 'default_viewmode': json.dumps(default_viewmode), 'show_get_juju_button': json.dumps(show_get_juju_button), } if config_js_path is None: config_js_path = os.path.join( build_dir, 'juju-ui', 'assets', 'config.js') render_to_file('config.js.template', context, config_js_path)
def write_gui_config(console_enabled, login_help, readonly, charmworld_url, charmstore_url, build_dir, secure=True, sandbox=False, cached_fonts=False, hide_login_button=False, config_js_path=None, ga_key='', juju_core_version=None, password=None, juju_env_uuid=None): """Generate the GUI configuration file.""" log('Generating the Juju GUI configuration file.') user = '******' # Normalize empty string passwords to None. If sandbox is enabled then set # the password to admin and it will auto login. if not password: if sandbox: password = '******' else: password = None api_backend = 'go' if secure: protocol = 'wss' else: log('Running in insecure mode! Port 80 will serve unencrypted.') protocol = 'ws' # Set up the help message displayed by the GUI login view. if login_help is None: env_name = os.getenv('JUJU_ENV_NAME') if env_name: login_help = ( 'The password is the admin-secret from the Juju environment. ' 'This can be found by looking in ~/.juju/environments/{}.jenv ' 'and searching for the password field. Note that using ' 'juju-quickstart (https://launchpad.net/juju-quickstart) can ' 'automate logging in, as well as other parts of installing ' 'and starting Juju.'.format(env_name)) else: # The Juju environment name is included in the hooks context # starting from juju-core v1.18. login_help = ( 'The password for newer Juju clients can be found by locating ' 'the Juju environment file placed in ~/.juju/environments/ ' 'with the same name as the current environment. For example, ' 'if you have an environment named "production", then the file ' 'is named ~/.juju/environments/production.jenv. Look for the ' '"password" field in the file, or if that is empty, for the ' '"admin-secret". Remove the quotes from the value, and use ' 'this to log in. The password for older Juju clients (< 1.16) ' 'is in ~/.juju/environments.yaml, and listed as the ' 'admin-secret for the environment you are using. Note that ' 'using juju-quickstart ' '(https://launchpad.net/juju-quickstart) can automate logging ' 'in, as well as other parts of installing and starting Juju.') if not juju_core_version: log('Retrieving Juju version.') juju_core_version = run('jujud', '--version').strip() context = { 'cached_fonts': json.dumps(cached_fonts), 'raw_protocol': protocol, 'address': unit_get('public-address'), 'console_enabled': json.dumps(console_enabled), 'login_help': json.dumps(login_help), 'password': json.dumps(password), 'api_backend': json.dumps(api_backend), 'readonly': json.dumps(readonly), 'user': json.dumps(user), 'protocol': json.dumps(protocol), 'sandbox': json.dumps(sandbox), 'charmworld_url': json.dumps(charmworld_url), 'charmstore_url': json.dumps(charmstore_url), 'ga_key': json.dumps(ga_key), 'hide_login_button': json.dumps(hide_login_button), 'juju_core_version': json.dumps(juju_core_version), 'juju_env_uuid': json.dumps(juju_env_uuid), } if config_js_path is None: config_js_path = os.path.join(build_dir, 'juju-ui', 'assets', 'config.js') render_to_file('config.js.template', context, config_js_path)