
    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rSrSrSrSrSrSr \\!   \"S'   Sr#\\!   \"S'   S r$S r% " S S\&5      r'\RP                  " \RR                  RT                  5      \RV                   " S S\'\RX                  5      5       5       r-\RP                  " \RR                  R\                  \RR                  R^                  5      \RV                   " S S \'\RX                  5      5       5       r0g)!zendpoints deploy command.    )absolute_import)division)unicode_literalsN)Final)config_reporter)
exceptions)services_util)
enable_api)base)log)
properties)
console_io)http_encodinga  Advice found for changes in the new service config. If this is a --validate-only run, the config push would have failed. See the outputted report for failure reason(s). If this is not a --validate-only run and you would like to ignore these warnings, rerun the command with --force. NOTE: setting this flag will ignore all change advice. For production systems, best practice is to set this for a single execution only after manually reviewing all changes with advice.zcAdvice found for changes in the new service config, but proceeding anyway because --force is set...zThe service {service_name} must exist in order to validate the configuration. Do you want to create the service in project {project_id}?zThe service {service_name} must exist in order to validate the configuration. To create the service in project {project_id}, rerun the command without the --validate-only flag.   z2.xSWAGGER_VERSIONz3.xOPENAPI_V3_VERSIONc                 d    U R                  SSSS9  [        R                  R                  U 5        g)z:Add common arguments for this command to the given parser.service_config_file+zThe service configuration file (or files) containing the API specification to upload. Proto Descriptors, Open API (Swagger) specifications, and Google Service Configuration files in JSON and YAML formats are acceptable.)nargshelpN)add_argumentr   
ASYNC_FLAGAddToParserparsers    (lib/surface/endpoints/services/deploy.py_CommonArgsr   I   s4    -	  	 //f%    c                    [         R                  " 5       n[         R                  " 5       nUR                  U S9nUR                  R                  U5      nUR                  nSR                  [        R                  R                  R                  R                  U 5      [        R                  R                  R                  R                  U5      S9$ )z3Generate a service management url for this service.)serviceNamezShttps://console.cloud.google.com/endpoints/api/{service}/overview?project={project})serviceproject)r	   GetMessagesModuleGetClientInstance#ServicemanagementServicesGetRequestservicesGetproducerProjectIdformatsixmovesurllibparsequote)r"   messagesclientget_requestresponser#   s         r   GenerateManagementUrlr4   X   s     ,,.(**,&<< = + __  -(&&'--3V))""((..w7))""((..w7 .4 .r   c                   v    \ rS rSrSr\S 5       rS\S\4S jr\	R                  4S jrSS jrS	 rS
 rS rSrg)_BaseDeployo   z0Create deploy base class for all release tracks.c                 b    [        U 5        U R                  SSSS9  U R                  SSSSSS	9  g
)zArgs is called by calliope to gather arguments for this command.

Args:
  parser: An argparse parser that you can use to add arguments that go on
    the command line after this command. Positional arguments are allowed.
