
    S2                        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s  Js  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r%\RL                  " \RN                  RP                  \RN                  RR                  \RN                  RT                  5      \RV                   " S S\RX                  5      5       5       r-g)z0`gcloud api-gateway api-configs create` command.    )absolute_import)division)unicode_literalsN)api_configs)apis)base)
operations)services_util)arg_parsers)
exceptions)common_flags)operations_util)resource_args)labels_util)log)http_encoding2   c                   \    \ rS rSrSrSSS.r\S 5       rS rS r	S	 r
S
 r SS jrS rSrg)Create+   zAdd a new config to an API.z`          {description}

          NOTE: If the specified API does not exist it will be created.z        To create an API config for the API 'my-api' with an OpenAPI spec, run:

          $ {command} my-config --api=my-api --openapi-spec=path/to/openapi_spec.yaml
        )DESCRIPTIONEXAMPLESc                    [         R                  R                  U 5        [        R                  " U 5        [
        R                  " U 5        [        R                  " U SSS9  [        R                  " U 5        U R                  SSSS9nUR                  S[        R                  " 5       SSS	9  UR                  S
[        R                  " 5       SSS	9  g )NcreatedT)
positionalz Configuration files for the API.)mutexrequiredhelpz--openapi-specFILEzoThe OpenAPI specifications containing service configuration information, and API specification for the gateway.)typemetavarr   z--grpc-fileszFiles describing the GRPC service. Google Service Configuration files in JSON or YAML formats as well as Proto descriptors should be listed.)r   
ASYNC_FLAGAddToParserr   AddDisplayNameArgr   AddCreateLabelsFlagsr   AddApiConfigResourceArg AddBackendAuthServiceAccountFlag	add_groupadd_argumentr   ArgList)parsergroups     -lib/surface/api_gateway/api_configs/create.pyArgsCreate.Args?   s    OO'""6*$$V,))&)M11&94&*"D  FE 
  "	   
  ".	  0    c           
      p   [         R                  " 5       n[        R                  " 5       n[        R
                  " 5       nUR                  R                  R                  5       nUR                  5       nUR                  U5      (       dN  UR                  U5      n[        R                  " UR                  USR                  UR!                  5       5      S9  / n/ n	/ n
[#        US5      (       a^  UR$                  (       aM  UR$                   Vs/ s H  oR'                  5       PM     snUl        U R)                  UR$                  5      u  pOJUR*                   Vs/ s H  oR'                  5       PM     snUl        U R-                  UR*                  5      nUR                  UUR.                  UR0                  UR2                  U	U
US9nSR                  UR!                  5       UR!                  5       5      n[        R                  " UR                  UUR4                  UUR6                  S9$ s  snf s  snf )Nz"Waiting for API [{}] to be created)wait_string
grpc_files)labelsdisplay_namebackend_authmanaged_service_configsgrpc_service_defsopen_api_docsz8Waiting for API Config [{0}] to be created for API [{1}])servicer2   is_async)apis_client	ApiClientapi_configs_clientApiConfigClientoperations_clientOperationsClientCONCEPTS
api_configParseParent	DoesExistr   r   PrintOperationResultnameformatNamehasattrr3   strip_Create__GrpcMessagesopenapi_spec_Create__OpenApiMessager4   r5   backend_auth_service_accountr:   async_)selfargsr   r   opsapi_config_refapi_refresr9   svc_configsgrpc_svc_defsfrespwaits                 r-   Run
Create.RunZ   s     "D$446K

,
,
.C]]--335N##%G >>'""KK c**
((C:AAlln
 MKMt\""t,0OO<OqO<do#'#6#6t#G k=.2.?.?@.?779.?@d++D,=,=>m n%)[[+/+<+<+/+L+L6A0=,9  ;D FLLw||~/D //		## ' = As   H.H3c                    [         R                  " 5       n/ nU H  n[        R                  " U5      nU R	                  XE5      nU(       ac  SU;   d  SU;   a2  U R                  UU5      nUR                  UR                  US95        Mo  [        R                  " SR                  U5      5      e[        R                  " S5      e   U$ )a8  Parses the Open API scoped configuraiton files into their necessary API Gateway message types.

Args:
  open_api_specs: Specs to be used with the API Gateway API Configuration

Returns:
  List of ApigatewayApiConfigOpenApiDocument messages

Raises:
  BadFileException: If there is something wrong with the files
swaggeropenapi)documentz6The file {} is not a valid OpenAPI configuration file.z.OpenAPI files should be of JSON or YAML format)apigateway_baseGetMessagesModule	endpointsReadServiceConfigFile_Create__ValidJsonOrYaml+_Create__MakeApigatewayApiConfigFileMessageappend"ApigatewayApiConfigOpenApiDocumentcalliope_exceptionsBadFileExceptionrI   )rR   open_api_specsmessagesconfig_filesconfig_fileconfig_contentsconfig_dictrb   s           r-   __OpenApiMessageCreate.__OpenApiMessage   s     002HL%!77Do**;Hk	#yK'?>>?JL(


hII J ! " $44Fvk"$ $ "22<> 	>! &$ r0   c                 z   / n/ nU GH.  n[         R                  " U5      nU R                  XE5      nU(       a]  UR                  S5      S:X  a#  UR	                  U R                  UU5      5        Mj  [        R                  " SR                  U5      5      e[         R                  " U5      (       a"  UR	                  U R                  XT5      5        M  [         R                  " U5      (       a%  [        R                  " SR                  U5      5      e[        R                  " SR                  U5      5      e   X24$ )aq  Parses the GRPC scoped configuraiton files into their necessary API Gateway message types.

Args:
  files: Files to be sent in as managed service configs and GRPC service
  definitions

Returns:
  List of ApigatewayApiConfigFileMessage, list of
  ApigatewayApiConfigGrpcServiceDefinition messages

Raises:
  BadFileException: If there is something wrong with the files
r    zgoogle.api.ServiceztThe file {} is not a valid api configuration file. The configuration type is expected to be of "google.api.Service".z[{}] cannot be used as it is an uncompiled proto file. However, uncompiled proto files can be included for display purposes when compiled as a source for a passed in proto descriptor.zqCould not determine the content type of file [{0}]. Supported extensions are .descriptor .json .pb .yaml and .yml)re   rf   rg   getri   rh   rk   rl   rI   IsProtoDescriptor<_Create__MakeApigatewayApiConfigGrpcServiceDefinitionMessage
IsRawProto)rR   filesgrpc_service_definitionsservice_configsrp   rq   rr   s          r-   __GrpcMessagesCreate.__GrpcMessages   s/     "O!77Do**;Hk	??6"&::

 
 778CEF $44Nf[!# # &&{33 ''FF.	/ ,,!22 vk"$ 	$ "22Cf[!# 	#3 : 44r0   c                     [         R                  " U/ SQ5      (       aD  [         R                  " U5      nU(       a  U$ [        R                  " SR                  U5      5      eg)a  Whether or not this is a valid json or yaml file.

Args:
  file_name: Name of the file
  file_contents: data for the file

Returns:
  Boolean for whether or not this is a JSON or YAML

Raises:
  BadFileException: File appears to be json or yaml but cannot be parsed.
)z.jsonz.yamlz.ymlz3Could not read JSON or YAML from config file [{0}].F)re   FilenameMatchesExtensionLoadJsonOrYamlrk   rl   rI   )rR   	file_namefile_contentsrr   s       r-   __ValidJsonOrYamlCreate.__ValidJsonOrYaml   s^     )))*DF F,,];k	!22VI&( 	( r0   c                     [         R                  " 5       nU(       d  [        R                  " U5      nUR	                  U[
        R                  R                  U5      S9$ )a  Constructs a ConfigFile message from a config file.

Args:
  file_contents: The contents of the config file.
  filename: The path to the config file.
  is_binary: If set to true, the file_contents won't be encoded.

Returns:
  The constructed ApigatewayApiConfigFile message.
)contentspath)rc   rd   r   EncodeApigatewayApiConfigFileosr   basename)rR   r   filename	is_binaryrn   s        r-   $__MakeApigatewayApiConfigFileMessage+Create.__MakeApigatewayApiConfigFileMessage   sR     002H#**=9m++WWh' ,  r0   c                 `   [         R                  " 5       n[        R                  R	                  U5      n[
        R                  R                  U5      n/ n/ n/ nUR                   H  n	[
        R                  R                  XYR                  5      n
[
        R                  R                  U
5      (       aL  [        R                  " U
5      nU R                  UU
5      nUR                  U
5        UR                  U5        M  UR                  U
5        M     U(       a5  [         R"                  " SR%                  SR                  U5      U5      5        U(       a5  [         R&                  " SR%                  SR                  U5      U5      5        U R                  XS5      nUR)                  XS9$ )a:  Constructs a GrpcServiceDefinition message from a proto descriptor and the provided list of input files.

Args:
  proto_desc_contents: The contents of the proto descriptor file.
  proto_desc_file: The path to the proto descriptor file.

Returns:
  The constructed ApigatewayApiConfigGrpcServiceDefinition message.
a  Proto descriptor's source protos [{0}] were not found on the file system and will not be included in the submitted GRPC service definition. If you meant to include these files, ensure the proto compiler was invoked in the same directory where the proto descriptor [{1}] now resides.z, zeAdded the source protos [{0}] to the GRPC service definition for the provided proto descriptor [{1}].T)fileDescriptorSetsource)rc   rd   
descriptorFileDescriptorSet
FromStringr   r   dirnamefilejoinrH   existsre   rf   rh   ri   r   warningrI   info(ApigatewayApiConfigGrpcServiceDefinition)rR   proto_desc_contentsproto_desc_filern   fdsproto_desc_dirgrpc_sourcesincluded_source_pathsnot_included_source_pathsfile_descriptorsource_pathsource_contentsr   file_descriptor_sets                 r-   5__MakeApigatewayApiConfigGrpcServiceDefinitionMessage<Create.__MakeApigatewayApiConfigGrpcServiceDefinitionMessage
  si    002H

&
&
1
12E
FCWW___5NL " 88GGLL1E1EFk		$	$#99+F889DF$$[1D!!((5 $ !	kk M
 &#<=OQ 	hh ;vdii 56HJ CCd4<<"5 = L Lr0    N)F)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr.   r]   rO   rM   rg   rh   rx   __static_attributes__r   r0   r-   r   r   +   sT     $K
- 0 04-^ D.5`4 6;,3Lr0   r   ).r   
__future__r   r   r   r   'cloudsdk.google.protobuf.descriptor_pb2googleprotobufdescriptor_pb2r   "googlecloudsdk.api_lib.api_gatewayr   r>   r   r<   r   rc   r	   r@    googlecloudsdk.api_lib.endpointsr
   re   googlecloudsdk.callioper   r   rk   &googlecloudsdk.command_lib.api_gatewayr   r   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   MAX_SERVICE_CONFIG_ID_LENGTHReleaseTracksReleaseTrackALPHABETAGADefaultUniverseOnlyCreateCommandr   r   r0   r-   <module>r      s     7 &  ' 	 < < P B F N G / ( E ? B @ < # 2!  D%%++T->->-C-C%%((*OLT OL *OLr0   