
    e&                     .   d 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
mZ dd	lZ G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d dej*                        Zd Zy	)z-Flags for serverless local development setup.    )absolute_import)division)unicode_literals)arg_parsers)base)map_util)
exceptionsNc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)FlagDefz<Object that holds a flag definition and adds it to a parser.c                      || _         || _        y N)namekwargsselfr   r   s      ,lib/googlecloudsdk/command_lib/code/flags.py__init__zFlagDef.__init__   s    DIDK    c                 4    | j                   |j                   k(  S r   r   r   others     r   __eq__zFlagDef.__eq__"       99

""r   c                 4    | j                   |j                   k7  S r   r   r   s     r   __ne__zFlagDef.__ne__%   r   r   c                 ,    t        | j                        S r   )hashr   r   s    r   __hash__zFlagDef.__hash__(   s    		?r   c                 R     |j                   | j                  fi | j                   y r   )add_argumentr   r   )r   parsers     r   ConfigureParserzFlagDef.ConfigureParser+   s    F		1T[[1r   N)	__name__
__module____qualname____doc__r   r   r   r    r$    r   r   r   r      s    D##2r   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)FlagDefsz Base type for all flag builders.c                 "    t               | _        y r   )set_operationsr   s    r   r   zFlagDefs.__init__2   s    uDr   c                 :    | j                  t        |fi |       y r   )_AddOperationr   r   s      r   _AddFlagzFlagDefs._AddFlag5   s    wt.v./r   c                 :    | j                   j                  |       y r   )r.   add)r   	operations     r   r0   zFlagDefs._AddOperation8   s    #r   c                 H    | j                   D ]  }|j                  |        y r   )r.   r$   )r   r#   r4   s      r   r$   zFlagDefs.ConfigureParser;   s     %%	' &r   N)r%   r&   r'   r(   r   r1   r0   r$   r)   r   r   r+   r+   /   s    (0$(r   r+   c                       e Zd ZdZd Zy)MutuallyExclusiveGroupDefzEFlag builder where all flags are added to a mutually exclusive group.c                 l    |j                  d      }| j                  D ]  }|j                  |        y )NF)required)add_mutually_exclusive_groupr.   r$   )r   r#   groupops       r   r$   z)MutuallyExclusiveGroupDef.ConfigureParserC   s3    ///?E r   N)r%   r&   r'   r(   r$   r)   r   r   r7   r7   @   s
    M r   r7   c                       e Zd ZdZd Zd Zy)BuilderFlagszFlags for builder settings.c                 ,    | j                  ddd       y )Nz--dockerfile
Dockerfilez!Dockerfile for the service image.)defaulthelpr1   r   s    r   AddDockerfilezBuilderFlags.AddDockerfileL   s    MM0  2r   c                 *    | j                  dd       y )Nz	--builderzGBuild with a given Cloud Native Computing Foundation Buildpack builder.rB   rC   r   s    r   
AddBuilderzBuilderFlags.AddBuilderR   s    MM  r   N)r%   r&   r'   r(   rD   rG   r)   r   r   r>   r>   I   s    #2r   r>   c                       e Zd Zd Zd Zy)CredentialFlagsc                 *    | j                  dd       y )Nz--service-accountzMWhen connecting to Google Cloud Platform services, use a service account key.rF   rC   r   s    r   AddServiceAccountz!CredentialFlags.AddServiceAccount[   s    MM  r   c                 .    | j                  dddd       y )Nz --application-default-credential
store_trueFzZWhen connecting to Google Cloud Platform services, use the application default credential.)actionrA   rB   rC   r   s    r   AddApplicationDefaultCredentialz/CredentialFlags.AddApplicationDefaultCredentiala   s!    MM**	  +r   N)r%   r&   r'   rK   rO   r)   r   r   rI   rI   Y   s    +r   rI   c                       e Zd ZdZd Zd Zy)EnvVarFlagszEnvironment variable flags.c           	          | j                  ddt        j                  t        j                  t        j
                  t        j
                        d       y )Nz
--env-vars	KEY=VALUEkey_type
value_typez8List of key-value pairs to set as environment variables.metavarrN   typerB   r1   r   UpdateActionArgDictsix	text_typer   s    r   
AddEnvVarszEnvVarFlags.AddEnvVarsm   sA    MM''  ]]s}}>G  Ir   c                     | j                  ddt        j                  t        j                  t        j                        d       y )Nz--env-vars-file	FILE_PATHrT   zIPath to a local YAML file with definitions for all environment variables.)rX   rY   rB   )r1   r   ArgDictFiler]   r^   r   s    r   AddEnvVarsFilezEnvVarFlags.AddEnvVarsFilev   s9    MM!!]]s}}>  r   N)r%   r&   r'   r(   r_   rc   r)   r   r   rQ   rQ   j   s    #Ir   rQ   c                        e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )CommonFlagsz;Flags that are common between the gcloud code dev commands.c                 8    t         t        |           i | _        y r   )superre   r   _group_cache)r   	__class__s    r   r   zCommonFlags.__init__   s    	+t%'Dr   c                 4    | j                  dt        d       y )Nz--local-portzoLocal port to which the service connection is forwarded. If this flag is not set, then a random port is chosen.rY   rB   )r1   intr   s    r   AddLocalPortzCommonFlags.AddLocalPort   s    MM9  :r   c                 *    | j                  dd       y )Nz--sourcez^The directory containing the source to build. If not specified, the current directory is used.rF   rC   r   s    r   	AddSourcezCommonFlags.AddSource   s    MM;  <r   c                 ,    | j                  ddd       y )Nz--service-nameFzName of the service.r9   rB   rC   r   s    r   AddServiceNamezCommonFlags.AddServiceName   s    MM"U9OMPr   c                 ,    | j                  ddd       y )Nz--imageFzName for the built image.rq   rC   r   s    r   AddImagezCommonFlags.AddImage   s    MM)e2MMNr   c                 T    | j                  dt        j                  d      d       y )Nz--memoryB)default_unitzContainer memory limit. Limit is expressed either as an integer representing the number of bytes or an integer followed by a unit suffix. Valid unit suffixes are "B", "KB", "MB", "GB", "TB", "KiB", "MiB", "GiB", "TiB", or "PiB".rk   )r1   r   
BinarySizer   s    r   	AddMemoryzCommonFlags.AddMemory   s)    MM##5)  *r   c                 T    | j                  dt        j                  d      d       y )Nz--cpug        )lower_boundzjContainer CPU limit. Limit is expressed as a number of CPUs. Fractional CPU limits are allowed (e.g. 1.5).rk   )r1   r   BoundedFloatr   s    r   AddCpuzCommonFlags.AddCpu   s)    MM%%#68  9r   c                 R    | j                  dt        j                         dd       y )Nz--cloudsql-instancesCLOUDSQL_INSTANCEzYCloud SQL instance connection strings. Must be in the form <project>:<region>:<instance>.)rY   rX   rB   )r1   r   ArgListr   s    r   AddCloudsqlInstancesz CommonFlags.AddCloudsqlInstances   s*    MM  "#)	  *r   c                 0    | j                  ddddd       y )Nz--readiness-probeFrM   TzAdd a readiness probe to the list of containers that delays deployment stabilization until the application app has bound to $PORTrA   rN   hiddenrB   rC   r   s    r   AddReadinessProbezCommonFlags.AddReadinessProbe   s(     	MMP  Qr   c                 @    d}|r|dz  }| j                  ddd|       y)z_AddFlag for service_config, which has two possible help strings.

    Args:
      include_app_engine_docs: Add paragraph that says app.yaml is allowed.
    zservice.yaml filename override. Defaults to the first file matching ```*service.dev.yaml``` then ```*service.yaml```, if any exist. This path is relative to the --source dir.a  