z--validate-only
store_truezIf included, the command validates the service configuration(s), but does not deploy them. The service must exist in order to validate the configuration(s).)actionr   z--forcez-fFz]Force the deployment even if any hazardous changes to the service configuration are detected.)r:   defaultr   N)r   r   r   s    r   Args_BaseDeploy.Argsr   sP     
-	   2  	r   file_contentsfilenamec                     [         R                  " 5       nUR                  R                  nX5R                  :w  a  [
        R                  " U5      nUR                  U[        R                  R                  U5      US9$ )a  Constructs a ConfigFile message from a config file.

Args:
  file_contents: The contents of the config file.
  filename: The full path to the config file.
  file_type: FileTypeValueValuesEnum describing the type of config file.

Returns:
  The constructed ConfigFile message.
)fileContentsfilePathfileType)
r	   r$   
ConfigFileFileTypeValueValuesEnumFILE_DESCRIPTOR_SET_PROTOr   Encodeospathbasename)selfr>   r?   	file_typer0   
file_typess         r   MakeConfigFileMessage!_BaseDeploy.MakeConfigFileMessage   so    " ..0H$$<<J888#**=9m"!!(+   r   c                    Sn[         R                  " U5      nUR                  R                  U5        UR                  R                  5         UR                  5       nU(       a  UR                  (       d  gUR                  nU HB  nUR                  (       d  M  U[        :  a  U" S[        R                  " U5      5        US-  nMD     U[        :  a	  U" SU5        U$ )ao  Run and display results (if any) from the Push Advisor.

Args:
  service: The name of the service for which to compare configs.
  service_config_id: The new config ID to compare against the active config.
  log_func: The function to which to pass advisory messages (default:
    log.warning).

Returns:
  The number of advisory messages returned by the Push Advisor.
r   z%s
   zL%s total changes with advice found, check config report file for full list.
)r   ConfigReporter
new_configSetConfigId
old_configSetConfigUseDefaultId	RunReportconfigChangesadvicesNUM_ADVICE_TO_PRINTr	   PushAdvisorConfigChangeToString)	rK   r"   service_config_idlog_funcnum_changes_with_advicereporterchange_reportchangeschanges	            r   ShowConfigReport_BaseDeploy.ShowConfigReport   s      --g6H ##$56 --/&&(M ; ;))G	"%88
mCCFK 	 1$  !44
! #"r   c                     g)zRun the Push Advisor and return whether the command should abort.

Args:
  unused_force: bool, unused in the default implementation.

Returns:
  True if the deployment should be aborted due to warnings, otherwise
  False if it's safe to continue.
F )rK   unused_forces     r   CheckPushAdvisor_BaseDeploy.CheckPushAdvisor   s     r   c                 R   [         R                  R                  R                  R	                  SS9n [
        R                  " X1U5        [        R                  R                  S5        g! [        R                   a(    [        R                  " SR                  X5      5         gf = f)zAttempt to enable a service. If lacking permission, log a warning.

Args:
  service_name: The service to enable.
  is_async: If true, return immediately instead of waiting for the operation
    to finish.
Trequired
zAttempted to enable service [{0}] on project [{1}], but did not have required permissions. Please ensure this service is enabled before using your Endpoints service.
N)r   VALUEScorer#   r(   r
   EnableServicer   statusPrintservices_exceptionsEnableServiceExceptionwarningr*   )rK   service_nameis_async
