Skip to content

Conversation

@timabrmsn
Copy link
Contributor

Draft PR for mostly done refactor so people can start getting eyes on it.

Still need to bring in @alanag13's checkpoint and @kiran-chaudhary's smart search changes. Plus refactoring tests.

cls=AdvancedQueryAndSavedSearchIncompatible,
callback=is_in_filter(Actor),
help="Filter alerts by including the given actor(s) who triggered the alert. "
"Args must match actor username exactly.",
Copy link
Contributor

Choose a reason for hiding this comment

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

should this just be actor instead of actor username?

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'm trying to make clear that when searching for actor you're searching usernames. Although I suppose most people using the CLI to search for alerts will already be familiar with the console and probably don't need that extra help?

def is_in_filter(filter_cls):
def callback(ctx, param, arg):
if arg:
ctx.obj.search_filters.append(filter_cls.is_in(arg))
Copy link
Contributor

@alanag13 alanag13 Jul 8, 2020

Choose a reason for hiding this comment

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

do click params that are multiple=True always come through as a list (even if only one item is enterred)?

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, and options that allow multiple values have to be called separately, so --option a --option b, you can't do --option a b

Copy link
Contributor

Choose a reason for hiding this comment

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

that will be an important breaking change to note

selected_rule = _get_rule_metadata(state.sdk, rule_id)
rule_detail = None
if selected_rule:
rule_type = selected_rule[0][u"type"]
Copy link
Contributor

Choose a reason for hiding this comment

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

a private _get_rule_type method might tighten this up a bit

@click.argument("checkpoint-name")
@sdk_options
def clear_checkpoint(state, checkpoint_name):
"""Remove the saved alert checkpoint from '--use-checkpoint/-c' mode."""
Copy link
Contributor

Choose a reason for hiding this comment

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

if --use-checkpoint has changed to --checkpoint-name, this comment should change, ideally we should update the relevant variable to checkpoint_name from use_checkpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The option to use checkpoint is still --use-checkpoint, this is just the arg name that you pass in when deleting a checkpoint. So the help looks like this:

Usage: code42 alerts clear-checkpoint [OPTIONS] CHECKPOINT_NAME

  Remove the saved alert checkpoint from '--use-checkpoint/-c' mode.

return super().invoke(ctx)

except click.UsageError as err:
self._suggest_cmd(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, i saw that click didnt have suggestions built in and was wondering how that would be handled, thanks for this.

)
if not suggested_commands:
raise usage_err
usage_err.message = "No such command '{}'. Did you mean {}?".format(
Copy link
Contributor

Choose a reason for hiding this comment

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

how will this be presented? Ideally I'm thinking one suggestion per line, like:

No such command 'blah'. Did you mean one of the following?

blag
blap
blar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what it looks like when there are multiple options.

PS C:\Users\tabra\PycharmProjects\code42cli> code42 employee
Usage: code42 [OPTIONS] COMMAND [ARGS]...
Try 'code42 -h' for help.

Error: No such command 'employee'. Did you mean high-risk-employee or departing-employee?

I would guess there's very rarely going to be a time when more than two are presented.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a fair point, this isn't exactly core functionality, we can always change this if needed later

@alanag13
Copy link
Contributor

alanag13 commented Jul 8, 2020

@timabrmsn it looks like the small legal hold refactor somehow broke a test but otherwise the format of the suggestions is the one last thing I saw and everything looks good. We should come up with a plan to break up the functionality and divide up testing.

Copy link
Contributor

@alanag13 alanag13 left a comment

Choose a reason for hiding this comment

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

🎉

@timabrmsn timabrmsn merged commit 292a307 into master Jul 9, 2020
@timabrmsn timabrmsn deleted the refactor/click branch December 28, 2020 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants