
                         P    S 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
g
)zGHelper functions for constructing and validating AlloyDB user requests.    )absolute_import)division)unicode_literals)
propertiesc                    UR                  5       nU R                  R                  S[        R                  R
                  R                  R                  UR                  UR                  UR                  S9nUR                  5       Ul        UR                  (       a  UR                  Ul        [        XR                  5      Ul        UR"                  (       a  UR"                  Ul        UR&                  (       a  UR$                  R)                  S5        UR*                  (       a  UR*                  Ul        UR/                  UUR                  UR                  5       S9$ )aW  Validates command line input arguments and passes parent's resources.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  cluster_ref: parent resource path of the resource being created
  args: Command line input arguments.

Returns:
  Fully-constructed request to create an AlloyDB user.
z)alloydb.projects.locations.clusters.users)
projectsIdlocationsId
clustersIdusersIdalloydbsuperuser)useruserIdparent)Userresource_parserCreater   VALUEScoreproject	GetOrFailregionclusterusernameRelativeNamenamepassword_ParseUserTypetypeuserTypedb_rolesdatabaseRoles	superuserappendkeep_extra_roleskeepExtraRoles2AlloydbProjectsLocationsClustersUsersCreateRequest)clientalloydb_messagescluster_refargsuser_resourceuser_refs         5lib/googlecloudsdk/command_lib/alloydb/user_helper.pyConstructCreateRequestFromArgsr.      s    #'')-##**1""''//99++mm + (  ,,.- 
]]!]]M)*:IIF-	]]"&--M	^^&&'9:	#'#8#8M 		L	L]]%%' 
M 
     c                 Z    [        XU5      u  p4U R                  X1R                  5       US9$ )a  Constructs the request to update an AlloyDB instance.

Args:
  alloydb_messages: Messages module for the API client.
  user_ref: parent resource path of the resource being updated
  args: Command line input arguments.

Returns:
  Fully-constructed request to update an AlloyDB user.
)r   r   
updateMask)ConstructUserAndMaskFromArgs1AlloydbProjectsLocationsClustersUsersPatchRequestr   )r(   r,   r*   r+   masks        r-   ConstructPatchRequestFromArgsr5   D   s?     5$- 
	K	K4464 
L 
 r/   c                    SnSnU R                  5       nUR                  5       Ul        SUR                  ;   a  UR                  Ul        XS4$ SUR                  ;   a6  UR
                  Ul        UR                  (       a  UR                  Ul        XT4$ SUR                  ;   a\  UR                  (       a  UR
                  R                  S5        OUR
                  R                  S5        UR
                  Ul        XT4$ US4$ )a  Validates command line arguments and creates the user and field mask.

Args:
  alloydb_messages: Messages module for the API client.
  user_ref: resource path of the resource being updated
  args: Command line input arguments.

Returns:
  An AlloyDB user and mask for update.
r   database_roleszset-passwordz	set-roleszset-superuserr   N)r   r   r   command_pathr   r    r!   r$   r%   r"   r#   remove)r(   r,   r*   password_pathdatabase_roles_pathr+   s         r-   r2   r2   X   s     -("'')-,,.- t(((!]]M'' D%%%"&--M%)%:%:m"-- )))~~
mm-.
mm-."&--M--		r/   c                     US:X  a   U R                   R                  R                  $ US:X  a   U R                   R                  R                  $ g )NBUILT_IN	IAM_BASED)r   UserTypeValueValuesEnumALLOYDB_BUILT_INALLOYDB_IAM_USER)r(   	user_types     r-   r   r      sE    *  88IIIK  88III	r/   N)__doc__
__future__r   r   r   googlecloudsdk.corer   r.   r5   r2   r    r/   r-   <module>rG      s-    N &  ' *)X('Tr/   