api.authentication.v1.totp — Argus-Toolbelt 1.0 documentation

# Source code for api.authentication.v1.totp

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

    @register_command(extending=('authentication','v1','totp'))
    def initialize(password: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Initiate a new TOTP generator for the user (PUBLIC)
    TOTP authentication requires a TOTP generator to be set up for the user.

    This operation allows the user to set up a TOTP generator.
    This requires TOTP authentication to be enabled for the user.
    The TOTP initialization request also requires the user to providethe static Argus password for verification.
    The TOTP generator code retrieved cannot be retrieved again. It should be added directly to the TOTP generator, and should not be stored elsewhere.

    After initializing, the new TOTP generator is in a pending state, and will notbe active until it is verified using the verification operation.

        :param str password: User password to verify this request
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises NotFoundException: on 404
        :returns: {"offset": 736, "limit": 407, "responseCode": 200, "count": 536, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Position husband fight impact.", "messageTemplate": "Stock different say go simply manage.", "field": "Several sometimes break happen professor country herself.", "parameter": {}, "timestamp": 1105513786}], "currentPage": 482, "size": 887}
        """
        from requests import post
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/authentication/v1/totp".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})

        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

    @register_command(extending=('authentication','v1','totp'))
    def verify(cookie: str = None, verificationCode: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Verify the pending TOTP generator for the user (PUBLIC)
    This operation will activate the pending generator.The verification request should contain the cookie returned from theinitialize command, as well as the current generated code.

    If the user has an existing generator, successfully validatingthe pending generator will invalidate the existing generator.

        :param str cookie: The cookie returned by the TOTP initialization request
        :param str verificationCode: Current code from TOTP generator, to verify correctly generated TOTP code
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises NotFoundException: on 404
        :returns: {"offset": 233, "limit": 93, "responseCode": 200, "count": 550, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Past middle so tonight.", "messageTemplate": "Town me forward entire.", "field": "Design view chance case.", "parameter": {}, "timestamp": 1192066739}], "currentPage": 815, "size": 593}
        """
        from requests import put
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/authentication/v1/totp".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 cookie:
            body.update({"cookie": cookie})

        if verificationCode:
            body.update({"verificationCode": verificationCode})

        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

    @register_command(extending=('authentication','v1','totp'))
    def revoke(json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Revoke the current TOTP generator for the user (PUBLIC)
    This operation invalidates the current generator config for the user.
    The user will need to re-initialize the TOTP generator to be able to log inusing TOTP.

        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises NotFoundException: on 404
        :returns: {"offset": 747, "limit": 440, "responseCode": 200, "count": 56, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Material across those check card soldier.", "messageTemplate": "Address suffer trade surface opportunity oil.", "field": "Take support address figure especially.", "parameter": {}, "timestamp": 703002969}], "currentPage": 302, "size": 506}
        """
        from requests import delete
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/authentication/v1/totp".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 = 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

    @register_command(extending=('authentication','v1','totp'))
    def authenticate(userName: str = None, domain: str = None, password: str = None, tokenCode: str = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Initiate a new user session using TOTP authentication (PUBLIC)
    Requires TOTP authentication to be enabled on the server, and for the user.
    Use /methods to check which authentication methods are available on the server.

    This is a 2-factor authentication method. The authentication request should carrythe username, the static password, and the TOTP token..
    Tokens cannot be reused. Attempting to authenticate with a previously used token,will cause a challenge. Wait for the tokencode to change and resubmit.

        :param str userName: Username to authenticate
        :param str domain: User domain
        :param str password: Static Argus password
        :param str tokenCode: Current code from TOTP generator
        :raises AuthenticationFailedException: on 401
        :raises ValidationErrorException: on 412
        :raises AccessDeniedException: on 403
        :raises NotFoundException: on 404
        :returns: {"offset": 311, "limit": 810, "responseCode": 200, "count": 123, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Pretty director occur push who lawyer order.", "messageTemplate": "Remain mouth pressure section laugh.", "field": "Because general born become.", "parameter": {}, "timestamp": 1352728051}], "currentPage": 259, "size": 134}
        """
        from requests import post
        from argus_api.exceptions import http

        url = "https://osl-argus-trunk-web1.mnemonic.no/web/api/authentication/v1/totp/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})

        if tokenCode:
            body.update({"tokenCode": tokenCode})

        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