Skip to content

Add events command to legal-hold #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 15, 2021
Merged

Conversation

maddie-vargo
Copy link
Contributor

This PR addresses Phase II of #176 to allow users to list legal hold administrative events. This command includes options to filter the results based on a specific legal hold uid, a beginning timestamp, an end timestamp, and a list of event types.

Testing Procedure

code42 legal-hold events
code42 legal-hold --matter-id <matter id> --begin 30d --end 04/01/2021 --event-type MembershipCreated 

PR Checklist
Did you remember to do the below?

  • Add unit tests to verify this change
  • Add an entry to CHANGELOG.md describing this change
  • Add docstrings for any new public parameters / methods / classes

@github-actions
Copy link

github-actions bot commented Apr 1, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️

CHANGELOG.md Outdated

### Added

- `code42 legal-hold events` command:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the command be called search-events instead?

  • It'd be a verb, like the rest of our commands
  • It'd mirror the file-events search command

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to search-events > let me know if this is not what you had in mind

),
help="Filter results by event types",
)
@click.option("--begin", **BEGIN_DATE_DICT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the begin_option defined in code42cli.options
There will be several advantages to doing this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with end_option

Copy link
Contributor Author

@maddie-vargo maddie-vargo Apr 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I avoided this option initially because the begin option requires a cursor initialized for state, which I didn't think was necessary. I've added a LegalHoldEvents cursor to the cursor_store.py to make it work, but not sure if that's appropriate.

Also, the begin_option is required, which is should not be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should implement the --use-checkpoint option for this command and probably also make a send-to. As I could see customers wanting to be able to automate sending this data into a SIEM.

Copy link
Contributor

@antazoey antazoey Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! @maddie-vargo Sorry, I did forget about that when I made my initial comments.

I do like the idea from @timabrmsn, supporting checkingpointing would be a nice feature. We can always add it later though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unparalleled-js would it be possible to use the begin_option but somehow designate it as optional? I left the original options in there for now.

I left checkpoint'ing off for now.



@pytest.fixture
def all_events_response(mocker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to have mock generator methods actually be generators and not just lists. I know it probably works fine, but I have seen bugs show up because the tests were doing this. There are some subtle differences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I'm still missing the mark here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works!
You could add more events to the list so that it yields more than once, that way it is more like what will happen in real life (unless there is often only a single event). Not a big deal though.

cli, ["legal-hold", "events", "--event-type", "HoldCreated"], obj=cli_state
)

assert "564564654566" in result.output
Copy link
Contributor

@antazoey antazoey Apr 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the test alone, it is not immediately clear why these values are expected.
Maybe a comment saying // From all_events_response would help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined variables at the top here. I don't love the names

OLDER_LEGAL_HOLD_CREATED_EVENT = "564564654566"
NEWER_LEGAL_HOLD_MEMBERSHIP_EVENT = "74533457745"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names are fine..

but alternatively they could be called
_CREATE_EVENT_ID and _MEMBERSHIP_EVENT_ID

Reasons:
1.) they are already in a legal hold module so don't need the prefix,
2.) they can be internal since nothing should be importing or using them outside of this test module, and
3.) ending with ID makes it more apparent that it's not a JSON object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took your suggestions. Thanks!


assert "Matter ID,Name,Description,Creator,Creation Date" not in result.output


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get test(s) for begin_date / end_date validation?
It could be to just assert the values were passed into py42 correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll work on this. I had tried this initially, but had trouble getting a test to recognize the date inputs in the runner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test titled test_search_events_is_called_with_expected_begin_timestamp

@matter_id_option
@matter_id_option(
True,
"Identification number of the legal hold matter the custodian will be added to.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@annie-payseur When you have chance, could you help review these option help texts? I will tag you in spots.

@matter_id_option
@matter_id_option(
True,
"Identification number of the legal hold matter the custodian will be removed from.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@format_option
@sdk_options()
def search_events(state, matter_id, event_type, begin, end, format):
"""Report on legal hold events."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@annie-payseur This is the command's help text: Report on legal hold events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing to Tools for getting legal hold event data. (which is more consistent with the help text for security-data)

@@ -169,6 +173,75 @@
]
}
"""
EVENTS_RESPONSE = """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something seems off about this response.... It is not valid JSON. Should these objects be under a list with key: legalHoldEvents

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or else I believe line 290 will create a response where this a str type (I think).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the fixture that uses this is ever used, if that is the, case can this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is no longer needed, since I moved to a generator format for the mocker. I forgot to take it out on my last push along with it's corresponding fixture.

@@ -212,6 +285,20 @@ def active_and_inactive_legal_hold_memberships_response(mocker):
return [_create_py42_response(mocker, ALL_ACTIVE_AND_INACTIVE_CUSTODIANS_RESPONSE)]


@pytest.fixture
def events_response(mocker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fixture used anywhere? I am not seeing.
Perhaps this and EVENTS_RESPONSE can be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is no longer needed. See my comment on the item above.

@maddie-vargo
Copy link
Contributor Author

Does anything else need to happen on this PR, or can it be merged and closed?

@antazoey
Copy link
Contributor

antazoey commented Apr 15, 2021

Does anything else need to happen on this PR, or can it be merged and closed?

Was just waiting for a bugfix release to happen (just did). I can merge this now, but do you mind fixing the CHANGELOG one last time? Just need to add your changes to a new Unreleased section (above the version section that was released today). After that, I will merge this in and get it officially tested and released ASAP.

@antazoey antazoey merged commit 79e292d into code42:master Apr 15, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants