
    =#              
       f   d Z ddlmZ ddlmZ ddlm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mZ ddlmZ ddlmZ  ej,                  dd      Z ej,                  dd      Z ej,                  ddddd      Z ej,                  ddddd      Z ej,                  dd      Z ej,                  d d!      Z ej,                  d"d#dd$ej:                  %      Z ej,                  d&d'dej>                  d( ej@                  d)*      +      Z! ej,                  d,dd-      Z" ej,                  d.d/d0d1      Z# ej,                  d2d3d4d1      Z$dAd5Z%d6 Z&d7 Z'd8 Z(d9 Z)d: Z* ej,                  d;dde*<      Z+g d=Z,d> Z- ej\                  ej^                  d?      Z0d@ Z1y)Bz?This module holds common flags used by the gcloud app commands.    )absolute_import)division)unicode_literalsN)	logs_util)storage_util)appinfo)arg_parsers)base)
exceptions)log)	constants)dockerdomainzYA valid domain which may begin with a wildcard, such as: `example.com` or `*.example.com`helpidzThe id of the certificate. This identifier is printed upon creation of a new certificate. Run `{parent_command} list` to view existing certificates.z--launch-browser
store_trueTlaunch_browserzCLaunch a browser if possible. When disabled, only displays the URL.)actiondefaultdestr   z--ignore-bad-certsFzTHIS ARGUMENT NEEDS HELP TEXT.)r   r   hiddenr   z--ignore-filezCOverride the .gcloudignore file and use the specified file instead.priorityzAn integer between 1 and 2^32-1 which indicates the evaluation order of rules. Lowest priority rules are evaluated first. The handle `default` may also be used to refer to the final rule at priority 2^32-1 which is always present in a set of rules.z--levelzCFilter entries with severity equal to or higher than a given level.any)r   requiredr   choicesz--logsz}Filter entries from a particular set of logs. Must be a comma-separated list of log names (request_log, stdout, stderr, etc).APP_LOG   )
min_length)r   r   r   metavartypez--server)r   r   	--service-szLimit to specific service.)r   r   	--version-vzLimit to specific version.c                 t     | j                   dg|rdgng ddd  | j                   dg|rdgng ddd y	)
zAdd arguments to a parser for selecting service and version.

  Args:
    parser: An argparse.ArgumentParser.
    short_flags: bool, whether to add short flags `-s` and `-v` for service
      and version respectively.
  r"   r#   FzThe service ID.r   r   r$   r%   zThe version ID.Nadd_argument)parsershort_flagss     +lib/googlecloudsdk/command_lib/app/flags.pyAddServiceVersionSelectArgsr-   _   s^     &)TFr &)TFr    c                     t        j                  dd      }|r6| j                         }|j                  |       |j	                  ddd       y|j                  |        y)	z;Add the --certificate-id flag to a domain-mappings command.z--certificate-idzA certificate id to use for this domain. May not be used on a domain mapping with automatically managed certificates. Use the `gcloud app ssl-certificates list` to see available certificates for this app.r   z--no-certificate-idr   z2Do not associate any certificate with this domain.)r   r   N)r
   Argumentadd_mutually_exclusive_groupAddToParserr)   )r*   include_no_certcertificate_idgroups       r,   AddCertificateIdFlagr6   r   sh     ==. //1Eu%	A  C
 v&r.   c                 Z    t        j                  dddgd      }|j                  |        y)z/Adds common flags to a domain-mappings command.z--certificate-management	automaticmanualzType of certificate management. 'automatic' will provision an SSL certificate automatically while 'manual' requires the user to provide a certificate id to provision.)r   help_strN)r
   ChoiceArgumentr2   )r*   certificate_arguments     r,   AddCertificateManagementFlagr=      s5    ,, H%EG ""6*r.   c                     | j                  d|d       | j                  d|dd       | j                  d|dd	       y
)z4Add the common flags to an ssl-certificates command.z--display-namez$A display name for this certificate.r'   z--certificateLOCAL_FILE_PATHz      The file path for the new certificate to upload. Must be in PEM
      x.509 format including the header and footer.
      )r   r    r   z--private-keyz      The file path to a local RSA private key file. The private key must be
      PEM encoded with header and footer and must be 2048 bits
      or fewer.
        Nr(   r*   r   s     r,   AddSslCertificateFlagsrA      sf     	1  3 	
	   		  r.   c                     | j                  d|d       | j                  d|ddgd d	       | j                  d
d       y)z1Add the common flags to a firewall-rules command.z--source-rangezUAn IP address or range in CIDR notation or the ```*``` wildcard to match all traffic.r'   z--actionALLOWDENYc                 "    | j                         S )N)upper)xs    r,   <lambda>z'AddFirewallRulesFlags.<locals>.<lambda>   s
    QWWYr.   zAllow or deny matched traffic.)r   r   r!   r   z--descriptionzA text description of the rule.r   Nr(   r@   s     r,   AddFirewallRulesFlagsrI      sg     	&'J  L 	j'&/.;	  =
 	=  ?r.   c                 ,    t        j                  d      )Na  The --docker-build flag no longer exists.

