:py:mod:`binaryai.utils` ======================== .. py:module:: binaryai.utils Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: binaryai.utils.QCloudHttpxAuth Functions ~~~~~~~~~ .. autoapisummary:: binaryai.utils.sha256sum binaryai.utils.sign binaryai.utils.getSignatureKey .. py:function:: sha256sum(path: str) -> str Computes sha256 hash sum of a file. :param path: path of file :returns: hex digest of sha256 .. py:function:: sign(key, msg) Modified from https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html .. py:function:: getSignatureKey(key, dateStamp, serviceName) Modified from https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html .. py:class:: QCloudHttpxAuth(qcloud_secret_id, qcloud_secret_key, qcloud_host, qcloud_region, qcloud_service, qcloud_action, qcloud_apiversion) Bases: :py:obj:`httpx.Auth` Auth class that allows us to connect to QCloud services .. py:attribute:: requires_request_body :value: True .. py:method:: auth_flow(r: httpx.Request) -> Generator[httpx.Request, httpx.Response, None] Adds the authorization headers required by QCloud Signature v3. .. py:method:: get_qcloud_request_headers_handler(r) Override get_qcloud_request_headers_handler() if you have a subclass that needs to call get_qcloud_request_headers() with an arbitrary set of QCloud credentials. The default implementation calls get_qcloud_request_headers() with self.qcloud_access_key, and self.qcloud_secret_access_key .. py:method:: get_qcloud_request_headers(r: httpx.Request, qcloud_secret_id, qcloud_secret_key) Returns a dictionary containing the necessary headers for Amazon's signature version 4 signing process. An example return value might look like { 'Authorization': '...', '...', } .. py:method:: get_canonical_path(r: httpx.Request) :classmethod: Create canonical path. According to QCloud, this should always be "/" .. py:method:: get_canonical_querystring(r: httpx.Request) :classmethod: Create the canonical query string. According to QCloud, by the end of this function our query string values must be URL-encoded (space=%20) and the parameters must be sorted by name. This method assumes that the query params in `r` are *already* url encoded. If they are not url encoded by the time they make it to this function, QCloud may complain that the signature for your request is incorrect. It appears elasticsearc-py url encodes query paramaters on its own: https://github.com/elastic/elasticsearch-py/blob/5dfd6985e5d32ea353d2b37d01c2521b2089ac2b/elasticsearch/connection/http_requests.py#L64 If you are using a different client than elasticsearch-py, it will be your responsibility to urleconde your query params before this method is called.