Skip to content

Expand v1alpha coverage; Add packaging and a CLI #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
101f3b2
create event_import v1alpha
dandye Mar 7, 2025
3ab7f99
add events_get
dandye Mar 7, 2025
3db7cf9
events_batch_get
dandye Mar 7, 2025
f0b9300
udm_events_find
dandye Mar 7, 2025
a8ebfdb
find assets and raw logs
dandye Mar 7, 2025
a0581fd
url_always_prepend_region
dandye Mar 7, 2025
7d55b44
get_detection
dandye Mar 7, 2025
a380a96
Add SDK wrapper
dandye Mar 7, 2025
94e317e
expand coverage of SDK
dandye Mar 7, 2025
9719f81
Use dotenv
dandye Mar 7, 2025
b856aac
Update readme with dotenv
dandye Mar 7, 2025
f0389a2
Code cleanup
dandye Mar 7, 2025
02c9d52
Google style guide
dandye Mar 7, 2025
d072b74
Update copyright year
dandye Mar 7, 2025
95d6673
Update copyright year throughout
dandye Mar 7, 2025
10856a7
SDK fixes
dandye Mar 7, 2025
ccd58e3
Makefile for wheel
dandye Mar 7, 2025
e009618
update docs with .env and build
dandye Mar 7, 2025
c8cb534
Bug fixes with packaging
dandye Mar 7, 2025
09fc059
2 space indent
dandye Mar 7, 2025
031ed85
2 space indent
dandye Mar 7, 2025
e64d3b0
isort imports
dandye Mar 7, 2025
b654695
Style fixes
dandye Mar 7, 2025
33e45fc
Presubmit fixes
dandye Mar 8, 2025
5ff9ba9
cover the search query get v1alpha api resource
dandye Mar 8, 2025
cee0332
revert changes to v2 py files
dandye Mar 11, 2025
b43aea3
Add IoC API resources
dandye Mar 11, 2025
70619b6
Revert changes to access_control
dandye Mar 11, 2025
0911b3a
revert updates to non-v1alpha py files
dandye Mar 11, 2025
4f92aa9
revert updates to non-v1alpha py files
dandye Mar 11, 2025
239ff30
yapf format to 2 spaces; isort imports
dandye Mar 11, 2025
7e897d5
refactor; lint
dandye Mar 11, 2025
1998d3d
Revert non-v1alpha file changes
dandye Mar 11, 2025
3a05a0f
Lint fixes
dandye Mar 11, 2025
08103ad
Linting fixes
dandye Mar 11, 2025
0b3399e
fix line-too-long
dandye Mar 11, 2025
2f563e7
linting; rm MCP files
dandye Mar 11, 2025
3021362
rm reference_lists (MCP files)
dandye Mar 11, 2025
809c978
linting
dandye Mar 11, 2025
9ecd908
linting
dandye Mar 11, 2025
ab00567
linting
dandye Mar 11, 2025
880bcd6
SDK bugs
dandye Mar 12, 2025
e1f79a0
linting
dandye Mar 12, 2025
1d95a08
linting
dandye Mar 12, 2025
1cf8368
linting
dandye Mar 12, 2025
3016298
Lint the ReadMe
dandye Mar 12, 2025
42061c4
lint
dandye Mar 12, 2025
39a2c9f
lint the ReadMe
dandye Mar 12, 2025
a932393
lint readme
dandye Mar 12, 2025
c8caa8b
ReadMe lint
dandye Mar 12, 2025
f2034bc
Fix .env in ReadMe
dandye Mar 12, 2025
2acac25
remove relative imports from tests
dandye Mar 12, 2025
3d92b96
import order
dandye Mar 12, 2025
59e8dd1
revert changes to regions and test
dandye Mar 12, 2025
daea913
revert changes to common/ files
dandye Mar 12, 2025
96fdbba
revert changes to create_list.py
dandye Mar 12, 2025
d3b0577
revert changes to get_udm_event
dandye Mar 12, 2025
1eaeb1a
Fix the build and release v0.1.3 to Artifacts
dandye Mar 12, 2025
52d13f8
Consistent quotes
dandye Mar 12, 2025
24f6b68
Add copyright and License
dandye Mar 20, 2025
69a4dbd
Rebrand as Chronicle API CLI
dandye Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Chronicle API SDK Configuration
CHRONICLE_CREDENTIALS_FILE=path/to/credentials.json
CHRONICLE_PROJECT_ID=your-project-id
CHRONICLE_INSTANCE=your-instance-id
CHRONICLE_REGION=your-region
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,48 @@ __pycache__/
venv/

