
    I\                        S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJr	  SSKJ
r
  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!r!\RD                  \RF                  " \RH                  RJ                  \RH                  RL                  \RH                  RN                  \RH                  RP                  5       " S S\RR                  5      5       5       r*S r+g)z&Workflow to set up gcloud environment.    )absolute_import)division)unicode_literalsN)base)
exceptions)
usage_text)	init_utilconfig)execution_utils)log)
properties)yaml)named_configs)
console_io)store)network_diagnostics)resource_projector)files)	platformsc                       \ rS rSrSr\R                  r\S 5       r	S r
S r SS jrS rSS	 jrS
 rS rS rS rS rSS jrSrg)Init,   a
  Initialize or reinitialize gcloud.

{command} launches an interactive Getting Started workflow for the gcloud
command-line tool.
It performs the following setup steps:

- Authorizes gcloud and other SDK tools to access Google Cloud using
  your user account credentials, or from an account of your choosing whose
  credentials are already available.
- Sets up a new or existing configuration.
- Sets properties in that configuration, including the current project and
  optionally, the default Google Compute Engine region and zone you'd like to
  use.

{command} can be used for initial setup of gcloud and to create new or
reinitialize gcloud configurations. More information about configurations can
be found by running `gcloud topic configurations`.

Properties set by {command} are local and persistent, and are not affected by
remote changes to the project. For example, the default Compute Engine zone in
your configuration remains stable, even if you or another user changes the
project-level default zone in the Cloud Platform Console.

To sync the configuration, re-run `{command}`.

## EXAMPLES

To launch an interactive Getting Started workflow, run:

  $ {command}

To launch an interactive Getting Started workflow without diagnostics, run:

  $ {command} --skip-diagnostics

c                     U R                  SSSSS9  U R                  SSSS	S
9  U R                  SSS	S
9  U R                  SS	SS9  U R                  S[        SSS9  g )Nobsolete_project_arg?TzTHIS ARGUMENT NEEDS HELP TEXT.)nargshiddenhelpz--console-only--no-launch-browserzPrevent the command from launching a browser for authorization. Use this flag if you are on a machine that does not have a browser and you cannot install the gcloud CLI on another machine with a browser.
store_true)r   action--no-browserzPrevent the command from launching a browser for authorization. Use this flag if you are on a machine that does not have a browser but you can install the gcloud CLI on another machine with a browser.z--skip-diagnosticszDo not run diagnostics.)r"   r   z--universe-domainzLIf set, creates the configuration with the specified [core/universe_domain].)typer   r   )add_argumentstr)parsers    lib/surface/init.pyArgs	Init.Args[   s    
-	  /
 <
   
 <
   	 &  
 '      c                    UR                   (       a!  [        R                  " UR                   S5      e[        R                  R                  S5        [        R                  R                  R                  R                  5       (       a  [        R                  " SS5      eU R                  5       nU(       d  g[        R                  R                  SR                  U5      5        UR                  (       d  [        R                  R                  S5        [        R                  R                  S5        [        R                  " 5       R!                  5       nU(       dZ  ["        R$                  " S	S
