
    9%                        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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SKJr  S r\
R,                  \
R.                  \
R0                  " \
R2                  R4                  \
R2                  R6                  \
R2                  R8                  5       " S S\
R:                  5      5       5       5       rg),Enable a personal auth session on a cluster.    N)dataproc)
exceptions)util)waiter)base)clusters)flags)log)
console_io)progress_tracker)filesc                     U R                   R                  XES9nU R                   R                  SU-   SU-   SU-   US9nU R                  R                  R                  U5      $ )a  Inject credentials into the given cluster.

The credentials must have already been encrypted before calling this method.

Args:
  dataproc: The API client for calling into the Dataproc API.
  project: The project containing the cluster.
  region: The region where the cluster is located.
  cluster_name: The name of the cluster.
  cluster_uuid: The cluster UUID assigned by the Dataproc control plane.
  credentials_ciphertext: The (already encrypted) credentials to inject.

Returns:
  An operation resource for the credential injection.
)clusterUuidcredentialsCiphertextz	projects/zregions/z	clusters/)projectregionclusterinjectCredentialsRequest)messagesInjectCredentialsRequest7DataprocProjectsRegionsClustersInjectCredentialsRequestclientprojects_regions_clustersInjectCredentials)r   r   r   cluster_namecluster_uuidcredentials_ciphertextinject_credentials_requestrequests           =lib/surface/dataproc/clusters/enable_personal_auth_session.py_inject_encrypted_credentialsr"   ,   sy    "  (00II  J  NUUG#& L(9	 V ;'
 
	2	2	D	DW	MM    c                   <    \ rS rSrSrSS0r\S 5       rS rS r	Sr
g	)
EnablePersonalAuthSessionG   r   EXAMPLESzv
          To enable a personal auth session, run:

            $ {command} my-cluster --region=us-central1
          c                     [         R                  " U R                  5       5      n[        R                  " USUR
                  5        [        R                  " U5        g)z{Method called by Calliope to register flags for this command.

Args:
  parser: An argparser parser used to register flags.
z!enable a personal auth session onN)dpDataprocReleaseTrackr
   AddClusterResourceArgapi_versionAddPersonalAuthSessionArgs)clsparserr   s      r!   ArgsEnablePersonalAuthSession.ArgsY   sE     {{3++-.H	(K ( 4 46	$$V,r#   c
                 *   [         R                  " U5      n
U
(       d%  [        R                  " SR	                  U5      5      e[         R
                  " 5       R                  XjU	5      n[        XUXEU5      nU(       a  [        R                  " X5        g g )Nz-Failure getting credentials to inject into {})
r   GetCredentialsr   PersonalAuthErrorformatPersonalAuthUtilsEncryptWithPublicKeyr"   r   WaitFor)selfr   r   r   r   r   cluster_keyaccess_boundary_jsonoperation_polleropenssl_executabledownscoped_tokenr   inject_operations                r!   inject_credentials,EnablePersonalAuthSession.inject_credentialsk   s     **+?@((
9
@
@
NP P!335JJ'9;4X5A5KM nn%8 r#   c                    Sn[         R                  " USSS9  [        R                  " U R	                  5       5      nUR
                  R                  R                  5       nUR                  nUR                  nUR                  nUR                  R                  XVUS9nUR                  R                  R                  U5      n	U	R                   n
UR"                  (       a:  [$        R&                  " UR"                  5       nUR)                  5       nS S S 5        O[*        R,                  " U5      n[.        R0                  " 5       R3                  5       (       a  SOSnS nUS:X  a  [4        R6                  " X5      nU(       d  SnS nUS:X  a@  [4        R6                  " X5      nUR8                  nU(       d   [$        R:                  " S5      n[B        RD                  " UR                  RF                  S
 5      n U(       d%  [H        RJ                  " SRM                  U5      5      e[N        RP                  " SRM                  U5      SS9   U RS                  X5XgXWUU5	        S S S 5        URT                  (       d  g SRM                  U5      n[N        RP                  " USS9    UR                  R                  R                  U5      n	[4        R6                  " X5      nU(       d%  [H        RJ                  " SRM                  U5      5      eSnUS:  a7   [V        RX                  " S5        U RS                  X5XgXWUU5	        SnUS:  a  M7  [H        RJ                  " S5      e! , (       d  f       GN<= f! [<         a    [>        R@                  " S	5         GNf = f! , (       d  f       GN>= f! [<         a%  n[>        RZ                  " U5        US-  n S nANS nAff = f! [         R\                  [^        4 a     S S S 5        g f = f! , (       d  f       g = f! [H        RJ                   a   n[>        RZ                  " U5         S nAg S nAff = f)NzA personal authentication session will propagate your personal credentials to the cluster, so make sure you trust the cluster and the user who created it.Tz Enabling session aborted by user)messagecancel_on_nocancel_string)	projectIdr   clusterNameECIESRSAopensslzcCould not find openssl on your system. The enable-session command requires openssl to be installed.c                     U R                   $ )N)name)	operations    r!   <lambda>/EnablePersonalAuthSession.Run.<locals>.<lambda>   s    )..r#   z.The cluster {} does not support personal auth.z1Injecting initial credentials into the cluster {})autotickzoPeriodically refreshing credentials for cluster {}. This will continue running until the command is interruptedr            z>Credential injection failed three times in a row, giving up...)0r   PromptContinuer)   r*   r+   CONCEPTSr   ParserG   r   rH   r   )DataprocProjectsRegionsClustersGetRequestr   r   Getr   access_boundaryr   
FileReaderreadr
   ProjectGcsObjectsAccessBoundaryr   r7   IsTinkLibraryInstalledr	   
ClusterKeyopenssl_commandFindExecutableOnPath
ValueErrorr   fatalr   CloudOperationPollerNoResourcesprojects_regions_operationsr   r5   r6   r   ProgressTrackerrA   refresh_credentialstimesleeperrorOperationCancelledErrorKeyboardInterrupt)r:   argsrD   r   cluster_refr   r   r   get_requestr   r   abfr<   cluster_key_typer;   r>   r=   update_messagefailure_counterrs                       r!   RunEnablePersonalAuthSession.Run{   s   .G 8: {{4,,./H--''--/K##GF**L##MMl N DKoo77;;KHG&&LD001S"xxz 21 #BB7K #'"8"8 ##w$)  K7" ''Bk 5 ''Bk//	A$99)D

 ==33(*3**<CC 	 ++
=
D
D 	6 ,;O 02D	F	 %%D| 
 ++NTJ	 OO==AA+N' ++GF+..@GG "# # -!	!jjn%%h&2&:<L&8:  m ! ,,NP P[ 212  	A
)) @ A	A H  !iinq m!
 224EF 	
5 KJ2	3 KJ6 '' 	iins   M6M0 9AP 	N P :&P  P"A/O.N) OO
M-0 NN
N&!P )
O3OOOOP 5P6P ?P  P
PP P Q(QQ N)__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodr1   rA   ru   __static_attributes__rw   r#   r!   r%   r%   G   s7     5 - 	- 	-"9 gr#   r%   )r|   rh   googlecloudsdk.api_lib.dataprocr   r)   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   #googlecloudsdk.command_lib.dataprocr	   r
   googlecloudsdk.corer   googlecloudsdk.core.consoler   r   googlecloudsdk.core.utilr   r"   DefaultUniverseOnlyHiddenReleaseTracksr+   ALPHABETAGACommandr%   rw   r#   r!   <module>r      s    3  ; 6 0 . ( 8 5 # 2 8 *N6 T..33T5F5F5I5IV V  
Vr#   