node_modules/

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
venv/
env/
ENV/

# IDE
.idea/
.vscode/
*.swp
*.swo

# Environment Variables
.env
.env.*
!.env.example

# Credentials
*credentials*.json
*creds*.json

# Logs
*.log
4 changes: 4 additions & 0 deletions .style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[style]
based_on_style = google
indent_width = 2
column_limit = 80
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: install dist clean

build:
python -m build

install:
python setup.py install

dist:
python setup.py bdist_wheel

clean:
rm -rf build/ dist/ *.egg-info/
170 changes: 160 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ samples try to use the file `.chronicle_credentials.json` in the user's home
directory. If this file is not found, you need to specify it explicitly by
adding the following argument to the sample's command-line:

```shell
-c <file_path>
```

or

```shell
--credentials_file <file_path>
```
`shell -c <file_path>` or `shell --credentials_file <file_path>`

## Usage

Expand All @@ -60,8 +52,166 @@ python3 -m lists.<sample_name> -h

### Lists API v1alpha

```
```shell
python -m lists.v1alpha.create_list -h
python -m lists.v1alpha.get_list -h
python -m lists.v1alpha.patch_list -h
```

## Installing the Chronicle REST API CLI

Install the CLI from source
```
python setup.py install
```

Alternatively, install the CLI from source using make
```
make install
```

Build the wheel file
```
make dist
```

## Using the Chronicle REST API CLI

The CLI provides a unified command-line interface for Chronicle APIs.
The CLI follows this pattern:
```
chronicle [common options] COMMAND_GROUP COMMAND [command options]
```

### Common Options

Common options can be provided either via command-line arguments or environment
variables:

| CLI Option | Environment Variable | Description |
|--------------------|----------------------------|--------------------------------|
| --credentials-file | CHRONICLE_CREDENTIALS_FILE | Path to service account file |
| --project-id | CHRONICLE_PROJECT_ID | GCP project id or number |
| --project-instance | CHRONICLE_INSTANCE | Chronicle instance ID (uuid) |
| --region | CHRONICLE_REGION | Region where project is located|

You can set these options in a `.env` file in your project root:

```bash
# .env file
CHRONICLE_CREDENTIALS_FILE=path/to/credentials.json
CHRONICLE_PROJECT_ID=your-project-id
CHRONICLE_INSTANCE=your-instance-id
CHRONICLE_REGION=your-region
```

The CLI will use values from the `.env` file or a file provided with the
`--env-file` parameter. Command-line options take precedence over environment
variables.

### Command Groups

#### Detection API
```bash
chronicle detect <command-group> <command> [options]
```

Available command groups:

- `alerts`
- `get <alert-id>`: Get alert by ID
- `update <alert-id>`: Update an alert
- `bulk-update`: Bulk update alerts matching a filter

- `detections`
- `get <detection-id>`: Get detection by ID
- `list [--filter <filter>]`: List detections

- `rules`
- `create`: Create a new rule
- `get <rule-id>`: Get rule by ID
- `delete <rule-id>`: Delete a rule
- `enable <rule-id>`: Enable a rule
- `list [--filter <filter>]`: List rules

- `retrohunts`
- `create`: Create a new retrohunt
- `get <retrohunt-id>`: Get retrohunt by ID

- `errors`
- `list [--filter <filter>]`: List errors

- `rulesets`
- `batch-update`: Batch update rule set deployments

#### Ingestion API
```bash
chronicle ingestion <command> [options]
```

Available commands:

- `import-events`: Import events into Chronicle
- `get-event <event-id>`: Get event details
- `batch-get-events`: Batch retrieve events

#### Search API
```bash
chronicle search <command> [options]
```

Available commands:

- `find-asset-events [--filter <filter>]`: Find events for an asset
- `find-raw-logs [--filter <filter>]`: Search raw logs
- `find-udm-events [--filter <filter>]`: Find UDM events

#### Lists API
```bash
chronicle lists <command> [options]
```

Available commands:

- `create <name> [--description <desc>] --lines <json-array>`: Create a new list
- `get <list-id>`: Get list by ID
- `patch <list-id> [--description <desc>]
[--lines-to-add <json-array>] \
[--lines-to-remove <json-array>]`: Update an existing list

### Examples

Using environment variables (after setting up .env):
```bash
# Get an alert
chronicle detect alerts get --alert-id ABC123 --env-file=.env

