a )gJ @sDddlmZmZmZeZddlmZddlm Z Gddde Z dS))absolute_importdivisionprint_function)abstractmethod) AnsiblePlugincsPeZdZfddZddZddZddZd d Zd d Ze d dZ Z S) HttpApiBasecs$tt|||_d|_d|_dS)NF)superr__init__ connection_become _become_pass)selfr  __class__D/usr/lib/python3.9/site-packages/ansible/plugins/httpapi/__init__.pyr szHttpApiBase.__init__cCs|j|_t|dpd|_dS)NZ become_passr)Zbecomer getattrr )rZbecome_contextrrr set_becomeszHttpApiBase.set_becomecCsdS)aCall 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)rusernamepasswordrrrloginszHttpApiBase.logincCsdS)z Call to implement session logout. Method to clear session gracefully e.g. tokens granted in login need to be revoked. Nr)rrrrlogout!szHttpApiBase.logoutcCs|d}|rd|iSdS)zReturn 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)infoget)rZresponseZ response_textZcookierrr update_auth)szHttpApiBase.update_authcCsB|jdkr>|jjr:d|j_||jd|jddSdS|S)aaOverridable 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. iNZ remote_userrTF)coder Z_authrZ get_option)rexcrrrhandle_httperror6s zHttpApiBase.handle_httperrorcKsdS)z(Prepares and sends request(s) to device.Nr)rdataZmessage_kwargsrrr send_requestTszHttpApiBase.send_request) __name__ __module__ __qualname__r rrrrrrr __classcell__rrrrr s   rN) Z __future__rrrtypeZ __metaclass__abcrZansible.pluginsrrrrrrs