
    O                         S 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.    N)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   FormatWithdrawResponser4   0   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   GetApiVersionFromArgsr?   G   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   GetMessagesModuler?   lenr   ArgumentTypeErrorstripsplitrematchr/   
capitalizeRequestedPrivilegedAccess%RequestedPrivilegedAccessGcpIamAccessgcpIamAccessresourceTyperesourcegrantrequestedPrivilegedAccessappend)
r   r   r   messagesrS   pattern
componentsresource_type	full_namerequested_privileged_accesss
             r   0SetRequestedPrivilegedAccessInCreateGrantRequestr]   Y   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   LoadGrantScopeFromYamlra   |   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   UpdateSettingsResourcerc      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   $SetUpdateMaskInUpdateSettingsRequestre      r"   r   )__doc__rL   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   googlecloudsdk.corer   r   r   r   r!   r4   r?   r]   ra   rc   re    r   r   <module>rk      sL     3 
 , / ( # $.$ F*r   