
    ?g                     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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
    Nc                    dD ]  }||vst        d|z         |d   | _        |d   g| _        |j                  d      r| j                  j	                  |d          t
        j                  j                         | _        |j                  d      r6i }|d   D ]  }|d   }|d   }|||<    | j                  j                  |       |j                  d	      r|| _
        nd
| _
        |xs d
| _        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valueprovideClusterInfoN)r   api_versionr
   safe_getextendosenvironcopyr   updateclustercwd)	selfexec_configr   r   keyadditional_varsitemr   r   s	            T/var/www/openai/venv/lib/python3.12/site-packages/kubernetes/config/exec_provider.py__init__zExecProvider.__init__"   s     -C+%%ACGI I - '|4 +,	'II[01::??$& O#E*F|W(-% + HHOOO, 45"DLDL;$    c           
         t        t        j                  d      xr t        j                  j                         }| j                  dd|id}|r||d   d<   | j
                  r| j
                  |d   d<   t        j                  |      | j                  d<   t        j                  | j                  t        j                  |rt        j                  nt        j                  |rt        j                  nd | j                  | j                  d	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isattyExecCredentialinteractive)r	   kindspecr%   responser   KUBERNETES_EXEC_INFOT)stdoutstderrstdinr   r   universal_newlinesshellr   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-   )hasattrsysr(   r!   r   r   jsondumpsr   
subprocessPopenr
   PIPEr)   r*   r   communicatewaitstripr   loads
ValueError)r   previous_responseis_interactivekubernetes_exec_infoprocessr(   r)   	exit_codemsgdatader   s               r   runzExecProvider.run>   s    X6N3::;L;L;N**$~ 
 7H (4<<6:ll (3+/::6J+K'(""II??!/3::Z__-#))4# #..0LLN	>-	9C\\^Fv&!#&&	B::f%D 4C$%BSHJ J 4 !1!11!l#T%5%578 8 H~  	B!;b@B B	Bs   %G 	G$GG$)N)__name__
__module____qualname____doc__r   rB    r   r   r   r      s    	8-r   r   )r0   r   r2   r/   config_exceptionr   objectr   rG   r   r   <module>rJ      s$     	  
 -U6 Ur   