Anons79 Mini Shell

Directory : /proc/self/root/lib/python2.7/site-packages/ansible/plugins/httpapi/
Upload File :
Current File : //proc/self/root/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyo

�
�Udac@`s�ddlmZmZmZeZdZddlZddlZddl	Z	ddl
mZddl
mZddlmZddlmZmZmZddlmZmZdd	lmZdd
lmZddlmZddlmZdd
l m!Z!ddl"m#Z#idd6dd6ded6Z$dZ%dZ&dZ'dZ(dZ)ddgZ*dZ+dZ,defd��YZ-e.e.d�Z/d �Z0dS(!i(tabsolute_importtdivisiontprint_functionse
---
author: Ansible Networking Team
httpapi : ftd
short_description: HttpApi Plugin for Cisco ASA Firepower device
description:
  - This HttpApi plugin provides methods to connect to Cisco ASA firepower
    devices over a HTTP(S)-based api.
version_added: "2.7"
options:
  token_path:
    type: str
    description:
      - Specifies the api token path of the FTD device
    vars:
      - name: ansible_httpapi_ftd_token_path
  spec_path:
    type: str
    description:
      - Specifies the api spec path of the FTD device
    default: '/apispec/ngfw.json'
    vars:
      - name: ansible_httpapi_ftd_spec_path
N(t__version__(tto_text(tAnsibleConnectionFailure(tFdmSwaggerParsertSpecProptFdmSwaggerValidator(t
HTTPMethodtResponseParams(t	HTTPError(t	urlencode(tHttpApiBase(tencode_multipart_formdata(tRequestField(tConnectionErrorsapplication/jsonsContent-TypetAcceptsFTD Ansible/%ss
User-Agenti�i�t
token_paths/api/fdm/{0}/fdm/tokens
/api/versionstv2tv1s�The API token path is incorrect. Please, check correctness of the `ansible_httpapi_ftd_token_path` variable in the inventory file.s�Ansible could not determine the API token path automatically. Please, specify the `ansible_httpapi_ftd_token_path` variable in the inventory file.tHttpApicB`s.eZd�Zd�Zd�Zd�Zd�Zd�Zdd�Z	d�Z
dddd�Zd	�Zdd
�Z
d�Zdd
�Zed��Zd�Zd�Zd�Zd�Zd�Zed��Zd�Zd�Zd�Zd�Zd�Zd�Zed��Zed��Z RS(cC`sPtt|�j|�||_d|_d|_d|_d|_t	|_
dS(N(tsuperRt__init__t
connectiontNonetaccess_tokent
refresh_tokent	_api_spect_api_validatortFalset_ignore_http_errors(tselfR((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRUs					cC`s�d�}d�}|jr-||j�}n*|rK|rK|||�}ntd��|j|�}y8|d|_|d|_id|jd6|j_Wn!tk
r�td|��nXdS(	NcS`sidd6|d6|d6S(Ntpasswordt
grant_typetusername((R#R!((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytrequest_token_payload_scS`sidd6|d6S(NRR"((R((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytrefresh_token_payloadfssHUsername and password are required for login in absence of refresh tokenRRs	Bearer %st
AuthorizationsPServer returned response without token info during connection authentication: %s(RRt_lookup_login_urlRRt_authtKeyErrorR(R R#R!R$R%tpayloadtresponse((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytlogin^s			


cC`s�|j�}|r|g}n|j�}x�|D]�}y|j||�}WnTtk
r�}|jjdd||f�t|d�r�|jdkr��q�q1X|s�|j|�n|Sq1Wt|r�t	nt
��dS(s� Try to find correct login URL and get api token using this URL.

        :param payload: Token request payload
        :type payload: dict
        :return: token generation response
        tvvvvs:REST:request to %s failed because of connection error: %s t	http_codei�N(t_get_api_token_patht_get_known_token_pathst_send_login_requestRRt
queue_messagethasattrR.t_set_api_token_pathtINVALID_API_TOKEN_PATH_MSGtMISSING_API_TOKEN_PATH_MSG(R R*tpreconfigured_token_pathttoken_pathsturlR+te((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR'}s 

cC`s~|jtjd|�|j|tj|�dtjdt�\}}|jtjd|j��|j|j	|��}|S(NR,tmethodtheadersslogin:status_code(
t_displayR	tPOSTt_send_auth_requesttjsontdumpstBASE_HEADERStgetcodet_response_to_jsont_get_response_value(R R*R9R+t
response_data((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR1�s*cC`s�idd6|jd6|jd6}|j�}|jtjd|�|j|tj|�dtjdt	�\}}|jtjd|j
��d|_d|_dS(	Ntrevoke_tokenR"Rttoken_to_revoketlogoutR;R<slogout:status_code(RRR/R=R	R>R?R@RARBRCR(R tauth_payloadR9R+tdummy((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRI�s

!	cK`sd}|j||d||�S(Ns6Server returned an error during authentication requesttdata(t_send_service_request(R tpathRLtkwargsterror_msg_prefix((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR?�scK`s�zwy#t|_|jj|||�SWnMtk
ru}|jt|j���}td||fd|j	��nXWdt
|_XdS(Ns%s: %sR.(tTrueRRtsendRRDRtreadRtcodeR(R RNRPRLROR:t	error_msg((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRM�s	'cC`sdS(N(R(R R+RF((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytupdate_auth�sc
C`sDt|||�}|r'tj|�nd}y�|j|d|�|r_|j|d|�n|jj||d|dt�\}}	|j|	�}
|j|d|
�it	t
j6|j�t
j
6|j|
�t
j6SWnctk
r?}t|j��}|j|d|�itt
j6|jt
j
6|j|�t
j6SXdS(NR9RLR;R<R+terror(tconstruct_url_pathR@RARR=RRRRBRERQR
tSUCCESSRCtSTATUS_CODERDtRESPONSERRRSRRT(
R turl_paththttp_methodtbody_paramstpath_paramstquery_paramsR9RLR+RFtvalueR:RU((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytsend_request�s('


cC`s	t|�}|jtjd|�t|d���}td|j�tjj	|j
��}|j�t|g�\}}t
t�}||d<t|�|d<|jj|d|dtjd|�\}	}
|j|
�}|jtjd	|�|j|�SWdQXdS(
NtuploadtrbtfileToUploadsContent-TypesContent-LengthRLR;R<supload:response(RXR=R	R>topenRRStosRNtbasenametnametmake_multipartRtdictRBtlenRRRRERD(R t	from_pathtto_urlR9tsrc_filetrftbodytcontent_typeR<RKRFRa((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytupload_file�s'

-c	C`s�t|d|�}|jtjd|�|jj|dddtjdt�\}}tj	j
|�r�t|j��}tj	j
||�}nt|d��}|j|j��WdQX|jtjd|�dS(NR_tdownloadRLR;R<twbt
downloaded(RXR=R	tGETRRRRRBRgRNtisdirtextract_filename_from_headerstinfotjoinRftwritetgetvalue(	R tfrom_urltto_pathR_R9R+RFtfilenametoutput_file((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyt
download_file�s-cC`sj|jtkp|jtk}|jrf|rfd|j_|j|jjd�|jjd��t	St
S(Ntremote_userR!(RTtTOKEN_EXPIRATION_STATUS_CODEtUNAUTHORIZED_STATUS_CODERRRR(R,t
get_optionRQR(R texctis_auth_related_code((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pythandle_httperrors(tcC`s-|jjdd||jj||f�dS(NR-sREST:%s:%s:%s
%s(RR2t_url(R R]ttitletmsg((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR=scC`st|j��S(N(RR}(RF((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyREscC`s
|jd�S(Nt	spec_path(R�(R ((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyt_get_api_spec_pathscC`sJy|j�}Wntk
r)t}nXg|D]}tj|�^q1S(s�Generate list of token generation urls based on list of versions supported by device(if exposed via API) or
        default list of API versions.

        :returns: list of token generation urls
        :rtype: generator
        (t_get_supported_api_versionsRtDEFAULT_API_VERSIONStTOKEN_PATH_TEMPLATEtformat(R tapi_versionstversion((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR0s


c	C`sltj}|jdtddd|dt�\}}|j|�}|j|d|�|j|�}|dS(s�
        Fetch list of API versions supported by device.

        :return: list of API versions suitable for device
        :rtype: list
        RNRPs*Can't fetch list of supported api versionsR;R<R+tsupportedVersions(R	RwRMtGET_API_VERSIONS_PATHRBRER=RD(R R]R+RFRatapi_versions_info((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR�)s		cC`s
|jt�S(N(R�tAPI_TOKEN_PATH_OPTION_NAME(R ((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR/>scC`s|jt|�S(N(t
set_optionR�(R R9((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR4AscC`sRy|rtj|�SiSWn0ttjdt�k
rMtd|��nXdS(NtJSONDecodeErrorsInvalid JSON response: %s(R@tloadstgetattrtdecodert
ValueErrorR(t
response_text((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRDDscC`s|jtjj|d�S(N(tapi_specRt
OPERATIONStgetR(R toperation_name((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytget_operation_specLscC`s(|r |jtjj|d�SdSdS(N(R�RtMODEL_OPERATIONSR�R(R t
model_name((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyt!get_operation_specs_by_model_nameOscC`s|jtjj|d�S(N(R�RtMODELSR�R(R R�((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pytget_model_specUscC`s|jj||�S(N(t
api_validatort
validate_data(R R�RL((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR�XscC`s|jj||�S(N(R�tvalidate_query_params(R R�tparams((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR�[scC`s|jj||�S(N(R�tvalidate_path_params(R R�R�((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR�^scC`s�|jdkr�|j�}|jd|dtj�}|tjrbt�j	|tj
�|_q�td|tj|tj
f��n|jS(NR\R]sCFailed to download API specification. Status code: %s. Response: %s(
RRR�RbR	RwR
RYRt
parse_specR[RRZ(R t
spec_path_urlR+((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR�as
!cC`s+|jdkr$t|j�|_n|jS(N(RRRR�(R ((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyR�msN(!t__name__t
__module__RR,R'R1RIR?RRMRVRbRsR�R�R=tstaticmethodRER�R0R�R/R4RDR�R�R�R�R�R�tpropertyR�R�(((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRTs8				 	
				
													cC`s?|}|r|j|�}n|r;|dt|�7}n|S(Nt?(R�R(RNR_R`R9((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRXtscC`sDd}tj||jd��}|r4|jd�Std��dS(Nsattachment; ?filename="?([^"]+)sContent-Dispositionis7No appropriate Content-Disposition header is specified.(tretmatchR�tgroupR�(t
response_infotcontent_header_regexR�((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyRy}s

(1t
__future__RRRttypet
__metaclass__t
DOCUMENTATIONR@RgR�tansibleRtansible_versiontansible.module_utils.basicRtansible.errorsRt3ansible.module_utils.network.ftd.fdm_swagger_clientRRRt'ansible.module_utils.network.ftd.commonR	R
t+ansible.module_utils.six.moves.urllib.errorRt+ansible.module_utils.six.moves.urllib.parseRtansible.plugins.httpapiR
turllib3Rturllib3.fieldsRtansible.module_utils.connectionRRBR�R�R�R�R�R�R5R6RRRXRy(((s?/usr/lib/python2.7/site-packages/ansible/plugins/httpapi/ftd.pyt<module>s@�!	

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