Source code for api.authentication.v1.signature.signature_authenticate

"""Autogenerated API"""
import requests
from argus_cli.plugin import register_command


[docs]@register_command(extending=('authentication','v1','signature','authenticate')) def authenticate(userName: str = None, domain: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict: """Initiate a new user session based on a cryptographic signature (INTERNAL) Requires SIGNATURE authentication to be enabled on the server, and for the user. The signature authentication requires a serialized SignedMessage object with a valid signature using the authenticating users private key. :param str userName: Username to authenticate :param str domain: User domain :returns: {"offset": 282, "limit": 758, "responseCode": 200, "count": 646, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Week thank everybody later we set part.", "messageTemplate": "Lay study night different.", "field": "Several fact start whom job.", "parameter": {}, "timestamp": 572439523}], "currentPage": 817, "size": 311} """ from requests import post from argus_api.exceptions import http url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/authentication/v1/signature/authenticate".format() headers = { 'Content-Type': 'application/json', 'User-Agent': 'ArgusToolbelt/1.0' } if apiKey: headers["Argus-API-Key"] = apiKey elif authentication and isinstance(authentication, dict): headers.update(authentication) elif callable(authentication): headers.update(authentication(url)) body = {} if userName: body.update({"userName": userName}) if domain: body.update({"domain": domain}) response = post(url, json=body if body else None, verify=verify, headers=headers) errors = [] if response.status_code == 401: raise http.AuthenticationFailedException(response) elif response.status_code == 403: raise http.AccessDeniedException(response) elif response.status_code == 412: raise http.ValidationErrorException(response) elif response.status_code == 404: raise http.ObjectNotFoundException(response) return response.json() if json else response