
    0                         S 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\5      rg)zApphub Applications API.    )absolute_import)division)unicode_literals)
list_pager)consts)utils)waiter)base)iam_utilc                       \ rS rSrSr\R                  R                  4S jrS r	  SS jr
S r\R                  R                  4S jrS	 rS
 rS rS rS rS rSrg)ApplicationsClient   z&Client for Applications in apphub API.c                 "   [         R                  " U5      U l        [         R                  " U5      U l        U R                  R
                  U l        U R                  R                  U l        [        R                  " U R                  U R                  R                  5      U l        [        R                  " U R                  R                  5      U l        [        R                  " U R                  U R                  R                  5      U l        g )N)api_lib_utilsGetClientInstanceclientGetMessagesModulemessagesprojects_locations_applications_app_clientprojects_locations_lookup_clientr	   CloudOperationPollerprojects_locations_operations_pollerCloudOperationPollerNoResources_delete_poller_lookup_poller)selfrelease_tracks     8lib/googlecloudsdk/api_lib/apphub/applications/client.py__init__ApplicationsClient.__init__    s    11-@DK!33MBDM{{BBD++88D..11DL !@@11D !5511D    c                 j    U R                   R                  US9nU R                  R                  U5      $ )zDescribe an application in the Project/location.

Args:
  app_id: str, the application id.

Returns:
  Described service project Resource.
name)r   -ApphubProjectsLocationsApplicationsGetRequestr   Get)r   app_iddescribe_reqs      r!   DescribeApplicationsClient.Describe1   s:     ==NN O L --r$   Nc           	      z    U R                   R                  US9n[        R                  " U R                  USUUSS9$ )a}  List applications in the Projects/Location.

Args:
  parent: str, projects/{projectId}/locations/{location}
  limit: int or None, the total number of results to return. Default value
    is None
  page_size: int, the number of entries in each batch (affects requests
    made, but not the yielded results). Default value is 100.

Returns:
  Generator of matching service projects.
)parentapplicationspageSize)field
batch_sizelimitbatch_size_attribute)r   .ApphubProjectsLocationsApplicationsListRequestr   YieldFromListr   )r   r/   r4   	page_sizelist_reqs        r!   ListApplicationsClient.List?   sN    $ }}KK L H ##' r$   c           	         U R                   R                  UUU R                   R                  U R                   R                  R                  U5      S9US9nU R                   R	                  XUS9n	U R
                  R                  U	5      n
U(       a  U
$ [        R                  " U R                  U
[        R                  R                  [        R                  R                  5      nU$ )a  Creates an application in the Project/location.

Args:
  app_id: str, Application ID
  scope_type: str, Scope of the Application
  display_name: str, Human-friendly display name
  description: str, Description of the Application
  attributes: Attributes, Attributes of the Application
  async_flag: Boolean value for async operation. If true the operation will
    be async
  parent: parent for project resource

Returns:
  Application or Operation based on async flag value.
type)descriptiondisplayNamescope
attributes)applicationapplicationIdr/   )r   ApplicationScopeTypeValueValuesEnum0ApphubProjectsLocationsApplicationsCreateRequestr   Creater   WaitForOperationr   api_lib_constsCreateApplicationWAIT_FOR_ADD_MESSAGEADD_TIMELIMIT_SEC)r   r*   
scope_typedisplay_namer?   rB   
async_flagr/   rC   
create_req	operationcreate_responses               r!   rI   ApplicationsClient.Create]   s    2 --++ mm!!$$88D " 
  , K OOf P J   ''
