
    ]                         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  G d	 d
e
j                        Zy)z=Fetch Hub-registered cluster credentials for Connect Gateway.    )absolute_import)division)unicode_literalsN)util)gateway)	resourcesc                   &    e Zd ZdZed        Zd Zy)GetCredentialsa  Fetch credentials for a fleet-registered cluster to be used in Connect Gateway.

  {command} updates the `kubeconfig` file with the appropriate credentials and
  endpoint information to send `kubectl` commands to a fleet-registered and
  -connected cluster through the Connect Gateway service.

  It takes a project, passed through by set defaults or flags. By default,
  credentials are written to `$HOME/.kube/config`. You can provide an alternate
  path by setting the `KUBECONFIG` environment variable. If `KUBECONFIG`
  contains multiple paths, the first one is used.

  Upon success, this command will switch the current context to the target
  cluster if other contexts are already present in the `kubeconfig` file.

  ## EXAMPLES

    Get the Gateway kubeconfig for a globally registered cluster:

      $ {command} my-cluster
      $ {command} my-cluster --location=global

    Get the Gateway kubeconfig for a cluster registered in us-central1:

      $ {command} my-cluster --location=us-central1
  c           	      (   t        j                  |t        j                  d      t        j                  d      dd       |j	                  ddddt        j                  d      	       |j	                  d
dddt        j                  d      	       y )Nz          The membership name that you choose to uniquely represent the cluster
          being registered in the fleet.
        z          The location of the membership resource, e.g. `us-central1`.
          If not specified, attempts to automatically choose the correct region.
        T)membership_helplocation_helpmembership_required
positionalz--use-client-side-generation
store_trueFzi          Generate the kubeconfig locally rather than generating
          it using an API call.
        )actionrequiredhiddenhelpz--force-use-agentzB          Force the use of Connect Agent-based transport.
        )r   AddMembershipResourceArgtextwrapdedentadd_argument)clsparsers     :lib/surface/container/fleet/memberships/get_credentials.pyArgszGetCredentials.Args7   s    &&  )  oo '  ! &__    	 __        c                     t        j                  |      }t        j                  |      }t        j                  |      }|j
                  r| j                  ||       y | j                  |||j                         y )N)force_use_agent)	r   ParseMembershipArg
fleet_utilMembershipLocationMembershipShortnameuse_client_side_generationRunGetCredentialsRunServerSider   )selfargsmembership_namelocationmembership_ids        r   RunzGetCredentials.Run]   sk    2248O,,_=H22?CM&&
]H5

43G3G  r   N)__name__
__module____qualname____doc__classmethodr   r,    r   r   r
   r
      s!    4 # #J
r   r
   )r0   
__future__r   r   r   r   &googlecloudsdk.api_lib.container.fleetr   r!   *googlecloudsdk.command_lib.container.fleetr   r   GetCredentialsCommandr
   r2   r   r   <module>r7      s4    D &  '  E > @KW22 Kr   