Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/clustering/k8s/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyo

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlmZdd
l
mZmZmZyddlZeZWnek
r�eZnXyddlmZeZWnek
r�eZnXyddlmZeZWnek
r!eZnXiidd6ddgd6d6ied6d6id6ied6d6idd6dgd6d6idd6ed6d gd6d!6ied6d"6Zd#efd$��YZd%�Zed&kr�e�ndS('i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�

module: k8s_auth

short_description: Authenticate to Kubernetes clusters which require an explicit login step

version_added: "2.8"

author: KubeVirt Team (@kubevirt)

description:
  - "This module handles authenticating to Kubernetes clusters requiring I(explicit) authentication procedures,
    meaning ones where a client logs in (obtains an authentication token), performs API operations using said
    token and then logs out (revokes the token). An example of a Kubernetes distribution requiring this module
    is OpenShift."
  - "On the other hand a popular configuration for username+password authentication is one utilizing HTTP Basic
    Auth, which does not involve any additional login/logout steps (instead login credentials can be attached
    to each and every API call performed) and as such is handled directly by the C(k8s) module (and other
    resource–specific modules) by utilizing the C(host), C(username) and C(password) parameters. Please
    consult your preferred module's documentation for more details."

options:
  state:
    description:
    - If set to I(present) connect to the API server using the URL specified in C(host) and attempt to log in.
    - If set to I(absent) attempt to log out by revoking the authentication token specified in C(api_key).
    default: present
    choices:
    - present
    - absent
  host:
    description:
    - Provide a URL for accessing the API server.
    required: true
  username:
    description:
    - Provide a username for authenticating with the API server.
  password:
    description:
    - Provide a password for authenticating with the API server.
  ca_cert:
    description:
    - "Path to a CA certificate file used to verify connection to the API server. The full certificate chain
      must be provided to avoid certificate validation errors."
    aliases: [ ssl_ca_cert ]
  validate_certs:
    description:
    - "Whether or not to verify the API server's SSL certificates."
    type: bool
    default: true
    aliases: [ verify_ssl ]
  api_key:
    description:
    - When C(state) is set to I(absent), this specifies the token to revoke.

requirements:
  - python >= 2.7
  - urllib3
  - requests
  - requests-oauthlib
s�
- hosts: localhost
  module_defaults:
    group/k8s:
      host: https://k8s.example.com/
      ca_cert: ca.pem
  tasks:
  - block:
    # It's good practice to store login credentials in a secure vault and not
    # directly in playbooks.
    - include_vars: k8s_passwords.yml

    - name: Log in (obtain access token)
      k8s_auth:
        username: admin
        password: "{{ k8s_admin_password }}"
      register: k8s_auth_results

    # Previous task provides the token/api_key, while all other parameters
    # are taken from module_defaults
    - name: Get a list of all pods from any namespace
      k8s_info:
        api_key: "{{ k8s_auth_results.k8s_auth.api_key }}"
        kind: Pod
      register: pod_list

    always:
    - name: If login succeeded, try to log out (revoke access token)
      when: k8s_auth_results.k8s_auth.api_key is defined
      k8s_auth:
        state: absent
        api_key: "{{ k8s_auth_results.k8s_auth.api_key }}"
s�
k8s_auth:
  description: Kubernetes authentication facts.
  returned: success
  type: complex
  contains:
    api_key:
      description: Authentication token.
      returned: success
      type: str
    host:
      description: URL for accessing the API server.
      returned: success
      type: str
    ca_cert:
      description: Path to a CA certificate file used to verify connection to the API server.
      returned: success
      type: str
    validate_certs:
      description: "Whether or not to verify the API server's SSL certificates."
      returned: success
      type: bool
    username:
      description: Username for authenticating with the API server.
      returned: success
      type: str
