
                         
   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	l
mZ dd
lmZ dddZd Zd Zd Zd Z e	j(                  e	j*                  j,                         G d de	j.                               Z e	j(                  e	j*                  j2                         G d de	j.                               Z e	j(                  e	j*                  j6                         G d de	j.                               Zy)zReplaces a user's password policy in a given instance.

Replaces a user's password policy in a given instance with specified policy.
    )absolute_import)division)unicode_literals)api_util)
operations)base)flags)users)
propertiesz{description}a            To replace the password policy with 2 minutes password
          expiration time for ``my-user'' in instance ``prod-instance'', run:

            $ {command} my-user --instance=prod-instance --password-policy-password-expiration-duration=2m

          To clear the existing password policy of ``my-user'' in instance
          ``prod-instance'', run:

            $ {command} my-user --instance=prod-instance --clear-password-policy
          )DESCRIPTIONEXAMPLESc                    t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j
                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  j                  |        | j                  j                  d       y)zArgs is called by calliope to gather arguments for this command.

  Args:
    parser: An argparse parser that you can use it to add arguments that go on
      the command line after this command. Positional arguments are allowed.
  N)r	   AddInstanceAddUsernameAddHost&AddPasswordPolicyAllowedFailedAttempts+AddPasswordPolicyPasswordExpirationDuration*AddPasswordPolicyEnableFailedAttemptsCheck+AddPasswordPolicyEnablePasswordVerification$AddPasswordPolicyClearPasswordPolicyr   
ASYNC_FLAGAddToParserdisplay_infoAddCacheUpdaterparsers    ,lib/surface/sql/users/set_password_policy.pyAddBaseArgsr   2   s     FF--..v633F;226:33F;,,V4//f%%%d+    c                      ~ y N r   s    r   AddBetaArgsr#   E       r   c                      ~ y r!   r"   r   s    r   AddAlphaArgsr&   J   r$   r   c                 |   t        j                  t         j                        }|j                  }|j                  }|j
                  j                  | j                  dt        j                  j                  j                  j                  id      }d}|j                  j                  |j                  |j                  | j                  | j                   | j"                              }t        j$                  ||j&                  |       }|j                  j)                  |j+                  |j                  | j                  | j                   | j"                  |j-                  |j                  | j                  | j                   | j"                  |                  }|j
                  j/                  d|j0                  |j                  	      }| j2                  r@|j4                  j                  |j7                  |j                  |j8                  
            S t4        j:                  j=                  ||d       y)zChanges a user's password in a given instance.

  Args:
    args: argparse.Namespace, The arguments that this command was invoked
      with.

  Returns:
    SQL user resource iterator.
  projectzsql.instances)params
collectionN)r(   instancenamehost)r(   r+   r,   r-   passwordPolicy)r(   r+   r,   r-   userzsql.operations)	operationr(   )r(   r0   zUpdating Cloud SQL user)r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesresource_parserParser+   r   VALUEScorer(   	GetOrFailr
   GetSqlUsersGetRequestusernamer-   CreatePasswordPolicyFromArgsr.   UpdateSqlUsersUpdateRequestUserCreater,   async_r   SqlOperationsGetRequestr0   OperationsV1Beta4WaitForOperation)	argsclientr3   r4   instance_refoperation_refr/   password_policyresult_operations	            r   RunBaseSetPasswordCommandrL   O   s    h::;&  *$$,''--
mm**//77AAB  . ", -					%%&&==}}yy	 & 
$ 66D''//  %%,,((&&==}}yy  "**}}==99, ! . ) 
/0 ((// %%"" 0 $- 
[[  $$,,!))]5L5L 	- 	NO O //
M0IKr   c                   *    e Zd ZdZeZed        Zd Zy)SetPasswordPolicyReplaces a user's password policy in a given instance.

  Replaces a user's password policy in a given instance with a specified
  username and host.
  c                     t        |        yzArgs is called by calliope to gather arguments for this command.

    Args:
      parser: An argparse parser that you can use it to add arguments that go on
        the command line after this command. Positional arguments are allowed.
    N)r   r   s    r   ArgszSetPasswordPolicy.Args   s     r   c                     t        |       y r!   rL   selfrF   s     r   RunzSetPasswordPolicy.Run   
    d#r   N	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodrR   rW   r"   r   r   rN   rN      s%      - $r   rN   c                   *    e Zd ZdZeZed        Zd Zy)SetPasswordPolicyBetarO   c                 0    t        |        t        |        yrQ   )r#   r   r   s    r   rR   zSetPasswordPolicyBeta.Args   s     r   c                     t        |       y r!   rT   rU   s     r   rW   zSetPasswordPolicyBeta.Run   rX   r   NrY   r"   r   r   rb   rb      s%      - $r   rb   c                   *    e Zd ZdZeZed        Zd Zy)SetPasswordPolicyAlpharO   c                 F    t        |        t        |        t        |        yrQ   )r&   r#   r   r   s    r   rR   zSetPasswordPolicyAlpha.Args   s     r   c                     t        |       y r!   rT   rU   s     r   rW   zSetPasswordPolicyAlpha.Run   rX   r   NrY   r"   r   r   rf   rf      s%      -	 	$r   rf   N)r]   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.sqlr	   r
   googlecloudsdk.corer   r^   r   r#   r&   rL   ReleaseTracksReleaseTrackGAUpdateCommandrN   BETArb   ALPHArf   r"   r   r   <module>rt      s   
 '  ' / 1 ( 0 0 *
 	
		$,&

3Kl D%%(()$** $ *$. D%%**+$D.. $ ,$0 D%%++,$T// $ -$r   