def register_if_not_exists_user()

in src/pkg/qs_user_gov.py [0:0]


def register_if_not_exists_user(user):
    """
    check to see if a user exists in a QuickSight namespace.
    If not, register it.
    """

    try:
        QS_CLIENT.describe_user(
            UserName=user.qs_username,
            AwsAccountId=user.account_id,
            Namespace=user.namespace,
        )
    except ClientError:
        if user.qs_role:
            QS_CLIENT.register_user(
                IdentityType='IAM',
                Email=user.email,
                UserRole=user.qs_role,
                IamArn=f'arn:aws:iam::{user.account_id}:role/{OKTA_ROLE_NAME}',
                SessionName=user.email,
                AwsAccountId=user.account_id,
                Namespace=user.namespace,
            )
            LOGGER.info(f"[{user.qs_username}] added to Namespace [{user.namespace}].")