def set_host(url_): hosts = get('host', 'auth') if url_ in [host_['url'] for host_ in hosts]: _config['host']['selected'] = url_ else: raise errors.ConfigError("There is no host with url {}".format(url_)) _persist()
def _get_selected_host_auth(): selected = get('host', 'selected') hosts = get('host', 'auth') for host_ in hosts: if host_['url'] == selected: return host_ raise errors.ConfigError("The selected host doesn't exist.")
def get(*args): try: prop = _config for at in list(args): prop = prop[at] return prop except KeyError as e: raise errors.ConfigError('missing property: {}'.format(_key_error_string(e)))
def username(): try: return _get_selected_host_auth()['username'] except KeyError as e: raise errors.ConfigError('missing property: {}'.format( _key_error_string(e)))