project_ids       r   AttemptToEnableService"_BaseDeploy.AttemptToEnableService   s     ""''//33T3BJzB 
jjt55 	kk F<,s   6A* *9B&%B&c                 f   [         R                  " 5       n[         R                  " 5       nUR                  R                  nS=U l        =U l        n/ nUR                  U l        SnU R                  (       d  UR                  S5      (       d  SUl	        Sn[        UR                  5       GH  u  p[         R                  " U
5      n[         R                  " U
/ SQ5      (       Ga-  [         R                  " U5      nU(       d%  [        R                   " SR                  U
5      5      eSU;   a  U(       a/  U["        :w  a%  [        R                   " SR                  U
5      5      eU(       d  ["        nS	U;  a%  [        R                   " S
R                  U
5      5      eU R
                  (       d,  UR%                  S	5      (       a  UR%                  S	5      U l        UR'                  U R)                  XZUR*                  5      5        GM\  SU;   Ga  U(       a/  U[,        :w  a%  [        R                   " SR                  U
5      5      eU(       d  [,        nSnSnUR%                  S5      =(       d    /  H  nSU;   d  M  U(       a%  [        R                   " SR                  U
5      5      eSU;  a%  [        R                   " SR                  U
5      5      e[.        R0                  R2                  R4                  R7                  UR%                  S5      5      R8                  nSnM     U R
                  c  U(       a  Xl        U	[;        UR                  5      S-
  :X  a#  U R
                  c  [        R                   " S5      eU R
                  (       a-  U(       a&  U R
                  U:w  a  [        R                   " S5      eUR'                  U R)                  XZUR*                  5      5        GM=  UR%                  S5      S:X  al  U R
                  (       d,  UR%                  S5      (       a  UR%                  S5      U l        UR'                  U R)                  UU
UR<                  5      5        GM  SU;   a  [;        UR                  5      S:  a%  [        R                   " SR                  U
5      5      eU R                  (       a  [>        R@                  " S5      eUR%                  S5      U l        / n  O[        R                   " SR                  U
5      5      e[         RB                  " U
5      (       a/  UR'                  U R)                  UU
URD                  5      5        GM  [         RF                  " U
5      (       a0  SnUR'                  U R)                  XZURH                  5      5        GM  [        R                   " SR                  U
5      5      e   U(       a  [J        RL                  " S5        Sn[         RN                  " U R
                  5      (       d  [P        RR                  RT                  RV                  RY                  SS9nU R                  (       a  [Z        R\                  " 5       (       d2  [>        R^                  " [`        R                  U R
                  US95      e[Z        Rb                  " [d        R                  U R
                  US95      (       d  g[         Rf                  " U R
                  U5        SnU(       aQ  [         Rh                  " U R
                  UURj                  U R                  S9n[         Rl                  " U5      U l7        Ov[         Rp                  " U R
                  [P        RR                  RT                  RV                  RY                  SS9[         R                  " U5      5      nURr                  U l7        U Rn                  (       d  [>        R^                  " S 5      eU Ru                  URv                  5      (       a  gU R                  (       Gd  URx                  R{                  5       nUR|                  R'                  URx                  Rz                  R                  U Rn                  S!S"95        URy                  US#9nUR                  U R
                  US$9nUR                  UU R
                  S%9nUR                  R                  U5      n[         R                  " UURj                  5        U(       a&  U R                  U R
                  URj                  5        U$ )&a  Run 'endpoints services deploy'.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  The response from the Update API call.

Raises:
  BadFileExceptionn: if the provided service configuration files are
      invalid or cannot be read.
NFr*   none)z.jsonz.yamlz.ymlz;Could not read JSON or YAML from service config file [{0}].swaggerzMalformed input. Found OpenAPI service config in file [{}], but a different OpenAPI version was specified in another file. Only one OpenAPI version is supported per deployment.hostzMalformed input. Found Swagger service config in file [{}], but no host was specified. Add a host specification to the config file.openapiserverszx-google-endpointzMalformed input. Found OpenAPI service config in file [{}], but multiple servers were specified with the "x-google-endpoint" extension. At most one server can have the "x-google-endpoint" extension per file.urlzMalformed input. Found OpenAPI service config in file [{}], but no url was specified for the server with the "x-google-endpoint" extension. Add a url specification to the server with the "x-google-endpoint" extension.TrQ   zMalformed input. No servers were specified with the "x-google-endpoint" extension in the provided OpenAPI file(s). Add a servers specification to at least one config file with exactly one server configured with the "x-google-endpoint" extension.a  Ambiguous input. Multiple OpenAPI files were provided with different server URLs containing the "x-google-endpoint" extension. When using multiple OpenAPI files, ensure that all files with the "x-google-endpoint" extension define the same server URL with at most one server with the "x-google-endpoint" extension defined per file. Additionally, at least one server across all provided files must have the "x-google-endpoint" extension.typezgoogle.api.ServicenamezAmbiguous input. Found normalized service configuration in file [{0}], but received multiple input files. To upload normalized service config, please provide it separately from other input files to avoid ambiguity.zYThe --validate-only flag is not supported when using normalized service configs as input.zPUnable to parse Open API, or Google Service Configuration specification from {0}zqCould not determine the content type of file [{0}]. Supported extensions are .json .yaml .yml .pb and .descriptorzSupport for uploading uncompiled .proto files is deprecated and will soon be removed. Use compiled descriptor sets (.pb) instead.
rk   )rv   rx   )validate_onlyz,Failed to retrieve Service Configuration Id.g      Y@)keyvalue)percentages)r!   trafficPercentStrategy)rolloutr!   )Fr	   r$   r%   rD   rE   rv   service_versionr   IsSpecifiedr*   	enumerater   ReadServiceConfigFileFilenameMatchesExtensionLoadJsonOrYamlcalliope_exceptionsBadFileExceptionr   getappendrN   OPEN_API_YAMLr   r+   r,   r-   r.   urlparsehostnamelenSERVICE_CONFIG_YAMLr   InvalidFlagErrorIsProtoDescriptorrF   
IsRawProto
PROTO_FILEr   ru   DoesServiceExistr   rn   ro   r#   r(   r   	CanPromptInvalidConditionErrorVALIDATE_NEW_ERRORPromptContinueVALIDATE_NEW_PROMPTCreateServicePushMultipleServiceConfigFilesasync_0GetServiceConfigIdFromSubmitConfigSourceResponser\   !PushNormalizedGoogleServiceConfigidrh   forceTrafficPercentStrategyPercentagesValueadditionalPropertiesAdditionalPropertyRollout.ServicemanagementServicesRolloutsCreateRequestservices_rolloutsCreateProcessOperationResultry   )rK   argsr0   r1   rM   config_contentsconfig_filesgive_proto_deprecate_warningoas_versionir   service_config_dictfound_x_google_endpointx_google_endpoint_service_nameswas_service_createdrx   push_config_resultr   traffic_percent_strategyr   rollout_createrollout_operations                          r   Run_BaseDeploy.Run   s<    ..0H,,.F$$<<JAEEDE,L++D $)  d&6&6x&@&@dkK"+D,D,D"E%;;<OPo		/	/
9
 
 ,::?K"#44v12 
 ++[O;%661 &,-  )K..%66+ &,-  ""':'>'>v'F'F 3 7 7 ?D 

((!
8P8P
 --[,>>%661 &,-  ,K %*
!+/
(&**95;;a"a'()::P f01  a):::
 f01  03yy/?/?/E/E/N/N%%,0 - )-%1 <8 &+I >
 3t//0144##+%662  0##'EE%662	 	 

((!
8P8P
 !$$V,0DD""':'>'>v'F'F 3 7 7 ?D


((!%00 ** ))*Q.%66B &,-  --7 
 255f=$
,
#44+*+	  **+>??&&#44	
 ##$788'+$&&j6K6K	
 "22Ff()	
 	
M #FZ $	kkP  ))$*;*;<<$$))1155t5Dj 
		##%%00 ''#00Z (  
 ((&&!..: ' 
 

 !!$"3"3Z@ (GG




++**	 
H
H   )JJ






 
 
(
(
,
,d
,
;

&
&
7
  244d!!,,
8  TZZ(( 33DDFk&&--

)
)
:
:
M
M(( N 	
 "*!@!@! "A "   ''!9 ! g  NN'' O n !2299.I**+<dkkJ	##D$5$5t{{Cr   c                 ,   U(       a  U R                   (       d{  [        R                  R                  SR	                  U R
                  U R                  5      5        [        U R                  5      n[        R                  R                  SU-   5        g g g )Nz7Service Configuration [{0}] uploaded for service [{1}]
zTo manage your API, go to: )r   r   rq   rr   r*   r\   rv   r4   )rK   resources_were_displayedmanagement_urls      r   Epilog_BaseDeploy.EpilogD  sr      (:(:	jjE
M
M$$d&7&7 -T->->?n	jj4~EF );r   )r\   rv   r   r   NF)__name__
__module____qualname____firstlineno____doc__staticmethodr<   strrN   r   ru   rc   rh   ry   r   r   __static_attributes__rf   r   r   r6   r6   o   sV    8 : : CF++ +#Z2BH
Gr   r6   c                       \ rS rSrSrSrg)DeployiR  a  Deploys a service configuration for the given service name.

This command is used to deploy a service configuration for a service
to Google Service Management. As input, it takes one or more paths
to service configurations that should be uploaded. These configuration
files can be Proto Descriptors, Open API (Swagger) specifications,
or Google Service Configuration files in JSON or YAML formats.

If a service name is present in multiple configuration files (given
in the `host` field in OpenAPI specifications or the `name` field in
Google Service Configuration files), the first one will take precedence.

This command will block until deployment is complete unless the
`--async` flag is passed.

## EXAMPLES
To deploy a single Open API service configuration, run:

  $ {command} ~/my_app/openapi.json

To run the deployment asynchronously (non-blocking), run:

  $ {command} ~/my_app/openapi.json --async

To deploy a service config with a Proto, run:

  $ {command} ~/my_app/service-config.yaml ~/my_app/service-protos.pb
rf   N)r   r   r   r   r   r   rf   r   r   r   r   R  s    r   r   c                   "    \ rS rSrSrSS jrSrg)DeployBetaAlphaiw  a  Deploys a service configuration for the given service name.

This command is used to deploy a service configuration for a service
to Google Service Management. As input, it takes one or more paths
to service configurations that should be uploaded. These configuration
files can be Proto Descriptors, Open API (Swagger) specifications,
or Google Service Configuration files in JSON or YAML formats.

If a service name is present in multiple configuration files (given
in the `host` field in OpenAPI specifications or the `name` field in
Google Service Configuration files), the first one will take precedence.

When deploying a new service configuration to an already-existing
service, some safety checks will be made comparing the new configuration
to the active configuration. If any actionable advice is provided, it
will be printed out to the log, and the deployment will be halted. It is
recommended that these warnings be addressed before proceeding, but they
can be overridden with the --force flag.

This command will block until deployment is complete unless the
`--async` flag is passed.

## EXAMPLES
To deploy a single Open API service configuration, run:

  $ {command} ~/my_app/openapi.json

To run the deployment asynchronously (non-blocking), run:

  $ {command} ~/my_app/openapi.json --async

To deploy a service config with a Proto, run:

  $ {command} ~/my_app/service-config.yaml ~/my_app/service-protos.pb
c                 *   U(       a  [         R                  O[         R                  nU R                  U R                  U R
                  U5      nUS:  a?  U(       a  U" SR                  [        5      5        gU" SR                  [        5      5        gg)a  Run the Push Advisor and return whether the command should abort.

Args:
  force: bool, if True, this method will return False even if warnings are
    generated.

Returns:
  True if the deployment should be aborted due to warnings, otherwise
  False if it's safe to continue.
r   z{0}
TF)	r   ru   errorrc   rv   r\   r*   FORCE_ADVICE_STRINGADVICE_STRING)rK   r   r]   num_advicess       r   rh    DeployBetaAlpha.CheckPushAdvisor  sx     $s{{H''4118K Q	'!!"567
  	'!!-01r   rf   Nr   )r   r   r   r   r   rh   r   rf   r   r   r   r   w  s    "Jr   r   )1r   
__future__r   r   r   rH   typingr    googlecloudsdk.api_lib.endpointsr   r   r	   googlecloudsdk.api_lib.servicesr
   rs   googlecloudsdk.callioper   r   googlecloudsdk.corer   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   six.moves.urllib.parser+   r   r   r   r   rZ   r   r   __annotations__r   r   r4   objectr6   ReleaseTracksReleaseTrackGADefaultUniverseOnlyCommandr   ALPHABETAr   rf   r   r   <module>r      sA      &  ' 	  < 7 : 6 M ( E # * 2 2 8 6 '    #s #!& E#J &&.`G& `GF D%%(()[$,,   *F D%%++T->->-C-CD=k4<< =  E=r   