3 L(Yw@sxdZddlZddlZddlZddlZddlmZddlZdZ dZ dZ dZ dZ dZdZd dZddZddZddZdS)z9Helpers for reading the Google Cloud SDK's configuration.N)environment_varsz*https://accounts.google.com/o/oauth2/tokenZgcloudAPPDATAz$application_default_credentials.jsonz gcloud.cmdconfig config-helper--formatjsoncCsy tjtjStk r YnXtjdkrDtjjtjjddt Sytjjtjt t Stk rtjj dd}tjj|dt SXdS)zReturns the absolute path the the Cloud SDK's configuration directory. Returns: str: The Cloud SDK config path. nt~z.configZ SystemDrivezC:\N) osenvironrZCLOUD_SDK_CONFIG_DIRKeyErrornamepathjoin expanduser_CONFIG_DIRECTORY_WINDOWS_CONFIG_ROOT_ENV_VARget)driverE/private/tmp/pip-build-nl73fm5q/google-auth/google/auth/_cloud_sdk.pyget_config_path+s  rcCst}tjj|tS)zGets the path to the application default credentials file. The path may or may not exist. Returns: str: The full path to application default credentials. )rr rr_CREDENTIALS_FILENAME)Z config_pathrrr(get_application_default_credentials_pathIsrcCsTtd}|jtj|}|r0tdjdj|tjj j d|dt |d|ddS) aLoads an authorized user credential. Args: info (Mapping[str, str]): The loaded file's data. Returns: google.oauth2.credentials.Credentials: The constructed credentials. Raises: ValueError: if the info is in the wrong format or missing data. refresh_token client_id client_secretzGAuthorized user info was not in the expected format, missing fields {}.z, N)rZ token_urirr)rrr) set differencesixiterkeys ValueErrorformatrgoogleZoauth2 credentialsZ Credentials_GOOGLE_OAUTH2_TOKEN_ENDPOINT)infoZ keys_neededmissingrrr load_authorized_user_credentialsUs r)cCstjdkrt}nt}ytj|fttjd}Wntjt t fk rJdSXyt j |j d}Wntk rtdSXy|ddddStk rdSXdS) zaGets the project ID from the Cloud SDK. Returns: Optional[str]: The project ID. r)stderrNzutf-8 configurationZ propertiescoreproject)r r_CLOUD_SDK_WINDOWS_COMMAND_CLOUD_SDK_POSIX_COMMAND subprocess check_output_CLOUD_SDK_CONFIG_COMMANDSTDOUTCalledProcessErrorOSErrorIOErrorrloadsdecoder"r )commandoutputr+rrrget_project_idqs" r;)rrrr)__doc__rr r0r Z google.authrZgoogle.oauth2.credentialsr$r&rrrr/r.r2rrr)r;rrrrs"