def set(self, d, path=''): if path == '': self.data.update(d) else: # throws KeyError dpath.set(self.data, path, d) self.save()
def DoSetAll(dictionary, path, param, vals): path += "/**/" + param orig_vals = DoGetAll(dictionary, path) orig_vals = sorted(orig_vals, key=lambda x: x[ 0]) # required to keep consistency in setting items by index if len(orig_vals) == len(vals): # orig_val=DoGet(dictionary, v[0]) # if not orig_val: # if isinstance(orig_val, int): # val=int(val) # elif isinstance(orig_val, float): # val=float(val) # print(datetime.datetime.now(),"---") for i, v in enumerate( orig_vals ): # required to keep consistency in setting items by index # g=DoSet(dictionary,v[0],vals[i]) dpu.set(dictionary, v[0], vals[i]) # print(datetime.datetime.now(),"---") save_gap_file(dictionary) else: print("Vals array is not same size as target params array") return dictionary
def set_bool_conf_val(path, val, monkey_config): """ Changes monkey's configuration by setting one of its boolean fields value :param path: Path to boolean value in monkey's configuration. E.g. ['monkey', 'system_info', 'should_use_mimikatz'] :param val: Boolean :param monkey_config: Monkey's configuration """ util.set(monkey_config, '/'.join(path), val)
def DoSet(dictionary, path, val): orig_val = DoGet(dictionary, path) if not orig_val: if isinstance(orig_val, int): val = int(val) elif isinstance(orig_val, float): val = float(val) dpu.set(dictionary, path, val) save_gap_file(dictionary) return dictionary
def resolve_references(self): """Resolve JSON pointers/references in the spec.""" # If we're currently processing, exit to avoid recursion. If we're already # done, also exit. Otherwise start processing. if self.__resolution_status in (self.__RS_PROCESSING, self.__RS_RESOLVED): return self.__resolution_status = self.__RS_PROCESSING from dpath import util as dutil changes = tuple(self._dereferencing_iterator(self.specs)) for path, value in changes: # Note that it's entirely possible for this set() to happen more than # once per path/value pair. If a definition is used twice, and references # another definition, then this second definition will be dereferenced # with both of the uses of the first. But the value will be identical, so # it makes no real changes. dutil.set(self.specs, list(path), value) self.__resolution_status = self.__RS_RESOLVED
def setval(self, path, val): # Sets/creates key in data to/with value if self.data is None: log.debug("Data is empty! Ignoring changes.") return elif dpath.set(self.data, path, val): log.debug("Changed: '%s'.", path) if self.alog: log.debug("New value is " + str(val)) else: dpath.new(self.data, path, val) log.debug("Created '%s'.", path) if self.alog: log.debug("New value is " + str(val))
def set(self, keypath: str, value: Any) -> None: '''Update value located at keypath.''' dpath.set(self, keypath, value, DpathMixin.separator)
def create_region(keycloak: KeycloakClient, vault: Vault, body, user): try: if body.get('users_group'): keycloak.group_get(body['users_group']) except KeycloakGetError as e: logger.exception(e) return problem( 400, 'Users group does not exist', f'Users group {body["users_group"]} does not exist in Keycloak, ' 'you have to create group first or use existing group.') tower = tower_model.Server.query.get(body['tower_id']) if not tower: return problem( 404, 'Not Found', f'Tower instance with ID {body["tower_id"]} does not exist') query = model.Region.query.filter(model.Region.name == body['name']) if query.count() > 0: return problem( 400, 'Bad Request', f'Region with name {body["name"]!r} already exists', ) try: owners_id = keycloak.group_create({ 'name': f'{body["name"]}-owners', }) logger.info(f'Created owners group {owners_id}') body['owner_group'] = owners_id keycloak.group_user_add(user, owners_id) logger.info(f'Added {user} to owners group {owners_id}') except KeycloakGetError as e: logger.exception(e) return problem_from_keycloak_error(e) except Exception as e: logger.exception(e) return problem(500, 'Unknown Error', f'Failed to create owner group in Keycloak, {e}') openstack_credentials = dpath.get(body, 'openstack/credentials') if not isinstance(openstack_credentials, str): openstack_credentials_path = f'{VAULT_PATH_PREFIX}/{body["name"]}/openstack' vault.write(openstack_credentials_path, openstack_credentials) dpath.set(body, 'openstack/credentials', openstack_credentials_path) satellite_credentials = dpath.get(body, 'satellite/credentials') if not isinstance(satellite_credentials, str): satellite_credentials_path = f'{VAULT_PATH_PREFIX}/{body["name"]}/satellite' vault.write(satellite_credentials_path, satellite_credentials) dpath.set(body, 'satellite/credentials', satellite_credentials_path) dns_server_key = dpath.get(body, 'dns_server/key') if not isinstance(dns_server_key, str): dns_server_key_path = f'{VAULT_PATH_PREFIX}/{body["name"]}/dns_server' vault.write(dns_server_key_path, dns_server_key) dpath.set(body, 'dns_server/key', dns_server_key_path) region = model.Region.from_dict(body) try: db.session.add(region) db.session.commit() logger.info( f'Region {region.name} (id {region.id}) created by user {user}') except sqlalchemy.exc.SQLAlchemyError: # If database transaction failed remove group in Keycloak. keycloak.group_delete(owners_id) raise return region.to_dict() | {'_href': _region_href(region)}
def edit(self, file, val): #To easily edit files or folders filer.set(self.fs, self.formatpath(file), val)