Exemple #1
0
def bulk_remove_alias(state, csv_rows, format):
    """Bulk remove aliases from users"""

    # Initialize the SDK before starting any bulk processes
    # to prevent multiple instances and having to enter 2fa multiple times.
    sdk = state.sdk
    success_header = "alias removed"

    csv_rows[0][success_header] = "False"
    formatter = OutputFormatter(format,
                                {key: key
                                 for key in csv_rows[0].keys()})
    stats = create_worker_stats(len(csv_rows))

    def handle_row(**row):
        try:
            _remove_cloud_alias(
                sdk, **{
                    key: row[key]
                    for key in row.keys() if key != success_header
                })
            row[success_header] = "True"
        except Exception as err:
            row[success_header] = f"False: {err}"
            stats.increment_total_errors()
        return row

    result_rows = run_bulk_process(
        handle_row,
        csv_rows,
        progress_label="Removing aliases from users:",
        stats=stats,
        raise_global_error=False,
    )
    formatter.echo_formatted_list(result_rows)
Exemple #2
0
def bulk_rename(state, csv_rows, format):
    """Rename all devices from the provided CSV containing a 'guid' and a 'name' column."""

    # Initialize the SDK before starting any bulk processes
    # to prevent multiple instances and having to enter 2fa multiple times.
    sdk = state.sdk

    csv_rows[0]["renamed"] = "False"
    formatter = OutputFormatter(format,
                                {key: key
                                 for key in csv_rows[0].keys()})
    stats = create_worker_stats(len(csv_rows))

    def handle_row(**row):
        try:
            _change_device_name(sdk, row["guid"], row["name"])
            row["renamed"] = "True"
        except Exception as err:
            row["renamed"] = f"False: {err}"
            stats.increment_total_errors()
        return row

    result_rows = run_bulk_process(
        handle_row,
        csv_rows,
        progress_label="Renaming devices:",
        stats=stats,
        raise_global_error=False,
    )
    formatter.echo_formatted_list(result_rows)
Exemple #3
0
def bulk_deactivate(state, csv_rows, format):
    """Deactivate a list of users."""

    # Initialize the SDK before starting any bulk processes
    # to prevent multiple instances and having to enter 2fa multiple times.
    sdk = state.sdk

    csv_rows[0]["deactivated"] = "False"
    formatter = OutputFormatter(format,
                                {key: key
                                 for key in csv_rows[0].keys()})
    stats = create_worker_stats(len(csv_rows))

    def handle_row(**row):
        try:
            _deactivate_user(
                sdk, **{
                    key: row[key]
                    for key in row.keys() if key != "deactivated"
                })
            row["deactivated"] = "True"
        except Exception as err:
            row["deactivated"] = f"False: {err}"
            stats.increment_total_errors()
        return row

    result_rows = run_bulk_process(
        handle_row,
        csv_rows,
        progress_label="Deactivating users:",
        stats=stats,
        raise_global_error=False,
    )
    formatter.echo_formatted_list(result_rows)