
                         P    d Z ddlmZ ddlmZ ddlmZ ddlmZ d Zd Zd Z	d	 Z
y
)zGHelper functions for constructing and validating AlloyDB user requests.    )absolute_import)division)unicode_literals)
propertiesc                    |j                         }| j                  j                  dt        j                  j
                  j                  j                  |j                  |j                  |j                        }|j                         |_        |j                  r|j                  |_        t        ||j                        |_        |j"                  r|j"                  |_        |j&                  r|j$                  j)                  d       |j*                  r|j*                  |_        |j/                  ||j                  |j                               S )ag  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)*:DIIF-	]]"&--M	^^&&'9:	#'#8#8M 		L	L]]%%' 
M 
     c                 f    t        | ||      \  }}| j                  ||j                         |      S )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   sE     5$- 
	K	Kx4464 
L 
 r/   c                    d}d}| j                         }|j                         |_        d|j                  v r|j                  |_        ||fS d|j                  v r2|j
                  |_        |j                  r|j                  |_        ||fS d|j                  v rX|j                  r|j
                  j                  d       n|j
                  j                  d       |j
                  |_        ||fS |dfS )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                     |dk(  r | j                   j                  j                  S |dk(  r | j                   j                  j                  S y )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/   