
    4                        S r SSKJr  SSKJr  SSKJr  SSKrSSK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 J!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*  \"RV                  RX                  S\"RV                  RZ                  S\"RV                  R\                  S0r/S r0S/r1 " S  S!\Rd                  5      r3g)"zDFunctions for creating a client to talk to the App Engine Admin API.    )absolute_import)division)unicode_literalsN)encoding)
exceptions)
list_pager)build)env)instances_util)operations_util)region_util)service_util)util)version_util)appengine_api_client_base)logs)convert_yaml)appinfo)base)log)
properties)	resources)filter)mapv1v1alphav1betac                 >    [         U    n[        R                  U5      $ N)APPENGINE_VERSIONS_MAPAppengineApiClientGetApiClient)release_trackapi_versions     6lib/googlecloudsdk/api_lib/app/appengine_api_client.pyGetApiClientForTrackr&   :   s    &}5+		(	(	55    python27c                   $   \ rS rSrSrS rS rS rS'S jrS(S jr	  S(S	 jr
S
 r  S(S jrS rS r S)S jrS rS r S*S jrS rS+S jrS'S jrS rS rS*S jrS*S jrS rS rS rS rS rS rS'S jr   S(S  jr!S! r"S" r#S# r$S$ r%S% r&S&r'g),r!   A   z=Client used by gcloud to communicate with the App Engine API.c                     U R                   R                  U R                  5       S9nU R                  R                  R                  U5      $ )zRetrieves the application resource.

Returns:
  An app resource representing the project's app.

Raises:
  apitools_exceptions.HttpNotFoundError if app doesn't exist
name)messagesAppengineAppsGetRequest
_FormatAppclientappsGet)selfrequests     r%   GetApplication!AppengineApiClient.GetApplicationD   s=     mm339J3KG;;((r'   c                     U R                   R                  U R                  5       US9nU R                  R                  R                  U5      $ )a'  Lists the available runtimes for the given App Engine environment.

Args:
  environment: The environment for the application, either Standard or
    Flexible.

Returns:
  v1beta|v1.ListRuntimesResponse, the list of Runtimes.

Raises:
  apitools_exceptions.HttpNotFoundError if app doesn't exist
)parentenvironment)r.    AppengineAppsListRuntimesRequestr0   r1   r2   ListRuntimes)r4   r:   r5   s      r%   r<   AppengineApiClient.ListRuntimesP   sF     mm<< k = G ;;((11r'   c                     UR                   U R                  R                  R                  R                  U R                  R                  R                  R
                  4;   nU$ )zChecks application resource to get serving status.

Args:
  app: appengine_v1_messages.Application, the application to check.

Returns:
  bool, whether the application is currently disabled. If serving or not
    set, returns False.
)servingStatusr.   ApplicationServingStatusValueValuesEnumUSER_DISABLEDSYSTEM_DISABLED)r4   appstoppeds      r%   	IsStoppedAppengineApiClient.IsStoppedb   sT     !!>>LL!!>>NN$P PG Nr'   Nc                 x   U R                   R                  U R                  5       U R                   R                  5       S9nU R                  R
                  R                  U5      n[        R                  " SR                  UR                  S95        [        R                  " U R                  R                  X1S9$ )zCreates missing app resources.

In particular, the Application.code_bucket GCS reference.

Args:
  progress_message: str, the message to use while the operation is polled,
    if not the default.

Returns:
  A long running operation.
)r-   repairApplicationRequest!Received operation: [{operation}]	operationmessage)r.   AppengineAppsRepairRequestr0   RepairApplicationRequestr1   r2   Repairr   debugformatr-   r   WaitForOperationapps_operations)r4   progress_messager5   rL   s       r%   RepairApplication$AppengineApiClient.RepairApplicationq   s     mm66__!%!G!G!I 7 KG   ''0III188.. 9 " # ++##YJ Jr'   c                    SnU(       a%  U R                   R                  U R                  XS9nO$U R                   R                  U R                  US9nU(       a  X4l        U R                  R
                  R                  U5      n[        R                  " SR                  UR                  S95        SR                  U R                  US9n[        R                  " U R                  R                  XVS9$ )	aH  Creates an App Engine app within the current cloud project.

Creates a new singleton app within the currently selected Cloud Project.
The action is one-time and irreversible.

