Skip to content

Commit 231cf93

Browse files
author
Juliya Smith
authored
Improvement/help (#18)
1 parent c5e7877 commit 231cf93

File tree

15 files changed

+128
-54
lines changed

15 files changed

+128
-54
lines changed

CHANGELOG.md

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

1919
- Bug where keyring caused errors on certain operating systems when not supported.
2020

21+
### Changed
22+
23+
- Updated help texts to be more descriptive.
24+
2125
## 0.4.2 - 2020-03-13
2226

2327
### Fixed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
packages=find_packages("src"),
2121
package_dir={"": "src"},
2222
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4",
23-
install_requires=["c42eventextractor==0.2.1", "keyring==18.0.1","py42==0.5.1"],
23+
install_requires=["c42eventextractor==0.2.2", "keyring==18.0.1","py42==0.6.0"],
2424
license="MIT",
2525
include_package_data=True,
2626
zip_safe=False,

src/code42cli/main.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import platform
2-
from argparse import ArgumentParser
2+
from argparse import ArgumentParser, RawDescriptionHelpFormatter
33

44
import code42cli.securitydata.main as securitydata
55
from code42cli.compat import str
66
from code42cli.profile import profile
77

88
# If on Windows, configure console session to handle ANSI escape sequences correctly
99
# source: https://bugs.python.org/issue29059
10-
if platform.system().lower() == "windows":
10+
if platform.system().lower() == u"windows":
1111
from ctypes import windll, c_int, byref
1212

1313
stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
@@ -18,8 +18,17 @@
1818

1919

2020
def main():
21-
code42_arg_parser = ArgumentParser()
22-
subcommand_parser = code42_arg_parser.add_subparsers()
21+
description = u"""
22+
Groups:
23+
profile - For managing Code42 settings.
24+
securitydata - Tools for getting security related data, such as file events.
25+
"""
26+
code42_arg_parser = ArgumentParser(
27+
formatter_class=RawDescriptionHelpFormatter,
28+
description=description,
29+
usage=u"code42 <group> <subcommand> <optional args>",
30+
)
31+
subcommand_parser = code42_arg_parser.add_subparsers(title=u"groups")
2332
profile.init(subcommand_parser)
2433
securitydata.init_subcommand(subcommand_parser)
2534
_run(code42_arg_parser)
@@ -30,7 +39,7 @@ def _run(parser):
3039
args = parser.parse_args()
3140
args.func(args)
3241
except AttributeError as ex:
33-
if str(ex) == "'Namespace' object has no attribute 'func'":
42+
if str(ex) == u"'Namespace' object has no attribute 'func'":
3443
parser.print_help()
3544
return
3645
raise ex

src/code42cli/profile/profile.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import print_function
22

3+
from argparse import RawDescriptionHelpFormatter
4+
35
import code42cli.arguments as main_args
46
import code42cli.profile.password as password
57
from code42cli.compat import str
@@ -52,14 +54,48 @@ def init(subcommand_parser):
5254
Args:
5355
subcommand_parser: The subparsers group created by the parent parser.
5456
"""
55-
parser_profile = subcommand_parser.add_parser(u"profile")
56-
profile_subparsers = parser_profile.add_subparsers()
57-
58-
parser_for_show = profile_subparsers.add_parser(u"show")
59-
parser_for_set = profile_subparsers.add_parser(u"set")
60-
parser_for_reset_password = profile_subparsers.add_parser(u"reset-pw")
61-
parser_for_list = profile_subparsers.add_parser(u"list")
62-
parser_for_use = profile_subparsers.add_parser(u"use")
57+
58+
description = u"""
59+
Subcommands:
60+
show - Print the details of a profile.
61+
set - Create or update profile settings. The first profile created will be the default.
62+
reset-pw - Change the stored password for a profile.
63+
list - Show all existing stored profiles.
64+
use - Set a profile as the default.
65+
"""
66+
parser_profile = subcommand_parser.add_parser(
67+
u"profile",
68+
formatter_class=RawDescriptionHelpFormatter,
69+
description=description,
70+
usage=u"code42 profile <subcommand> <optional args>",
71+
)
72+
profile_subparsers = parser_profile.add_subparsers(title="subcommands")
73+
74+
parser_for_show = profile_subparsers.add_parser(
75+
u"show",
76+
description=u"Print the details of a profile.",
77+
usage=u"code42 profile show <optional-args>",
78+
)
79+
parser_for_set = profile_subparsers.add_parser(
80+
u"set",
81+
description=u"Create or update profile settings. The first profile created will be the default.",
82+
usage=u"code42 profile set <optional-args>",
83+
)
84+
parser_for_reset_password = profile_subparsers.add_parser(
85+
u"reset-pw",
86+
description=u"Change the stored password for a profile.",
87+
usage=u"code42 profile reset-pw <optional-args>",
88+
)
89+
parser_for_list = profile_subparsers.add_parser(
90+
u"list",
91+
description=u"Show all existing stored profiles.",
92+
usage=u"code42 profile list <optional-args>",
93+
)
94+
parser_for_use = profile_subparsers.add_parser(
95+
u"use",
96+
description=u"Set a profile as the default.",
97+
usage=u"code42 profile use <profile-name>",
98+
)
6399

64100
parser_for_show.set_defaults(func=show_profile)
65101
parser_for_set.set_defaults(func=set_profile)

src/code42cli/sdk_client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
from py42 import debug_level
2-
from py42 import settings
3-
from py42.sdk import SDK
1+
import py42.sdk
2+
import py42.sdk.settings.debug as debug
43

54
from code42cli.util import print_error
65

76

87
def create_sdk(profile, is_debug_mode):
98
if is_debug_mode:
10-
settings.debug_level = debug_level.DEBUG
9+
py42.sdk.settings.debug.level = debug.DEBUG
1110
try:
1211
password = profile.get_password()
13-
return SDK.create_using_local_account(profile.authority_url, profile.username, password)
12+
return py42.sdk.from_local_account(profile.authority_url, profile.username, password)
1413
except Exception:
1514
print_error(
1615
u"Invalid credentials or host address. "
@@ -21,7 +20,8 @@ def create_sdk(profile, is_debug_mode):
2120

2221
def validate_connection(authority_url, username, password):
2322
try:
24-
SDK.create_using_local_account(authority_url, username, password)
23+
py42.sdk.from_local_account(authority_url, username, password)
2524
return True
2625
except:
26+
print(username, password, authority_url)
2727
return False

src/code42cli/securitydata/arguments/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _add_actor_arg(parser):
116116
nargs=u"+",
117117
action=u"store",
118118
dest=SearchArguments.ACTOR,
119-
help=u"Limits events to only those enacted by these actors.",
119+
help=u"Limits events to only those enacted by the cloud service user of the person who caused the event.",
120120
)
121121

122122

src/code42cli/securitydata/date_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime, timedelta
22

33
from c42eventextractor.common import convert_datetime_to_timestamp
4-
from py42.sdk.file_event_query.event_query import EventTimestamp
4+
from py42.sdk.queries.fileevents.filters.event_filter import EventTimestamp
55

66
_MAX_LOOK_BACK_DAYS = 90
77
_FORMAT_VALUE_ERROR_MESSAGE = u"input must be a date in YYYY-MM-DD or YYYY-MM-DD HH:MM:SS format."

src/code42cli/securitydata/extraction.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
from c42eventextractor import FileEventHandlers
66
from c42eventextractor.extractors import FileEventExtractor
7-
from py42.sdk.file_event_query.cloud_query import Actor
8-
from py42.sdk.file_event_query.device_query import DeviceUsername
9-
from py42.sdk.file_event_query.event_query import Source
10-
from py42.sdk.file_event_query.exposure_query import ExposureType, ProcessOwner, TabURL
11-
from py42.sdk.file_event_query.file_query import MD5, SHA256, FileName, FilePath
7+
from py42.sdk.queries.fileevents.filters import *
128

139
from code42cli.compat import str
1410
from code42cli.profile.profile import get_profile

src/code42cli/securitydata/main.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
from argparse import RawDescriptionHelpFormatter
2+
13
from code42cli.securitydata.subcommands import clear_checkpoint, print_out, write_to
24
from code42cli.securitydata.subcommands import send_to
35

46

57
def init_subcommand(subcommand_parser):
6-
securitydata_arg_parser = subcommand_parser.add_parser("securitydata")
7-
securitydata_subparser = securitydata_arg_parser.add_subparsers()
8-
send_to.init(securitydata_subparser)
9-
write_to.init(securitydata_subparser)
10-
print_out.init(securitydata_subparser)
11-
clear_checkpoint.init(securitydata_subparser)
8+
description = u"""
9+
Subcommands:
10+
print - Print file events to stdout.
11+
send-to - Send file events to the given server address.
12+
write-to - Write file events to the file with the given name.
13+
clear-checkpoint - Remove the saved checkpoint from 'incremental' (-i) mode.
14+
"""
15+
securitydata_arg_parser = subcommand_parser.add_parser(
16+
u"securitydata",
17+
formatter_class=RawDescriptionHelpFormatter,
18+
description=description,
19+
epilog=u"Use '--profile <profile-name>' to execute any of these commands for the given profile.",
20+
usage=u"code42 securitydata <subcommand> <optional args>",
21+
)
22+
securitydata_subparsers = securitydata_arg_parser.add_subparsers(title=u"subcommands")
23+
send_to.init(securitydata_subparsers)
24+
write_to.init(securitydata_subparsers)
25+
print_out.init(securitydata_subparsers)
26+
clear_checkpoint.init(securitydata_subparsers)

src/code42cli/securitydata/subcommands/clear_checkpoint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ def init(subcommand_parser):
88
Args:
99
subcommand_parser: The subparsers group created by the parent parser.
1010
"""
11-
parser = subcommand_parser.add_parser("clear-checkpoint")
11+
parser = subcommand_parser.add_parser(
12+
u"clear-checkpoint",
13+
description=u"Remove the saved checkpoint from 'incremental' (-i) mode.",
14+
usage=u"code42 securitydata clear-checkpoint <optional-args>",
15+
)
1216
add_profile_name_arg(parser)
1317
parser.set_defaults(func=clear_checkpoint)
1418

0 commit comments

Comments
 (0)