
                         "   d Z ddlmZ ddlmZ ddlmZ ddl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
 Zd Z e
j$                  e
j&                  j(                  e
j&                  j*                         G d de
j,                               Zy)z(Fetch default Config Connector identity.    )absolute_import)division)unicode_literalsN)util)base)log)
propertiesc                     t        j                          d| j                  z   }| j                  }| j                  xs2 t
        j                  j                  j                  j                         }t        |||       y)z@Base operations for `get-config-connector-identity` run command.zkrmapihost-N)
container_utilCheckKubectlInstallednamelocationprojectr	   VALUEScore	GetOrFail$GetConfigConnectorIdentityForCluster)args
cluster_idr   
project_ids       Elib/surface/anthos/config/controller/get_config_connector_identity.py_BaseRunr      sZ    &&(tyy(*]](||Iz0055==GGI*&xZH    c                    t        j                  | |      5  t        j                         }t        j                  g d|j
                  t        j                  j
                  d       |j                         j                  dd      }t        j                  j                  dj                  ||             ddd       y# 1 sw Y   yxY w)	z4Get Config Connector identity for the given cluster.)getConfigConnectorContextz-oz0jsonpath="{.items[0].spec.googleServiceAccount}"zconfig-control)out_funcerr_func	namespace" a0  Default Config Connector identity: [{identity}].

For example, to give Config Connector permission to manage Google Cloud resources in the same project:
gcloud projects add-iam-policy-binding {project_id} \
    --member "serviceAccount:{identity}" \
    --role "roles/owner" \
    --project {project_id}
)identityr   N)composer_utilTemporaryKubeconfigioStringIORunKubectlCommandwriter   errgetvaluereplacestatusPrintformat)r   r   r   outputr"   s        r   r   r   )   s    ((:>[[]F## % .4\\-0WW]].>@  ((b1HJJ	' (.v* (. (67 ?>>s   B"CCc                   .    e Zd ZdZddiZed        Zd Zy)GetConfigConnectorIdentityzFetch default Config Connector identity.

  {command} prints the default Config Connector Google Service Account in
  a specific Anthos Config Controller.
  EXAMPLESz          To print the default Config Connector identity used by your
          Config Controller 'main' in the location 'us-central1', run:

            $ {command} main --location=us-central1
      c                 R    | j                  dd       | j                  ddd       y)	zRegister flags for this command.

    Args:
      parser: An argparse.ArgumentParser-like object. It is mocked out in order
        to capture some information, but behaves like an ArgumentParser.
    r   z%Name of the Anthos Config Controller.)helpz
--locationTz6The location (region) of the Anthos Config Controller.)requiredr4   N)add_argument)parsers    r   ArgszGetConfigConnectorIdentity.ArgsQ   s5     %LM
E  Gr   c                     t        |       y)zThis is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.
    N)r   )selfr   s     r   RunzGetConfigConnectorIdentity.Run_   s     TNr   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr8   r;    r   r   r1   r1   @   s3     
- G Gr   r1   )r?   
__future__r   r   r   r%    googlecloudsdk.api_lib.containerr   r   googlecloudsdk.callioper   #googlecloudsdk.command_lib.composerr#   googlecloudsdk.corer   r	   r   r   ReleaseTracksReleaseTrackALPHAGACommandr1   rB   r   r   <module>rM      sw    / &  ' 	 C ( E # *I7. D%%++T->->-A-AB% % C%r   