HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/awscli/customizations/eks/__pycache__/kubeconfig.cpython-36.pyc
3

�T_�$�@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
Gdd�de�ZGdd�de�ZGd	d
�d
e�Z
dd�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�N)�OrderedDict)�EKSError)�ordered_yaml_load�ordered_yaml_dumpc@seZdZdZdS)�KubeconfigErrorz& Base class for all kubeconfig errors.N)�__name__�
__module__�__qualname__�__doc__�rr� /usr/lib/python3.6/kubeconfig.pyrsrc@seZdZdZdS)�KubeconfigCorruptedErrorz+ Raised when a kubeconfig cannot be parsed.N)rrr	r
rrrrr
sr
c@seZdZdZdS)�KubeconfigInaccessableErrorz< Raised when a kubeconfig cannot be opened for read/writing.N)rrr	r
rrrrr!src	Cs(tddgfdgfdd
d	t�fd
gfg�S)N�
apiVersion�v1�clusters�contexts�current-context��kind�ConfigZpreferences�users)rr)rr)rr)rrrrr�_get_new_kubeconfig_content%src@s&eZdZddd�Zdd�Zdd�ZdS)	�
KubeconfigNcCs||_|dkrt�}||_dS)N)�pathr�content)�selfrrrrr�__init__2szKubeconfig.__init__cCs
t|j�S)z+ Return the stored content in yaml format. )rr)rrrr�dump_content8szKubeconfig.dump_contentcCs&d|jkrdS|dd�|jdD�kS)zg
        Return true if this kubeconfig contains an entry
        For the passed cluster name.
        rFcSsg|]}|d�qS)�namer)�.0�clusterrrr�
<listcomp>Csz*Kubeconfig.has_cluster.<locals>.<listcomp>)r)rrrrr�has_cluster<s
zKubeconfig.has_cluster)N)rrr	rrr#rrrrr1s
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�KubeconfigValidatorcCstdd�j|_dS)N)rr�_validation_content)rrrrrHszKubeconfigValidator.__init__cCs*t|t�std��|j|�|j|�dS)z�
        Raises KubeconfigCorruptedError if the passed content is invalid

        :param config: The config to validate
        :type config: Kubeconfig
        z(Internal error: Not a Kubeconfig object.N)�
isinstancerr
�_validate_config_types�_validate_list_entry_types)r�configrrr�validate_configMs

z#KubeconfigValidator.validate_configcCs~t|jt�std��xd|jj�D]V\}}||jkr |j|dk	r t|j|t|��r tdj|t|j|�t|����q WdS)z�
        Raises KubeconfigCorruptedError if any of the entries in config
        are the wrong type

        :param config: The config to validate
        :type config: Kubeconfig
        zContent not a dictionary.Nz%{0} is wrong type:{1} (Should be {2}))r&r�dictr
r%�items�type�format)rr)�key�valuerrrr'Zs
z*KubeconfigValidator._validate_config_typescCsdx^|jj�D]P\}}||jkrt|j|�tkrx*|j|D]}t|t�s<tdj|���q<WqWdS)z�
        Raises KubeconfigCorruptedError if any lists in config contain objects
        which are not dictionaries

        :param config: The config to validate
        :type config: Kubeconfig
        zEntry in {0} not a dictionary.N)	r%r,rr-�listr&rr
