Skip to content

Commit c9f925a

Browse files
author
Juliya Smith
authored
auto console w sdk (#293)
1 parent a2214e0 commit c9f925a

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1616

1717
- New command `code42 users remove-role` to remove a user role from a single user.
1818

19+
- New command `code42 shell` that opens an IPython console with a pre-initialized py42 sdk.
20+
1921
## 1.6.1 - 2021-05-27
2022

2123
### Fixed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"c42eventextractor==0.4.1",
3838
"keyring==18.0.1",
3939
"keyrings.alt==3.2.0",
40+
"ipython>=7.16.1",
4041
"pandas>=1.1.3",
4142
"py42>=1.14.2",
4243
],

src/code42cli/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1+
from py42.__version__ import __version__ as py42version
2+
3+
from code42cli.__version__ import __version__ as cliversion
4+
5+
16
PRODUCT_NAME = "code42cli"
27
MAIN_COMMAND = "code42"
8+
BANNER = f"""\b
9+
dP""b8 dP"Yb 8888b. 888888 dP88 oP"Yb.
10+
dP `" dP Yb 8I Yb 88__ dP 88 "' dP'
11+
Yb Yb dP 8I dY 88"" d888888 dP'
12+
YboodP YbodP 8888Y" 888888 88 .d8888
13+
14+
code42cli version {cliversion}, by Code42 Software.
15+
powered by py42 version {py42version}."""

src/code42cli/cmds/shell.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import click
2+
import IPython
3+
4+
from code42cli import BANNER
5+
from code42cli.options import sdk_options
6+
7+
8+
@click.command()
9+
@sdk_options()
10+
def shell(state):
11+
"""Open an IPython shell with py42 initialized as `sdk`."""
12+
IPython.embed(colors="Neutral", banner1=BANNER, user_ns={"sdk": state.sdk})

src/code42cli/main.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import click
55
from click_plugins import with_plugins
66
from pkg_resources import iter_entry_points
7-
from py42.__version__ import __version__ as py42version
87
from py42.settings import set_user_agent_suffix
98

9+
from code42cli import BANNER
1010
from code42cli import PRODUCT_NAME
11-
from code42cli.__version__ import __version__ as cliversion
1211
from code42cli.click_ext.groups import ExceptionHandlingGroup
1312
from code42cli.cmds.alert_rules import alert_rules
1413
from code42cli.cmds.alerts import alerts
@@ -20,18 +19,10 @@
2019
from code42cli.cmds.legal_hold import legal_hold
2120
from code42cli.cmds.profile import profile
2221
from code42cli.cmds.securitydata import security_data
22+
from code42cli.cmds.shell import shell
2323
from code42cli.cmds.users import users
2424
from code42cli.options import sdk_options
2525

26-
BANNER = f"""\b
27-
dP""b8 dP"Yb 8888b. 888888 dP88 oP"Yb.
28-
dP `" dP Yb 8I Yb 88__ dP 88 "' dP'
29-
Yb Yb dP 8I dY 88"" d888888 dP'
30-
YboodP YbodP 8888Y" 888888 88 .d8888
31-
32-
code42cli version {cliversion}, by Code42 Software.
33-
powered by py42 version {py42version}."""
34-
3526

3627
# Handle KeyboardInterrupts by just exiting instead of printing out a stack
3728
def exit_on_interrupt(signal, frame):
@@ -73,12 +64,13 @@ def cli(state, python):
7364

7465
cli.add_command(alerts)
7566
cli.add_command(alert_rules)
76-
cli.add_command(security_data)
67+
cli.add_command(audit_logs)
68+
cli.add_command(cases)
7769
cli.add_command(departing_employee)
70+
cli.add_command(devices)
7871
cli.add_command(high_risk_employee)
7972
cli.add_command(legal_hold)
8073
cli.add_command(profile)
81-
cli.add_command(devices)
74+
cli.add_command(security_data)
75+
cli.add_command(shell)
8276
cli.add_command(users)
83-
cli.add_command(audit_logs)
84-
cli.add_command(cases)

0 commit comments

Comments
 (0)