N(t
AnsibleModule(turlparsetparse_qst	urlencode(t
OAuth2Session(tmake_headerstpresenttdefaulttabsenttchoiceststatetrequiredthosttusernametno_logtpasswordtpathttypetssl_ca_certtaliasestca_certtboolt
verify_ssltvalidate_certstapi_keytKubernetesAuthModulecB`sJeZd�Zd�Zd�Zd�Zd�Zdd�Zd�Z	RS(c	C`s�tj|dtdddddgfdddgfg�tsP|jd	�ntsf|jd
�nts||jd�ndS(Nt
argument_spectrequired_ifRRRRRR sOThis module requires the python 'requests' package. Try `pip install requests`.saThis module requires the python 'requests-oauthlib' package. Try `pip install requests-oauthlib`.sMThis module requires the python 'urllib3' package. Try `pip install urllib3`.(Rt__init__tK8S_AUTH_ARG_SPECtHAS_REQUESTStfailtHAS_REQUESTS_OAUTHtHAS_URLLIB3(tself((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyR$�scC`s*|jjd�}|jjd�}|jjd�}|jjd�|_|jjd�|_|jjd�|_|jjd�|_|r�|r�||_n	||_|j�|dkr�|j�}t	d|jd|d|d|d|j�}n|j
�t	�}|jd	td
|�dS(NRRRRRR RRtchangedtk8s_auth(
tparamstgett
auth_usernamet
auth_passwordtauth_api_keytcon_hostt
con_verify_catopenshift_discovertopenshift_logintdicttopenshift_logoutt	exit_jsontFalse(R*RRRtnew_api_keytresult((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pytexecute_module�s,	
	
	c
C`s�dj|j�}tj|d|j�}|jdkrg|jdddd|d|jd	|j�ny*|j�}|d
|_	|d|_
Wn/tk
r�}|jdd
dt
j��nXdS(Ns*{0}/.well-known/oauth-authorization-servertverifyi�s#Couldn't find OpenShift's OAuth APItmethodtGETturltreasontstatus_codetauthorization_endpointttoken_endpointtmsgs9Something went wrong discovering OpenShift OAuth details.t	exception(tformatR2trequestsR.R3RBtfail_requestRAtjsontopenshift_auth_endpointtopenshift_token_endpointt	Exceptiont	fail_jsont	tracebackt
format_exc(R*R@trett
oauth_infote((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyR4�s
c	
C`s�tdd�}|j|jdddd�\}}tddj|j|j��}|j|d	i|d
6|jd�d6d|jd
t	�}|j
dkr�|jdddd|d|jd|j
�ni}x>t
t|jd�j�j�D]\}}|d||<q�Wd|d<|j|jd	idd6dd6dd6dt|�d|j�}|j
d kr�|jd!dd"d|jd|jd|j
�n|j�d#S($Nt	client_idsopenshift-challenging-clientRt1tcode_challenge_methodtS256t
basic_auths{0}:{1}theaderssX-Csrf-Tokent
authorizationR=tallow_redirectsi.sAuthorization failed.R>R?R@RARBtLocationitauthorization_codet
grant_typesapplication/jsontAccepts!application/x-www-form-urlencodedsContent-Types.Basic b3BlbnNoaWZ0LWNoYWxsZW5naW5nLWNsaWVudDo=t
Authorizationtdatai�s(Failed to obtain an authorization token.tPOSTtaccess_token(Rtauthorization_urlRKR
RGR/R0R.R3R9RBRIRAR
R	RYtquerytitemstpostRLRRJ(	R*tos_oauthRdRtauth_headersRQtqwargstktv((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyR5s:!		/
	
	cC`s{dj|j|j�}idd6dd6dj|j�d6}idd6d	d
6}tj|d|d|d
|j�}dS(Ns4{0}/apis/oauth.openshift.io/v1/oauthaccesstokens/{1}sapplication/jsonR_sContent-Types
Bearer {0}R`soauth.openshift.io/v1t
apiVersiont
DeleteOptionstkindRYRJR=(RGR2R1RHtdeleteR3(R*R@RYRJRQ((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyR7.s
cC`s|jd|�dS(NRE(RN(R*RE((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyR'=scK`sHi}x(|j�D]\}}||d|<qW|jd||�dS(Ntreq_RE(RfRN(R*REtkwargstreq_infoRkRl((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyRI@sN(
t__name__t
__module__R$R<R4R5R7tNoneR'RI(((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyR!�s		"		,	cC`sSt�}y|j�Wn5tk
rN}|jdt|�dtj��nXdS(NRERF(R!R<RMRNtstrRORP(tmoduleRS((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pytmainGs
	t__main__( t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNROtansible.module_utils.basicRt+ansible.module_utils.six.moves.urllib_parseR	R
RRHtTrueR&tImportErrorR9trequests_oauthlibRR(turllib3.utilR
R)R%R!RyRt(((sK/usr/lib/python2.7/site-packages/ansible/modules/clustering/k8s/k8s_auth.pyt<module>sT


>"








�	

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]