o
    w                     @   s  d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddl	Z	ddl
mZ ddlZddlZddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlZG dd dejZdZdZG dd deZe Zej Z!dZ"dZ#ej$Z%dZ&dZ'dZ(d:ddZ)dd Z*G dd deZ+d:ddZ,d d! Z-d"d# Z.G d$d% d%eZ/G d&d' d'eZ0d(e0fd)d*Z1d+ej2 Z3d,d- Z4G d.d/ d/eZ5d0d1 Z6d2d3 Z7d4d5 Z8d6d7 Z9d8d9 Z:dS );zConfig for Google Cloud CLIs.    )absolute_import)division)unicode_literalsN)Dict)
exceptions)named_configs)encoding)files)pkg_resources)	platformsc                   @      e Zd ZdZdS )ErrorzExceptions for the cli module.N__name__
__module____qualname____doc__ r   r   7/tmp/google-cloud-sdk/lib/googlecloudsdk/core/config.pyr   (       r   CLOUDSDK_CONFIGCLOUDSDK_ACTIVE_CONFIG_NAMEc                   @   sT   e Zd ZdZdZedd Zedd Zedd Zed	d
 Z	dd Z
dd ZdS )InstallationConfiga'  Loads configuration constants from the core config file.

  Attributes:
    version: str, The version of the core component.
    revision: long, A revision number from a component snapshot.  This is a long
      int but formatted as an actual date in seconds (i.e 20151009132504). It is
      *NOT* seconds since the epoch.
    user_agent: str, The base string of the user agent to use when making API
      calls.
    documentation_url: str, The URL where we can redirect people when they need
      more information.
    release_notes_url: str, The URL where we host a nice looking version of our
      release notes.
    snapshot_url: str, The url for the component manager to look at for updates.
    disable_updater: bool, True to disable the component manager for this
      installation.  We do this for distributions through another type of
      package manager like apt-get.
    disable_usage_reporting: bool, True to disable the sending of usage data by
      default.
    snapshot_schema_version: int, The version of the snapshot schema this code
      understands.
    release_channel: str, The release channel for this Cloud SDK distribution.
    config_suffix: str, A string to add to the end of the configuration
      directory name so that different release channels can have separate
      config.
  z%Y%m%d%H%M%Sc                  C   s&   t tttd} tdi | S )z|Initializes the object with values from the config file.

    Returns:
      InstallationSpecificData: The loaded data.
    zconfig.jsonNr   )jsonloadsr   Decoder
   GetResourcer   r   )datar   r   r   LoadQ   s   zInstallationConfig.Loadc                 C   s   t ttj| S )a]  Formats a given time as a revision string for a component snapshot.

    Args:
      time_struct: time.struct_time, The time you want to format.

    Returns:
      int, A revision number from a component snapshot.  This is a int but
      formatted as an actual date in seconds (i.e 20151009132504).  It is *NOT*
      seconds since the epoch.
    )inttimestrftimer   REVISION_FORMAT_STRING)time_structr   r   r   FormatRevision]   s   z!InstallationConfig.FormatRevisionc                 C   s   t t| tjS )aE  Parse the given revision into a time.struct_time.

    Args:
      revision: long, A revision number from a component snapshot.  This is a
        long int but formatted as an actual date in seconds (i.e
        20151009132504). It is *NOT* seconds since the epoch.

    Returns:
      time.struct_time, The parsed time.
    )r    strptimesix	text_typer   r"   revisionr   r   r   ParseRevisionm   s   z InstallationConfig.ParseRevisionc                 C   s   t t| S )aq  Parse the given revision into seconds since the epoch.

    Args:
      revision: long, A revision number from a component snapshot.  This is a
        long int but formatted as an actual date in seconds (i.e
        20151009132504). It is *NOT* seconds since the epoch.

    Returns:
      int, The number of seconds since the epoch that this revision represents.
    )r    mktimer   r*   r(   r   r   r   ParseRevisionAsSeconds}   s   z)InstallationConfig.ParseRevisionAsSecondsc                 C   s^   || _ || _t|| _t|| _t|| _t|| _|| _|| _|	| _	t|
