HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/awscli/customizations/eks/__pycache__/update_kubeconfig.cpython-310.pyc
o

.&�aS/�@s�ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZddlmZe�e�Zej�d�Zd	ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZdS)�N)�OrderedDict)�BasicCommand)�	uni_print)�EKSClusterError)�
Kubeconfig�KubeconfigError�KubeconfigLoader�KubeconfigWriter�KubeconfigValidator�KubeconfigAppender)�ordered_yaml_dumpz~/.kube/configz%client.authentication.k8s.io/v1alpha1c	@steZdZdZe�ddd�Zdddd�dd	d
d�ddd
d�d
dd
dd
d�ddd
dd�ddd
d�gZdd�Zdd�Z	dS)�UpdateKubeconfigCommandzupdate-kubeconfig�eksz_description.rst�namez�The name of the cluster for which to create a kubeconfig entry. This cluster must exist in your account and in the specified or configured default Region for your AWS CLI installation.T)r�	help_text�required�
kubeconfigaOptionally specify a kubeconfig file to append with your configuration. By default, the configuration is written to the first file path in the KUBECONFIG environment variable (if it is set) or the default kubeconfig path (.kube/config) in your home directory.Fzrole-arnz�To assume a role for cluster authentication, specify an IAM role ARN with this option. For example, if you created a cluster while assuming an IAM role, then you must also assume that role to connect to the cluster the first time.zdry-run�
store_truezRPrint the merged kubeconfig to stdout instead of writing it to the specified file.)r�action�defaultrr�verbosez_Print more detailed output when writing to the kubeconfig file, including the appended entries.)rrrr�aliaszBAlias for the cluster context name. Defaults to match cluster ARN.cCs*td�|D]}tt|��td�qdS)z�
        Display entries in yaml format

        :param entries: a list of OrderedDicts to be printed
        :type entries: list
        z
Entries:

�
N)rr)�self�entries�entry�r�M/usr/lib/python3/dist-packages/awscli/customizations/eks/update_kubeconfig.py�_display_entriesgs

�z(UpdateKubeconfigCommand._display_entriescCs�t|j|j|j|�}|��}|��}ttj�	dd�|j
�}|�|d�}|�|d�}t
�}	|	�||||j�}
|jrBt|���dSt�}|�|�|rXtd�|
d|j��ntd�|
d|j��|jrp|�|
||g�dSdS)N�
KUBECONFIG�rzUpdated context {0} in {1}
zAdded new context {0} to {1}
)�	EKSClient�_sessionr�role_arn�get_cluster_entry�get_user_entry�KubeconfigSelector�os�environ�getr�choose_kubeconfig�has_clusterr�insert_cluster_user_pairr�dry_runr�dump_contentr	�write_kubeconfig�format�pathrr)r�parsed_args�parsed_globals�client�new_cluster_dict�
new_user_dict�config_selector�config�updating_existing�appender�new_context_dict�writerrrr�	_run_mainssN����

�
�
��z!UpdateKubeconfigCommand._run_mainN)
�__name__�
__module__�__qualname__�NAMEr�	FROM_FILE�DESCRIPTION�	ARG_TABLErr=rrrrr
'sJ��
���	�	��7r
c@s*eZdZ		ddd�Zdd�Zdd�ZdS)	r&Ncs�|durt�}|�_|durt|�}|�_|dur"��|�g�_dS|dkr(t}�fdd�|�tj	�D��_t
�j�dkrCtg�_dSdS)a6
        Parse KUBECONFIG into a list of absolute paths.
        Also replace the empty list with DEFAULT_PATH

        :param env_variable: KUBECONFIG as a long string
        :type env_variable: string

        :param path_in: The path passed in through the CLI
        :type path_in: string or None
        Nr cs&g|]}t|���dkr��|��qS)r)�len�strip�_expand_path)�.0�element�rrr�
<listcomp>�s
�z/KubeconfigSelector.__init__.<locals>.<listcomp>r)r
�
_validatorr�_loaderrG�_paths�DEFAULT_PATH�splitr'�pathseprE)r�env_variable�path_in�	validator�loaderrrJr�__init__�s 

��zKubeconfigSelector.__init__cCs�|jD]7}z|j�|�}|�|�rt�d�|��|WSWqty:}zt�d�||��WYd}~qd}~ww|j�|jd�S)a�
        Choose which kubeconfig file to read from.
        If name is already an entry in one of the $KUBECONFIG files,
        choose that one.
        Otherwise choose the first file.

        :param cluster_name: The name of the cluster which is going to be added
        :type cluster_name: String

        :return: a chosen Kubeconfig based on above rules
        :rtype: Kubeconfig
        zFound entry to update at {0}zPassing {0}:{1}Nr)	rNrM�load_kubeconfigr+�LOG�debugr0r�warning)r�cluster_name�candidate_path�
loaded_config�errrr*�s

�
���z$KubeconfigSelector.choose_kubeconfigcCstj�tj�|��S)z4 A helper to expand a path to a full absolute path. )r'r1�abspath�
expanduser)rr1rrrrG�szKubeconfigSelector._expand_path)NN)r>r?r@rVr*rGrrrrr&�s
�!r&c@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)r!NcCs"||_||_||_d|_||_dS�N)r"�
_cluster_name�	_role_arn�_cluster_description�_globals)r�sessionr[r#r3rrrrV�s

zEKSClient.__init__cCs�|jdurG|jdur|j�d�}n|jjd|jj|jj|jjd�}|j|jd�}|d|_d|jvr6t	d��|jddvrGt	d	�
|jd���|jS)
z�
        Use an eks describe-cluster call to get the cluster description
        Cache the response in self._cluster_description.
        describe-cluster will only be called once.
        Nr)�region_name�endpoint_url�verify)r�cluster�statuszCluster not found)�ACTIVE�UPDATINGzCluster status is {0})rdrer"�
create_client�regionrh�
verify_ssl�describe_clusterrbrr0)rr4�full_descriptionrrr�_get_cluster_description�s$

�

�z"EKSClient._get_cluster_descriptioncCsX|���dddi�d}|���d�}|���d�}tdtd|fd|fg�fd	|fg�S)
ze
        Return a cluster entry generated using
        the previously obtained description.
        �certificateAuthority�datar �endpoint�arnrjzcertificate-authority-data�serverr)rsr)r)r�	cert_datarvrwrrrr$s
����zEKSClient.get_cluster_entrycCs�|���d��d�d}td|���dd�fdtdtdtfd	d
|ddd
|jgfdg�fg�fg�}|jdurD|ddd	�d|jg�|jj	rYtdd|jj	fg�g|ddd<|S)zb
        Return a user entry generated using
        the previously obtained description.
        rw�:�rr �user�exec�
apiVersion�argsz--regionrz	get-tokenz--cluster-name)�command�awsNz--role)r�AWS_PROFILE�value�env)
rsr)rPr�API_VERSIONrbrc�extendr"�profile)rro�generated_userrrrr%s<��	���
�
�zEKSClient.get_user_entryra)r>r?r@rVrsr$r%rrrrr!�s

r!)r'�logging�botocore.compatr�awscli.customizations.commandsr�awscli.customizations.utilsr�$awscli.customizations.eks.exceptionsr�$awscli.customizations.eks.kubeconfigrrrr	r
r�&awscli.customizations.eks.ordered_yamlr�	getLoggerr>rXr1r`rOr�r
�objectr&r!rrrr�<module>s
 
zG