o
    vis                     @   s@   d dl Z d dlZd dlZd dlZddlmZ G dd deZdS )    N   )ConfigExceptionc                   @   s0   e Zd ZdZd	ddZedd Zd	ddZdS )
ExecProvidera,  
    Implementation of the proposal for out-of-tree client
    authentication providers as described here --
    https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md

    Missing from implementation:

    * TLS cert support
    * caching
    Nc           	      C   s   dD ]}||vrt d| q|d | _|d g| _|dr'| j|d  tj | _|drMi }|d D ]}|d }|d }|||< q8| j	| |d	rV|| _
nd
| _
|p\d
| _d
S )z
        exec_config must be of type ConfigNode because we depend on
        safe_get(self, key) to correctly handle optional exec provider
        config parameters.
        )command
apiVersionz)exec: malformed request. missing key '%s'r   r   argsenvnamevalueprovideClusterInfoN)r   api_versionr   safe_getextendosenvironcopyr   updateclustercwd)	selfexec_configr   r   keyadditional_varsitemr	   r
    r   ^/home/air/biblejyuku/back/venv/lib/python3.10/site-packages/kubernetes/config/exec_provider.py__init__"   s,   




zExecProvider.__init__c                 C   s
   t jdv S )N)win32cygwin)sysplatform)r   r   r   r   shell>   s   
zExecProvider.shellc              
   C   s  t tjdo
tj }| jdd|id}|r||d d< | jrI| jj|d d< | jjdrI| jjd D ]}|d	 d
krH|d |d d d<  nq4t	|| j
d< tj| jtj|r\tjntj|rctjnd | j| j
d| jd}| \}}| }|dkrd| }	| }|r|	d| 7 }	t|	zt|}
W n ty } ztd| d }~ww dD ]}||
vrtd| q|
d | jkrtd|
d | jf |
d S )NisattyExecCredentialinteractive)r   kindspecr&   responser   
extensionsr	   z!client.authentication.k8s.io/exec	extensionconfigKUBERNETES_EXEC_INFOT)stdoutstderrstdinr   r   universal_newlinesr!   r   zexec: process returned %dz. %sz)exec: failed to decode process output: %s)r   r%   statusz*exec: malformed response. missing key '%s'r   z-exec: plugin api version %s does not match %sr0   )hasattrr   r,   r"   r   r   r
   getjsondumpsr   
subprocessPopenr   PIPEr-   r.   r   r!   communicatewaitstripr   loads
ValueError)r   previous_responseis_interactivekubernetes_exec_infor)   processr,   r-   	exit_codemsgdatader   r   r   r   runG   sp   	zExecProvider.run)N)__name__
__module____qualname____doc__r   propertyr!   rE   r   r   r   r   r      s    

r   )r3   r   r5   r   config_exceptionr   objectr   r   r   r   r   <module>   s   