| _
t|| _d S N)versionr)   str
user_agentdocumentation_urlrelease_notes_urlsnapshot_urldisable_updaterdisable_usage_reportingsnapshot_schema_versionrelease_channelconfig_suffix)selfr.   r)   r0   r1   r2   r3   r4   r5   r6   r7   r8   r   r   r   __init__   s   




zInstallationConfig.__init__c                 C   s
   | j dkS )zDetermines if this distribution is using an alternate release channel.

    Returns:
      True if this distribution is not one of the 'stable' release channels,
      False otherwise.
    rapid)r7   r9   r   r   r   IsAlternateReleaseChannel   s   
z,InstallationConfig.IsAlternateReleaseChannelN)r   r   r   r   r"   staticmethodr   r$   r*   r,   r:   r=   r   r   r   r   r   3   s    



r   z&32555940559.apps.googleusercontent.comZmssLNjJy2998hD4CTg2ejr2)openidz.https://www.googleapis.com/auth/userinfo.email.https://www.googleapis.com/auth/cloud-platform/https://www.googleapis.com/auth/appengine.admin0https://www.googleapis.com/auth/sqlservice.login'https://www.googleapis.com/auth/compute)rA   rB   rC   rD   z/https://www.googleapis.com/auth/accounts.reauthc                 C   s,   | pt  j}|rt|st|dS dS )a@  Error if the current user does not have write access to the sdk root.

  Args:
    sdk_root_override: str, The full path to the sdk root to use instead of
      using config.Paths().sdk_root.

  Raises:
    exceptions.RequiresAdminRightsError: If the sdk root is defined and the user
      does not have write access.
  N)Pathssdk_root
file_utilsHasWriteAccessInDirr   RequiresAdminRightsError)sdk_root_overriderF   r   r   r   EnsureSDKWriteAccess   s   
rK   c                   C   s    t jt jt jtjdS )zWGets the path the main gcloud entrypoint.

  Returns:
    str: The path to gcloud.py
  z	gcloud.py)ospathjoindirnamegooglecloudsdk__file__r   r   r   r   
GcloudPath   s   rR   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )
_SqlCursorz'Context manager to access sqlite store.c                 C   s   || _ d | _d | _d S r-   )_store_file_connection_cursor)r9   
store_filer   r   r   r:      s   
z_SqlCursor.__init__c                 C   s4   t j| jt jd dd| _| jd | j | _| S )NT)detect_typesisolation_levelcheck_same_threadzPRAGMA busy_timeout = 1000)sqlite3connectrT   PARSE_DECLTYPESrU   executecursorrV   r<   r   r   r   	__enter__   s   z_SqlCursor.__enter__c                 C   s   |s| j   | j   d S r-   )rU   commitclose)r9   exc_typeunused_valueunused_tracebackr   r   r   __exit__  s   
z_SqlCursor.__exit__c                 C   s   | j jS r-   )rV   rowcountr<   r   r   r   RowCount  s   z_SqlCursor.RowCountc                 G   s   | j j| S r-   )rV   r^   )r9   argsr   r   r   Execute
     z_SqlCursor.ExecuteN)	r   r   r   r   r:   r`   rf   rh   rj   r   r   r   r   rS      s    rS   c                 C   s>   | du rzt j j} W t| S  t jy   Y dS w t| S )zGets the config sqlite store for a given config name.

  Args:
    config_name: string, The configuration name to get the config store for.

  Returns:
    SqliteConfigStore, The corresponding config store, or None if no config.
  N)r   ConfigurationStoreActiveConfignameNamedConfigFileAccessError_GetSqliteStore)config_namer   r   r   GetConfigStore  s   
rr   c              	   C   s>   g d}t | |vrtd| |ddd |D dS )zValidates boolean attributes.

  Args:
    attribute_name: str, the name of the attribute
    attribute_value: str | bool, the value of the attribute to validate

  Raises:
    InvalidValueError: if value is not boolean
  )true1onyesyfalse0offnon nonez`The [{0}] value [{1}] is not valid. Possible values: [{2}]. (See http://yaml.org/type/bool.html)z, c                 S   s   g | ]}|r|nd qS )z''r   ).0xr   r   r   
<listcomp>?  s    z%_BooleanValidator.<locals>.<listcomp>N)	StringizelowerInvalidValueErrorformatrN   )attribute_nameattribute_valueaccepted_stringsr   r   r   _BooleanValidator!  s   
r   c                 C   s   t | tjr| S t| S r-   )
isinstancer&   string_typesr/   )valuer   r   r   r   D  s   r   c                   @   r   )r   zNAn exception to be raised when the set value of a config attribute is invalid.Nr   r   r   r   r   r   J  r   r   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd%ddZdd Z	d&ddZ
d'ddZdd Zd%ddZd%ddZdefddZdd Zdedefd d!Zdedefd"d#Zd$S )(SqliteConfigStorezSqlite backed config store.c                 C   s   t || _|| _| d d S )NzLCREATE TABLE IF NOT EXISTS config (config_attr TEXT PRIMARY KEY, value BLOB))rS   rV   _config_name_Execute)r9   rW   rq   r   r   r   r:   Q  s
   