Args:
  location: str, The location (region) of the app, i.e. "us-central"
  service_account: str, The app level service account of the app, i.e.
    "123@test-app.iam.gserviceaccount.com"
  ssl_policy: enum, the app-level SSL policy to update for this App Engine
    app. Can be DEFAULT or MODERN.

Raises:
  apitools_exceptions.HttpConflictError if app already exists

Returns:
  A long running operation.
N)id
locationIdserviceAccount)rZ   r[   rJ   rK   zMCreating App Engine application in project [{project}] and region [{region}].)projectregionrM   )r.   r@   r]   	sslPolicyr1   r2   Creater   rR   rS   r-   r   rT   rU   )r4   locationservice_account
ssl_policycreate_requestrL   rN   s          r%   	CreateAppAppengineApiClient.CreateApp   s    & N}}00\\h 1 Pn }}00\\h 1 0n !+  ''7III188.. 9 " #$$*F4<<2: %+ %<  ++DKK,G,G,5H Hr'   c           	         U R                  XUXEUU5      nSR                  US9n	UR                  [        R                  [        R                  4;   a  U	S-  n	U R                  5       n
U(       a  UR                  5       (       a  U
(       d  [        R                  " S5        O[        R                  " U R                  R                  U
5      n[        R                  " U R                  R                  XUS9n[        R                  " X5      nU(       a  [        R                   R#                  U5      nU(       a  UR%                  5       (       a   [&        R(                  R+                  UR,                  S[.        R0                  R2                  R4                  R6                  0SS9n[8        R:                  " 5       R=                  U[        R>                  S	9  [        RN                  " U R                  R                  U
5      n[        R                  " U R                  R                  UUS9$ ! [@        RB                   a    [D        RF                  " U RI                  5       RJ                  5      n[&        R(                  RM                  S
[.        R0                  R2                  R4                  R6                  UUR,                  S9n[8        R:                  " 5       R=                  U[        R>                  S	9   GN!f = f)a  Updates and deploys new app versions.

Args:
  service_name: str, The service to deploy.
  version_id: str, The version of the service to deploy.
  service_config: AppInfoExternal, Service info parsed from a service yaml
    file.
  manifest: Dictionary mapping source files to Google Cloud Storage
    locations.
  build: BuildArtifact, a wrapper which contains either the build
    ID for an in-progress parallel build, the name of the container image
    for a serial build, or the options for creating a build elsewhere. Not
    present during standard deploys.
  extra_config_settings: dict, client config settings to pass to the server
    as beta settings.
  service_account_email: Identity of this deployed version. If not set, the
    Admin API will fall back to use the App Engine default appspot service
    account.

Returns:
  The Admin API Operation, unfinished.

Raises:
  apitools_exceptions.HttpNotFoundError if build ID doesn't exist
zUpdating service [{service}]servicez  (this may take several minutes)zIUnable to determine build from Operation metadata. Skipping log streaming)rN   poller	projectIdzcloudbuild.projects.builds)params
collection)outz$cloudbuild.projects.locations.builds)rm   
projectsIdlocationsIdbuildsId)rj   )(_CreateVersionrS   r
   FLEXMANAGED_VMS_ResolveMetadataTypeIsBuildOptionsr   warningr   AppEngineOperationBuildPollerr1   rU   rT   GetBuildFromOperationapp_cloud_buildBuildArtifactMakeBuildIdArtifact	IsBuildIdr   REGISTRYParse
identifierr   VALUEScorer]   	GetOrFailcloudbuild_logsCloudBuildClientStreamstatusapitools_exceptionsHttpNotFoundErrorr   ConvertToCloudRegionr6   r[   r`   AppEngineOperationPoller)r4   service_name
version_idservice_configmanifestr	   extra_config_settingsservice_account_emailrL   rN   operation_metadata_typerj   build_id	build_refr^   done_pollers                   r%   DeployService AppengineApiClient.DeployService   si   B ##Ln$,5J$9;I -33L3IGchh8833g"779%%''$ - 	. !>>KK'')@B#44KK''	 #880!//CCHM%""M&&,,!2!2!7!7!?!?!I!IJ3 - 5	 	((*11)1L "::##%<>K++##  !22 M**4+>+>+@+K+KL&&--=!((--55??%%	 . '	
 	((*11)1LMs   BH- -C	K:9K:c                 |    SU R                   R                  R                  5       -   n[        U R                  U5      $ )zAAttempts to resolve the expected type for the operation metadata.OperationMetadata)r1   _VERSIONtitlegetattrr.   )r4   metadata_type_names     r%   ru   'AppengineApiClient._ResolveMetadataType  s4     -t{{/C/C/I/I/KK4=="455r'   c                     U R                  X4X%UU5      nU R                  R                  U R                  US9US9n	U R                  R
                  R                  U	5      $ )ac  Begins the updates and deployment of new app versions.

Args:
  service_name: str, The service to deploy.
  version_id: str, The version of the service to deploy.
  service_config: AppInfoExternal, Service info parsed from a service yaml
    file.
  manifest: Dictionary mapping source files to Google Cloud Storage
    locations.
  build: BuildArtifact, a wrapper which contains either the build ID for an
    in-progress parallel build, the name of the container image for a serial
    build, or the options to pass to Appengine for a server-side build.
  extra_config_settings: dict, client config settings to pass to the server
    as beta settings.
  service_account_email: Identity of this deployed version. If not set, the
    Admin API will fall back to use the App Engine default appspot service
    account.

Returns:
  The Admin API Operation, unfinished.
r   )r9   version)_CreateVersionResourcer.   *AppengineAppsServicesVersionsCreateRequest_GetServiceRelativeNamer1   apps_services_versionsr`   )
r4   r   r   r   r   r	   r   r   version_resourcerd   s
             r%   rr   !AppengineApiClient._CreateVersion  sn    : 22>3=3H3HJ ]]MM+++F  N "N ;;--44^DDr'   c                     U R                   R                  U R                  U5      S9nU R                  R                  R                  U5      $ )zzDescribe the given service.

Args:
  service: str, the ID of the service

Returns:
  Service resource object from the API
r,   )r.   AppengineAppsServicesGetRequestr   r1   apps_servicesr3   )r4   ri   r5   s      r%   GetServiceResource%AppengineApiClient.GetServiceResource3  sF     mm;;))'2 < 4G;;$$((11r'   c                 ,    US0nU R                  X5      $ )zSets the default serving version of the given services.

