Source code for api.authentication.v1.apikey

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


[docs]@register_command(extending=('authentication','v1','apikey')) def list(json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict: """List current user apikeys (PUBLIC) :raises AuthenticationFailedException: on 401 :raises ValidationErrorException: on 412 :raises AccessDeniedException: on 403 :raises NotFoundException: on 404 :returns: {"offset": 575, "limit": 377, "responseCode": 200, "count": 901, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Even war treat star local.", "messageTemplate": "Community model later prevent Mrs western fly card.", "field": "Much kid appear successful.", "parameter": {}, "timestamp": 1346853085}], "currentPage": 416, "size": 272} """ from requests import get from argus_api.exceptions import http url = "https://portal.mnemonic.no/web/api/authentication/v1/apikey".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 = {} response = get(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
[docs]@register_command(extending=('authentication','v1','apikey')) def initiate(password: str = None, description: str = None, validSources: list = None, expirationDays: int = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict: """Initiate a new apikey for current user (PUBLIC) :param str password: User password to verify this request :param str description: [\s\w\{\}\$\-\(\)\.\[\]"\'_/\\,\*\+\#:@!?;]* :param list validSources: Client IP/CIDR networks which the api key will be valid for. :param int expirationDays: Requested expiration days, 0 means unlimited. Default is 3 months. If user does not have permissions to specify expiration period, an error will be returned. :raises AuthenticationFailedException: on 401 :raises ValidationErrorException: on 412 :raises AccessDeniedException: on 403 :raises NotFoundException: on 404 :returns: {"offset": 907, "limit": 710, "responseCode": 200, "count": 436, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Front room anything like party big generation.", "messageTemplate": "Clear door less close perhaps according not.", "field": "Site character around billion mention base.", "parameter": {}, "timestamp": 233105796}], "currentPage": 144, "size": 783} """ from requests import post from argus_api.exceptions import http url = "https://portal.mnemonic.no/web/api/authentication/v1/apikey".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 password: body.update({"password": password}) if description: body.update({"description": description}) if validSources: body.update({"validSources": validSources}) if expirationDays: body.update({"expirationDays": expirationDays}) 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
[docs]@register_command(extending=('authentication','v1','apikey')) def authenticate(apikey: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict: """Initiate a new user session using API key (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. Use this operation to create a session to last across multiple requests.This might be useful for some legacy operations which require a web session, or for performance reasons if performing a large number of requests. End session using /logout For one-shot requests, use Argus-API-Key header. :param str apikey: :raises AuthenticationFailedException: on 401 :raises ValidationErrorException: on 412 :returns: {"offset": 426, "limit": 656, "responseCode": 200, "count": 990, "metaData": {"additionalProperties": {}}, "messages": [{"message": "More instead hundred week including.", "messageTemplate": "Religious collection set.", "field": "Many bill real line these.", "parameter": {}, "timestamp": 1121003113}], "currentPage": 291, "size": 663} """ from requests import post from argus_api.exceptions import http url = "https://portal.mnemonic.no/web/api/authentication/v1/apikey/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 apikey: body.update({"apikey": apikey}) 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
[docs]@register_command(extending=('authentication','v1','apikey')) def renew(keyID: int, password: str = None, expirationDays: int = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict: """Renew an apikey for current user (PUBLIC) API keys have limited validity. This operationallows the user to renew a key, to allow it to remain functional for a new validity period. :param int keyID: Key ID :param str password: User password to verify this request :param int expirationDays: Requested expiration days, 0 means unlimited. Default is 3 months. If user does not have permissions to specify expiration period, an error will be returned. :raises AuthenticationFailedException: on 401 :raises ValidationErrorException: on 412 :raises AccessDeniedException: on 403 :raises NotFoundException: on 404 :returns: {"offset": 918, "limit": 132, "responseCode": 200, "count": 359, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Goal appear indicate vote draw.", "messageTemplate": "Return who talk success television beautiful.", "field": "Morning for safe parent live organization.", "parameter": {}, "timestamp": 62890912}], "currentPage": 740, "size": 849} """ from requests import put from argus_api.exceptions import http url = "https://portal.mnemonic.no/web/api/authentication/v1/apikey/{keyID}".format(keyID=keyID) 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 password: body.update({"password": password}) if expirationDays: body.update({"expirationDays": expirationDays}) response = put(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
[docs]@register_command(extending=('authentication','v1','apikey')) def revoke(keyID: int,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict: """Revoke an apikey from current user (PUBLIC) :param int keyID: Key ID :raises AuthenticationFailedException: on 401 :raises ValidationErrorException: on 412 :raises AccessDeniedException: on 403 :raises NotFoundException: on 404 :returns: {"offset": 207, "limit": 725, "responseCode": 200, "count": 241, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Ability remain international travel.", "messageTemplate": "Poor I choose team paper term.", "field": "Accept or mission health again professional within.", "parameter": {}, "timestamp": 1071642388}], "currentPage": 493, "size": 67} """ from requests import delete from argus_api.exceptions import http url = "https://portal.mnemonic.no/web/api/authentication/v1/apikey/{keyID}".format(keyID=keyID) 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 = {} response = delete(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