
                             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                    U R                   (       d  [        R                  " S5        g[        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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 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.z@'use_gcloud_config' is false, skipping gcloud config processing.Ncorebillingcontext_aware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_keymtlsuse_client_certificate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)use_gcloud_configr   r   load_configgetr   KeyErrorr   r   openreadstripr   r   IOError)r   configscore_configbilling_configr   auth_configr   r+   r#   
token_filetokens              r   process_configr<   5   s   		&	&LLJ M'FB'+;;y"-.++or2-FB'+";;'?D7'$	 8"**	 8!',	 8 '+	 82%	 8,'$	 8)3	 
K
#$78!"34O ?,-AA,-AAoo? LL		@!"j!'') # +';UC+'8$?1 + 
 
& #" oo
Ms<   1
G G% *G	G% 
GG
G"G% % HHc                     [         b  [        R                  " S5        [         $ 0 q  [        R                  " / SQ[
        R                  S9n U R                  5       u  pU(       a  [        R                  " SU5        U R                  S:w  aa  [        R                  " SU R                  U(       a  UR                  5       OS	U(       a  UR                  5       5        [         $ S	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=jsonz--quiet)stderrz9Continuing with empty gcloud config data due to error: %sz*Stderr message from gcloud config list: %sr   zUContinuing with empty gcloud config data due to returncode %s. Stdout: %s, Stderr: %s zIContinuing with empty gcloud config data due to invalid config format: %s)_config_cacher   r   r   run_gcloud_command
subprocessPIPEcommunicateFileNotFoundErrorr   str
returncoder4   jsonloadsJSONDecodeError)processouterres       r   r/   r/      sA    LL-.-
..6zG ""$HC 	OO@#F1OO					  !# JJsOM 
9 
 OOCSV , 
		 OO		 
 
s5   7D
 .E 

E%D?9E?EFE<<F)__doc__rJ   r   rD   typingr   abslr   r   gcloud_wrapperr   rB   _flagvalues
FlagValuesrH   r   r<   r/    r   r   <module>rX      s    6       ( ""--  S> 	Da@ 1 1 < < a@ a@H*T#tCH~-. *r   