Source code for ads.jobs.builders.infrastructure.utils
#!/usr/bin/env python# -*- coding: utf-8; -*-# Copyright (c) 2021, 2022 Oracle and/or its affiliates.# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/importcopyALIAS_MAP={"file_uri":"script_uri",}
[docs]defnormalize_config(config:dict)->dict:""" Normalize property names in a configuration so that they work directly with ADS. Parameters ---------- config: dict input configuration, usually coming directly from an OCI response Returns ------- dict output configuration """normalized={}fork,vinconfig.items():k=ALIAS_MAP[k]ifkinALIAS_MAPelsekifisinstance(v,dict):normalized[k]=normalize_config(v)else:normalized[k]=vreturnnormalized
[docs]defget_value(obj,attr,default=None):"""Gets a copy of the value from a nested dictionary of an object with nested attributes. Parameters ---------- obj : An object or a dictionary attr : Attributes as a string seprated by dot(.) default : Default value to be returned if attribute is not found. Returns ------- Any: A copy of the attribute value. For dict or list, a deepcopy will be returned. """keys=attr.split(".")val=defaultforkeyinkeys:ifhasattr(obj,key):val=getattr(obj,key)elifhasattr(obj,"get"):val=obj.get(key,default)else:returndefaultobj=valreturncopy.deepcopy(val)