Skip to content

Commit 2c64d16

Browse files
author
Juliya Smith
authored
Casing (#28)
1 parent 3b763c1 commit 2c64d16

12 files changed

Lines changed: 91 additions & 79 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1010

1111
## Unreleased
1212

13+
### Changes
14+
15+
- `securitydata` renamed to `security-data`.
16+
- From `security-data` related subcommands (such as `print`):
17+
- `--c42username` flag renamed to `--c42-username`.
18+
- `--filename` flag renamed to `--file-name`.
19+
- `--filepath` flag renamed to `--file-path`.
20+
- `--processOwner` flag renamed to `--process-owner`
21+
1322
### Added
1423

1524
- `code42 profile create` command.

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The Code42 CLI
22

33
Use the `code42` command to interact with your Code42 environment.
4-
`code42 securitydata` is a CLI tool for extracting AED events.
4+
`code42 security-data` is a CLI tool for extracting AED events.
55
Additionally, you can choose to only get events that Code42 previously did not observe since you last recorded a checkpoint
66
(provided you do not change your query).
77

@@ -45,7 +45,7 @@ You can add multiple profiles with different names and the change the default pr
4545
code42 profile use MY_SECOND_PROFILE
4646
```
4747

48-
When the `--profile` flag is available on other commands, such as those in `securitydata`, it will use that profile instead of the default one.
48+
When the `--profile` flag is available on other commands, such as those in `security-data`, it will use that profile instead of the default one.
4949

5050
To see all your profiles, do:
5151

@@ -61,72 +61,72 @@ Using the CLI, you can query for events and send them to three possible destinat
6161
To print events to stdout, do:
6262

6363
```bash
64-
code42 securitydata print -b 2020-02-02
64+
code42 security-data print -b 2020-02-02
6565
```
6666

6767
Note that `-b` or `--begin` is usually required.
6868
To specify a time, do:
6969

7070
```bash
71-
code42 securitydata print -b 2020-02-02 12:51
71+
code42 security-data print -b 2020-02-02 12:51
7272
```
7373

7474
Begin date will be ignored if provided on subsequent queries using `-i`.
7575

7676
Use different format with `-f`:
7777

7878
```bash
79-
code42 securitydata print -b 2020-02-02 -f CEF
79+
code42 security-data print -b 2020-02-02 -f CEF
8080
```
8181

8282
The available formats are CEF, JSON, and RAW-JSON.
8383

8484
To write events to a file, do:
8585

8686
```bash
87-
code42 securitydata write-to filename.txt -b 2020-02-02
87+
code42 security-data write-to filename.txt -b 2020-02-02
8888
```
8989

9090
To send events to a server, do:
9191

9292
```bash
93-
code42 securitydata send-to syslog.company.com -p TCP -b 2020-02-02
93+
code42 security-data send-to syslog.company.com -p TCP -b 2020-02-02
9494
```
9595

9696
To only get events that Code42 previously did not observe since you last recorded a checkpoint, use the `-i` flag.
9797

9898
```bash
99-
code42 securitydata send-to syslog.company.com -i
99+
code42 security-data send-to syslog.company.com -i
100100
```
101101

102102
This is only guaranteed if you did not change your query.
103103

104104
To send events to a server using a specific profile, do:
105105

106106
```bash
107-
code42 securitydata send-to --profile PROFILE_FOR_RECURRING_JOB syslog.company.com -b 2020-02-02 -f CEF -i
107+
code42 security-data send-to --profile PROFILE_FOR_RECURRING_JOB syslog.company.com -b 2020-02-02 -f CEF -i
108108
```
109109

110110
You can also use wildcard for queries, but note, if they are not in quotes, you may get unexpected behavior.
111111

112112
```bash
113-
code42 securitydata print --actor "*"
113+
code42 security-data print --actor "*"
114114
```
115115

116116
Each destination-type subcommand shares query parameters
117117

118118
- `-t` (exposure types)
119119
- `-b` (begin date)
120120
- `-e` (end date)
121-
- `--c42username`
121+
- `--c42-username`
122122
- `--actor`
123123
- `--md5`
124124
- `--sha256`
125125
- `--source`
126-
- `--filename`
127-
- `--filepath`
128-
- `--processOwner`
129-
- `--tabURL`
126+
- `--file-name`
127+
- `--file-path`
128+
- `--process-owner`
129+
- `--tab-url`
130130
- `--include-non-exposure` (does not work with `-t`)
131131
- `--advanced-query` (raw JSON query)
132132

add_high_risk_employee.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
user_id,risk_factors

src/code42cli/cmds/securitydata/enums.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ def __iter__(self):
4444

4545

4646
class SearchArguments(object):
47+
"""These string values should match `argparse` stored parameter names. For example, for the
48+
CLI argument `--c42-username`, the string should be `c42_username`."""
4749
ADVANCED_QUERY = u"advanced_query"
4850
BEGIN_DATE = u"begin"
4951
END_DATE = u"end"
5052
EXPOSURE_TYPES = u"type"
51-
C42USERNAME = u"c42username"
53+
C42_USERNAME = u"c42_username"
5254
ACTOR = u"actor"
5355
MD5 = u"md5"
5456
SHA256 = u"sha256"
5557
SOURCE = u"source"
56-
FILENAME = u"filename"
57-
FILEPATH = u"filepath"
58-
PROCESS_OWNER = u"processOwner"
59-
TAB_URL = u"tabURL"
58+
FILE_NAME = u"file_name"
59+
FILE_PATH = u"file_path"
60+
PROCESS_OWNER = u"process_owner"
61+
TAB_URL = u"tab_url"
6062
INCLUDE_NON_EXPOSURE_EVENTS = u"include_non_exposure"
6163

6264
def __iter__(self):
@@ -66,13 +68,13 @@ def __iter__(self):
6668
self.BEGIN_DATE,
6769
self.END_DATE,
6870
self.EXPOSURE_TYPES,
69-
self.C42USERNAME,
71+
self.C42_USERNAME,
7072
self.ACTOR,
7173
self.MD5,
7274
self.SHA256,
7375
self.SOURCE,
74-
self.FILENAME,
75-
self.FILEPATH,
76+
self.FILE_NAME,
77+
self.FILE_PATH,
7678
self.PROCESS_OWNER,
7779
self.TAB_URL,
7880
self.INCLUDE_NON_EXPOSURE_EVENTS,

src/code42cli/cmds/securitydata/extraction.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ def _create_filters(args):
9999
filters = []
100100
event_timestamp_filter = _get_event_timestamp_filter(args.begin, args.end)
101101
not event_timestamp_filter or filters.append(event_timestamp_filter)
102-
not args.c42username or filters.append(DeviceUsername.is_in(args.c42username))
102+
not args.c42_username or filters.append(DeviceUsername.is_in(args.c42_username))
103103
not args.actor or filters.append(Actor.is_in(args.actor))
104104
not args.md5 or filters.append(MD5.is_in(args.md5))
105105
not args.sha256 or filters.append(SHA256.is_in(args.sha256))
106106
not args.source or filters.append(Source.is_in(args.source))
107-
not args.filename or filters.append(FileName.is_in(args.filename))
108-
not args.filepath or filters.append(FilePath.is_in(args.filepath))
109-
not args.processOwner or filters.append(ProcessOwner.is_in(args.processOwner))
110-
not args.tabURL or filters.append(TabURL.is_in(args.tabURL))
107+
not args.file_name or filters.append(FileName.is_in(args.file_name))
108+
not args.file_path or filters.append(FilePath.is_in(args.file_path))
109+
not args.process_owner or filters.append(ProcessOwner.is_in(args.process_owner))
110+
not args.tab_url or filters.append(TabURL.is_in(args.tab_url))
111111
_try_append_exposure_types_filter(filters, args.include_non_exposure, args.type)
112112
return filters
113113

@@ -175,9 +175,9 @@ def _handle_result():
175175

176176

177177
def _try_append_exposure_types_filter(filters, include_non_exposure_events, exposure_types):
178-
exposure_filter = _create_exposure_type_filter(include_non_exposure_events, exposure_types)
179-
if exposure_filter:
180-
filters.append(exposure_filter)
178+
_exposure_filter = _create_exposure_type_filter(include_non_exposure_events, exposure_types)
179+
if _exposure_filter:
180+
filters.append(_exposure_filter)
181181

182182

183183
def _create_exposure_type_filter(include_non_exposure_events, exposure_types):

src/code42cli/cmds/securitydata/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
def load_subcommands():
9-
"""Sets up the `securitydata` subcommand with all of its subcommands."""
10-
usage_prefix = u"code42 securitydata"
9+
"""Sets up the `security-data` subcommand with all of its subcommands."""
10+
usage_prefix = u"code42 security-data"
1111

1212
print_func = Command(
1313
u"print",
@@ -48,7 +48,7 @@ def load_subcommands():
4848

4949
def clear_checkpoint(sdk, profile):
5050
"""Removes the stored checkpoint that keeps track of the last event you got.
51-
To use, run `code42 securitydata clear-checkpoint`.
51+
To use, run `code42 security-data clear-checkpoint`.
5252
This affects `incremental` mode by causing it to behave like it has never been run before.
5353
"""
5454
FileEventCursorStore(profile.name).replace_stored_insertion_timestamp(None)
@@ -121,8 +121,8 @@ def _load_search_args(arg_collection):
121121
help=u"Limits events to those with given exposure types. "
122122
u"Available choices={0}".format(list(enums.ExposureType())),
123123
),
124-
enums.SearchArguments.C42USERNAME: ArgConfig(
125-
u"--{}".format(enums.SearchArguments.C42USERNAME),
124+
enums.SearchArguments.C42_USERNAME: ArgConfig(
125+
u"--{}".format(enums.SearchArguments.C42_USERNAME),
126126
nargs=u"+",
127127
help=u"Limits events to endpoint events for these users.",
128128
),
@@ -147,13 +147,13 @@ def _load_search_args(arg_collection):
147147
nargs=u"+",
148148
help=u"Limits events to only those from one of these sources. Example=Gmail.",
149149
),
150-
enums.SearchArguments.FILENAME: ArgConfig(
151-
u"--{}".format(enums.SearchArguments.FILENAME),
150+
enums.SearchArguments.FILE_NAME: ArgConfig(
151+
u"--{}".format(enums.SearchArguments.FILE_NAME),
152152
nargs=u"+",
153153
help=u"Limits events to file events where the file has one of these names.",
154154
),
155-
enums.SearchArguments.FILEPATH: ArgConfig(
156-
u"--{}".format(enums.SearchArguments.FILEPATH),
155+
enums.SearchArguments.FILE_PATH: ArgConfig(
156+
u"--{}".format(enums.SearchArguments.FILE_PATH),
157157
nargs=u"+",
158158
help=u"Limits events to file events where the file is located at one of these paths.",
159159
),

src/code42cli/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class Command(object):
1616
commands to make it available for use.
1717
1818
Args:
19-
name (str): The name of the command. For example, in
19+
name (str or unicode): The name of the command. For example, in
2020
`code42 profile show`, "show" is the name, while "profile"
2121
is the name of the parent command.
2222
23-
description (str): Descriptive text to be displayed when using -h.
23+
description (str or unicode): Descriptive text to be displayed when using -h.
2424
2525
usage (str, optional): A usage example to be displayed when using -h.
2626
handler (function, optional): The function to be exectued when the command is run.

src/code42cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _load_top_commands():
3131
u"profile", u"For managing Code42 settings.", subcommand_loader=profile.load_subcommands
3232
),
3333
Command(
34-
u"securitydata",
34+
u"security-data",
3535
u"Tools for getting security related data, such as file events.",
3636
subcommand_loader=secmain.load_subcommands,
3737
),

tests/cmds/securitydata/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def sqlite_connection(mocker):
5656
"600",
5757
"-e",
5858
"2020-02-02",
59-
"--c42username",
59+
"--c42-username",
6060
"test.testerson",
6161
"--actor",
6262
"test.testerson",
@@ -66,13 +66,13 @@ def sqlite_connection(mocker):
6666
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
6767
"--source",
6868
"Gmail",
69-
"--filename",
69+
"--file-name",
7070
"file.txt",
71-
"--filepath",
71+
"--file-path",
7272
"/path/to/file.txt",
73-
"--processOwner",
73+
"--process-owner",
7474
"test.testerson",
75-
"--tabURL",
75+
"--tab-url",
7676
"https://example.com",
7777
"--include-non-exposure",
7878
]

0 commit comments

Comments
 (0)