zSqliteConfigStore.__init__c                 G   s4   | j }|j| W  d    S 1 sw   Y  d S r-   )rV   rj   )r9   ri   curr   r   r   r   Y  s   $zSqliteConfigStore._Executec                 C   s   d}| j 0}z|d|f }W n tjy- } ztd|t| W Y d}~nd}~ww W d   n1 s8w   Y  |du rM|rMtd| |d S |du rSdS |d S )z2Returns the attribute value from the SQLite table.Nz.SELECT value FROM config WHERE config_attr = ?z1Could not load config attribute [%s] in cache: %sz.The required config attribute [%s] is not set.r   )rV   rj   fetchoner[   OperationalErrorloggingwarningr/   )r9   config_attrrequiredloaded_configr   er   r   r   _LoadAttribute]  s8   z SqliteConfigStore._LoadAttributec                 C   s   d}| j 6}z	|d }W n tjy* } ztdt| W Y d}~nd}~ww W d   |S W d   |S 1 s>w   Y  |S )z7Returns the entire config object from the SQLite table.Nz4SELECT config_attr, value FROM config ORDER BY rowidz-Could not store config attribute in cache: %s)rV   rj   fetchallr[   r   r   r   r/   )r9   r   r   r   r   r   r   _Loadv  s,   




zSqliteConfigStore._LoadFc                 C   s,   |  ||}|du st| dkrdS |S )zGets the given attribute.

    Args:
      config_attr: string, The attribute key to get.
      required: bool, True to raise an exception if the attribute is not set.

    Returns:
      object, The value of the attribute, or None if it is not set.
    Nr~   )r   r   r   r9   r   r   
attr_valuer   r   r   Get  s   
zSqliteConfigStore.Getc                 C   s*   t |trt|d}| || dS )zSets the value for an attribute.

    Args:
      config_attr: string, the primary key of the attribute to store.
      config_value: obj, the value of the config key attribute.
    zutf-8N)r   r   r   dumpsencode_StoreAttributer9   r   config_valuer   r   r   Set  s   
zSqliteConfigStore.SetTc                 C   sF   |  ||}|rt|| |du rdS t| }|dkrdS |dv S )a:  Gets the given attribute in bool form.

    Args:
      config_attr: string, The attribute key to get.
      required: bool, True to raise an exception if the attribute is not set.
      validate: bool, True to validate the value

    Returns:
      bool, The value of the attribute, or None if it is not set.
    Nr~   )rt   rs   ru   rv   rw   )r   r   r   r   )r9   r   r   validater   attr_string_valuer   r   r   _GetBoolAttribute  s   
