
    g                     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
)z0Common utility functions for sql users commands.    )absolute_import)division)unicode_literals)
exceptionsc                     UR                   (       a   U R                  R                  R                  $ UR                  (       a   U R                  R                  R
                  $ g)a   Parses the correct retained password type for the arguments given.

Args:
  sql_messages: the proto definition for the API being called
  args: argparse.Namespace, The arguments that this command was invoked with.

Returns:
  DualPasswordType enum or None
N)discard_dual_passwordUserDualPasswordTypeValueValuesEnumNO_DUAL_PASSWORDretain_passwordDUAL_PASSWORDsql_messagesargss     +lib/googlecloudsdk/command_lib/sql/users.pyParseDualPasswordTyper      sI     
<<MMM	<<JJJ	    c                     UR                   (       a=  U R                  R                  R                  UR                   R	                  5       5      $ g )N)typer	   TypeValueValuesEnumlookup_by_nameupperr   s     r   ParseUserTyper   +   s9    	YY00??		 	r   c                 0   [        U S5      (       a9  U R                  (       a(  U R                  (       d  [        R                  " SS5      e[        U S5      (       a;  U R
                  (       a)  U R                  (       a  [        R                  " SS5      eggg)zValidates that the arguments for setting a password are correct.

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

Returns:
  throws exception or None
r   z--retain-passwordz'Must set --password to non-empty value.r   z--discard-dual-passwordzKCannot set --password to non-empty value while discarding the old password.N)hasattrr   passwordr   InvalidArgumentExceptionr   )r   s    r   ValidateSetPasswordRequestr   2   s     T   $($8$8

-
-   
 #'#=#=$--

-
-! $-. . CP#=r   c                    Sn[        US5      (       a  UR                  nUR                  nUR                  nUR                  nUR
                  n[        USLUSLUSLUSLUSL/5      nU(       d  gUc  U R                  5       nU(       a  U R                  5       $ Ub  XAl        SUl	        Ub  [        U5      S-   Ul        Ub  Xal	        Ub  Xql        U$ )ae  Generates password policy for the user.

Args:
  sql_messages: module, The messages module that should be used.
  password_policy: sql_messages.UserPasswordValidationPolicy,
  The policy to build the new policy off.
  args: argparse.Namespace, The arguments that this command was invoked with.

Returns:
  sql_messages.UserPasswordValidationPolicy or None

Nclear_password_policyTs)r   r    'password_policy_allowed_failed_attempts,password_policy_password_expiration_duration,password_policy_enable_failed_attempts_check,password_policy_enable_password_verificationanyUserPasswordValidationPolicyallowedFailedAttemptsenableFailedAttemptsCheckstrpasswordExpirationDurationenablePasswordVerification)	r   password_policyr   r    allowed_failed_attemptspassword_expiration_durationenable_failed_attempts_checkenable_password_verificationshould_generate_policys	            r   CreatePasswordPolicyFromArgsr3   J   s   $ T*++ 66 HH!%!R!R!%!R!R!%!R!RT)"$."$."$.4'   
 "??AO 4466(,C)04O-!-14$2&(+2,O.!-0L-!-1M.	r   N)__doc__
__future__r   r   r   googlecloudsdk.callioper   r   r   r   r3    r   r   <module>r8      s*    7 &  ' .&.09r   