def filter_response_rest(response, projection, fields): if fields is not None: fields.replace(" ", "") fields.replace("/", ".") fields = parse_fields(fields) deleted_keys = set() for key in nested_key(response): simplfied_key = remove_index(key) if projection == "noAcl": if simplfied_key == "owner" or simplfied_key == "items.owner": deleted_keys.add(key) if simplfied_key == "acl" or simplfied_key == "items.acl": deleted_keys.add(key) if ( simplfied_key == "defaultObjectAcl" or simplfied_key == "items.defaultObjectAcl" ): deleted_keys.add(key) if fields is not None: if simplfied_key not in fields: deleted_keys.add(key) proxy = scalpl.Cut(response) for key in deleted_keys: del proxy[key] return proxy.data
def __postprocess_rest(cls, data): proxy = scalpl.Cut(data) keys = utils.common.nested_key(data) for key in keys: if key.endswith("createdBefore"): proxy[key] = proxy[key].replace("T00:00:00Z", "") proxy["kind"] = "storage#bucket" return proxy.data
def __preprocess_rest(cls, data): proxy = scalpl.Cut(data) keys = utils.common.nested_key(data) proxy.pop("iamConfiguration.bucketPolicyOnly", None) for key in keys: if key.endswith("createdBefore"): proxy[key] = proxy[key] + "T00:00:00Z" return proxy.data
def __preprocess_rest(cls, data): proxy = scalpl.Cut(data) keys = utils.common.nested_key(data) proxy.pop("iamConfiguration.bucketPolicyOnly", False) for key in keys: if key.endswith("createdBefore"): proxy[key] = proxy[key] + "T00:00:00Z" rest_only = {} for field in Bucket.rest_only_fields: if field in proxy: rest_only[field] = proxy.pop(field) return proxy.data, rest_only
def get_issue(self, issue_key): try: ji = self.jira.issue(issue_key) except jira.exceptions.JIRAError as e: return {'error': str(e.text)}, False, e.status_code j_from = scalpl.Cut(ji.raw) j_to = scalpl.Cut({}) ar = [f['name'] for f in j_from['fields.fixVersions']] j_from.update({'fields.fixVersionsStr': ", ".join(ar)}) ar = [f['name'] for f in j_from['fields.components']] j_from.update({'fields.componentsStr': ", ".join(ar)}) for field in ['key', 'fields.summary', 'fields.created', 'fields.priority.name', 'fields.priority.iconUrl', 'fields.issuetype.name', 'fields.issuetype.iconUrl', 'fields.fixVersionsStr', 'fields.status.name', 'fields.assignee.name', 'fields.componentsStr', 'fields.resolution', 'fields.resolutiondate']: tokens = field.split('.') for n in range(0, len(tokens)): token = ".".join(tokens[0:n]) if token and token not in j_to: j_to.update({token: {}}) j_to.update({field: j_from[field]}) return {'results': j_to.data}, False, http.client.OK
def __preprocess_rest(cls, data): proxy = scalpl.Cut(data) keys = utils.common.nested_key(data) if "iamConfiguration.uniformBucketLevelAccess.enabled" not in proxy: if "iamConfiguration.bucketPolicyOnly" in proxy: proxy[ "iamConfiguration.uniformBucketLevelAccess.enabled"] = proxy[ "iamConfiguration.bucketPolicyOnly"] else: proxy.pop("iamConfiguration.bucketPolicyOnly", False) for key in keys: if key.endswith("createdBefore"): proxy[key] = proxy[key] + "T00:00:00Z" return proxy.data
def create_leaf(data, setter): try: leaf = safe_set(data, setter["path"], setter["value"]) except NoChild as error: parent = error.parent parent_path = error.parent_path child_path = error.child_path log.debug( "No Child for \n\tparent:{0}\n\tat path:{1}\n\tcan't establish child path:{2}" .format(str(parent), str(parent_path), str(child_path))) # create child branch: child_branch = {} child_branch_key = parent_path[-1] child = child_branch for depth, key in enumerate(child_path[1:]): if depth < len(child_path) - 2: child[key] = {} child = child[key] else: child[key] = setter['value'] log.debug("Generated Child branch: {0}".format(str(child_branch))) if isinstance(parent, list): # we don't seem to reach this block log.debug( "Parent is a list: parent:{0} parent_path:{1} child_path:{2}". format(str(parent), str(parent_path), str(child_path))) dict_replacement = {i: elem for i, elem in enumerate(parent)} log.debug("Replacement dict: {0}".format(str(dict_replacement))) safe_set(data, parent_path, dict_replacement) log.debug("Found list, converted to dict: {0}".format( str(dict_replacement))) processor = scalpl.Cut(data) log.debug("New state: {0}".format( str(processor[join_path(parent_path)]))) # processor.update({ join_path(parent_path+[child_branch_key]): child_branch}) elif isinstance(parent, dict): ## why would that even trigger log.debug( "Parent is a dict: parent:{0} parent_path:{1} child_path:{2}". format(str(parent), str(parent_path), str(child_path))) # raise Exception("Unknown exception") pass else: log.debug( "Parent a scalar: parent:{0} parent_path:{1} child_path:{2}". format(str(parent), str(parent_path), str(child_path))) safe_set(data, parent_path, {}) log.debug("Before safe_set: {0}".format(str(data))) safe_set(data, parent_path + [child_branch_key], child_branch) log.debug("After safe_set: {0}".format(str(data)))
def __postprocess_rest(cls, data, rest_only): proxy = scalpl.Cut(data) keys = utils.common.nested_key(data) for key in keys: if key.endswith("createdBefore"): proxy[key] = proxy[key].replace("T00:00:00Z", "") proxy["kind"] = "storage#bucket" if "acl" in data: for entry in data["acl"]: entry["kind"] = "storage#bucketAccessControl" if "defaultObjectAcl" in data: for entry in data["defaultObjectAcl"]: entry["kind"] = "storage#objectAccessControl" proxy.update(rest_only) return proxy.data
def update_leaf(data, setter): try: leaf = safe_merge(data, setter["path"], setter["value"]) except NoChild as error: parent = error.parent parent_path = error.parent_path child_path = error.child_path log.debug( "No Child for \n\tparent:{0}\n\tat path:{1}\n\tcan't establish child path:{2}" .format(str(parent), str(parent_path), str(child_path))) # new_dict=addict.Dict() # create child branch: child_branch = {} child_branch_key = child_path[0] child = child_branch for depth, key in enumerate(child_path): if depth < len(child_path) - 1: child[key] = {} child = child[key] else: child[key] = setter['value'] log.debug("Generated Child branch: {0}".format(str(child_branch))) if isinstance(parent, list): log.debug( "Parent is a list: parent:{0} parent_path:{1} child_path:{2}". format(str(parent), str(parent_path), str(child_path))) if isinstance(child_branch_key, int): parent.append(child_branch[child_branch_key]) ### dict_replacement={ i: elem for i,elem in enumerate(parent) } ### safe_set(data, parent_path, dict_replacement) ### print("Found list, converted to dict: {0}".format(str(dict_replacement))) ### processor=scalpl.Cut(data) ### print("New state: {0}".format(str(processor[join_path(parent_path)]))) ### # processor.update({ join_path(parent_path+[child_branch_key]): child_branch}) elif isinstance(parent, dict): ## why would that even trigger log.debug( "Parent is a dict: parent:{0} parent_path:{1} child_path:{2}". format(str(parent), str(parent_path), str(child_path))) # raise Exception("Unknown exception") processor = scalpl.Cut(parent) log.debug("Scalped parent: {0}".format(str(processor))) processor.update({parent_path[-1]: child_branch}) else: log.debug("Or else...") safe_set(data, parent_path, {}) safe_set(data, parent_path, child_branch)
def process_data(data, setters, mergers): processor = scalpl.Cut(data) for setter in setters: try: del processor[setter['jmespath']] except (KeyError, IndexError) as error: # it's not there anyway pass try: processor.update({setter['jmespath']: setter['value']}) except (KeyError, IndexError): create_leaf(data, setter) for merger in mergers: try: update_leaf(data, merger) # processor.update({merger['jmespath']: merger['value']}) except (KeyError, IndexError): # update_leaf(data, merger) pass
def filter_response_rest(response, projection, fields): if fields is not None: fields = parse_fields(fields) deleted_keys = set() for key in nested_key(response): simplfied_key = remove_index(key) maybe_delete = True if projection == "noAcl": maybe_delete = False if simplfied_key.startswith("owner"): deleted_keys.add("owner") elif simplfied_key.startswith("items.owner"): deleted_keys.add(key[0 : key.find("owner") + len("owner")]) elif simplfied_key.startswith("acl"): deleted_keys.add("acl") elif simplfied_key.startswith("items.acl"): deleted_keys.add(key[0 : key.find("acl") + len("acl")]) elif simplfied_key.startswith("defaultObjectAcl"): deleted_keys.add("defaultObjectAcl") elif simplfied_key.startswith("items.defaultObjectAcl"): deleted_keys.add( key[0 : key.find("defaultObjectAcl") + len("defaultObjectAcl")] ) else: maybe_delete = True if fields is not None: if maybe_delete: for field in fields: if field != "" and simplfied_key.startswith(field): maybe_delete = False break if maybe_delete: deleted_keys.add(key) proxy = scalpl.Cut(response) for key in deleted_keys: del proxy[key] return proxy.data