
                         F    d dl Z d dlZd dlZd dlZddlmZ  G d de      Zy)    N   )ConfigExceptionc                       e Zd ZdZd ZddZy)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
    c                    dD ]  }||vst        d|z         |d   | _        |d   g| _        |j                  d      r| j                  j	                  |d          t
        j                  j                         | _        |j                  d      r7i }|d   D ]  }|d   }|d   }|||<    | j                  j                  |       y	y	)
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valueN)
r   api_versionr
   safe_getextendosenvironcopyr   update)selfexec_configkeyadditional_varsitemr   r   s          2lib/third_party/kubernetes/config/exec_provider.py__init__zExecProvider.__init__$   s     )	K	K!" # 	# ) #<0DY'(DIF#
ii{6*+zz DHE"oe$$F|W % % hhooo& #    Nc                    | j                   ddt        j                  j                         id}|r||d   d<   t	        j
                  |      | j                  d<   t        j                  | j                  t        j                  t        j                  | j                  d      }|j                         \  }}|j                         }|d	k7  r*d
|z  }|j                         }|r|d|z  z  }t        |      	 t	        j                  |      }dD ]  }
|
|vst        d|
z         |d   | j                   k7  rt        d|d   d| j                         |d   S # t         $ r}	t        d|	z        d }	~	ww xY w)NExecCredentialinteractive)r	   kindspecr!   responseKUBERNETES_EXEC_INFOT)stdoutstderrr   universal_newlinesr   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 z does not match r'   )r   sysr$   isattyjsondumpsr   
subprocessPopenr
   PIPEcommunicatewaitstripr   loads
ValueError)r   previous_responsekubernetes_exec_infoprocessr$   r%   	exit_codemsgdatader   s              r   runzExecProvider.run;   s   && 3::,,.
 1B6":.'+zz2F'GDHH#$		HH!G **,VVIA~')3c||~f	vC  NZZd 0	DL!" # 	# 0 LT---!,/1A1AC D D>  NG"LMMNs   8E 	E7$E22E7)N)__name__
__module____qualname____doc__r   r;    r   r   r   r      s    	'.$r   r   )r*   r   r,   r(   config_exceptionr   objectr   r@   r   r   <module>rC      s$      	  
 -G6 Gr   