Source code for api.authentication.v1.password.password_authenticate
"""Autogenerated API"""
import requests
from argus_cli.plugin import register_command
[docs]@register_command(extending=('authentication','v1','password','authenticate'))
def authenticate(userName: str = None, domain: str = None, password: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
"""Initiate a new user session using Password authentication (PUBLIC)
Requires password 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: Static Argus-password for user
:raises AuthenticationFailedException: on 401
:raises ValidationErrorException: on 412
:raises AccessDeniedException: on 403
:raises NotFoundException: on 404
:returns: {"offset": 394, "limit": 482, "responseCode": 200, "count": 896, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Tell soon design condition particularly our capital listen.", "messageTemplate": "Six keep candidate thank.", "field": "Analysis parent world movement during price.", "parameter": {}, "timestamp": 556970427}], "currentPage": 535, "size": 169}
"""
from requests import post
from argus_api.exceptions import http
url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/authentication/v1/password/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})
if password:
body.update({"password": password})
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