3I#44((==((::	O r$   c                    Sn[         R                  " U5      R                  5       nU R                  R	                  US9nUR
                  b  [         R                  " U5      R                  [         R                  " U5      R                  R                  UR
                  5      S9Ul        [         R                  " U[        R                  R                  5      nUR                  (       a  [         R                  " U5      R                  [         R                  " U5      R                  R                  UR                  5      S9Ul        [         R                  " U[        R                  R                   5      nUR"                  =(       d    /  GH#  n[         R                  " U5      R%                  5       nUR'                  SS5      Ul        UR'                  SS5      (       a  UR'                  SS5      Ul        U[,        R.                  R0                  :X  aN  UR'                  SS5      (       a7  [         R                  " U5      R3                  UR'                  S5      S9Ul        UR6                  R9                  U5        [         R                  " U[        R                  R:                  5      nGM&     UR<                  =(       d    /  GH#  n	[         R                  " U5      R%                  5       n
U	R'                  SS5      U
l        U	R'                  SS5      (       a  U	R'                  SS5      U
l        U[,        R.                  R0                  :X  aN  U	R'                  SS5      (       a7  [         R                  " U5      R3                  U	R'                  S5      S9U
l        UR>                  R9                  U
5        [         R                  " U[        R                  R@                  5      nGM&     URB                  =(       d    /  GH   n[         R                  " U5      R%                  5       nUR'                  SS5      Ul        UR'                  S5      (       a  UR'                  S5      Ul        U[,        R.                  R0                  :X  aM  UR'                  S5      (       a7  [         R                  " U5      R3                  UR'                  S5      S9Ul        URD                  R9                  U5        [         R                  " U[        R                  RF                  5      nGM#     URH                  b@  URH                  Ul        [         R                  " U[        R                  RJ                  5      nURL                  b@  URL                  Ul&        [         R                  " U[        R                  RN                  5      nU R                  RQ                  UURS                  5       US	9nU RT                  RW                  U5      nURX                  (       a  U$ [         RZ                  " U R\                  U[        R                  R^                  [        R                  R`                  5      nU$ )
zUpdates an Apphub application.

Args:
  args: args, Arguments provided by the client
  app_ref: Application reference
  release_track: release_track provided by the client

Returns:
  Application or Operation based on async flag value.
 )rB   Nr=   emailzdisplay-namezchannel-uri)uri)rC   r'   
updateMask)1r   r   
Attributesr   rE   environment_typeEnvironmentrG   environmentAddToUpdateMaskrK   UpdateApplication"UPDATE_MASK_ENVIRONMENT_FIELD_NAMEcriticality_typeCriticalitycriticality"UPDATE_MASK_CRITICALITY_FIELD_NAMEbusiness_ownersContactInfogetrX   r@   r
   ReleaseTrackALPHAChannelchannelbusinessOwnersappend&UPDATE_MASK_BUSINESS_OWNERS_FIELD_NAMEdeveloper_ownersdeveloperOwners'UPDATE_MASK_DEVELOPER_OWNERS_FIELD_NAMEoperator_ownersoperatorOwners&UPDATE_MASK_OPERATOR_OWNERS_FIELD_NAMErP   #UPDATE_MASK_DISPLAY_NAME_FIELD_NAMEr?   "UPDATE_MASK_DESCRIPTION_FIELD_NAME/ApphubProjectsLocationsApplicationsPatchRequestRelativeNamer   Patchasync_rJ   r   WAIT_FOR_UPDATE_MESSAGErN   )r   argsapp_refr    update_maskrB   rC   b_ownerbusiness_ownerd_ownerdeveloper_ownero_owneroperator_owner	patch_reqrS   patch_responses                   r!   UpdateApplicationsClient.Update   s0    K00?JJLJ--++z+BK(,>>
 ..K++D,A,AB 	 	  "11


*
*
M
Mk
 ,>>
 ..K++D,A,AB 	 	  "11


*
*
M
Mk
 ''-2-$66
  %[[$7n	^T	*	*%,[[%F"	$++11	1;;}d++#0#B#B$GM2G3 
  &&~6!11


*
*
Q
Qk .$ ((.B.%77
  &kk'48o	^T	*	*&-kk.$&G#	$++11	1;;}d++$1$C$C%GM2G3 
!   ''8!11


*
*
R
Rk /$ ''-2-$66
  %[[$7n	^	$	$%,[[%@"	$++11	1;;}%%#0#B#B$GM2G3 
  &&~6!11


*
*
Q
Qk .$ $ $ 1 1k!11


*
*
N
Nk
 # $ 0 0k!11


*
*
M
Mk
 MM!!# N I   &&y1I{{"33((@@((::	N r$   c                 &   U R                   R                  US9nU R                  R                  U5      nU(       a  U$ [        R
                  " U R                  U[        R                  R                  [        R                  R                  5      nU$ )a  Delete an application in the Project/location.

Args:
  app_id: str, The name for the application being deleted
  async_flag: Boolean value for async operation. If true the operation will
    be async

Returns:
  Empty Response Message or Operation based on async flag value.
r&   )r   0ApphubProjectsLocationsApplicationsDeleteRequestr   Deleter   rJ   r   rK   DeleteApplicationWAIT_FOR_DELETE_MESSAGEREMOVE_TIMELIMIT_SEC)r   r*   rQ   
remove_reqrS   delete_responses         r!   r   ApplicationsClient.Delete  s     OO P J   ''
3I#44((@@((==	O r$   c                 j    U R                   R                  US9nU R                  R                  U5      $ )zFetch the IAM Policy attached to the sepcified application.

Args:
  app_id: str, the application id.

Returns:
  The application's IAM Policy.
)resource)r   6ApphubProjectsLocationsApplicationsGetIamPolicyRequestr   GetIamPolicy)r   r*   get_reqs      r!   r   ApplicationsClient.GetIamPolicy/  s=     	LL 	M 	
 
 ((11r$   c                 x    [         R                  " X R                  R                  5      nU R	                  X5      $ )zSets an application's IamPolicy to the one provided.

If 'policy_file' has no etag specified, this will BLINDLY OVERWRITE the IAM
policy!

Args:
    app_id: str, the application id..
    policy_file: a policy file.

Returns:
    The IAM Policy.
)r   ParsePolicyFiler   Policy_SetIamPolicyHelper)r   r*   policy_filepolicys       r!   SetIamPolicyApplicationsClient.SetIamPolicy@  s/     %%k==3G3GHF##F33r$   c                     U R                   R                  UU R                   R                  US9S9nU R                  R	                  U5      $ )N)r   )r   setIamPolicyRequest)r   6ApphubProjectsLocationsApplicationsSetIamPolicyRequestSetIamPolicyRequestr   r   )r   r*   r   set_reqs       r!   r   &ApplicationsClient._SetIamPolicyHelperP  sV    LL $ A A !B !  	M 	
  ((11r$   c                     U R                  U5      n[        R                  " U R                  R                  XBU5        U R                  X5      $ )a  Does an atomic Read-Modify-Write, adding the member to the role.

Args:
    app_id: str, the application id.
    member: str, the principal to add the binding for.
    role: predefined role, the role name to assign to the principal.

Returns:
    The IAM Policy.

)r   r   AddBindingToIamPolicyr   Bindingr   r   r*   memberroler   s        r!   AddIamPolicyBinding&ApplicationsClient.AddIamPolicyBindingY  sA     v&F""4==#8#8&$O##F33r$   c                 t    U R                  U5      n[        R                  " XBU5        U R                  X5      $ )a
  Does an atomic Read-Modify-Write, removing the member to the role.

Args:
    app_id: str, the application id.
    member: str, the principal to add the binding for.
    role: predefined role, the role name to assign to the principal.

Returns:
    The IAM Policy.

)r   r   RemoveBindingFromIamPolicyr   r   s        r!   RemoveIamPolicyBinding)ApplicationsClient.RemoveIamPolicyBindingi  s5     v&F''=##F33r$   )r   r   r   r   r   r   r   )Nd   )__name__
__module____qualname____firstlineno____doc__r
   ri   rj   r"   r,   r:   rI   r   r   r   r   r   r   r   __static_attributes__ r$   r!   r   r      sg    .#'#4#4#:#: "." 	<1f 150A0A0G0G AF82"4 24 4r$   r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.apphubr   rK   r   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   googlecloudsdk.command_lib.iamr   objectr   r   r$   r!   <module>r      s3     &  ' ' B @ . ( 3Z4 Z4r$   