a f'@sXdZddlmZddlZddlZddlZddlZddlmZddl m Z m Z m Z m Z ddlmZddlmZmZmZmZgd Zd d dd Zejd ddZejd ddZdZedededdZhdZddiZdhZ dZ!dZ"dZ#dZ$e%e&Z'ddZ(ee(iZ)eefddZ*d d!Z+d"d#Z,d$d%Z-d&d'Z.d(d)Z/d*d+Z0d,d-Z1dS).a Helpers for loading and validating service configuration. You can configure services by passing a config dict directly, or by loading one from a configuration file. The following keys are required:: fingerprint key_file region tenancy user Additionally, the following keys are optional:: additional_user_agent (default "") log_requests (default False) pass_phrase (required if your key_file has a passphrase) )absolute_importN)six)ConfigFileNotFoundProfileNotFound InvalidConfigInvalidKeyFilePath)signers)AUTHENTICATION_TYPE_FIELD_NAME#get_authentication_type_from_config DELEGATION_TOKEN_FILE_FIELD_NAME^([0-9a-zA-Z-_]+[.:])([0-9a-zA-Z-_]*[.:]){3,}([0-9a-zA-Z-_]+)$z^([0-9a-f]{2}:){15}[0-9a-f]{2}$)tenancyuser fingerprint>key_fileregionrrrrZ key_contentZOCI_CONFIG_FILEZ OCI_REGIONrzFor more info about config file and how to get required information, see https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htmcCsD|t}|durtdtj|}tj|s@td|dS)NzNERROR: Please specify the location of the delegation_token_file in the config.z%Delegation token file not found at {})getr rospath expanduserisfileformat)rZdelegation_token_file_pathZ#expanded_delegation_token_file_pathr ./usr/lib/python3.9/site-packages/oci/config.py2_validate_delegation_token_with_instance_principalLs    r"cCst|}tjdd}||s,td|||vrHtd||ttt }| ||t |d|d<t D]}||vrrt d|tqrt||||S)aCreate a config dict from a file. :param file_location: Path to the config file. Defaults to ~/.oci/config and with a fallback to environment variable OCI_CONFIG_FILE, then ~/.oraclebmc/config. :param profile_name: The profile to load from the config file. Defaults to "DEFAULT" :return: A config dict that can be used to create clients. N)Z interpolationzCould not find config file at {}, please follow the instructions in the link to setup the config file https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htmz)Profile '{}' not found in config file {} rz'{}' cannot be specified in a config file for security reasons. To use this key you must add it to the config programmatically. )_get_config_path_with_fallback configparserZ ConfigParserreadrrr!CONFIG_FILE_DEBUG_INFORMATION_LOGdictrupdate_as_boolCONFIG_FILE_BLACKLISTED_KEYS ValueErrorinvalid_key_file_path_checker) file_location profile_nameexpanded_file_locationparserrkeyr r r!r_s   rc KsDd|vr|dvr |S|dvrdS|dvr,dStd|dS)N)TF)1ZyestrueZonT)0noZfalseZoffFz({!r} is not a valid alias for True/False)lowerr+r)xr r r!r)s  r)cCs6t|dkr td|dn|r2td|dS)NrzError in config: {}rz'Found the following config errors: {!r})lenr+r)r?r r r!_raise_on_errorss rIcCstj|}tjt}|tks4|tkrHtj|rHtd||Stj t r|tdt tjtj t }|Stj|r|}|Std||S)NzConfig file found at {}znNo file location specified and default file does not exist. Getting path info from the environment variable {}) rrrFALLBACK_DEFAULT_LOCATIONDEFAULT_LOCATIONrr8r9rr;rCONFIG_FILE_PATH_ENV_VAR_NAME)r-r/Z'expanded_fallback_default_file_locationr r r!r#s$    r#cCshd|vrdtj|d}tj|sdt|d||}|rFd|nd}d|||t}t|dS)Nrz at line {}rzRConfig file {} is invalid: the key_file's value '{}'{} must be a valid file path. ) rrrrrget_linenum_from_filerr&r)rr/r.Z key_file_path line_numberZ line_messagemessager r r!r,s r,cCst|d}d}d|d}t|D]\\}}|}t|dkrN|ddkrNq$||vrZd}|r$||vr$|dWdSq$Wdn1s0YdS) NrF[]rr#T)open enumeratestriprH)r1filenameZprofilefZ profile_foundZ profile_tokenrNliner r r!rMs     :rM)2__doc__Z __future__rr$rreZloggingZ oci._vendorr exceptionsrrrrZauthr utilr r r r __all__rrjoinrKrJZDEFAULT_PROFILEcompiler<r5r6r*rLr:r7r&Z getLogger__name__r8r"r4rrrAr)rIr#r,rMr r r r!sT    *