DisableUserWrapper

This script allows disabling a specified user using one or more of the following integrations: SailPointIdentityIQ, ActiveDirectoryQuery, Okta, MicrosoftGraphUser, and IAM.

python · Common Scripts

Source

import traceback

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401


def create_commands(username: str) -> List[CommandRunner.Command]:
    """Create commands to disable user.

    Args:
        username (str): The username to create disable-user commands with.

    Returns:
        list of CommandRunner.Commands to disable the user.
    """

    commands: list = [
        CommandRunner.Command(commands="ad-disable-account", args_lst={"username": username}),
        CommandRunner.Command(
            commands="iam-disable-user", args_lst={"user-profile": {"user_name": username, "sAMAccountName": username}}
        ),
        CommandRunner.Command(commands="okta-deactivate-user", args_lst={"username": username}),
        CommandRunner.Command(commands="msgraph-user-account-disable", args_lst={"user": username}),
        CommandRunner.Command(commands="identityiq-disable-account", args_lst={"id": username}),
    ]

    return commands


def disable_user(args: dict):
    """Disable user from supported integrations.

    Will not return errors on un-supported commands unless there is no supported ones.

    args (dict):
        args[approve_action]: Must be yes in order for the command to work.
        args[username]: The username to disable.

    Returns:
        The CommandResults of all the supported commands.
    """
    if not argToBoolean(args.get("approve_action", False)):
        return "approve_action must be `yes`"
    username = args.get("username")
    if not username:
        raise ValueError("username is not specified")

    command_executors = create_commands(username)
    return CommandRunner.run_commands_with_summary(command_executors)


""" MAIN FUNCTION """


def main():  # pragma: no cover
    try:
        return_results(disable_user(demisto.args()))
    except Exception as e:
        error_msg = f"Failed to execute DisableUserWrapper. Error: {e!s}\n {traceback.format_exc()}"
        if "The commands that run are not supported in this Instance" in str(e):
            error_msg = "No disable-user supported integrations were found in this instance."

        return_error(error_msg)


""" ENTRY POINT """

if __name__ in ("__main__", "__builtin__", "builtins"):  # pragma: no cover
    main()

README

This script allows disabling a specified user using one or more of the following integrations: SailPointIdentityIQ, ActiveDirectoryQuery, Okta, MicrosoftGraphUser, and IAM.

Script Data


Name Description
Script Type python3
Tags basescript
Cortex XSOAR Version 6.0.0

Inputs


Argument Name Description
username The username of the user to disable.
approve_action Whether to run the command. This is used to prevent unwanted calls to the command.

Outputs


Path Description Type
IdentityIQ.AccountDisable.active Indicates the status of account (should be false after request is successfully completed). Boolean
IAM.UserProfile The user profile. Unknown
IAM.Vendor.active Gives the active status of user. Can be true or false. Boolean
IAM.Vendor.brand The integration name. String
IAM.Vendor.details Tells the user if the API was successful, otherwise provides error information. Unknown
IAM.Vendor.email The employee email address. String
IAM.Vendor.errorCode The HTTP error response code. Number
IAM.Vendor.errorMessage The reason the API failed. String
IAM.Vendor.id The employee user ID in the app. String
IAM.Vendor.instanceName The integration instance name. Unknown
IAM.Vendor.success If true, the command was executed successfully. Boolean
IAM.Vendor.username The employee username in the app. String
IAM.Vendor.action The command name. String