def _set(name, value): """ :returns: process status :rtype: int """ config_path, toml_config = _load_config() section, subkey = _split_key(name) config_schema = _get_config_schema(section) python_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} toml_config[name] = python_value if (name == 'core.reporting' and python_value is True) or \ (name == 'core.email'): analytics.segment_identify(toml_config) _save_config_file(config_path, toml_config) _check_config(toml_config_pre, toml_config) _save_config_file(config_path, toml_config) return 0
def set_val(name, value, config_path=None): """ :param name: name of paramater :type name: str :param value: value to set to paramater `name` :type param: str :param config_path: path to config to use :type config_path: str :returns: Toml config, message of change :rtype: Toml, str """ if config_path: toml_config = load_from_path(config_path, True) else: toml_config = get_config(True) section, subkey = split_key(name) config_schema = get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) # remove token when core.dcos_url is changed token_unset = False if value_exists and old_value != new_value and name == "core.dcos_url": token_unset = bool(toml_config.pop("core.dcos_acs_token", False)) toml_config[name] = new_value check_config(toml_config_pre, toml_config, section) save(toml_config, config_path) msg = "[{}]: ".format(name) if name == "core.dcos_acs_token": if not value_exists: msg += "set" elif old_value == new_value: msg += "already set to that value" else: msg += "changed" elif not value_exists: msg += "set to '{}'".format(new_value) elif old_value == new_value: msg += "already set to '{}'".format(old_value) else: msg += "changed from '{}' to '{}'".format(old_value, new_value) if token_unset: msg += "\n[core.dcos_acs_token]: removed" return toml_config, msg
def _save_auth_keys(key_dict): """ :param key_dict: auth parameters dict :type key_dict: dict :rtype: None """ config_path = os.environ[constants.DCOS_CONFIG_ENV] toml_config = config.mutable_load_from_path(config_path) section = 'core' config_schema = json.loads( pkg_resources.resource_string( 'dcoscli', 'data/config-schema/core.json').decode('utf-8')) for k, v in iteritems(key_dict): python_value = jsonitem.parse_json_value(k, v, config_schema) name = '{}.{}'.format(section, k) toml_config[name] = python_value serial = toml.dumps(toml_config._dictionary) with util.open_file(config_path, 'w') as config_file: config_file.write(serial) return None
def set_val(name, value): """ :param name: name of paramater :type name: str :param value: value to set to paramater `name` :type param: str :returns: Toml config, message of change :rtype: Toml, str """ toml_config = get_config(True) section, subkey = split_key(name) config_schema = get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) # remove token when core.dcos_url is changed token_unset = False if value_exists and old_value != new_value and name == "core.dcos_url": token_unset = bool(toml_config.pop("core.dcos_acs_token", False)) toml_config[name] = new_value check_config(toml_config_pre, toml_config, section) save(toml_config) msg = "[{}]: ".format(name) if name == "core.dcos_acs_token": if not value_exists: msg += "set" elif old_value == new_value: msg += "already set to that value" else: msg += "changed" elif not value_exists: msg += "set to '{}'".format(new_value) elif old_value == new_value: msg += "already set to '{}'".format(old_value) else: msg += "changed from '{}' to '{}'".format(old_value, new_value) if token_unset: msg += ("\n[core.dcos_acs_token]: removed\n" "Please run `dcos auth login` to authenticate to new dcos_url") return toml_config, msg
def set_val(name, value): """ :param name: name of paramater :type name: str :param value: value to set to paramater `name` :type param: str :returns: Toml config :rtype: Toml """ toml_config = util.get_config(True) section, subkey = split_key(name) config_schema = get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) toml_config[name] = new_value check_config(toml_config_pre, toml_config) save(toml_config) msg = "[{}]: ".format(name) if name == "core.dcos_acs_token": if not value_exists: msg += "set" elif old_value == new_value: msg += "already set to that value" else: msg += "changed" elif not value_exists: msg += "set to '{}'".format(new_value) elif old_value == new_value: msg += "already set to '{}'".format(old_value) else: msg += "changed from '{}' to '{}'".format(old_value, new_value) emitter.publish(DefaultError(msg)) return toml_config
def set_val(name, value): """ :param name: name of paramater :type name: str :param value: value to set to paramater `name` :type param: str :returns: Toml config :rtype: Toml """ toml_config = util.get_config(True) section, subkey = split_key(name) config_schema = get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) toml_config[name] = new_value check_config(toml_config_pre, toml_config) save(toml_config) if not value_exists: emitter.publish("[{}]: set to '{}'".format(name, new_value)) elif old_value == new_value: emitter.publish("[{}]: already set to '{}'".format(name, old_value)) else: emitter.publish( "[{}]: changed from '{}' to '{}'".format( name, old_value, new_value)) return toml_config
def _set(name, value): """ :returns: process status :rtype: int """ toml_config = util.get_config(True) section, subkey = _split_key(name) config_schema = _get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) toml_config[name] = new_value if (name == 'core.reporting' and new_value is True) or \ (name == 'core.email'): analytics.segment_identify(toml_config) _check_config(toml_config_pre, toml_config) config.save(toml_config) if not value_exists: emitter.publish("[{}]: set to '{}'".format(name, new_value)) elif old_value == new_value: emitter.publish("[{}]: already set to '{}'".format(name, old_value)) else: emitter.publish( "[{}]: changed from '{}' to '{}'".format( name, old_value, new_value)) return 0
def _save_auth_keys(key_dict): """ :param key_dict: auth parameters dict :type key_dict: dict :rtype: None """ toml_config = util.get_config(True) section = 'core' config_schema = json.loads( pkg_resources.resource_string( 'dcoscli', 'data/config-schema/core.json').decode('utf-8')) for k, v in iteritems(key_dict): python_value = jsonitem.parse_json_value(k, v, config_schema) name = '{}.{}'.format(section, k) toml_config[name] = python_value config.save(toml_config) return None
def set_val(name, value): """ :param name: name of paramater :type name: str :param value: value to set to paramater `name` :type param: str :returns: Toml config :rtype: Toml """ toml_config = util.get_config(True) section, subkey = split_key(name) config_schema = get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) toml_config[name] = new_value check_config(toml_config_pre, toml_config) save(toml_config) if not value_exists: emitter.publish("[{}]: set to '{}'".format(name, new_value)) elif old_value == new_value: emitter.publish("[{}]: already set to '{}'".format(name, old_value)) else: emitter.publish("[{}]: changed from '{}' to '{}'".format( name, old_value, new_value)) return toml_config
def _set(name, value): """ :returns: process status :rtype: int """ toml_config = util.get_config(True) section, subkey = _split_key(name) config_schema = _get_config_schema(section) new_value = jsonitem.parse_json_value(subkey, value, config_schema) toml_config_pre = copy.deepcopy(toml_config) if section not in toml_config_pre._dictionary: toml_config_pre._dictionary[section] = {} value_exists = name in toml_config old_value = toml_config.get(name) toml_config[name] = new_value if (name == 'core.reporting' and new_value is True) or \ (name == 'core.email'): analytics.segment_identify(toml_config) _check_config(toml_config_pre, toml_config) config.save(toml_config) if not value_exists: emitter.publish("[{}]: set to '{}'".format(name, new_value)) elif old_value == new_value: emitter.publish("[{}]: already set to '{}'".format(name, old_value)) else: emitter.publish("[{}]: changed from '{}' to '{}'".format( name, old_value, new_value)) return 0