Source code for api.authentication.v1.ldap.ldap_authenticate

"""Autogenerated API"""

from argus_cli.plugin import register_command



[docs]@register_command(extending=("authentication","v1","ldap","authenticate")) def authenticate( userName: str = None, domain: str = None, password: str = None, json: bool = True, verify: bool = True, apiKey: str = None, authentication: dict = {} ) -> dict: """Initiate a new user session using LDAP authentication (PUBLIC) Requires ldap authentication to be enabled on the server, and for the userUse /methods to check which authentication methods are available on the server. :param str userName: Username to authenticate :param str domain: User domain :param str password: LDAP password for user :raises AuthenticationFailedException: on 401 :raises ValidationErrorException: on 412 :returns: {'offset': 382, 'limit': 749, 'responseCode': 200, 'count': 37, 'metaData': {'additionalProperties': {}}, 'messages': [{'message': 'Population sea tree big wear skin.', 'messageTemplate': 'Friend one someone short development success.', 'field': 'Day society history building foreign material man pay.', 'parameter': {}, 'timestamp': 295071459}], 'currentPage': 481, 'size': 66} """ from requests import post from argus_api.exceptions import http url = "https://portal.mnemonic.no/web/api/authentication/v1/ldap/authenticate".format() headers = { 'Content-Type': 'application/json', 'User-Agent': 'ArgusToolbelt/' } if apiKey: headers["Argus-API-Key"] = apiKey elif authentication and isinstance(authentication, dict): headers.update(authentication) elif callable(authentication): headers.update(authentication(url)) body = { "userName": userName, "domain": domain, "password": password } response = post(url, json=body if body else None, verify=verify, headers=headers ) 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