Instance Config Multi Factor Authentication (MFA)Routes

# hide
import os
import pandas as pd
import nbdev
# [ {key: value} for key, value in  os.environ.items() if 'domo' in key.lower()]
auth = dmda.DomoTokenAuth(
    domo_instance=os.environ["DOMO_INSTANCE"],
    domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)

# auth = dmda.DomoTokenAuth(
#     domo_instance=os.environ["DOMO_DATACREW_INSTANCE"],
#     domo_access_token=os.environ["DOMO_DATACREW_ACCESS_TOKEN"],
# )
await auth.print_is_token()
🎉 token_auth token retrieved from datacrew-space ⚙️
True

Update MFA configuration

Enable MFA


source

toggle_enable_mfa

 toggle_enable_mfa (auth:domolibrary.client.DomoAuth.DomoAuth,
                    is_enable_MFA:bool=False,
                    session:httpx.AsyncClient=None, debug_api:bool=False,
                    parent_class:str=None, debug_num_stacks_to_drop:int=1)

source

MFA_UPDATE_Value_Error

 MFA_UPDATE_Value_Error (message)

base exception


source

MFA_UPDATE_Error

 MFA_UPDATE_Error (res:domolibrary.client.ResponseGetData.ResponseGetData,
                   message=None)

base exception

# Sample code for enabling/disabling MFA in domo instance
await toggle_enable_mfa(auth=auth, is_enable_MFA=False, debug_api=False)
ResponseGetData(status=200, response='toggled MFA off', is_success=True, parent_class=None)

GET Domo instance MFA configuration


source

get_mfa_config

 get_mfa_config (auth:domolibrary.client.DomoAuth.DomoAuth,
                 incl_is_multifactor_required:bool=True,
                 incl_num_days_valid:bool=True,
                 incl_max_code_attempts:bool=True,
                 session:httpx.AsyncClient=None, parent_class:str=None,
                 debug_api:bool=False, debug_num_stacks_to_drop:int=1,
                 return_raw:bool=False)
Type Default Details
auth DomoAuth
incl_is_multifactor_required bool True
incl_num_days_valid bool True how long MFA is valid
incl_max_code_attempts bool True
session AsyncClient None
parent_class str None
debug_api bool False
debug_num_stacks_to_drop int 1
return_raw bool False
Returns ResponseGetData

source

MFA_GET_Error

 MFA_GET_Error (res:domolibrary.client.ResponseGetData.ResponseGetData,
                message=None)

base exception

# Sample code for getting current MFA configuration in domo instance

(
    await get_mfa_config(
        auth=auth,
        debug_api=False,
        incl_is_multifactor_required=True,
        incl_num_days_valid=True,
        incl_max_code_attempts=True,
    )
).response
{'is_multifactor_required': True, 'num_days_valid': 15, 'max_code_attempts': 5}

Set max code attempts before MFA resets

# # | export

# # updating multiple states at the /customer-states/ endpoint is not supported

# @gd.route_function
# async def set_mfa_config(
#     auth: dmda.DomoAuth,
#     is_enable_MFA: bool,
#     max_code_attempts: int,
#     session: httpx.AsyncClient = None,
#     debug_api: bool = False,
#     parent_class: str = None,
#     debug_num_stacks_to_drop: int = 1,
# ) -> rgd.ResponseGetData:
#     """Sets the max number of invalid log in attempts before the MFA code is reset"""

#     url = f"https://{auth.domo_instance}.domo.com/api/content/v1/customer-states/"

#     if not max_code_attempts > 0:
#         raise MFA_UPDATE_Value_Error(
#             message="max max_code_attempts must be greater than 0. unable to set MFA max code attempts",
#         )

#     payload = [
#         {"name": "domo.policy.multifactor.maxCodeAttempts", "value": max_code_attempts},
#         {
#             "name": "domo.policy.multifactor.required",
#             "value": "yes" if is_enable_MFA else "no",
#         },
#     ]

#     res = await gd.get_data(
#         auth=auth,
#         url=url,
#         method="POST",
#         body=payload,
#         debug_api=debug_api,
#         session=session,
#         parent_class=parent_class,
#         num_stacks_to_drop=debug_num_stacks_to_drop,
#     )

#     if not res.is_success:
#         raise MFA_UPDATE_Error(
#             res=res,
#             message=f"failed to update max number of code attempts for MFA in {auth.domo_instance}",
#         )

#     # res.response = (
#     #     f"set max number of code attempts to {max_code_attempts} in {auth.domo_instance}"
#     # )

#     return res

source

set_mfa_max_code_attempts

 set_mfa_max_code_attempts (auth:domolibrary.client.DomoAuth.DomoAuth,
                            max_code_attempts:int,
                            session:httpx.AsyncClient=None,
                            debug_api:bool=False, parent_class:str=None,
                            debug_num_stacks_to_drop:int=1)

Sets the max number of invalid log in attempts before the MFA code is reset

# Sample code for setting number of max login attempts before MFA expires
await set_mfa_max_code_attempts(auth=auth, max_code_attempts=5, debug_api=False)
ResponseGetData(status=200, response='set max number of code attempts to 5 in datacrew-space', is_success=True, parent_class=None)

Set max days before MFA expires


source

set_mfa_num_days_valid

 set_mfa_num_days_valid (auth:domolibrary.client.DomoAuth.DomoAuth,
                         num_days_valid:int,
                         session:httpx.AsyncClient=None,
                         debug_api:bool=False, parent_class:str=None,
                         debug_num_stacks_to_drop:int=1)

Sets the number of days before the user must re-authenticate

# Sample code for number of days before MFA expires
await set_mfa_num_days_valid(auth=auth, num_days_valid=15, debug_api=False)
ResponseGetData(status=200, response='num days MFA valid set to 15 in datacrew-space', is_success=True, parent_class=None)