
    IiYW                        S SK Jr  S SKrS SKrS SKJrJr  S SKJr  S SKJr  SSK	J
r
  \R                  " SS5      r\R                  " S	S5      r\" \R                  " S
S5      5      r\R                  " SS5      R!                  5       S;   r\R                  " SS5      R!                  5       S;   r\R                  " SS5      R!                  5       S;   r\" \R                  " SS5      5      rS r " S S\5      rS rS rS rS rS rS rS rS rS r S\\S\\S 4S! jr!S" r"S.S# jr#S/S$ jr$S% r%S0S& jr&S' r'S( r(S) r)S1S* jr*S+ r+ " S, S-\5      r,\," 5       r-g)2    )absolute_importN)datetimetimezone)	timedelta)local   )Result,OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_HOSTNAME,OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_USERNAME(OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_PORT22,OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_AUTO_ADDfalse)yestruety15OPENSHIFT_CLIENT_PYTHON_DEFAULT_LOAD_SYSTEM_HOST_KEYSr   'OPENSHIFT_CLIENT_PYTHON_SKIP_TLS_VERIFY&OPENSHIFT_CLIENT_PYTHON_MASTER_TIMEOUTc                  (    [         R                  S   $ )Nr   )contextstack     >/venv/lib/python3.13/site-packages/openshift_client/context.pycur_contextr      s    ==r   c                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSS jrS rS rS rS rS rS rS rSrg)Context!   c                 P   S U l         S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        S U l	        SU l
        S U l        S U l        S U l        S U l        SU l        S U l        S U l        SU l        SU l        SU l        S U l        [,        R.                  " 5        Hs  n[,        R0                  " US   5      nU(       a2  UR2                  S:X  d   UR2                  R5                  S5      (       a  MU  [,        R6                  " US   5      U l          g    g )NF   X  Tr   openshift_clientzopenshift_client.)parentoc_pathkubeconfig_path
api_servertokenca_cert_pathproject_nameloglevel_valueskip_tls_verifytracking_strategyno_trackingtimeout_datetimeoptions
ssh_clientssh_hostnamessh_portssh_usernamessh_passwordssh_timeoutssh_auto_add_hostssh_load_system_host_keys
frame_infoinspectr   	getmodule__name__
startswithgetframeinfo)selfframemodules      r   __init__Context.__init__"   s   #
  "#!%  $    !&)-& ]]_E&&uQx0F6??.@@FOOD^D^_rDsDs%2258<DO %r   c                     [        [        R                  5      S:  a  [        R                  S   U l        [        R                  R	                  U 5        U R                  5         U $ )Nr   r   )lenr   r   r'   appendreconnect_sshrB   s    r   	__enter__Context.__enter__G   sF    w}}!!--+DKT"r   c                 z    U R                   (       a#   U R                   R                  5         S U l         g g !    N= fN)r4   closerK   s    r   	close_sshContext.close_sshN   s6    ??%%' #DO s   6 :c                    U R                  5         U R                  (       Ga[  SSKn[        SS5      UR                  R
                  l        [        SS5      UR                  R
                  l        UR                  5       U l	        U R                  (       a  U R                  R                  5         U R                  (       a)  U R                  R                  UR                  5       5        U R                  R                  U R                  U R                   U R"                  U R$                  U R&                  S9  U R                  R)                  5       nUR*                  R-                  UR/                  5       5        gg)zJ
If you lose a connection to the bastion, you can restablish it.
:return:
r   N   (   )hostnameportusernamepasswordtimeout)rQ   r5   paramikopowpacket
PacketizerREKEY_BYTESREKEY_PACKETS	SSHClientr4   r;   load_system_host_keysr:   set_missing_host_key_policyAutoAddPolicyconnectr6   r7   r8   r9   get_transportagentAgentRequestHandleropen_session)rB   r[   	transports      r   rJ   Context.reconnect_sshW   s   
 	  69BZHOO&&27:1bzHOO&&4&002DO --557 %%;;H<R<R<TUOO##T->->T]]]a]n]n-1->->HXHX $ Z 557INN..y/E/E/GH3 r   c                 `    [         R                  R                  5         U R                  5         g rO   )r   r   poprQ   )rB   typevalue	tracebacks       r   __exit__Context.__exit__x   s    r   c                 "    U R                  5       $ )zN
The API has been flagged for deprecation.  Please use get_api_server instead
)get_api_serverrK   s    r   get_api_urlContext.get_api_url}   s     ""$$r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r*   r'   rt   r   default_api_serverrK   s    r   rt   Context.get_api_server   s?    ??&??";;";;--//)))r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r+   r'   	get_tokenr   default_tokenrK   s    r   r{   Context.get_token   s?    ::!::;;";;((**$$$r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r,   r'   get_ca_cert_pathr   default_ca_cert_pathrK   s    r   r   Context.get_ca_cert_path   sC    ($$$;;";;//11+++r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r(   r'   get_oc_pathr   default_oc_pathrK   s    r   r   Context.get_oc_path   s?    <<#<<;;";;**,,&&&r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r)   r'   get_kubeconfig_pathr   default_kubeconfig_pathrK   s    r   r   Context.get_kubeconfig_path   C    +''';;";;2244...r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ g)z
:rtype SSHClient:
N)r4   r'   get_ssh_clientrK   s    r   r   Context.get_ssh_client   s8     ??&??";;";;--//r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ g rO   )r7   r'   get_ssh_usernamerK   s    r   r   Context.get_ssh_username   :    ($$$;;";;//11r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ g rO   )r8   r'   get_ssh_passwordrK   s    r   r   Context.get_ssh_password   r   r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ g rO   )r5   r'   get_ssh_hostnamerK   s    r   r   Context.get_ssh_hostname   r   r   c                     U R                   b  U R                   $ U R                  c'  U R                  b  U R                  R                  5       $ [        R
                  $ rO   )r-   r*   r'   get_projectr   default_projectrK   s    r   r   Context.get_project   sN    ($$$ ??"t{{'>;;**,,&&&r   Nc                     Uc  0 nUnU R                   (       d   UR                  [        R                  5        OU R                   R	                  US9  U R
                  (       a  UR                  U R
                  5        U$ )N)add_to)r'   updater   default_optionsget_optionsr3   )rB   r   	aggregates      r   r   Context.get_options   sf    >F	 {{W445 KK##9#5 <<T\\*r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r.   r'   get_loglevelr   default_loglevelrK   s    r   r   Context.get_loglevel   sC    *&&&;;";;++--'''r   c                     U R                   b  U R                   $ U R                  b  U R                  R                  5       $ [        R                  $ rO   )r/   r'   get_skip_tls_verifyr   default_skip_tls_verifyrK   s    r   r   Context.get_skip_tls_verify   r   r   c                     [        5       n[        R                  " [        R                  5      nUb1  UR
                  b  X!R
                  :  a  SU4$ UR                  nUb  M1  g)z
:return: Returns any Context which claims it is timed out. Returns (True,Context) if any surrounding timeout context is expired. If not, returns (False,None)
T)FN)r   r   nowr   utcr2   r'   )rB   cr   s      r   get_out_of_timeContext.get_out_of_time   sW     Mll8<<(m!!-#8J8J2JQwA m r   c                    [        5       nSn[        R                  " [        R                  5      nSnUb  UR
                  bv  X1R
                  :  a  SU4$ Uc   UR
                  U-
  R                  5       nUnO@UR
                  U-
  R                  5       U:  a  UnUR
                  U-
  R                  5       nUR                  nUb  M  Ub
  US:  a  SU4$ X$4$ )a'  
