Skip to content

Commit 211a7d6

Browse files
authored
Chore/set up automation (#4)
1 parent 6855267 commit 211a7d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1735
-235
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
source = src

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
[*.py]
14+
max_line_length = 100

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python: [2.7, 3.5, 3.6, 3.7, 3.8]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Setup Python
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: ${{ matrix.python }}
19+
- name: Install tox
20+
run: pip install tox==3.14.3
21+
- name: Run Tox
22+
run: tox -e py # Run tox using the version of Python in `PATH`

.github/workflows/publish.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v1
14+
with:
15+
python-version: '3.x'
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install setuptools wheel twine
20+
- name: Build Release
21+
run: |
22+
python setup.py sdist bdist_wheel
23+
- name: Set File Names and Release IDs
24+
run: |
25+
src_file=( ./dist/*.tar.gz )
26+
wheel_file=( ./dist/*.whl )
27+
echo "::set-env name=RELEASE_ID::$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)"
28+
echo "::set-env name=SOURCE_DIST_FILE::$(basename $src_file)"
29+
echo "::set-env name=WHEEL_FILE::$(basename $wheel_file)"
30+
- name: Set Upload Url
31+
run: |
32+
echo "::set-env name=UPLOAD_URL::https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets{?name,label}"
33+
- name: Output Variables For Uploading
34+
id: get_upload_vars
35+
run: |
36+
echo "Release ID: $RELEASE_ID"
37+
echo "Source Dist File: $SOURCE_DIST_FILE"
38+
echo "Source Dist Upload Url: $SOURCE_DIST_URL"
39+
echo "Wheel File: $WHEEL_FILE"
40+
echo "Upload Url: $UPLOAD_URL"
41+
echo "::set-output name=source_dist_path::./dist/${SOURCE_DIST_FILE}"
42+
echo "::set-output name=source_dist_name::${SOURCE_DIST_FILE}"
43+
echo "::set-output name=wheel_path::./dist/${WHEEL_FILE}"
44+
echo "::set-output name=wheel_name::./dist/${WHEEL_FILE}"
45+
echo "::set-output name=upload_url::${UPLOAD_URL}"
46+
- name: Upload Source Distribution to GitHub release
47+
uses: actions/[email protected]
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
upload_url: ${{ steps.get_upload_vars.outputs.upload_url }}
52+
asset_path: ${{ steps.get_upload_vars.outputs.source_dist_path }}
53+
asset_name: ${{ steps.get_upload_vars.outputs.source_dist_name }}
54+
asset_content_type: application/x-gzip
55+
- name: Upload Wheel to GitHub Release
56+
uses: actions/[email protected]
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
upload_url: ${{ steps.get_upload_vars.outputs.upload_url }}
61+
asset_path: ${{ steps.get_upload_vars.outputs.wheel_path }}
62+
asset_name: ${{ steps.get_upload_vars.outputs.wheel_name }}
63+
asset_content_type: application/zip
64+
- name: Publish Build to PyPI
65+
env:
66+
TWINE_USERNAME: '__token__'
67+
TWINE_PASSWORD: ${{ secrets.PYPI_ACCESS_TOKEN }}
68+
run: |
69+
twine upload dist/*

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Test config file
22
*config.cfg
33

4+
.DS_Store
5+
46
# IDE files
57
.idea/
8+
.vscode
69

710
# Database files
811
*.db

CHANGELOG.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -10,22 +11,36 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1011
## Unreleased
1112

1213
### Removed
13-
- Removed config file settings and `-c` CLI arg. Use `c42sec profile set`.
14-
- Removed `--clear-password` CLI argument. Use `c42sec profile set -p`. You will be prompted.
14+
15+
- Removed config file settings and `-c` CLI arg. Use `code42 profile set`.
16+
- Removed `--clear-password` CLI argument. Use `code42 profile set -p`. You will be prompted.
17+
- Removed top-level destination args. Use subcommands `write-to`. `send-to`, `print` off of `code42 security data`.
1518

1619
### Added
17-
- Added ability to view your profile: `c42sec profile show`.
20+
21+
- Added ability to view your profile: `code42 profile show`.
22+
- Added `securitydata` subcommands:
23+
- Use `code42 securitydata write-to` to output to a file.
24+
- Use `code42 securitydata send-to` to output to a server.
25+
- Use `code42 securitydata print` to outputs to stdout.
26+
- Use `code42 securitydata clear-cursor` to remove the stored cursor for 'incremental' mode.
27+
- Added support for raw JSON queries via `code42 securitydata [subcommand] --advanced-query [JSON]`.
1828

1929
### Changed
20-
- Renamed `c42aed` to `c42sec`.
21-
- Moved CLI arguments `-s`, `-u`, and `--ignore-ssl-errors` to `c42sec profile set` command.
2230

31+
- Renamed base command `c42aed` to `code42`.
32+
- Moved CLI arguments `-s`, `-u`, and `--ignore-ssl-errors` to `code42 profile set` command.
33+
- Renamed and moved top-level `-r` flag.
34+
- Use `-i` on one of these `securitydata` subcommands `write-to`. `send-to`, `print`.
35+
- Moved search arguments to individual `securitydata` subcommands `write-to`. `send-to`, `print`.
2336

2437
## 0.1.1 - 2019-10-29
2538

2639
### Fixed
40+
2741
- Issue where IOError message was inaccurate when using the wrong port for server destinations.
2842

2943
### Added
44+
3045
- Error handling for all socket errors.
3146
- Error handling for IOError 'connection refused'.

CONTRIBUTING.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Contributing to code42cli
2+
3+
## Development environment
4+
5+
Install code42cli and its development dependencies. The `-e` option installs py42 in
6+
["editable mode"](https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs).
7+
8+
```bash
9+
$ pip install -e .[dev]
10+
```
11+
12+
If you are using `zsh`, you may need to escape the brackets.
13+
14+
We use [black](https://black.readthedocs.io/en/stable/) to automatically format our code.
15+
After installing dependencies, be sure to run:
16+
17+
```bash
18+
$ pre-commit install
19+
```
20+
21+
This will set up a pre-commit hook that will automatically format your code to our desired styles whenever you commit.
22+
It requires python 3.6 to run, so be sure to have a python 3.6 executable of some kind in your PATH when you commit.
23+
24+
## General
25+
26+
* Use positional argument specifiers in `str.format()`
27+
* Use syntax and built-in modules that are compatible with both Python 2 and 3.
28+
* Use the `code42cli._internal.compat` module to create abstractions around functionality that differs between 2 and 3.
29+
30+
## Changes
31+
32+
Document all notable consumer-affecting changes in CHANGELOG.md per principles and guidelines at
33+
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
34+
35+
## Tests
36+
37+
We use [tox](https://tox.readthedocs.io/en/latest/#) to run the
38+
[pytest](https://docs.pytest.org/) test framework on Python 2.7, 3.5, 3.6, and 3.7.
39+
40+
To run all tests, run this at the root of the repo:
41+
42+
```bash
43+
$ tox
44+
```
45+
46+
If you're using a virtual environment, this will only run the tests within that environment/version of Python.
47+
To run the tests on all supported versions of Python in a local dev environment, we recommend using
48+
[pyenv](https://github.com/pyenv/pyenv) and tox in your system (non-virtual) environment:
49+
50+
```bash
51+
$ pip install tox
52+
$ pyenv install 2.7.16
53+
$ pyenv install 3.5.7
54+
$ pyenv install 3.6.9
55+
$ pyenv install 3.7.4
56+
$ pyenv local 2.7.16 3.5.7 3.6.9 3.7.4
57+
$ tox
58+
```
59+
60+
### Writing tests
61+
62+
Put actual before expected values in assert statements. Pytest assumes this order.
63+
64+
```python
65+
a = 4
66+
assert a % 2 == 0
67+
```
68+
69+
Use the following naming convention with test methods:
70+
71+
test\_\[unit_under_test\]\_\[variables_for_the_test\]\_\[expected_state\]
72+
73+
Example:
74+
75+
```python
76+
def test_add_one_and_one_equals_two():
77+
```

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README.md LICENSE.md tox.ini

README.md

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,79 @@
1-
# c42sec
1+
# The Code42 CLI
22

3-
The c42seceventcli AED module contains a CLI tool for extracting AED events as well as an optional state manager
4-
for recording timestamps. The state manager records timestamps so that on future runs,
5-
you only extract events you did not previously extract.
3+
Use the `code42` command to interact with your Code42 environment.
4+
`code42 securitydata` is a CLI tool for extracting AED events.
5+
Additionally, `code42 securitydata` can record a checkpoint so that you only get events you have not previously gotten.
66

77
## Requirements
88

99
- Python 2.7.x or 3.5.0+
1010
- Code42 Server 6.8.x+
1111

1212
## Installation
13-
Install `c42sec` using:
13+
Install the `code42` CLI using:
1414

1515
```bash
1616
$ python setup.py install
1717
```
1818

1919
## Usage
2020

21-
First, set your profile
22-
21+
First, set your profile:
2322
```bash
24-
c42sec profile set -s https://example.authority.com -u [email protected] -p
23+
code42 profile set -s https://example.authority.com -u [email protected]
2524
```
25+
Your profile contains the necessary properties for logging into Code42 servers.
26+
You will prompted for a password if there is not one saved for your current username/authority URL combination.
2627

27-
`-p` will prompt for your password securely. If your username does not have a password stored, you will be prompted anyway.
28+
To explicitly set your password, use `-p`:
29+
```bash
30+
code42 profile set -p
31+
```
32+
You will be securely prompted to input your password.
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 there is a password set for your profile.
2835

2936
To ignore SSL errors, do:
37+
```bash
38+
code42 profile set --disable-ssl-errors
39+
```
3040

41+
To re-enable SSL errors, do:
3142
```bash
32-
c42sec profile set --ignore-ssl-errors true
43+
code42 profile set --enable-ssl-errors
3344
```
3445

46+
Next, you can query for events and send them to three possible destination types
47+
* stdout
48+
* A file
49+
* A server, such as SysLog
50+
51+
To print events to stdout, do:
52+
```bash
53+
code42 securitydata print
54+
```
55+
56+
To write events to a file, do:
57+
```bash
58+
code42 securitydata write-to filename.txt
59+
```
60+
61+
To send events to a server, do:
62+
```bash
63+
code42 securitydata send-to https://syslog.company.com -p TCP
64+
```
65+
66+
Each destination-type subcommand shares query parameters
67+
* `-t` (exposure types)
68+
* `-b` (begin date)
69+
* `-e` (end date)
70+
* `--advanced-query` (raw JSON query)
71+
72+
Note that you cannot use other query parameters if you use `--advanced-query`.
73+
74+
To learn more about acceptable arguments, add the `-h` flag to `code42` or and of the destination-type subcommands.
75+
76+
3577
# Known Issues
3678

3779
Only the first 10,000 of each set of events containing the exact same insertion timestamp is reported.

aed_config.default.cfg

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)