%PDF- %PDF-
| Direktori : /lib/python3.9/site-packages/ansible/plugins/httpapi/__pycache__/ |
| Current File : //lib/python3.9/site-packages/ansible/plugins/httpapi/__pycache__/__init__.cpython-39.pyc |
a
�)gJ � @ sD d dl mZmZmZ eZd dlmZ d dlm Z G dd� de �Z
dS )� )�absolute_import�division�print_function)�abstractmethod)�
AnsiblePluginc sP e Zd Z� fdd�Zdd� Zdd� Zdd� Zd d
� Zdd� Ze d
d� �Z
� ZS )�HttpApiBasec s$ t t| ��� || _d| _d| _d S )NF� )�superr �__init__�
connection�_become�_become_pass)�selfr �� __class__� �D/usr/lib/python3.9/site-packages/ansible/plugins/httpapi/__init__.pyr
s zHttpApiBase.__init__c C s |j | _t|d�pd| _d S )NZbecome_passr )Zbecomer �getattrr
)r Zbecome_contextr r r �
set_become s zHttpApiBase.set_becomec C s dS )a Call a defined login endpoint to receive an authentication token.
This should only be implemented if the API has a single endpoint which
can turn HTTP basic auth into a token which can be reused for the rest
of the calls for the session.
Nr )r �username�passwordr r r �login s zHttpApiBase.loginc C s dS )z� Call to implement session logout.
Method to clear session gracefully e.g. tokens granted in login
need to be revoked.
Nr )r r r r �logout! s zHttpApiBase.logoutc C s |� � �d�}|rd|iS dS )z�Return per-request auth token.
The response should be a dictionary that can be plugged into the
headers of a request. The default implementation uses cookie data.
If no authentication data is found, return None
z
Set-CookieZCookieN)�info�get)r ZresponseZ
response_textZcookier r r �update_auth) s zHttpApiBase.update_authc C sB |j dkr>| jjr:d| j_| �| j�d�| j�d�� dS dS |S )aa Overridable method for dealing with HTTP codes.
This method will attempt to handle known cases of HTTP status codes.
If your API uses status codes to convey information in a regular way,
you can override this method to handle it appropriately.
:returns:
* True if the code has been handled in a way that the request
may be resent without changes.
* False if the error cannot be handled or recovered from by the
plugin. This will result in the HTTPError being raised as an
exception for the caller to deal with as appropriate (most likely
by failing).
* Any other value returned is taken as a valid response from the
server without making another request. In many cases, this can just
be the original exception.
i� NZremote_userr TF)�coder Z_authr Z
get_option)r �excr r r �handle_httperror6 s
zHttpApiBase.handle_httperrorc K s dS )z(Prepares and sends request(s) to device.Nr )r �dataZmessage_kwargsr r r �send_requestT s zHttpApiBase.send_request)�__name__�
__module__�__qualname__r
r r r r r r r �
__classcell__r r r r r s
r N)Z
__future__r r r �typeZ
__metaclass__�abcr Zansible.pluginsr r r r r r �<module> s