Args:
  service_name: str, The service name
  version_id: str, The version to set as default.
Returns:
  Long running operation.
g      ?)SetTrafficSplit)r4   r   r   allocationss       r%   SetDefaultVersion$AppengineApiClient.SetDefaultVersion@  s     s#K::r'   c                    [         R                  " U R                  R                  UUS.5      nU R                  R	                  U R                  US9U R                  R                  US9USS9nSR                  US9nU R                  R                  R                  U5      n[        R                  " U R                  R                  UUS9$ )	a2  Sets the traffic split of the given services.

Args:
  service_name: str, The service name
  allocations: A dict mapping version ID to traffic split.
  shard_by: A ShardByValuesEnum value specifying how to shard the traffic.
  migrate: Whether or not to migrate traffic.
Returns:
  Long running operation.
)r   shardByr   )splitr   )r-   ri   migrateTraffic
updateMaskz-Setting traffic split for service [{service}]rh   rM   )r   PyValueToMessager.   TrafficSplit!AppengineAppsServicesPatchRequestr   ServicerS   r1   r   Patchr   rT   rU   )	r4   r   r   shard_bymigratetraffic_splitupdate_service_requestrN   rL   s	            r%   r   "AppengineApiClient.SetTrafficSplitN  s     --dmm.H.H>I:B/DEM "]]LL))|)D%%M%:	 M  >DD E G))//0FGI++DKK,G,G,54;= =r'   c                 l   U R                   R                  US9nU R                   R                  U R                  US9U R                   R	                  US9SS9nSR                  US9nU R                  R                  R                  U5      n[        R                  " U R                  R                  XeS9$ )	zSets the ingress traffic allowed for a service.

Args:
  service_name: str, The service name
  ingress_traffic_allowed: An IngressTrafficAllowed enum.

Returns:
  The completed Operation. The Operation will contain a Service resource.
)ingressTrafficAllowedr   )networkSettingsr   )r-   ri   r   z0Setting ingress settings for service [{service}]rh   rM   )r.   NetworkSettingsr   r   r   rS   r1   r   r   r   rT   rU   )r4   r   ingress_traffic_allowednetwork_settingsr   rN   rL   s          r%   SetIngressTrafficAllowed+AppengineApiClient.SetIngressTrafficAllowedl  s     }}445 5 7!]]LL))|)D%%6F%G$ M &
 AGG H G))//0FGI++##YA Ar'   c                    U R                   R                  U R                  UUS9S9nU R                  R                  R                  U5      nSR                  X5      n[        R                  " U R                  R                  XES9$ )zDeletes the specified version of the given service.