:return: Returns the number of seconds a command needs to finish to satisfy
existing timeout contexts and the Context which possessed the minimum; i.e. (secs, Context).
A minimum of 1 second is always returned if a timeout context exists. If no timeout context exists,
(None,None) is returned.
Nr   )r   r   r   r   r   r2   total_secondsr'   )rB   r   min_secsr   limiting_contexts        r   get_min_remaining_seconds!Context.get_min_remaining_seconds  s     Mll8<<(m!!-+++a4K% ! 2 2S 8GGIH'($((3.==?(J'($ ! 2 2S 8GGIHA m HqL&&&))r   c                 Z    [        U R                  [        5      (       a  U R                  $ g)z
:return: If this contextmanager was returned by `with tracking()`, returns
the Result object which has tracked all internal oc invocations. Otherwise,
returns None.
N)
isinstancer0   r	   rK   s    r   
get_resultContext.get_result!  s&     d,,f55)))r   c                    U nUb  UR                   (       a  g UR                  (       aL  [        UR                  [        5      (       a  UR                  R	                  U5        OUR                  U5        UR
                  nUb  M  g g rO   )r1   r0   r   r	   
add_actionr'   )rB   actionr   s      r   register_actionContext.register_action1  sd    m}}""a116::''226:''/A mr   c                     U(       a:  US:  a4  [         R                  " [        R                  5      [	        US9-   U l        gSU l        g)a  
Sets the internal timeout for this context the specified number of
seconds in the future from the time it is called. Internal use only.
:param seconds: The number of seconds from now to start timing out oc invocations. If None, timeout
    for this context is cleared.
:return: N/A
r   )secondsN)r   r   r   r   r   r2   )rB   r   s     r   set_timeoutContext.set_timeout?  s5     w{$,LL$>SZA[$[D!$(D!r   )r*   r,   r<   r)   r.   r1   r(   r3   r'   r-   r/   r:   r4   r5   r;   r8   r6   r9   r7   r2   r+   r0   rO   )r?   
__module____qualname____firstlineno__rE   rL   rQ   rJ   rq   ru   rt   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r   r   r!   r!   !   s}    #J#IB
%*%,'/'((/*> )r   r!   c                     U [         l        g)z
Sets the default full path of the oc binary to execute for this thread.
If no client_path() context is in use, this path will be used.
N)r   r   paths    r   set_default_oc_pathr   M  s    
 #Gr   c                     U [         l        g rO   )r   r   r   s    r   set_default_kubeconfig_pathr   U  s
    &*G#r   c                     [        U 5        g)zV
The API has been flagged for deprecation.  Please use set_default_api_server instead
N)set_default_api_server)urls    r   set_default_api_urlr   Z  s     3r   c                     U [         l        g rO   )r   rx   )servers    r   r   r   a  s
    !'Gr   c                     U [         l        g rO   )r   r   )names    r   set_default_projectr   e  s
    "Gr   c                     U [         l        g rO   )r   r|   vs    r   set_default_tokenr   i  s
    Gr   c                     U [         l        g rO   )r   r   r   s    r   set_default_loglevelr   m  s
     Gr   c                     U [         l        g rO   )r   r   )do_skips    r   set_default_skip_tls_verifyr   q  s
    &-G#r   c                      [        5       n U $ )z
:return:  Returns a blank context which can be used to temporarily replace a real context in a with statement.
Mostly useful for debugging programs without having to tab/untab a large amount of code.
)r!   r   s    r   blankr   u  s    
 		AHr   r%   c                     [        5       nU c  [        n U (       a&  SU ;   a   U R                  SS5      u  Ul        Ul        OXl        X'l        Xl        X7l        Xgl        XGl        XWl	        U$ )a  
Will ssh to the specified host to in order to run oc commands. If hostname is not specified,
the environment variable OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_HOSTNAME will be used. If the environment variable is
not defined, this context will have no effect and the current host will be assumed to be the
host on which oc will be run.
:param hostname: The hostname or IP address. Defaults to environment variable OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_HOSTNAME if None.
        If the hostname is of the form 'user@host', the string will be split and the user will take precedence over
        any argument / environment variable supplied.
:param port: The ssh port. Defaults to OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_PORT, then None.
:param username: The username to use. Defaults to OPENSHIFT_CLIENT_PYTHON_DEFAULT_USERNAME, then None.
:param password: The username's password
:param auto_add_host: Whether to auto accept host certificates. Defaults to OPENSHIFT_CLIENT_PYTHON_DEFAULT_SSH_AUTO_ADD, then false.
:param load_system_host_keys: Whether load known_hosts. Defaults to DEFAULT_LOAD_SYSTEM_HOST_KEYS, then true.
:param connect_timeout: Connection timeout
:return:
@r   )
r!   DEFAULT_SSH_HOSTNAMEsplitr7   r5   r6   r8   r9   r:   r;   )rV   rW   rX   rY   auto_add_hostrb   connect_timeoutr   s           r   client_hostr   ~  sb    & 		A'C8O)1Q)?&!!JN#M'"7Hr   c                 &    [        5       nXl        U$ )z
Specifies the full path to the oc binary in this context. If unspecified, 'oc' is invoked and
it should be in $PATH.
:param oc_path: Fully path to executable oc binary
:return:
)r!   r(   )r(   r   s     r   client_pathr     s     		AIHr   c                 >    [        5       nX#l        Xl        Xl        U$ )a  
Establishes a context in which inner oc interactions
will target the specified OpenShift API server (--server arguments).
Contexts can be nested. The most immediate ancestor cluster context
will define the API server targeted by an action.
:param api_url: The oc --server argument to use.
:param kubeconfig_path: The oc --kubeconfig argument to use.
:return: The context object. Can be safely ignored.
)r!   r)   r*   r,   )api_urlr,   r)   r   s       r   r*   r*     s      		A'L!NHr   c                 &    [        5       nXl        U$ )z
Establishes a context in which inner oc interactions
will include the specified token on the command line with --token.
:param val: The oc --token argument to use.
:return: The context object. Can be safely ignored.
)r!   r+   )valr   s     r   r+   r+     s     		AGHr   c                 ^    [        5       nU (       d  U$ U R                  S5      S   Ul        U$ )a^  
Establishes a context in which inner oc interactions
will impact the named OpenShift project. project contexts
can be nested. The most immediate ancestor project context
will define the project used by an action.
:param name: The name of the project. If None, parent context project will be used.
:return: The context object. Can be safely ignored.
/r   )r!   r   r-   )r   r   s     r   projectr     s.     		A ZZ_R(ANHr   c                     [        5       nU (       a#  [        U 5      (       d  [        S5      eXl        U$ [	        SU5      Ul        U$ )a  
Establishes a context in which all inner actions will
be tracked (unless a inner no_tracking context prevents
tracking). Trackers can be nested -- all actions
performed within a tracker's context will be tracked unless
there is a descendant no_tracking context which blocks tracking
from propagating to this ancestor.
:param action_handler: If specified, after each oc action is
performed, this method will be called with the Action object.
If not specified, all Actions will aggregate into a internally
managed Result object which can be accessed with get_result.
:param limit: If specified, it allows to specify a limit on the
number of actions stored by a given tracking context. If not
specified or given a value less than 0, it will store unlimited number of oc
interactions, and the limit value will be stored in the Result object.
:return: The tracker contextmanager. If action_handler is not
specified, call get_result to receive a Result object with all
tracked Action objects.
z&Expected action_handler to be callabletracking)r!   callable
ValueErrorr0   r	   )action_handlerlimitr   s      r   r   r     sH    ( 		A''EFF, H %Z7Hr   c                  (    [        5       n SU l        U $ )a;  
Prevent outer tracker contexts from registering
oc actions in their tracker objects. This is useful
when a large amount of data is going to be transferred
via stdout/stderr OR when certain actions make carry
confidential data that should not appear in trackers.
:return: The context object. Can be safely ignored.
T)r!   r1   r   s    r   r1   r1     s     		AAMHr   c                  p    [        5       n0 Ul        U  H  nUR                  R                  U5        M      U$ )a  
Establishes a context in which inner oc invocations will be passed
an arbitrary set of options. This is most useful in ensuring, for
example, that a certain --token, --as, --context, etc, is passed to each
oc invocation.

Keys should be long form option names, without preceding hyphens. e.g.
{ 'token': '.....' } .

Unlike most other contexts, .options is additive. If on oc invocation is
embedded within two .options, it will include both sets. Inner option
contexts will override the same key specified at outer levels. A value
of None will prevent the option from being passed.

Tip for flags: Even flags like --insecure-skip-tls-verify can be
specified as key=value:  --insecure-skip-tls-verify=true

:param args: A vararg list of dicts.
    Keys in dicts will be pre-pended with '-' if single letter or
    '--' if multiple letter not already preceded with a hyphen.

:return: The context object. Can be safely ignored.
)r!   r3   r   )argsr   ds      r   r3   r3     s5    2 		AAI			  Hr   c                 &    [        5       nXl        U$ )a3  
Establishes a context in which inner oc interactions
will execute with the specified loglevel. loglevel contexts
can be nested. The most immediate ancestor loglevel context
will define the loglevel used by an action.
:param v: The loglevel to use (0-9).
:return: The context object. Can be safely ignored.
)r!   r.   )r   r   s     r   loglevelr   4  s     		AHr   c                 2    [        5       nU (       + Ul        U$ )z
Establishes a context in which inner oc interactions
will pass honor/ignore tls verification.
:param enable: If false, --insecure-skip-tls-verify will be passed to oc invocations
:return: The context object. Can be safely ignored.
)r!   r/   )enabler   s     r   
tls_verifyr  B  s     		A"
AHr   c                 <    [        5       nUR                  U 5        U$ )ap  
Establishes a context in which inner oc interactions
must terminate within a specified period. timeout contexts
can be nested and each nested layer will be enforced.
If actions run longer than the specified timeout, an exception
will be thrown.
:param seconds: The number of seconds before actions should time out.
:return: The context object. Can be safely ignored.
)r!   r   )r   r   s     r   rZ   rZ   N  s     		AMM'Hr   c                       \ rS rSrS rSrg)ThreadLocalContexti]  c                    [         R                  " SS5      U l        [         R                  " SS 5      U l        [         R                  " SS 5      U l        S U l        [         R                  " SS 5      U l        [         R                  " SS 5      U l        0 U l        [         R                  " SS 5      U l	        [         R                  " SS 5      U l
        [        5       nUR                  [        5        U/U l        g )	N'OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_PATHoc+OPENSHIFT_CLIENT_PYTHON_DEFAULT_CONFIG_PATH*OPENSHIFT_CLIENT_PYTHON_DEFAULT_API_SERVER,OPENSHIFT_CLIENT_PYTHON_DEFAULT_CA_CERT_PATH'OPENSHIFT_CLIENT_PYTHON_DEFAULT_PROJECT+OPENSHIFT_CLIENT_PYTHON_DEFAULT_OC_LOGLEVEL/OPENSHIFT_CLIENT_PYTHON_DEFAULT_SKIP_TLS_VERIFY)osgetenvr   r   rx   r|   r   r   r   r   r   r!   r   MASTER_TIMEOUTr   )rB   root_contexts     r   rE   ThreadLocalContext.__init__^  s    !yy)RTXY')yy1^`d'e$"$)),XZ^"_!$&II.\^b$c!!yy)RTXY! "		*WY] ^')yy1bdh'i$y  0 #^
r   )
rx   r   r   r   r   r   r   r   r|   r   N)r?   r   r   r   rE   r   r   r   r   r  r  ]  s    $r   r  )NNNrO   )NN)T).
__future__r   r=   r  r   r   r   	threadingr   resultr	   r  r   DEFAULT_SSH_USERNAMEintDEFAULT_SSH_PORTlowerDEFAULT_SSH_AUTO_ADDDEFAULT_LOAD_SYSTEM_HOST_KEYSGLOBAL_SKIP_TLS_VERIFYr  r   objectr!   r   r   r   r   r   r   r   r   r   r   r   r*   r+   r   r   r1   r3   r   r  rZ   r  r   r   r   r   <module>r     s   &  	 '    yy!OQUV yy!OQUV ryy!KTRS yy!OQXY__a f   "		*aci j p p r w !  #LgV\\^ c   RYYGLMi)f i)X	#+
 (#!. $4?S^b2Jg #$N
$
$>H	$ $2 
r   