
                             S r SSKrSSKrSSKrSSKJr  SSKJr  SSKrSSK	J
r
  SqS\R                  R                  S\S\\\4   S	\4S
 jrS\R                  R                  SS4S jrS\\\\\4   4   4S jrg)z0BQ CLI helper functions for gcloud interactions.    N)Dict)flags)gcloud_runnerflag_values	flag_namegcloud_config_sectiongcloud_property_namec                 J   U(       d  gX2;  a  gX   nX#   n[         R                  " SU5        UR                  (       a0  [         R                  " SUU5        [        R
                  " XU5        gUR                  U:w  a%  [         R                  " SUUR                  UU5        gg)zCUpdates flag if it's using the default and the gcloud value exists.NzGcloud config exists for %szSThe `%s` flag is using a default value and a value is set in gcloud, using that: %szExecuting with different configuration than in gcloud.The flag "%s" has become set to "%s" but gcloud sets "%s" as "%s".To update the gcloud value, start from `gcloud config list`.)loggingdebugusing_default_valueinfobq_utils
UpdateFlagvaluewarning)r   r   r   r	   flaggcloud_values         $platform/bq/utils/bq_gcloud_utils.py5_use_gcloud_value_if_exists_and_flag_is_default_valuer      s     

6
		$&<,	---/CD	LL		 =zz\!OO	G 	

 "    returnc                    [        5       nUR                  S0 5      nUR                  S0 5      nUR                  S0 5      nUR                  S0 5      n[        U SUSS9  [        U SUS	S9  [        U S
US
S9  [        U SUSS9  [        U SUSS9  [        U SUSS9  U(       a  U(       d  g US   nUS
   nU(       a  U(       a  U S   R                  (       a  U S   R                  (       d  [
        R                  " S5        g[
        R                  " S5         [        U5       nUR                  5       R                  5       n	SSS5        [        R                  " U SW	5        [        R                  " U SS5        ggg! [         a     gf = f! , (       d  f       NQ= f! [         a    [
        R                  " S5         gf = f)zHProcesses the user configs from gcloud and sets flag values accordingly.corebillingauthapi_endpoint_overrides
project_idproject)r   r   r   r	   quota_project_idquota_projectuniverse_domainrequest_reasonapibigquerybigquery_discovery_api_keyapi_keyNaccess_token_fileoauth_access_tokenuse_google_authzpUsers gcloud config file and bigqueryrc file have incompatible configurations. Defaulting to the bigqueryrc filezNUsing the gcloud configuration to get TPC authorisation from access_token_fileTzACould not open `access_token_file` file, ignoring gcloud settings)load_configgetr   KeyErrorr   r   r   r   openreadstripr   r   IOError)
r   configscore_configbilling_configauth_configr   r(   r"   
token_filetokens
             r   process_configr8   5   s   M'FB'+;;y"-.FB'+";;'?D7'$	 8"**	 8!',	 8 '+	 82%	 8,'$	 
K
#$78!"34O ?,-AA,-AAoo? LL		@!"j!'') # +';UC+'8$?1 + 
 
& #" oo
Ms<   +
E> F $FF >
F
F
FF  GGc                  2   [         b  [        R                  " S5        [         $ 0 q  [        R                  " / SQ[
        R                  S9n U R                  5       u  pU(       a  [        R                  " SU5        [         $  [        R                  " U5      q [         $ ! [         a0  n[        R                  " S[        U5      5        [         s SnA$ SnAff = f! [        R                   a&  n[        R                  " SU5         SnA[         $ SnAff = f)zWLoads the user configs from gcloud, cache the result, and returns them as a dictionary.NzUsing cached gcloud config)configlistz--format=json)stderrz9Continuing with empty gcloud config data due to error: %szIContinuing with empty gcloud config data due to invalid config format: %s)_config_cacher   r   r   run_gcloud_command
subprocessSTDOUTcommunicateFileNotFoundErrorr   strjsonloadsJSONDecodeError)processouterres       r   r+   r+      s     LL-.-
..+J4E4EG ""$HC 	OOCS JJsOM 
+ 
 OOCSV  
		 OO		 
 
s5   7B C 
C)%CCCD0DD)__doc__rD   r   r?   typingr   abslr   r   gcloud_wrapperr   r=   _flagvalues
FlagValuesrC   r   r8   r+    r   r   <module>rR      s    6       ( ""--  S> 	DS@ 1 1 < < S@ S@l#T#tCH~-. #r   