Docker images are now built remotely using Google Container Builder. To run a
Docker build on your own host, you can run:
  docker build -t gcr.io/<project>/<service.version> .
  gcloud docker push gcr.io/<project>/<service.version>
  gcloud app deploy --image-url=gcr.io/<project>/<service.version>
If you don't already have a Dockerfile, you must run:
  gcloud beta app gen-config
first to get one.
  )argparseArgumentTypeError)unused_values    r,   ValidateDockerBuildFlagrN      s    "" $ 	 r.   z--docker-build)r   r   r!   )debuginfowarningerrorcriticalc                     t        j                  d       | j                  st        j                  |      t
        j                  j                  | j                        S )zGets a bucket reference for a Cloud Build.

  Args:
    app: App resource for this project
    project: str, The name of the current project.

  Returns:
    storage_util.BucketReference, The bucket to use.
  z/No bucket specified, retrieving default bucket.)r   rO   
codeBucketr   DefaultBucketAccessErrorr   BucketReferenceFromUrl)appprojects     r,   GetCodeBucketr[      sD     ))=>	

-
-g
66		%	%	-	-cnn	==r.   zMay only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.c                     | yt        |      dk7  rt        j                         t        j                  D ]  }| j                  |      s y t        j                  |       )a   Check the user-provided image URL.

  Ensures that:
  - it is consistent with the services being deployed (there must be exactly
    one)
  - it is an image in a supported Docker registry

  Args:
    image_url: str, the URL of the image to deploy provided by the user
    services: list, the services to deploy

  Raises:
    MultiDeployError: if image_url is provided and more than one service is
      being deployed
    docker.UnsupportedRegistryError: if image_url is provided and does not point
      to one of the supported registries
  Nr   )lenr   MultiDeployErrorr   ALL_SUPPORTED_REGISTRIES
startswithr   UnsupportedRegistryError)	image_urlservicesregistrys      r,   ValidateImageUrlre      s\    ( 
]a

%
%
''44hH% 5 	''	22r.   )F)2__doc__
__future__r   r   r   rK   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.storager   googlecloudsdk.appengine.apir   googlecloudsdk.callioper	   r
   googlecloudsdk.command_lib.appr   googlecloudsdk.corer   googlecloudsdk.core.dockerr   r   r0   DOMAIN_FLAGCERTIFICATE_ID_FLAGLAUNCH_BROWSERIGNORE_CERTS_FLAGIGNORE_FILE_FLAGFIREWALL_PRIORITY_FLAG
LOG_LEVELSLEVELDEFAULT_LOGSArgListLOGSSERVER_FLAGSERVICEVERSIONr-   r6   r=   rA   rI   rN   DOCKER_BUILD_FLAGLOG_SEVERITIESr[   RegexpValidatorMODULE_VERSION_ID_RE_STRINGVERSION_TYPEre    r.   r,   <module>r      s    F &  '  0 7 0 / ( 5 # 0 -dmm-/
 $dmm24  ,<	NP
 "DMM	)+  !4==	NP  '?A  		N  	" t}} ""				*, dmmt"BD $--85J $--85J&'*+4?  "DMM	)	 	"  C>" +{**''PQ3r.   