chefsessionlib package¶
Submodules¶
chefsessionlib.chefsessionlib module¶
Main code for chefsessionlib.
- class chefsessionlib.chefsessionlib.ChefSession(user_id: str, private_key_contents: str, client_version: str = '12.0.2', authentication_version: str = '1.0', api_version: int = 1, user_agent: str = 'python/cheflib')[source]¶
Bases:
Session
Implements a chef server authentication scheme on a requests Session.
- property authentication_version: str¶
The authentication version to use for the server.
- Returns:
The authenticated version provided to the constructor. Defaults to ‘1.0’.
- static canonical_path(path: str) str [source]¶
Enforces the rules for the canonical path.
- The rules of the canonical path are:
- The authentication method does not support consecutive slashes so those are replace with a single one
if present.
Only the url portion of a path is used for the authentication so the parameters part is discarded If the path is more than one character (/ is a valid path to request) then any possible trailing slashes
are removed.
- Parameters:
path – The path requested.
- Returns:
The canonical path according to the rules.
- property canonical_user_id: str¶
The canonical user id.
Depending on the authentication version a different representation of the provided user id is calculated. For authentication version 1.1 the provided user id gets its digest hashed with sha1 and the result is b64 encoded and then decoded to utf-8.
- Returns:
A string of the appropriate representation of the user id based on the authentication version used.
- static get_current_timestamp() <module 'datetime' from '/home/docs/.asdf/installs/python/3.9.18/lib/python3.9/datetime.py'> [source]¶
The current timestamp.
- Returns:
The current timestamp with the appropriate format.
- property hashing_method: str¶
The name of the hashing method to be used according to the requested authentication method.
- Returns:
The name of the method.
- request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None) Response [source]¶
Verbatim copy of the request method of requests.Session.
Hijacks the request, applies the authentication headers and checks the response status code for success.
- Returns:
The response object if the status code is not 401
- Raises:
InvalidAuthentication if the status code is set to 401. –
- property user_id: str¶
The user id provided.
chefsessionlib.chefsessionlibexceptions module¶
Custom exception code for chefsessionlib.
- exception chefsessionlib.chefsessionlibexceptions.InvalidAuthentication[source]¶
Bases:
Exception
The authentication did not succeed.
Module contents¶
chefsessionlib package.
Import all parts from chefsessionlib here