# Source code for api.authentication.v1.impersonate

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

    @register_command(extending=('authentication','v1','impersonate'))
    def constrain(userName: str = None, domain: str = None, customerID: list = None, functionID: list = None, function: list = None,json: bool = True, verify: bool = True, apiKey: str = "", authentication: dict = {}) -> dict:
        """Request an impersonated session (TEST)
    This operation will spawn a new user session impersonating another user, where the active users permissions are constrained to the intersection of the impersonating and impersonated users, and limited to the subset optionally specified in the request. In addition to returning the impersonating session token, the new session will be set as cookies, overwriting any existing session cookies.

        :param str userName: Username of user to impersonate.
        :param str domain: Domain of user to impersonate (id or name)
        :param list customerID: Set of customers the session should be valid for. If not specified, customers will be inherited from active permissions.
        :param list functionID: Set of functions/roles (by ID) the session should be granted (default is all current functions). Cannot extend the current set of functions.
        :param list function: Set of functions/roles (by name) the session should be granted (default is all current functions). Cannot extend the current set of functions.
        :returns: {"offset": 467, "limit": 715, "responseCode": 200, "count": 424, "metaData": {"additionalProperties": {}}, "messages": [{"message": "Military well company take.", "messageTemplate": "Learn through front.", "field": "Note building better spring what produce.", "parameter": {}, "timestamp": 89676216}], "currentPage": 423, "size": 831}
        """
        from requests import post
        from argus_api.exceptions import http

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

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

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

        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