z#SqliteConfigStore._GetBoolAttributec                 C   s   | j |||d}|S )a  Gets the boolean value for this attribute.

    Args:
      config_attr: string, The attribute key to get.
      required: bool, True to raise an exception if the attribute is not set.
      validate: bool, Whether or not to run the fetched value through the
        validation function.

    Returns:
      bool, The boolean value for this attribute, or None if it is not set.

    Raises:
      InvalidValueError: if value is not boolean
    )r   )r   )r9   r   r   r   r   r   r   r   GetBool  s   zSqliteConfigStore.GetBoolc                 C   sD   |  ||}|du rdS zt|W S  ty!   tdj||dw )a  Gets the given attribute in integer form.

    Args:
      config_attr: string, The attribute key to get.
      required: bool, True to raise an exception if the attribute is not set.

    Returns:
      int, The integer value of the attribute, or None if it is not set.
    Nz<The attribute [{attr}] must have an integer value: [{value}])attrr   )r   r   
ValueErrorr   r   r   r   r   r   _GetIntAttribute  s   

z"SqliteConfigStore._GetIntAttributec                 C   s   |  ||}|S )zGets the integer value for this attribute.

    Args:
      config_attr: string, The attribute key to get.
      required: bool, True to raise an exception if the attribute is not set.

    Returns:
      int, The integer value for this attribute.
    )r   )r9   r   r   r   r   r   r   GetInt  s   
zSqliteConfigStore.GetIntc                 C   sJ   |  ||}|du rtdj|dzt|W S  ty$   | Y S w )a?  Gets the JSON value for this attribute.

    Args:
      config_attr: string, The attribute key to get.
      required: bool, True to raise an exception if the attribute is not set.

    Returns:
      The JSON value for this attribute or None.

    Raises:
      sqlite3.DataError: if the attribute value is None.
    Nz"The attribute [{attr}] is not set.)r   )r   r[   	DataErrorr   r   r   r   r   r   r   r   GetJSON  s   
zSqliteConfigStore.GetJSONr   c                 C   s   |  d||f dS )zStores the input config attributes to the record of config_name in the cache.

    Args:
      config_attr: string, the primary key of the attribute to store.
      config_value: obj, the value of the config key attribute.
    z5REPLACE INTO config (config_attr, value) VALUES (?,?)N)r   r   r   r   r   r     s   z!SqliteConfigStore._StoreAttributec              
   C   sv   t  j| j}ztj|rt| W dS t	d| W dS  t
y: } zt	dt| W Y d}~dS d}~ww )z'Permanently erases the config .db file.z5Failed to delete config DB: path [%s] does not exist.z&Could not delete config from cache: %sN)rE   config_db_pathr   r   rL   rM   existsremover   r   OSErrorr/   )r9   r   r   r   r   r   DeleteConfig  s   
zSqliteConfigStore.DeleteConfigreturnc                 C   s4   |  d|f | j dk rtd|| jf dS )a  Deletes a specified attribute from the config.

    Args:
      config_attr: string, the primary key of the attribute to delete.

    Returns:
      Whether the attribute was successfully deleted.

    Raises:
      sqlite3.OperationalError: if the attribute could not be deleted.
    z(DELETE FROM config WHERE config_attr = ?   z7Could not delete attribute [%s] from config store [%s].T)r   rV   rh   r[   r   r   r9   r   r   r   r   _DeleteAttribute  s   z"SqliteConfigStore._DeleteAttributec                 C   s
   |  |S )zRemoves an attribute from the config.

    Args:
      config_attr: string, the primary key of the attribute to remove.

    Returns:
      Whether the attribute was successfully removed.
    )r   r   r   r   r   Remove6  s   
	zSqliteConfigStore.RemoveN)F)T)FT)r   r   r   r   r:   r   r   r   r   r   r   r   r   r   r   r/   r   r   boolr   r   r   r   r   r   r   N  s"    