Args:
  service_name: str, The service name
  version_id: str, The version to delete.

Returns:
  The completed Operation.
r   r   r,   zDeleting [{0}/{1}]rM   )
r.   *AppengineAppsServicesVersionsDeleteRequest_FormatVersionr1   r   DeleterS   r   rT   rU   )r4   r   r   delete_requestrL   rN   s         r%   DeleteVersion AppengineApiClient.DeleteVersion  s     ]]MM  l,6 ! 8 N 9N 2299.II")),CG++##YA Ar'   c                 4   U R                   R                  U R                  UUS9U R                   R                  US9SS9nU R                  R
                  R                  U5      nU(       a+  [        R                  " U R                  R                  U5      $ U$ )aX  Sets the serving status of the specified version.

Args:
  service_name: str, The service name
  version_id: str, The version to delete.
  serving_status: The serving status to set.
  block: bool, whether to block on the completion of the operation

Returns:
  The completed Operation if block is True, or the Operation to wait on
  otherwise.
r   )r?   r?   )r-   r   r   )
r.   )AppengineAppsServicesVersionsPatchRequestr   Versionr1   r   r   r   rT   rU   )r4   r   r   serving_statusblockpatch_requestrL   s          r%   SetServingStatus#AppengineApiClient.SetServingStatus  s     MMKK  l,6 ! 8%%N%C"	 L $M
 2288GI--dkk.I.I.79 9 r'   c           	         / nU H  nU R                   R                  U R                  UR                  UR                  5      S9n [
        R                  " U R                  R                  USSSS9 H1  nUR                  [        R                  R                  U5      5        M3     M     U$ ! [        R                   a     M  f = f)zProduces a generator of all instances for the given versions.

Args:
  versions: list of version_util.Version

Returns:
  A list of instances_util.Instance objects for the given versions
r9   	instancesd   pageSizefield
batch_sizebatch_size_attribute)r.   1AppengineAppsServicesVersionsInstancesListRequestr   ri   rZ   r   YieldFromListr1    apps_services_versions_instancesappendr   InstanceFromInstanceResourcer   r   )r4   versionsr   r   r5   instances         r%   ListInstances AppengineApiClient.ListInstances  s     IOO$$W__gjjA P Cg"00KK88!+-H 

%%::8DF-	   !22 s   A!B--CCc           
         U R                  5       n[        R                  " SR                  U5      5        [        R
                  " XA(       a  U/OS5      nU R                  U5      n[        R                  " SR                  [        [        [        U5      5      5      5        [        R                  " XR(       a  U/OSU5      n[        [        X55      5      nU R                  U5      $ )a(  Generator of all instances, optionally filtering by service or version.

Args:
  service: str, the ID of the service to filter by.
  version: str, the ID of the version to filter by.
  version_filter: filter function accepting version_util.Version

Returns:
  generator of instance_util.Instance
zAll services: {0}NzVersions: {0})ListServicesr   rR   rS   r   GetMatchingServicesListVersionslistr   strr   GetMatchingVersionsr   r   )r4   ri   r   version_filterservicesr   s         r%   GetAllInstances"AppengineApiClient.GetAllInstances  s       "HII!((23//w7)D2H   *HIIo$$T#c8*<%=>?//w7)D';HF>45Hh''r'   c                     U R                   R                  UR                  5       U R                   R                  US9S9nU R                  R
                  R                  U5      n[        R                  " U R                  R                  U5      $ )a  Enable debugging of a Flexible instance.

Args:
  res: A googleclousdk.core.Resource object.
  ssh_key: str, Public SSH key to add to the instance. Examples:
    `[USERNAME]:ssh-rsa [KEY_VALUE] [USERNAME]` ,
    `[USERNAME]:ssh-rsa [KEY_VALUE] google-ssh {"userName":"[USERNAME]",`
    `"expireOn":"[EXPIRE_TIME]"}`
    For more information, see Adding and Removing SSH Keys
    (https://cloud.google.com/compute/docs/instances/adding-removing-ssh-
    keys).

Returns:
  The completed Operation.
)sshKey)r-   debugInstanceRequest)
r.   2AppengineAppsServicesVersionsInstancesDebugRequestRelativeNameDebugInstanceRequestr1   r   Debugr   rT   rU   )r4   resssh_keyr5   rL   s        r%   DebugInstance AppengineApiClient.DebugInstance  s~      mmNN!]]??w?O O QG <<BB7KI++DKK,G,G,57 7r'   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      n[        R                  " U R                  R                  U5      $ )zvDelete a Flexible instance.