SS9(       d?  [        R                  R                  S5        [        R                  R                  S5        g[&        R(                  " 5          U R+                  U5        U R-                  U5        SSS5        g! , (       d  f       g= f)z7Allows user to select configuration, and initialize it.z`gcloud init` has changed and no longer takes a PROJECT argument. Please use `gcloud source repos clone` to clone this project's source repositories.zJWelcome! This command will take you through the configuration of gcloud.

zdisable_prompts/--quietz5gcloud init command cannot run with disabled prompts.Nz3Your current configuration has been set to: [{0}]

z@You can skip diagnostics next time by using the following flag:
z"  gcloud init --skip-diagnostics

zNetwork errors detected.z!Would you like to continue anywayF)messageprompt_stringdefaultz7You can re-run diagnostics with the following command:
z!  gcloud info --run-diagnostics

)r   c_excInvalidArgumentExceptionr   statuswriter   VALUEScoredisable_promptsGetBool_PickConfigurationformatskip_diagnosticsr   NetworkDiagnostic	RunChecksr   PromptContinuer   WithLegacyQuota_PickProperties
_Summarize)selfargsconfiguration_namenetwork_passeds       r(   RunInit.Run   s     **

#
#,- - JJ 8 9 --5577**
#
AC C 002JJLf/02   	jj + ,	jj=>*<<>HHJn((.= **

 ( )
**

@
A
 
			
4 
oo() 
 		s   #G::
Hc                 <   UR                   (       aC  [        R                  " [        R                  R                  R                   UR                   5        UR                   (       + =(       d;    UR                   [        R                  R                  R                   R
                  :H  nU R                  UR                  UR                  UUR                  S9(       d  g U R                  UR                  S9(       d  g U R                  5         U R                  5         g )Npreselected)universe_domainr   PersistPropertyr4   r5   r/   _PickAccountconsole_only
no_browseraccount_PickProjectproject_PickDefaultRegionAndZone_CreateBotoConfig)rA   rB   is_default_universes      r(   r?   Init._PickProperties   s      



 
 
0
0$2F2FH     	O
 1 1 6 6 F F N NN  4??,?LL  " 6""$r+   Nc                    Sn[         R                  " 5       nU(       a  U(       aG  UnXv;  a?  [        R                  R	                  SR                  USR                  U5      5      5        gO/ nU(       a  UR                  S5        UR                  S5        [        R                  " Xh-   SSS9n	U	c  gU	[        U5      :  a  Xi   nOnU(       a  U	[        U5      :X  a  S	nOUgU(       a/  [        R                  R	                  S
R                  U5      5        g[        R                  " SS9n
U
(       d  gS	nU(       a7  U(       a  S/nOU(       a  S/nO/ nU R                  SS/SS/U-   SS9(       d  gO9[        R                  " [        R                  R                   R"                  W5        [        R                  R	                  SR                  [        R                  R                   R"                  R%                  5       5      5        g	)a  Checks if current credentials are valid, if not runs auth login.

Args:
  console_only: bool, True if the auth flow shouldn't use the browser
  no_browser: bool, True if the auth flow shouldn't use the browser and
    should ask another gcloud installation to help with the browser flow.
  is_default_universe: bool, True if selected universe is the default
  preselected: str, disable prompts and use this value if not None

Returns:
  bool, True if valid credentials are setup.
Fz7
[{0}] is not one of your credentialed accounts [{1}].
,z!Sign in with a new Google AccountzSkip this stepzChoose the account you want to use for this configuration.
To use a federated user account, exit this command and sign in to the gcloud CLI with your login configuration file, then run this command again.

Select an account:N)r-   r.   Tz&
[{0}] is not a credentialed account.
z7You must sign in to continue. Would you like to sign inr.   r    r#   authloginz--forcez--brief)disable_user_outputzYou are signed in as: [{0}].

)c_storeAvailableAccountsr   r2   r3   r9   joinappendr   PromptChoicelenr=   _RunCmdr   rK   r4   r5   rO   Get)rA   rM   rN   rT   rI   new_credentialsaccountsrO   additional_optionsidxanswerbrowser_argss               r(   rL   Init._PickAccount   s    O((*H	"
**

 &&,fWchhx6H&IK #  

#
#$G
H!!"23 %%))   ;XM' SCM%9 /		jj
4
;
;K
H  ((Gf
 o 
-.&'\\67+$i0<?.3  5 5   !2!2!7!7!?!?IJJ7fZ..33;;??ABDr+   c                 4   [         R                  R                  5       n[         R                  R                  5       nU(       a  UR                  U;  aE  [         R                  R                  UR                  5        UR                  5         UR                  $ [        U5      S:X  aX  UR                  [         R                  S5      nU(       a1  UR                  5       (       d  UR                  5         UR                  $ / n[        R                  R                  SR                  UR                  5      5        [        R                  R                  5         [        R                  R                  [         R"                  " [$        R&                  R)                  5       5      5        [        R*                  R                  5         [        R                  R                  S5        [        R                  R                  5         UR-                  SR                  UR                  5      5        UR-                  S5        [/        [0        R2                  " U5      5       VVs/ s H  u  pVUR4                  (       a  M  UPM     nnnUR7                  S U 5       5        [8        R:                  " USS	9nUc  gUS
:X  a  U R=                  5         UR                  $ US:X  a  U R?                  5       $ XxS-
     n	[         R                  RA                  U	5        U	$ s  snnf )zhAllows user to re-initialize, create or pick new configuration.

Returns:
  Configuration name or None.
   Nz4Settings from your current configuration [{0}] are:

z9Re-initialize this configuration [{0}] with new settings zCreate a new configurationc              3   D   #    U  H  nS R                  U5      v   M     g7f)z9Switch to and re-initialize existing configuration: [{0}]N)r9   ).0names     r(   	<genexpr>*Init._PickConfiguration.<locals>.<genexpr>K  s&      /-t3396$<@-s    zPick configuration to use:)r-   r      )!r   ConfigurationStore
AllConfigsActiveConfigrp   CreateConfigActivatera   getDEFAULT_CONFIG_NAMEGetPropertiesr   r2   r3   r9   flushr   dumpr   r4   	AllValuesoutr_   sortedsix	iteritems	is_activeextendr   r`   _CleanCurrentConfiguration_CreateConfigurationActivateConfig)
rA   configsactive_configdefault_configchoicesrp   cconfig_choicesrg   config_names
             r(   r8   Init._PickConfiguration  sL    ..99;G!44AACMm((7 &&33M4F4FG
 7|q{{=#D#DdKn	 < < > >!"""GJJLf]//02JJJJTYYz00::<=>GGMMOJJTJJNNCJJ	 ! NN/0*0w1G*H **Hwt[[ *HN *NN /-/ / 
!
!'3O
PC
{
ax
%%'
ax&&(( q)K$$33K@*s   L:Lc                    [         R                  " US9nUbg  [        R                  " [        R                  R
                  R                  U5        [        R                  R                  SR                  U5      5        U$ )zAllows user to select a project.

Args:
  preselected: str, use this value if not None

Returns:
  str, project_id or None if was not selected.
rH   z.Your current project has been set to: [{0}].

)r	   PickProjectr   rK   r4   r5   rQ   r   r2   r3   r9   )rA   rI   
project_ids      r(   rP   Init._PickProjectZ  sa     &&;?J  !2!2!7!7!?!?L	jjIz*,r+   c                 t  ^   T R                  / SQS/S9nSnSnUba  [
        R                  " U5      nUR                  S0 5      nUR                  S/ 5       H#  nUS   S	:X  a  US
   nM  US   S:X  d  M  US
   nM%     U(       d  [        R                  " SS9nU(       d  gU 4S jnU(       a  T R                  / SQU/5      nU" SU/ SQ5      nU(       a  U(       d  US   nU(       a  T R                  / SQU/5      nU" SU/ SQ5        g! [         a"    [        R                  R	                  S5         gf = f)zFPulls metadata properties for region and zone and sets them in gcloud.)computezproject-infodescribez--quiet)paramsa  Not setting default zone/region (this feature makes it easier to use
[gcloud compute] by setting an appropriate default value for the
--zone and --region flag).
See https://cloud.google.com/compute/docs/gcloud-compute section on how to set
default compute region and zone manually. If you would like [gcloud init] to be
able to do this for you the next time you run it, make sure the
Compute Engine API is enabled for your project on the
https://console.developers.google.com/apis page.

NcommonInstanceMetadataitemskeyzgoogle-compute-default-zonevaluezgoogle-compute-default-regionz;Do you want to configure a default Compute Region and Zone?rX   c                 *  > U(       d  TR                  U5      nUc  g[        U5      nSR                  U 5      n[        R                  " SR                  U 5      /U Vs/ s H  oUS   PM	     sn-   USS[
        R                  " 5       S9nUb  US:X  a  gX6S-
     n[        R                  " [        R                  R                  R                  U 5      US   5        [        R                  R                  S	R                  XS   5      5        U$ s  snf )
zDSet named compute property to default_value or get via list command.NzWhich Google Compute Engine {0} would you like to use as project default?
If you do not specify a {0} via a command line flag while working with Compute Engine resources, the default is assumed.zDo not set default {0}rp   T)r-   r.   allow_freeformfreeform_suggesterr   rl   zYour project default Compute Engine {0} has been set to [{1}].
You can change it by running [gcloud config set compute/{0} NAME].

)rb   listr9   r   r`   r   TextChoiceSuggesterr   rK   r4   r   Propertyr   r2   r3   )rp   default_valuelist_commandvaluesr-   r   rg   rA   s          r(   SetProperty3Init._PickDefaultRegionAndZone.<locals>.SetProperty  s   l+>
fE GMfG	 	 %%%,,T23*01&V}&124)==?	A ;#(
1u  !2!2!:!:!C!CD!I!.v!68	jj C t6%:;=  2s   D
)r   zonesr   zone)r   r   r   region)r   regionsr   )r   r   r   )
rb   	Exceptionr   r2   r3   r   MakeSerializablery   r   r=   )	rA   project_infodefault_zonedefault_regionmetadataitemrh   r   r   s	   `        r(   rR   Init._PickDefaultRegionAndZonej  sM   \\"I*3 " 6l  LN'88Fl!!":B?h,,w+$;77g,%[;;=.	 , ((,.f > \\"B#/.2lv|-IJDNH~n||$F%3$46n.*HIW  	jj 
 
 s   D )D76D7c                    [         R                  R                  S5        [        R                  R
                  R                  R                  5       (       a_  [         R                  R                  SR                  [        R                  R
                  R                  R                  5       5      5        O[         R                  R                  S5        [        R                  R
                  R                  R                  5       nU(       a.  [         R                  R                  SR                  U5      5        [        R                  R                  R                  R                  5       nU(       a.  [         R                  R                  SR                  U5      5        [        R                  R                  R                  R                  5       nU(       a.  [         R                  R                  SR                  U5      5        [         R                  R                  S5        [         R                  R                  SR                  US	95        [         R                  R                  S
5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        [         R                  R                  S5        g )Nz5The Google Cloud CLI is configured and ready to use!
z>* Commands that require authentication will use {0} by defaultzL* Commands that require authentication will fail until you are authenticatedz2* Commands will reference project `{0}` by defaultz:* Compute Engine commands will use region `{0}` by defaultz9* Compute Engine commands will use zone `{0}` by default
zDRun `gcloud help config` to learn how to change individual settings
zThis gcloud configuration is called [{config}]. You can create additional configurations if you work with multiple accounts and/or projects.r
   z1Run `gcloud topic configurations` to learn more.
zSome things to try next:
z* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.zl* Run `gcloud topic --help` to learn about advanced features of the CLI like arg files and output formattingzF* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.)r   r2   Printr   r4   r5   rO   rc   r9   rQ   r   r   r   )rA   rC   rQ   r   r   s        r(   r@   Init._Summarize  s   JJMN%%))++	jj
J6*##((0044679 
jj $$,,002G	jj
>6'? &&--113F	jj
F6&> $$))--/D	jj
F6$< JJOQ JJ	F"4F57 JJIJJJ12JJ	 JJ	34 JJ	r+   c                 
   [         R                  " S5      nUR                  5       n[        R                  R                  U5        [        R                  R                  U5        [        R                  R                  5         U$ )NzEnter configuration name. Names start with a lower case letter and contain only lower case letters a-z, digits 0-9, and hyphens '-':  )	r   PromptResponsestripr   rt   rw   r   ActivePropertiesFile
Invalidate)rA   rC   s     r(   r   Init._CreateConfiguration  sm    #22	PQ ,113$$112DE$$334FG&&113r+   c                 \   [        5       nU(       d  [        R                  " S5        g [        R                  " [
        R                  R                  SS5      5      n[
        R                  R                  U5      (       a$  [        R                  " SR                  US95        g SSSU/n[        R                  R                  5       [        R                  R                  :X  a  [        R                  " U/UQ76 nO[        R                   " U/UQ76 n[        R"                  " US	[        R$                  R                  [        R$                  R                  S
9nUS:X  a-  [        R&                  R)                  SR                  US95        g [        R&                  R)                  S5        g )Nz;Unable to find [gsutil]. Not configuring default .boto file~z.botozINot configuring default .boto file. File already exists at [{boto_path}].)	boto_pathr   z-nz-oT)no_exitout_funcerr_funcr   zCreated a default .boto configuration file at [{boto_path}]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
zxError creating a default .boto configuration file. Please run [gsutil config -n] if you would like to create this file.
)_FindGsutilr   debugr   ExpandHomeDirospathr^   existsr9   r   OperatingSystemCurrentWINDOWSr   ArgsForCMDToolArgsForExecutableToolExecfile_only_loggerr2   r3   )rA   gsutil_pathr   command_argsgsutil_argsreturn_codes         r(   rS   Init._CreateBotoConfig  s]   -K	ii  ##BGGLLg$>?I	ww~~i  	ii ++16I6+FH dD)4L  ((*i.G.G.O.OO#22; B4@Bk $99+ I;GIk "&&{D030D0D0J0J030D0D0J0JLK a	jj  FYF	! 
jj - .r+   c                    [         R                  " [         R                  R                  R                  S 5        [         R                  " [         R                  R                  R
                  S 5        [         R                  " [         R                  R                  R                  S 5        [         R                  " [         R                  R                  R                  S 5        [        R                  R                  5         g N)r   rK   r4   r5   rO   rQ   r   r   r   r   r   r   )rA   s    r(   r   Init._CleanCurrentConfiguration  s    z0055==tDz0055==tDz0088??Fz0088==tD&&113r+   c                    U R                   R                  U5      (       d  [        R                  " SU5        g Uc  / nX-   n[        R                  " SSR	                  U5      5         U(       a  UR                  S5        [        R                  R                  R                  R                  5       c  U(       a  UR                  S5        [        R                  R                  R                  R                  5       (       a  UR                  S5        [        R                  " U R                  U5      5      $ ! [          aP  n[        R                  " SSR	                  X-   5      5        ["        R$                  " X-   UR&                  5      eS nAf[(         a*    [        R                  " SSR	                  X-   5      5        e f = f)	NzCommand %s does not exist.zExecuting: [gcloud %s] z--no-user-output-enabledz--verbosity=nonez
--log-httpz[%s] has failed
zFailed to run [%s]
)_cli_power_users_onlyIsValidCommandr   infor^   r_   r   r4   r5   	verbosityrc   log_httpr7   r   r   ExecuteCommandDoNotUse
SystemExitr0   FailedSubCommandcodeBaseException)rA   cmdr   r[   rB   excs         r(   rb   Init._RunCmd%  sS   %%44S99	hh+S1~f<DHH%sxx~6 
./



 
 
*
*
.
.
0
8
&'						(	(	0	0	2	2L!00

%
%d
+- -  ;	hh"CHHS\$:;""3<:: 	hh%sxx'=>s   )CD9 9
GAF7G r   )NT)__name__
__module____qualname____firstlineno____doc__r   SDK_TOOLS_CATEGORYcategorystaticmethodr)   rE   r?   rL   r8   rP   rR   r@   r   rS   r   rb   __static_attributes__r   r+   r(   r   r   ,   sm    #J $$(( (T**X(  $Wr:x QJf/b$.L4r+   r   c                     [         R                  " 5       R                  n U (       d  g[        R                  R                  5       [        R                  R                  :X  a  SnOSn[        R                  R                  X5      $ )zBFinds the bundled gsutil wrapper.

Returns:
  The path to gsutil.
Nz
gsutil.cmdgsutil)
r   Pathssdk_bin_pathr   r   r   r   r   r   r^   )r   r   s     r(   r   r   F  s[     ,,,	
&&(I,E,E,M,MMFF	l	++r+   ),r   
__future__r   r   r   r   googlecloudsdk.callioper   r   r0   r   googlecloudsdk.command_libr	   googlecloudsdk.corer   r   r   r   r   "googlecloudsdk.core.configurationsr   googlecloudsdk.core.consoler   googlecloudsdk.core.credentialsr   r\   googlecloudsdk.core.diagnosticsr   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   r   r   UniverseCompatibleReleaseTracksReleaseTrackALPHABETAPREVIEWGACommandr   r   r   r+   r(   <module>r     s     - &  ' 	 ( 7 . 0 & / # * $ < 2 < ? ; * . 
 	P4<< P Pf,r+   