r   r   c                 C   s   t  j| }t|| }|S )z Get a sqlite-based Config Store.)rE   r   r   r   )rq   sqlite_config_fileconfig_storer   r   r   rp   B  s   
rp   gcloudc                  C   s   t tjt} | r| S tj tjjkrtj	
t dtS t tjd}|r.tj	
|tS t tjdd}tj	
|tj	jtS )zuReturns the path to the user's global config area.

  Returns:
    str: The path to the user's global config area.
  z.configAPPDATASystemDrivezC:)r   GetEncodedValuerL   environr   r   OperatingSystemCurrentWINDOWSrM   rN   rG   
GetHomeDir _CLOUDSDK_GLOBAL_CONFIG_DIR_NAMEsep)global_config_dirappdatadriver   r   r   _GetGlobalConfigDirL  s   
r   c                   @   sD  e Zd ZdZdZdZdZdd Zedd Z	ed	d
 Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zed'd( Zed)d* Zed+d, Zed-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!d9d: Z"dS );rE   zClass to encapsulate the various directory paths of the Cloud SDK.

  Attributes:
    global_config_dir: str, The path to the user's global config area.
  z.install
propertiesNc                 C   s   t  | _d S r-   )r   _global_config_dirr<   r   r   r   r:   m  rk   zPaths.__init__c                 C   s   | j S r-   )r   r<   r   r   r   r   p  s   zPaths.global_config_dirc                 C   s   t tjtttj	S )zSearches for the Cloud SDK root directory.

    Returns:
      str, The path to the root of the Cloud SDK or None if it could not be
      found.
    )
rG   FindDirectoryContainingrL   rM   rO   r   r   rQ   rE   CLOUDSDK_STATE_DIRr<   r   r   r   rF   t  s   zPaths.sdk_rootc                 C   s   | j }|rtj|dS dS )zForms a path to bin directory by using sdk_root.

    Returns:
      str, The path to the bin directory of the Cloud SDK or None if it could
      not be found.
    binN)rF   rL   rM   rN   r9   rF   r   r   r   sdk_bin_path  s   zPaths.sdk_bin_pathc                 C      t j| jdS )z6Gets the dir path that will contain all cache objects.cacherL   rM   rN   r   r<   r   r   r   	cache_dir     zPaths.cache_dirc                 C   r   )zGets the path to the file to store credentials in.

    This is generic key/value store format using sqlite.

    Returns:
      str, The path to the credential db file.
    zcredentials.dbr   r<   r   r   r   credentials_db_path     	zPaths.credentials_db_pathc                 C   r   )zGets the path to the file to store configs in.

    This is generic key/value store format using sqlite.

    Returns:
      str, The path to the config db file.
    z{}_configs.dbr   r<   r   r   r   r     r   zPaths.config_db_pathc                 C   r   )zGets the path to the file to store cached access tokens in.

    This is generic key/value store format using sqlite.

    Returns:
      str, The path to the access token db file.
    zaccess_tokens.dbr   r<   r   r   r   access_token_db_path  r   zPaths.access_token_db_pathc                 C   r   )zGets the path to the directory to put logs in for calliope commands.

    Returns:
      str, The path to the directory to put logs in.
    logsr   r<   r   r   r   logs_dir     zPaths.logs_dirc                 C   r   )zeGets the path to the file to store the client ID.

    Returns:
      str, The path to the file.
    z.metricsUUIDr   r<   r   r   r   cid_path  r   zPaths.cid_pathc                 C   r   )aF  Gets the path to the file to cache information about update checks.

    This is stored in the config directory instead of the installation state
    because if the SDK is installed as root, it will fail to persist the cache
    when you are running gcloud as a normal user.

    Returns:
      str, The path to the file.
    z.last_update_check.jsonr   r<   r   r   r   update_check_cache_path     zPaths.update_check_cache_pathc                 C   r   )aI  Gets the path to the file to cache information about survey prompting.

    This is stored in the config directory instead of the installation state
    because if the SDK is installed as root, it will fail to persist the cache
    when you are running gcloud as a normal user.

    Returns:
      str, The path to the file.
    z.last_survey_prompt.yamlr   r<   r   r   r   survey_prompting_cache_path  r   z!Paths.survey_prompting_cache_pathc                 C   r   )aI  Gets the path to the file to cache information about opt-in prompting.

    This is stored in the config directory instead of the installation state
    because if the SDK is installed as root, it will fail to persist the cache
    when you are running gcloud as a normal user.

    Returns:
      str, The path to the file.
    z.last_opt_in_prompt.yamlr   r<   r   r   r   opt_in_prompting_cache_path  r   z!Paths.opt_in_prompting_cache_pathc                 C   s   | j }|sdS tj|| jS )zkGets the path to the installation-wide properties file.

    Returns:
      str, The path to the file.
    N)rF   rL   rM   rN   CLOUDSDK_PROPERTIES_NAMEr   r   r   r   installation_properties_path  s   z"Paths.installation_properties_pathc                 C   s   t j| j| jS )zyGets the path to the properties file in the user's global config dir.

    Returns:
      str, The path to the file.
    )rL   rM   rN   r   r   r<   r   r   r   user_properties_path  s   zPaths.user_properties_pathc                 C   r   )zGets the path to the file pointing at the user's active named config.

    This is the file that stores the name of the user's active named config,
    not the path to the configuration file itself.

    Returns:
      str, The path to the file.
    active_configr   r<   r   r   r   named_config_activator_path  s   