Args:
  res: A googlecloudsdk.core.Resource object.

Returns:
  The completed Operation.
r,   )	r.   3AppengineAppsServicesVersionsInstancesDeleteRequestr   r1   r   r   r   rT   rU   )r4   r   r5   rL   s       r%   DeleteInstance!AppengineApiClient.DeleteInstance  sf     mmOO P !G<<CCGLI++DKK,G,G,57 7r'   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )zDescribe the given instance of the given version of the given service.

Args:
  res: A googlecloudsdk.core.Resource object.

Raises:
  apitools_exceptions.HttpNotFoundError: If instance does not
    exist.

Returns:
  Version resource object from the API
r,   )r.   0AppengineAppsServicesVersionsInstancesGetRequestr   r1   r   r3   )r4   r   r5   s      r%   GetInstanceResource&AppengineApiClient.GetInstanceResource  sE     mmLL M !G;;77;;GDDr'   c                 z    U R                  UUU R                  R                  R                  R                  U5      $ )a  Stops the specified version.

Args:
  service_name: str, The service name
  version_id: str, The version to stop.
  block: bool, whether to block on the completion of the operation


Returns:
  The completed Operation if block is True, or the Operation to wait on
  otherwise.
)r   r.   r   rA   STOPPEDr4   r   r   r   s       r%   StopVersionAppengineApiClient.StopVersion  s9       ::BB	 r'   c                 z    U R                  UUU R                  R                  R                  R                  U5      $ )a  Starts the specified version.

Args:
  service_name: str, The service name
  version_id: str, The version to start.
  block: bool, whether to block on the completion of the operation

Returns:
  The completed Operation if block is True, or the Operation to wait on
  otherwise.
)r   r.   r   rA   SERVINGr  s       r%   StartVersionAppengineApiClient.StartVersion,  s9       ::BB	 r'   c                    U R                   R                  U R                  5       S9n/ n[        R                  " U R
                  R                  USSSS9 H  n0 nUR                  (       a?  UR                  R                  R                   H  nUR                  XER                  '   M     UR                  [        R                  " U R                  UR                   U5      5        M     U$ )zbLists all services for the given application.

Returns:
  A list of service_util.Service objects.
r   r   r   r   r   )r.    AppengineAppsServicesListRequestr0   r   r   r1   r   r   r   additionalPropertiesvaluekeyr   r   r   r]   rZ   )r4   r5   r   ri   r   r   s         r%   r   AppengineApiClient.ListServices>  s     mm<<  = "GH++!!7*Z9 m	]]..CCE%*[[-		
" Doo


t||WZZ
GI9 Or'   c                     U R                   R                  U R                  X5      U R                   R                  R                  R                  S9nU R
                  R                  R                  U5      $ )zDescribe the given version of the given service.

Args:
  service: str, the ID of the service for the version to describe.
  version: str, the ID of the version to describe.

Returns:
  Version resource object from the API.
)r-   view)r.   'AppengineAppsServicesVersionsGetRequestr   ViewValueValuesEnumFULLr1   r   r3   )r4   ri   r   r5   s       r%   GetVersionResource%AppengineApiClient.GetVersionResourceR  sa     mmCC  2mm556I6I$$ D QG ;;--11'::r'   c           	      z   / nU H  nU R                   R                  U R                  UR                  5      S9n [        R
                  " U R                  R                  USSSS9 H1  nUR                  [        R                  R                  XS5      5        M3     M     U$ ! [        R                   a     M  f = f)zLists all versions for the specified services.

Args:
  services: A list of service_util.Service objects.
Returns:
  A list of version_util.Version objects.
