Exemplo n.º 1
0
def _list(state, format=None):
    """List available saved searches."""
    formatter = DataFrameOutputFormatter(format)
    response = state.sdk.securitydata.savedsearches.get()
    saved_searches_df = DataFrame(response["searches"])
    formatter.echo_formatted_dataframes(saved_searches_df,
                                        columns=["name", "id", "notes"])
Exemplo n.º 2
0
    def test_echo_formatted_dataframes_prints_no_results_found_when_dataframes_empty(
            self, fmt, capsys):
        formatter = DataFrameOutputFormatter(fmt)

        def empty_results():
            yield DataFrame()

        formatter.echo_formatted_dataframes(empty_results())
        captured = capsys.readouterr()
        assert "No results found." in captured.out
Exemplo n.º 3
0
def show_user(state, username, include_legal_hold_membership, format):
    """Show user details."""
    columns = (["userUid", "status", "username", "orgUid", "roles"]
               if format == OutputFormat.TABLE else None)
    response = state.sdk.users.get_by_username(username, incRoles=True)
    df = DataFrame.from_records(response["users"], columns=columns)
    if include_legal_hold_membership and not df.empty:
        df = _add_legal_hold_membership_to_user_dataframe(state.sdk, df)
    formatter = DataFrameOutputFormatter(format)
    formatter.echo_formatted_dataframes(df)
Exemplo n.º 4
0
 def test_echo_formatted_dataframes_uses_pager_when_len_rows_gt_threshold_const(
         self, mocker):
     mock_echo = mocker.patch("click.echo")
     mock_pager = mocker.patch("click.echo_via_pager")
     formatter = DataFrameOutputFormatter(OutputFormat.TABLE)
     rows_len = output_formats_module.OUTPUT_VIA_PAGER_THRESHOLD + 1
     big_df = DataFrame([{"column": val} for val in range(rows_len)])
     small_df = DataFrame([{"column": val} for val in range(5)])
     formatter.echo_formatted_dataframes(big_df)
     formatter.echo_formatted_dataframes(small_df)
     assert mock_echo.call_count == 1
     assert mock_pager.call_count == 1
Exemplo n.º 5
0
def list_backup_sets(
    state,
    active,
    inactive,
    org_uid,
    include_usernames,
    format,
):
    """Get information about many devices and their backup sets."""
    if inactive:
        active = False
    columns = ["guid", "userUid"]
    df = _get_device_dataframe(state.sdk, columns, active, org_uid)
    if include_usernames:
        df = _add_usernames_to_device_dataframe(state.sdk, df)
    df = _add_backup_set_settings_to_dataframe(state.sdk, df)
    formatter = DataFrameOutputFormatter(format)
    formatter.echo_formatted_dataframes(df)
Exemplo n.º 6
0
def list_users(
    state,
    org_uid,
    role_name,
    active,
    inactive,
    include_legal_hold_membership,
    include_roles,
    format,
):
    """List users in your Code42 environment."""
    if inactive:
        active = False
    role_id = _get_role_id(state.sdk, role_name) if role_name else None
    columns = (["userUid", "status", "username", "orgUid"]
               if format == OutputFormat.TABLE else None)
    if include_roles and columns:
        columns.append("roles")
    df = _get_users_dataframe(state.sdk, columns, org_uid, role_id, active,
                              include_roles)
    if include_legal_hold_membership:
        df = _add_legal_hold_membership_to_user_dataframe(state.sdk, df)
    formatter = DataFrameOutputFormatter(format)
    formatter.echo_formatted_dataframes(df)
Exemplo n.º 7
0
def list_devices(
    state,
    active,
    inactive,
    org_uid,
    include_backup_usage,
    include_usernames,
    include_settings,
    include_legal_hold_membership,
    include_total_storage,
    exclude_most_recently_connected,
    last_connected_after,
    last_connected_before,
    created_after,
    created_before,
    format,
):
    """Get information about many devices."""
    if inactive:
        active = False
    columns = [
        "computerId",
        "guid",
        "name",
        "osHostname",
        "status",
        "lastConnected",
        "creationDate",
        "productVersion",
        "osName",
        "osVersion",
        "userUid",
    ]
    df = _get_device_dataframe(
        state.sdk,
        columns,
        active,
        org_uid,
        (include_backup_usage or include_total_storage),
    )
    if exclude_most_recently_connected:
        most_recent = (df.sort_values(["userUid", "lastConnected"],
                                      ascending=False).groupby("userUid").head(
                                          exclude_most_recently_connected))
        df = df.drop(most_recent.index)
    if last_connected_after:
        df = df.loc[to_datetime(df.lastConnected) > last_connected_after]
    if last_connected_before:
        df = df.loc[to_datetime(df.lastConnected) < last_connected_before]
    if created_after:
        df = df.loc[to_datetime(df.creationDate) > created_after]
    if created_before:
        df = df.loc[to_datetime(df.creationDate) < created_before]
    if include_total_storage:
        df = _add_storage_totals_to_dataframe(df, include_backup_usage)
    if include_settings:
        df = _add_settings_to_dataframe(state.sdk, df)
    if include_usernames:
        df = _add_usernames_to_device_dataframe(state.sdk, df)
    if include_legal_hold_membership:
        df = _add_legal_hold_membership_to_device_dataframe(state.sdk, df)
    formatter = DataFrameOutputFormatter(format)
    formatter.echo_formatted_dataframes(df)