An App Engine config path (typically ```app.yaml```) may also be provided here, and we will build with a Cloud Native Computing Foundation Buildpack builder selected from gcr.io/gae-runtimes/buildpacks, according to the App Engine ```runtime``` specified in app.yaml.service_configSERVICE_CONFIG?)rX   nargsrB   NrC   )r   include_app_engine_docs	help_texts      r   AddServiceConfigPositionalArgz)CommonFlags.AddServiceConfigPositionalArg   s?    	<  12i 	MM 	  r   c                 H    | j                  dt        j                  d       y )Nz--allow-secret-managerzBSuppress warnings if secrets need to be pulled from secret manager)rN   rB   )r1   r   StoreTrueFalseActionr   s    r   AddAllowSecretManagerFlagz%CommonFlags.AddAllowSecretManagerFlag   s$    MM //  r   c           	          | j                  ddt        j                  t        j                  t        j
                  t        j
                        d       y )Nz	--secretsrS   rT   z*List of key-value pairs to set as secrets.rW   rZ   r   s    r   
AddSecretszCommonFlags.AddSecrets   s@    MM''  ]]s}}>9  ;r   c                 X    | j                  ddddd       | j                  ddd	       y )
Nz--cloudFrM   Tzdeploy code to Cloud Runr   z--regionz region to deploy the dev service)rB   r   rC   r   s    r   AddCloudzCommonFlags.AddCloud   s>    MM'  ) 	MM;D  Jr   c                     || j                   vr' |       }|| j                   |<   | j                  |       | j                   |   S r   )rh   r0   )r   klassr;   s      r   	_GetGroupzCommonFlags._GetGroup   sF    D%%%ge!&d
U##r   c                 ,    | j                  t              S r   )r   rI   r   s    r   CredentialsGroupzCommonFlags.CredentialsGroup   s    >>/**r   c                 ,    | j                  t              S r   )r   rQ   r   s    r   EnvVarsGroupzCommonFlags.EnvVarsGroup   s    >>+&&r   c                 ,    | j                  t              S r   )r   r>   r   s    r   BuildersGroupzCommonFlags.BuildersGroup   s    >>,''r   c                     | j                          |t        j                  j                  k(  r| j	                          |t        j                  j                  k(  }| j                  |       y )N)r   )_AddBetaFlagsr   ReleaseTrackALPHA_AddAlphaFlagsr   )r   release_trackappyaml_supports      r   AddAlphaAndBetaFlagsz CommonFlags.AddAlphaAndBetaFlags  sW    ))///
 $t'8'8'>'>>O&&&Or   c                    | j                         j                          | j                          | j                          | j	                         j                          | j	                         j                          | j                          | j                          | j                          | j                         j                          y)z0Set up flags that are for alpha and beta tracks.N)r   rD   ro   rm   r   rK   rO   r   r   r   rG   r   s    r   r   zCommonFlags._AddBetaFlags  s    &&(NN--/;;=""$OO##%r   c                 <   | j                          | j                          | j                          | j                          | j	                          | j                         j                          | j                         j                          | j                          y)z+Set up flags that are for alpha track only.N)	r   rr   rt   ry   r}   r   r_   rc   r   r   s    r   r   zCommonFlags._AddAlphaFlags  sk     	MMONNKKM""$&&(MMOr   )F)r%   r&   r'   r(   r   rm   ro   rr   rt   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)ri   s   @r   re   re      so    C:<QO*9*
Q4;J$+'(P
&
r   re   c                       e Zd ZdZy)InvalidFlagErrorzFlag settings are illegal.N)r%   r&   r'   r(   r)   r   r   r   r   &  s    "r   r   c                     d| v rA| j                  d      r/| j                  d      s| j                  d      st        d      yyyy)z>Validate flag requirements that cannot be handled by argparse.cloudsql_instancesservice_accountapplication_default_credentialzd--cloudsql-instances requires --service-account or --application-default-credential to be specified.N)IsSpecifiedr   )	namespaces    r   Validater   *  sa    i'01  !23  !AB
 O P P C 4 2 (r   )r(   
__future__r   r   r   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer	   r]   objectr   r+   r7   r>   rI   rQ   re   Errorr   r   r)   r   r   <module>r      s    4 &  ' / ( 9 * 
2f 2((v ("   ,  +/ +"+ ,c( cL#z'' #Pr   