r   r   r   r   r   )r.   (AppengineAppsServicesVersionsListRequestr   rZ   r   r   r1   r   r   r   r   FromVersionResourcer   r   )r4   r   r   ri   r5   r   s         r%   r   AppengineApiClient.ListVersionsb  s     HFF--gjj9 G ;g!//KK..!+-G //""66wHJ- " O	 !22 s   A!B""B:9B:c                 (   U R                   R                  SR                  U R                  5      S9n[        R
                  " U R                  R                  USSSS9nU Vs/ s H"  n[        R                  R                  U5      PM$     sn$ s  snf )zList all regions for the project, and support for standard and flexible.

Returns:
  List of region_util.Region instances for the project.
zapps/{0}r,   	locationsr   r   r   )r.   !AppengineAppsLocationsListRequestrS   r]   r   r   r1   apps_locationsr   RegionFromRegionResource)r4   r5   regionslocs       r%   ListRegionsAppengineApiClient.ListRegions~  s     mm==t||, > .G &&""G;Z9G CJJ'3K11#6'JJJs   #)Bc                    U R                   R                  U R                  US9S9nU R                  R                  R                  U5      nSR                  U5      n[        R                  " U R                  R                  UUS9$ )zDeletes the specified service.

Args:
  service_name: str, Name of the service to delete.

Returns:
  The completed Operation.
r   r,   zDeleting [{}]rM   )
r.   "AppengineAppsServicesDeleteRequestr   r1   r   r   rS   r   rT   rU   )r4   r   r   rL   rN   s        r%   DeleteService AppengineApiClient.DeleteService  s     ]]EE))|)D F FN))00@I$$\2G++DKK,G,G,54;= =r'   c                     U R                   R                  U R                  U5      S9nU R                  R                  R                  U5      $ )zGrabs details about a particular gcloud operation.

Args:
  op_id: str, ID of operation.

Returns:
  Operation resource object from API call.