# Create a list
chronicle lists create --name "blocklist" --description "Blocked IPs" \
--lines '["1.1.1.1", "2.2.2.2"]' \
--env-file=.env

# Search for events
chronicle search find-raw-logs --filter "timestamp.seconds > 1600000000" \
--env-file=.env

# Override a specific environment variable
chronicle --region us-central1 detect alerts get --alert-id ABC123 \
--env-file=.env
```

## Running Individual Scripts

You can also run individual API sample scripts directly.
Each script supports the `-h` flag to show available options:

```bash
# Get help for a specific script
python -m detect.v1alpha.get_alert -h
python -m search.v1alpha.find_asset_events -h
python -m lists.v1alpha.patch_list -h
```

## License

Apache 2.0 - See [LICENSE](LICENSE) for more information.
Empty file added __init__.py
Empty file.
19 changes: 19 additions & 0 deletions chronicle_api.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Metadata-Version: 2.2
Name: chronicle-api
Version: 0.1.3
Summary: Chronicle API SDK and CLI
Author: Google LLC
Author-email: [email protected]
License: Apache 2.0
Requires-Python: >=3.10
License-File: LICENSE
Requires-Dist: click>=8.0.0
Requires-Dist: google-auth>=2.0.0
Requires-Dist: requests>=2.25.0
Requires-Dist: python-dotenv>=1.0.0
Dynamic: author
Dynamic: author-email
Dynamic: license
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary
66 changes: 66 additions & 0 deletions chronicle_api.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
LICENSE
README.md
pyproject.toml
setup.py
chronicle_api.egg-info/PKG-INFO
chronicle_api.egg-info/SOURCES.txt
chronicle_api.egg-info/dependency_links.txt
chronicle_api.egg-info/entry_points.txt
chronicle_api.egg-info/requires.txt
chronicle_api.egg-info/top_level.txt
common/__init__.py
common/chronicle_auth.py
common/chronicle_auth_test.py
common/datetime_converter.py
common/datetime_converter_test.py
common/project_id.py
common/project_instance.py
common/regions.py
common/regions_test.py
detect/v1alpha/__init__.py
detect/v1alpha/batch_update_curated_rule_set_deployments.py
detect/v1alpha/bulk_update_alerts.py
detect/v1alpha/create_retrohunt.py
detect/v1alpha/create_rule.py
detect/v1alpha/delete_rule.py
detect/v1alpha/enable_rule.py
detect/v1alpha/get_alert.py
detect/v1alpha/get_detection.py
detect/v1alpha/get_retrohunt.py
detect/v1alpha/get_rule.py
detect/v1alpha/list_detections.py
detect/v1alpha/list_errors.py
detect/v1alpha/list_rules.py
detect/v1alpha/update_alert.py
detect/v1alpha/update_rule.py
ingestion/v1alpha/__init__.py
ingestion/v1alpha/create_udm_events.py
ingestion/v1alpha/event_import.py
ingestion/v1alpha/events_batch_get.py
ingestion/v1alpha/events_get.py
ingestion/v1alpha/get_udm_event.py
iocs/v1alpha/__init__.py
iocs/v1alpha/batch_get_iocs.py
iocs/v1alpha/get_ioc.py
iocs/v1alpha/get_ioc_state.py
lists/v1alpha/__init__.py
lists/v1alpha/create_list.py
lists/v1alpha/get_list.py
lists/v1alpha/patch_list.py
lists/v1alpha/patch_list_test.py
sdk/__init__.py
sdk/cli.py
sdk/commands/__init__.py
sdk/commands/common.py
sdk/commands/detect.py
sdk/commands/ingestion.py
sdk/commands/iocs.py
sdk/commands/lists.py
sdk/commands/search.py
search/v1alpha/__init__.py
search/v1alpha/asset_events_find.py
search/v1alpha/client.py
search/v1alpha/raw_logs_find.py
search/v1alpha/search_queries_list.py
search/v1alpha/search_query_get.py
search/v1alpha/udm_events_find.py
1 change: 1 addition & 0 deletions chronicle_api.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions chronicle_api.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[console_scripts]
chronicle = sdk.cli:cli
4 changes: 4 additions & 0 deletions chronicle_api.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
click>=8.0.0
google-auth>=2.0.0
requests>=2.25.0
python-dotenv>=1.0.0
7 changes: 7 additions & 0 deletions chronicle_api.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
common
detect
ingestion
iocs
lists
sdk
search
2 changes: 1 addition & 1 deletion common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 Google LLC
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Empty file added detect/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion detect/v1alpha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Google LLC
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
Loading