
                         V    d dl Z d dlmZ ddlmZ dZdZdZdZd	 Z	 G d
 de
      Zd Zy)    N)Configuration   )ConfigExceptionKUBERNETES_SERVICE_HOSTKUBERNETES_SERVICE_PORTz3/var/run/secrets/kubernetes.io/serviceaccount/tokenz4/var/run/secrets/kubernetes.io/serviceaccount/ca.crtc                 0    d}d| v xs d| v }|rd}|| |fz  S )z!Adapted golang's net.JoinHostPortz%s:%s:%z[%s]:%s )hostporttemplatehost_requires_bracketings       5lib/third_party/kubernetes/config/incluster_config.py_join_host_portr      s1    ( D[7C4KH	T4L	      c                   <    e Zd Zej                  fdZd Zd Zd Zy)InClusterConfigLoaderc                 .    || _         || _        || _        y N)_token_filename_cert_filename_environ)selftoken_filenamecert_filenameenvirons       r   __init__zInClusterConfigLoader.__init__(   s    )D'DDMr   c                 D    | j                          | j                          y r   )_load_config_set_config)r   s    r   load_and_setz"InClusterConfigLoader.load_and_set-   s    r   c                 \   t         | j                  vst        | j                  vrt        d      | j                  t            r| j                  t           st        d      dt	        | j                  t            | j                  t                 z   | _        t        j                  j                  | j                        st        d      t        | j                        5 }|j                         | _        | j                  st        d      	 d d d        t        j                  j                  | j                        st        d      t        | j                        5 }|j                         st        d      	 d d d        | j                  | _        y # 1 sw Y   xY w# 1 sw Y   'xY w)NzService host/port is not set.z#Service host/port is set but empty.zhttps://z#Service token file does not exists.zToken file exists but empty.z+Service certification file does not exists.zCert file exists but empty.)SERVICE_HOST_ENV_NAMEr   SERVICE_PORT_ENV_NAMEr   r   r   ospathisfiler   openreadtokenr   ssl_ca_cert)r   fs     r   r    z"InClusterConfigLoader._load_config1   sN   T]]2T]]2;<<MM/0MM/0ABB /D!E!%/D!EGGDI 77>>$../ABB	d""	#q668djZZ<==  
$
 77>>$--.IJJ	d!!	"aVVX;<<  
# **D 
$	# 
#	"s    -FF"F"F+c                     t               }| j                  |_        | j                  |_        d| j                  z   |j                  d<   t        j
                  |       y )Nzbearer authorization)r   r   r,   r+   api_keyset_default)r   configurations     r   r!   z!InClusterConfigLoader._set_configO   sJ    !OMM $ 0 0M-6-CM/*m,r   N)	__name__
__module____qualname__r&   r   r   r"   r    r!   r   r   r   r   r   &   s    <>JJ 
+<-r   r   c                  J    t        t        t              j                          y)a  
    Use the service account kubernetes gives to pods to connect to kubernetes
    cluster. It's intended for clients that expect to be running inside a pod
    running on kubernetes. It will raise an exception if called from a process
    not running in a kubernetes environment.
  )r   r   N)r   SERVICE_TOKEN_FILENAMESERVICE_CERT_FILENAMEr"   r   r   r   load_incluster_configr9   W   s     +)++7<>r   )r&   kubernetes.clientr   config_exceptionr   r$   r%   r7   r8   r   objectr   r9   r   r   r   <module>r=      s?   " 
 + -1 1 N N !.-F .-b	:r   