r,   )r.   !AppengineAppsOperationsGetRequest_FormatOperationr1   rU   r3   )r4   op_idr5   s      r%   GetOperationAppengineApiClient.GetOperation  sH     mm==""5) > +G ;;&&**733r'   c                    U R                   R                  U R                  5       US9n[        R                  " U R
                  R                  USSSS9nU Vs/ s H  n[        R                  " U5      PM     sn$ s  snf )zLists all operations for the given application.

Args:
  op_filter: String to filter which operations to grab.

Returns:
  A list of opeartion_util.Operation objects.
)r-   r   
operationsr   r   r   )	r.   "AppengineAppsOperationsListRequestr0   r   r   r1   rU   r   	Operation)r4   	op_filterr5   r9  ops        r%   ListOperations!AppengineApiClient.ListOperations  sw     mm>>__ ? G ))##WLZ9J 5??JbO%%b)J???s    A<c           
      \   [         R                  " UR                  R                  5       5      nSU;  a  SUS'   SU;   a  SU;   a  [        R
                  " S5      e [        R                  " U R                  R                  5      nUR                  U5      n	[         R"                  " S	R                  [$        R&                  " U	S
SS95      5        Ub  XiS'   0 U	S'   X)S   S'   U(       a{  UR)                  5       (       a  SUR*                  0U	S   S'   OQUR-                  5       (       a  SUR*                  0U	S   S'   O'UR/                  5       (       a  UR*                  U	S   S'   [0        R2                  " U R4                  R6                  U	5      nUR8                  (       a$  UR8                  R:                  R=                  S S9  U(       a  SU	;  a  0 U	S'   U	S   R?                  U5        SU	;   a  U	RA                  S5      n/ n[C        URE                  5       5       HA  u  pURG                  U R4                  R6                  RH                  RK                  XS95        MC     U R4                  R6                  RI                  US9Ul&        SU	;   a  / n[C        U	S   5       Hd  nURO                  5       n[         R"                  " SU5         URG                  [Q        U R4                  R6                  RR                  U5      5        Mf     U(       a?  [         R"                  " SU5        UUl.        [         R"                  " SUR\                  5         UR^                  R`                  R:                  R=                  [b        Rd                  " S 5      S9  X;l3        U$ ! [         aG  n
[        R
                  " SR                  UR                  [        R                  " U
5      S95      eSn
A
ff = f! [T         a$    [V        RX                  R[                  SU S35      ef = f! [T         a     Nf = f)!a  Constructs a Version resource for deployment.

Args:
  service_config: ServiceYamlInfo, Service info parsed from a service yaml
    file.
  manifest: Dictionary mapping source files to Google Cloud Storage
    locations.
  version_id: str, The version of the service.
  build: BuildArtifact, The build ID, image path, or build options.
  extra_config_settings: dict, client config settings to pass to the server
    as beta settings.
  service_account_email: identity of this deployed version. If not set,
    Admin API will fallback to use the App Engine default appspot SA.

Returns:
  A Version resource whose Deployment includes either a container pointing
    to a completed image, or a build pointing to an in-progress build.

entrypoint app_engine_apisapp_engine_bundled_serviceszdCannot specify both `app_engine_apis` and `app_engine_bundled_services` in the same `app.yaml` file.zc[{f}] could not be converted to the App Engine configuration format for the following reason: {msg})fmsgNzConverted YAML to JSON: "{0}"   T)indent	sort_keysr\   
deploymentfilesimage	containercloudBuildIdr	   cloudBuildOptionsc                     U R                   $ r   r  )xs    r%   <lambda>;AppengineApiClient._CreateVersionResource.<locals>.<lambda>
  s    r'   rQ  betaSettings)r  r  )r  appEngineBundledServiceszenum_value: %szInvalid bundled service: .zBundled services enums: %sz-version_resource.appEngineBundledServices: %sr  )4copydeepcopyparsedToDictr   ConfigErrorr   GetSchemaParserr1   r   ConvertValue
ValueErrorrS   filesix	text_typer   rR   jsondumpsIsImager   r}   rv   r   r   r.   r   envVariablesr  sortupdategetsorteditemsr   BetaSettingsValueAdditionalPropertyrU  upperr   0AppEngineBundledServicesValueListEntryValuesEnumAttributeErrorr   
validationValidationErrorrV  rJ  rK  operator
attrgetterrZ   )r4   r   r   r   r	   r   r   config_dictschema_parserjson_version_resourceer   	json_dict
attributesr  r  bundled_services_enumsr   
enum_values                      r%   r   )AppengineApiClient._CreateVersionResource  s   2 -- 5 5 < < >?K ;&"$k, 	[()[8""G 
<"224;;3G3GHm+88E II-44

(dCE F (0E,-*,,'3;,'0	U%%<
l+K8 ??E,,8
l+G4 !! 	l+,?@001F1F1FH $$##88== >  	4	402n-N+223HI ..'++N;ijy01*#MM!!33FF G &	' 2 '+mm&;&;&M&M) 'N '+# "%::! 
 :
;, "'')
		"J/
	
 
'
'--''XX  
 		(*@	
 5K1		;55	
!!''<<AA!!%( B  %}  <""3396##q)9 4: 4;< <<J  	""22),q9 	(  
s8   ;N 9O-AP 
O*#AO%%O*-.P
P+*P+c                    SnU R                   R                  5       nU Vs/ s H  nU R                   R                  " S0 UD6PM!     snUl        U R                   R	                  U R                  5       UUS9nU R                  R                  R                  U5      n[        R                  " SR                  UR                  US95        [        R                  " U R                  R                  U5      $ s  snf )zUpdates an application's dispatch rules.

Args:
  dispatch_rules: [{'service': str, 'domain': str, 'path': str}], dispatch-
      rules to set-and-replace.

Returns:
  Long running operation.
zdispatchRules,r-   applicationr   4Received operation: [{operation}] with mask [{mask}]rL   mask )r.   r@   UrlDispatchRuledispatchRulesAppengineAppsPatchRequestr0   r1   r2   r   r   rR   rS   r-   r   rT   rU   )r4   dispatch_rulesupdate_maskapplication_updaterupdate_requestrL   s          r%   UpdateDispatchRules&AppengineApiClient.UpdateDispatchRulesJ  s     #K2241?(A1?A )-(E(E(J(J1?(A$]]<<__& =  N
   &&~6IIIDKK.. L   ++DKK,G,G,57 7(As   &C6c                    SnU R                   R                  5       nXl        U R                   R                  U R	                  5       UUS9nU R
                  R                  R                  U5      n[        R                  " SR                  UR                  US95        [        R                  " U R
                  R                  U5      $ )zUpdates an application's database_type.

Args:
  database_type: New database type to switch to

Returns:
  Long running operation.
databaseTyper  r  r  )r.   r@   r  r  r0   r1   r2   r   r   rR   rS   r-   r   rT   rU   )r4   database_typer  r  r  rL   s         r%   UpdateDatabaseType%AppengineApiClient.UpdateDatabaseTypei  s     !K224&3#]]<<__& =  N
   &&~6IIIDKK..{ L 4 5 ++DKK,G,G,57 7r'   c                     U R                   R                  U R                  U5      U R                   R                  US9S9nU R                  R
                  R                  U5      $ )zChecks if the service contains a Gen1 app.

Args:
  service_name: str, The service name
  project_id: str, The project id

Returns:
  boolean, True if the service contains a Gen1 app, False otherwise
)rk   )r-   checkGen1AppIdRequest)r.   3AppengineAppsServicesMigrationCheckGen1appIdRequestr   CheckGen1AppIdRequestr1   apps_services_migrationCheckGen1appId)r4   r   
project_idr5   s       r%   CheckGen1AppId!AppengineApiClient.CheckGen1AppId  sd     mmOO)),7"mmAA  B 
 P G ;;..==gFFr'   c           	         U[         ;   a+  U R                  R                  R                  R                  nO*U R                  R                  R                  R
                  nU R                  R                  U R                  U5      U R                  R                  UUUS9S9nU R                  R                  R                  U5      $ )a  Migrates the app.yaml file provided by the user to be Gen2 compatible.

Args:
  project_id: str, The project id
  config_as_string: str, The config as a string
  runtime: str, The runtime
  service_name: str, The service name

Returns:
  str, The migrated config as a string
)rk   configAsStringruntime)r-   migrateConfigYamlRequest)gen1_runtimesr.   MigrateConfigYamlRequestRuntimeValueValuesEnumGEN1_PYTHON27$MIGRATION_ASSIST_RUNTIME_UNSPECIFIED6AppengineAppsServicesMigrationMigrateConfigYamlRequestr   r1   r  MigrateConfigYaml)r4   r  config_as_stringr  r   runtime_enumreqs          r%   r  $AppengineApiClient.MigrateConfigYaml  s     -
--
0
0
G
G
U
U 
 --
0
0
G
G
l
l  --
N
N)),7!%!G!G +  "H "
 O C ;;..@@EEr'   c           	         U[         ;   a+  U R                  R                  R                  R                  nO*U R                  R                  R                  R
                  nU R                  R                  U R                  U5      U R                  R                  UUUS9S9nU R                  R                  R                  U5      n[        R                  " U R                  R                  U5      $ )zMigrates the code file provided by the user to Gen2 runtime.

Args:
  project_id: str, The project id
  code_as_string: str, The code as a string
  runtime: str, The runtime
  service_name: str, The service name

Returns:
  Long running operation
)rk   codeAsStringr  )r-   migrateCodeFileRequest)r  r.   MigrateCodeFileRequestr  r  r  4AppengineAppsServicesMigrationMigrateCodeFileRequestr   r1   r  MigrateCodeFiler   rT   rU   )r4   r  code_as_stringr  r   r  r5   rL   s           r%   r  "AppengineApiClient.MigrateCodeFile  s     -
--
.
.
E
E
S
S 
 --
.
.
E
E
j
j  	JJ--l;#'==#G#G$+$ $H $ 	K 	
  33CCGLI++##Y r'   r  r   )NN)UNSPECIFIEDF)T)NNN)(__name__
__module____qualname____firstlineno____doc__r6   r<   rF   rW   re   r   ru   rr   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r  r   r,  r0  r6  r>  r   r  r  r  r  r  __static_attributes__r  r'   r%   r!   r!   A   s    E
)2$J0'H^ +/*.Pd6 ,0+/%EN2; 7<=<A.A& "46(07.7E"&$(; 8K="4@. 4837KZ7>76G$F@!r'   r!   )4r  
__future__r   r   r   rX  rc  rs  apitools.base.pyr   r   r   r   googlecloudsdk.api_lib.appr	   rz   r
   r   r   r   r   r   r   googlecloudsdk.api_lib.app.apir   !googlecloudsdk.api_lib.cloudbuildr   r   /googlecloudsdk.appengine.admin.tools.conversionr   googlecloudsdk.appengine.apir   googlecloudsdk.callioper   calliope_basegooglecloudsdk.corer   r   r   ra  	six.movesr   r   ReleaseTrackGAALPHABETAr    r&   r  AppengineApiClientBaser!   r  r'   r%   <module>r     s     K &  '    % > ' ? * 1 5 6 2 3 + 3 D E H 0 9 # * ) 
   !!4$$i##X 6 V2II Vr'   