Skip to content

Commit afb8a7d

Browse files
author
Juliya Smith
authored
Feature/multiple profiles (#12)
1 parent a7c31cb commit afb8a7d

31 files changed

+999
-688
lines changed

CHANGELOG.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
99
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
1010

11-
## Unreleased
11+
## 0.4.0 - 2020-03-12
12+
13+
### Added
14+
15+
- Support for multiple profiles:
16+
- Optional `--profile` flag for:
17+
- `securitydata write-to`, `print`, and `send-to`,
18+
- `profile show`, `set`, and `reset-pw`.
19+
- `code42 profile use` command for changing the default profile.
20+
- `code42 profile list` command for listing all the available profiles.
21+
- The following search args can now take multiple values:
22+
- `--c42username`,
23+
- `--actor`,
24+
- `--md5`,
25+
- `--sha256`,
26+
- `--filename`,
27+
- `--filepath`,
28+
- `--processOwner`,
29+
- `--tabURL`
1230

1331
### Fixed
1432

@@ -18,6 +36,7 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1836

1937
- Begin dates are no longer required for subsequent interactive `securitydata` commands.
2038
- When provided, begin dates are now ignored on subsequent interactive `securitydata` commands.
39+
- `--profile` arg is now required the first time setting up a profile.
2140

2241
## 0.3.0 - 2020-03-04
2342

README.md

+40-8
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ $ python setup.py install
2121

2222
First, set your profile:
2323
```bash
24-
code42 profile set -s https://example.authority.com -u [email protected]
24+
code42 profile set --profile MY_FIRST_PROFILE -s https://example.authority.com -u [email protected]
2525
```
26+
The `--profile` flag is required the first time and it takes a name.
27+
On subsequent uses of `set`, not specifying the profile will set the default profile.
28+
2629
Your profile contains the necessary properties for logging into Code42 servers.
27-
After running this `code42 profile set`, you will be prompted about storing a password.
28-
If you agree, you will be securely prompted to input your password.
29-
Your password is not stored in plain-text, and is not shown when you do `code42 profile show`.
30-
However, `code42 profile show` will confirm that there is a password set for your profile.
30+
After running `code42 profile set`, the program prompts you about storing a password.
31+
If you agree, you are then prompted to input your password.
32+
33+
Your password is not stored in plain-text and is not shown when you do `code42 profile show`.
34+
However, `code42 profile show` will confirm that a password exists for your profile.
3135
If you do not set a password, you will be securely prompted to enter a password each time you run a command.
3236

33-
To ignore SSL errors, do:
37+
For development purposes, you may need to ignore ssl errors. If you need to do this, do:
3438
```bash
3539
code42 profile set --disable-ssl-errors
3640
```
@@ -40,7 +44,19 @@ To re-enable SSL errors, do:
4044
code42 profile set --enable-ssl-errors
4145
```
4246

43-
Next, you can query for events and send them to three possible destination types
47+
You can add multiple profiles with different names and the change the default profile with the `use` command:
48+
```bash
49+
code42 profile use MY_SECOND_PROFILE
50+
```
51+
When the `--profile` flag is available on other commands, such as those in `securitydata`,
52+
it will use that profile instead of the default one.
53+
54+
To see all your profiles, do:
55+
```bash
56+
code42 profile list
57+
```
58+
59+
Using the CLI, you can query for events and send them to three possible destination types:
4460
* stdout
4561
* A file
4662
* A server, such as SysLog
@@ -58,6 +74,12 @@ code42 securitydata print -b 2020-02-02 12:51
5874
```
5975
Begin date will be ignored if provided on subsequent queries using `-i`.
6076

77+
Use different format with `-f`:
78+
```bash
79+
code42 securitydata print -b 2020-02-02 -f CEF
80+
```
81+
The available formats are CEF, JSON, and RAW-JSON.
82+
6183
To write events to a file, do:
6284
```bash
6385
code42 securitydata write-to filename.txt -b 2020-02-02
@@ -74,6 +96,16 @@ code42 securitydata send-to syslog.company.com -i
7496
```
7597
This is only guaranteed if you did not change your query.
7698

99+
To send events to a server using a specific profile, do:
100+
```bash
101+
code42 securitydata send-to --profile PROFILE_FOR_RECURRING_JOB syslog.company.com -b 2020-02-02 -f CEF -i
102+
```
103+
104+
You can also use wildcard for queries, but note, if they are not in quotes, you may get unexpected behavior.
105+
```bash
106+
code42 securitydata print --actor "*"
107+
```
108+
77109

78110
Each destination-type subcommand shares query parameters
79111
* `-t` (exposure types)
@@ -92,7 +124,7 @@ Each destination-type subcommand shares query parameters
92124
* `--advanced-query` (raw JSON query)
93125

94126
You cannot use other query parameters if you use `--advanced-query`.
95-
To learn more about acceptable arguments, add the `-h` flag to `code42` or and of the destination-type subcommands.
127+
To learn more about acceptable arguments, add the `-h` flag to `code42` or any of the destination-type subcommands.
96128

97129

98130
# Known Issues

src/code42cli/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.4.0"

src/code42cli/arguments.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PROFILE_NAME_KEY = u"profile_name"
2+
PROFILE_HELP_MESSAGE = (
3+
u"The name of the profile containing your Code42 username and authority host address."
4+
)
5+
6+
7+
def add_arguments_to_parser(parser):
8+
add_debug_arg(parser)
9+
add_profile_name_arg(parser)
10+
11+
12+
def add_debug_arg(parser):
13+
parser.add_argument(
14+
u"-d",
15+
u"--debug",
16+
dest=u"is_debug_mode",
17+
action=u"store_true",
18+
help=u"Turn on Debug logging.",
19+
)
20+
21+
22+
def add_profile_name_arg(parser):
23+
parser.add_argument(
24+
u"--profile", action=u"store", dest=PROFILE_NAME_KEY, help=PROFILE_HELP_MESSAGE
25+
)

src/code42cli/compat.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from urlparse import urljoin, urlparse
1616

1717
str = unicode
18+
19+
import repr as reprlib
1820
else:
1921
from urllib.parse import urljoin, urlparse
2022

2123
str = str
24+
25+
import reprlib

src/code42cli/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ def _run(parser):
3434
parser.print_help()
3535
return
3636
raise ex
37+
38+
39+
if __name__ == "__main__":
40+
main()

0 commit comments

Comments
 (0)