z!Paths.named_config_activator_pathc                 C   r   )zvGets the path to the directory that stores the named configs.

    Returns:
      str, The path to the directory.
    configurationsr   r<   r   r   r   named_config_directory  r   zPaths.named_config_directoryc                 C   r   )a  Gets the path to the config sentinel.

    The sentinel is a file that we touch any time there is a change to config.
    External tools can check this file to see if they need to re-query gcloud's
    credential/config helper to get updated configuration information. Nothing
    is ever written to this file, it's timestamp indicates the last time config
    was changed.

    This does not take into account config changes made through environment
    variables as they are transient by nature. There is also the edge case of
    when a user updated installation config. That user's sentinel will be
    updated but other will not be.

    Returns:
      str, The path to the sentinel file.
    config_sentinelr   r<   r   r   r   config_sentinel_file  s   zPaths.config_sentinel_filec                 C   r   )ag  Gets the path to the sentinel used to check for PPK encoding validity.

    The presence of this file is simply used to indicate whether or not we've
    correctly encoded the PPK used for ssh on Windows (re-encoding may be
    necessary in order to fix a bug in an older version of winkeygen.exe).

    Returns:
      str, The path to the sentinel file.
    z.valid_ppk_sentinelr   r<   r   r   r   valid_ppk_sentinel_file(  r   zPaths.valid_ppk_sentinel_filec                 C   r   )z*Absolute path of the container config dir.
kubernetesr   r<   r   r   r   container_config_path5  r   zPaths.container_config_pathc                 C   r   )z%Absolute path of the virtual env dir.virtenvr   r<   r   r   r   virtualenv_dir:  r   zPaths.virtualenv_dirc                 C   sx   |sd}| dd}tj tjjkr3| ds/| ds/| ds/| dr3d| }tj	| j
d	|S )
zGets the path to store legacy credentials in.

    Args:
      account: str, Email account tied to the authorizing credentials.

    Returns:
      str, The path to the credentials file.
    default:r}   zCON.zPRN.zAUX.zNUL..legacy_credentials)replacer   r   r   r   upper
startswithrL   rM   rN   r   r9   accountr   r   r   LegacyCredentialsDir?  s   		zPaths.LegacyCredentialsDirc                 C      t j| |dS )zGets the path to store legacy bq credentials in.

    Args:
      account: str, Email account tied to the authorizing credentials.

    Returns:
      str, The path to the bq credentials file.
    zsinglestore_bq.jsonrL   rM   rN   r   r   r   r   r   LegacyCredentialsBqPath^  s   	
zPaths.LegacyCredentialsBqPathc                 C   r   )zGets the path to store legacy gsutil credentials in.

    Args:
      account: str, Email account tied to the authorizing credentials.

    Returns:
      str, The path to the gsutil credentials file.
    z.botor   r   r   r   r   LegacyCredentialsGSUtilPathk     	z!Paths.LegacyCredentialsGSUtilPathc                 C   r   )zGets the path to store legacy key file in.

    Args:
      account: str, Email account tied to the authorizing credentials.

    Returns:
      str, The path to the key file.
    zprivate_key.p12r   r   r   r   r   LegacyCredentialsP12KeyPathv  r   z!Paths.LegacyCredentialsP12KeyPathc                 C   r   )zGets the file path to store application default credentials in.

    Args:
      account: str, Email account tied to the authorizing credentials.

    Returns:
      str, The path to the file.
    zadc.jsonr   r   r   r   r   LegacyCredentialsAdcPath  r   zPaths.LegacyCredentialsAdcPathc                 C   r   )zuGet the path to cache whether or not we're on a GCE machine.

    Returns:
      str, The path to the GCE cache.
    gcer   r<   r   r   r   GCECachePath  s   zPaths.GCECachePath)#r   r   r   r   r   r   r   r:   propertyr   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   rE   b  sh    























rE   c                 C   s,   t  j}ttj|  t| | |S r-   )	uuiduuid4hexrG   MakeDirrL   rM   rO   WriteFileContents	uuid_pathcidr   r   r   _GenerateCID  s   
r  c                  C   sB   t  j} zt| }|r|W S W t| S  tjy    Y t| S w )zyGets the client id from the config file, or generates a new one.

  Returns:
    str, The hex string of the client id.
  )rE   r   rG   ReadFileContentsr   r  r	  r   r   r   GetCID  s   
r  c                  C   s"   ddl m}  tj|  d}|S )z{Gets the certificate_config.json default file path.

  Returns:
    str, The default path to the config file.
    exist.
  r   
_cloud_sdkzcertificate_config.json)google.authr  rL   rM   rN   get_config_path)r  config_pathr   r   r   CertConfigDefaultFilePath  s
   r  c                  C   s   ddl m}  |  S )zYGets the ADC default file path.

  Returns:
    str, The path to the default ADC file.
  r   r  )r  r  (get_application_default_credentials_pathr  r   r   r   ADCFilePath  s   r  c                  C   s   ddl m}  ttj| jdS )zrGets the value of the ADC environment variable.

  Returns:
    str, The value of the env var or None if unset.
  r   environment_varsN)r  r  r   r   rL   r   CREDENTIALSr  r   r   r   ADCEnvVariable  s   
r  r-   );r   
__future__r   r   r   r   r   rL   r[   r    typingr   r  rP   googlecloudsdk.corer   "googlecloudsdk.core.configurationsr   googlecloudsdk.core.utilr   r	   rG   r
   r   r&   r   r   r   objectr   r   INSTALLATION_CONFIGr.   CLOUD_SDK_VERSIONCLOUDSDK_CLIENT_IDCLOUDSDK_CLIENT_NOTSOSECRETr0   CLOUDSDK_USER_AGENTCLOUDSDK_SCOPES CLOUDSDK_EXTERNAL_ACCOUNT_SCOPESREAUTH_SCOPErK   rR   rS   rr   r   r   r   r   rp   r8   r   r   rE   r  r  r  r  r  r   r   r   r   <module>   sf   


"# u
  5