
                             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 rS rS rS rS rS rS rS rS rg)z,Utility functions for `gcloud pam` commands.    )absolute_import)division)unicode_literalsN)apis)arg_parsers)base)log)yamlc                     SUl         U$ )zRModify request hook to set the force field in delete entitlement requests to true.T)force
unused_refunused_argsreqs      *lib/googlecloudsdk/command_lib/pam/util.py'SetForceFieldInDeleteEntitlementRequestr      s    #)	*    c                     UR                   R                  R                  5       nUR                  R	                  5       R                  5       Ul        UR                  R                  5       Ul        U$ )zRModify request hook to parse the entitlement name into a CreateEntitlementRequest.)	CONCEPTSentitlementParseresultParentRelativeNameparentNameentitlementId)r   argsr   r   s       r   0ParseEntitlementNameIntoCreateEntitlementRequestr   %   sU    ))//1+!!((*779#*!((--/#	*r   c                     SUl         U$ )zWModify request hook to set the update mask field in update entitlement requests to '*'.*
updateMaskr   s      r   'SetUpdateMaskInUpdateEntitlementRequestr$   -       #.	*r   c                    0 nU R                   (       a  U R                   US'   U R                  (       d  U$ 0 US'   U R                  R                  nU H;  nUR                  S;   d  M  UR                  R
                  US   UR                  '   M=     [        R                  R                  SR                  U R                   5      5        U$ )z-Formats the response of the withdraw command.namemetadata)
apiVersion
createTimetargetzGrant withdrawal initiated. The operation will complete in some time. To track its status, run:
`gcloud pam operations wait {}`
Note that the wait command requires you to have the `privilegedaccessmanager.operations.get` permission on the resource.)
r'   r(   additionalPropertieskeyvaluestring_valuer	   statusPrintformat)responser   modified_response
propertiesprops        r   FormatWithdrawResponser7   3   s    ]] (f			"$J  55*dxx9904

0G0G
#DHH-  **N vhmm 
r   c                     U R                   R                  5       nU[        R                  R                  :X  a  gU[        R                  R                  :X  a  gU[        R                  R
                  :X  a  gg)z{Return API version based on args.

Args:
  args: The argparse namespace.

Returns:
  API version (e.g. v1alpha or v1beta).
v1alphav1betav1N)calliope_commandReleaseTrackr   ALPHABETAGA)r   release_tracks     r   GetApiVersionFromArgsrB   J   sb     ''446-d''---d'',,,d''*** +r   c                    UR                   (       d  U$ [        R                  " S[        U5      5      n[	        UR                   5      S:  a  [
        R                  " S5      eUR                    H  nUR                  5       nSnUR                  S5      n[        R                  " XT5      (       a  [	        U5      S:w  a%  [
        R                  " SR                  U5      5      eSUS	   R                  5       S
S -   nSU-   nUR                  5       n	UR                  5       U	l        XyR                  l        XR                  l        UR$                  R&                  R)                  U	5        M     U$ )z]Modify request hook to populate the requestedPrivilegedAccess field in create grant requests.privilegedaccessmanager   z/Only one resource is supported for grant scope.z%^(projects|organizations|folders)\/.+/   zcInvalid resource name: {}. Resource name must be of the form (projects|organizations|folders)/<id>.z$cloudresourcemanager.googleapis.com/r   Nz&//cloudresourcemanager.googleapis.com/)requested_resourcesr   GetMessagesModulerB   lenr   ArgumentTypeErrorstripsplitrematchr2   
capitalizeRequestedPrivilegedAccess%RequestedPrivilegedAccessGcpIamAccessgcpIamAccessresourceTyperesourcegrantrequestedPrivilegedAccessappend)
r   r   r   messagesrV   pattern
componentsresource_type	full_namerequested_privileged_accesss
             r   0SetRequestedPrivilegedAccessInCreateGrantRequestr`   \   sP   		!	!J##!6t!<( 		!	!"Q&

'
'9  **h~~H6G$J88G&&#j/Q*>))44:F84D 
 	/A1I1I1KCR1PP  98CI"*"D"D"F668  , =J,,98A,,5II''../JK' +* 
*r   c                 Z    U (       a
  U S   (       d  / $ [         R                  " U S   5      $ )a:  Loads a YAML document from a stream.

This function takes a stream (expected to be a list with a single string
element) and parses it as a YAML document. It returns the loaded YAML data as
a Python object (typically a list or dictionary).

Args:
  stream: The stream to load from.

Returns:
 The loaded YAML data.
r   )r
   load)streams    r   LoadGrantScopeFromYamlrd      s%     
vayI	6!9	r   c                 .    UR                   S-   Ul         U$ )zFModify request hook to update the resource field in settings requests.z	/settings)r'   r   s      r   UpdateSettingsResourcerf      s    XX##(	*r   c                     SUl         U$ )zTModify request hook to set the update mask field in update settings requests to '*'.r!   r"   r   s      r   $SetUpdateMaskInUpdateSettingsRequestrh      r%   r   )__doc__
__future__r   r   r   rO   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   googlecloudsdk.corer	   r
   r   r   r$   r7   rB   r`   rd   rf   rh    r   r   <module>ro      sS     3 &  ' 	 , / ( # $.$ F*r   