r.)rr)r/r0�elementrrrr(qs

z.KubeconfigValidator._validate_list_entry_typesN)rrr	rr*r'r(rrrrr$Gs
r$c@seZdZddd�Zdd�ZdS)�KubeconfigLoaderNcCs|dkrt�}||_dS)N)r$�
_validator)rZ	validatorrrrr�szKubeconfigLoader.__init__cCs�y"t|d��}t|�}WdQRXWnrtk
rd}z&|jtjkrFd}ntdj|���WYdd}~Xn2tjk
r�}zt	dj|���WYdd}~XnXt
||�}|jj|�|S)aP
        Loads the kubeconfig found at the given path.
        If no file is found at the given path,
        Generate a new kubeconfig to write back.
        If the kubeconfig is valid, loads the content from it.
        If the kubeconfig is invalid, throw the relevant exception.

        :param path: The path to load a kubeconfig from
        :type path: string

        :raises KubeconfigInaccessableError: if the kubeconfig can't be opened
        :raises KubeconfigCorruptedError: if the kubeconfig is invalid

        :return: The loaded kubeconfig
        :rtype: Kubeconfig
        �rNz&Can't open kubeconfig for reading: {0}z'YamlError while loading kubeconfig: {0})
�openr�IOError�errno�ENOENTrr.�yamlZ	YAMLErrorr
rr4r*)rr�streamZloaded_content�eZ
loaded_configrrr�load_kubeconfig�s
z KubeconfigLoader.load_kubeconfig)N)rrr	rr=rrrrr3�s
r3c@seZdZdd�ZdS)�KubeconfigWritercCs�tjj|j�}ytj|�Wn<tk
rX}z |jtjkrHtdj|���WYdd}~XnXy(t	|jd��}t
|j|�WdQRXWn0tk
r�}ztdj|���WYdd}~XnXdS)a
        Write config to disk.
        OK if the file doesn't exist.

        :param config: The kubeconfig to write
        :type config: Kubeconfig

        :raises KubeconfigInaccessableError: if the kubeconfig
        can't be opened for writing
        z'Can't create directory for writing: {0}Nzw+z&Can't open kubeconfig for writing: {0})
�osr�dirname�makedirs�OSErrorr8ZEEXISTrr.r6rrr7)rr)Z	directoryr<r;rrr�write_kubeconfig�sz!KubeconfigWriter.write_kubeconfigN)rrr	rCrrrrr>�sr>c@s(eZdZdd�Zddd�Zd	dd�ZdS)
�KubeconfigAppendercCs�||jkrg|j|<|j|}t|t�s>tdj|t|�t���d}x@t|�D]4\}}d|krLd|krL|d|dkrL|||<d}qLW|s�|j|�||j|<|S)z�
        Insert entry into the array at content[key]
        Overwrite an existing entry if they share the same name

        :param config: The kubeconfig to insert an entry into
        :type config: Kubeconfig
        z1Tried to insert into {0},which is a {1} not a {2}FrT)rr&r1rr.r-�	enumerate�append)rr)r/�entryZarray�foundZcounterZexisting_entryrrr�insert_entry�s&





zKubeconfigAppender.insert_entryNcCs4tdtd|dfd|dfg�fd|p,|dfg�S)zE Generate a context to associate cluster and user with a given alias.�contextr!r�user)r)rr!rK�aliasrrr�
_make_context�s

z KubeconfigAppender._make_contextcCsL|j|||d�}|j|d|�|j|d|�|j|d|�|d|jd<|S)ag
        Insert the passed cluster entry and user entry,
        then make a context to associate them
        and set current-context to be the new context.
        Returns the new context

        :param config: the Kubeconfig to insert the pair into
        :type config: Kubeconfig

        :param cluster: the cluster entry
        :type cluster: OrderedDict

        :param user: the user entry
        :type user: OrderedDict

        :param alias: the alias for the context; defaults top user entry name
        :type context: str

        :return: The generated context
        :rtype: OrderedDict
        )rLrrrrzcurrent-context)rMrIr)rr)r!rKrLrJrrr�insert_cluster_user_pair�sz+KubeconfigAppender.insert_cluster_user_pair)N)N)rrr	rIrMrNrrrrrD�s

rD)r?r:Zloggingr8Zbotocore.compatrZ$awscli.customizations.eks.exceptionsrZ&awscli.customizations.eks.ordered_yamlrrrr
rr�objectrr$r3r>rDrrrr�<module>s;*