Skip to content

Commit 92130dd

Browse files
authored
release 🚚 (#55)
2 parents 4aa5c39 + 85adb8e commit 92130dd

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

‎README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ with DiodeDryRunClient(app_name="my_app", output_dir="/tmp") as client:
9090
```
9191

9292
The produced file can later be ingested by a real Diode instance using
93-
`load_dryrun_entities` with a standard `DiodeClient`:
93+
`load_dryrun_entities` with a standard `DiodeClient` or via the bundled
94+
`diode-replay-dryrun` helper:
9495

9596
```python
9697
from netboxlabs.diode.sdk import DiodeClient, load_dryrun_entities
@@ -104,6 +105,17 @@ with DiodeClient(
104105
client.ingest(entities=entities)
105106
```
106107

108+
Alternatively, the same file can be ingested using the `diode-replay-dryrun`
109+
command shipped with the SDK:
110+
111+
```bash
112+
diode-replay-dryrun \
113+
--target grpc://localhost:8080/diode \
114+
--app-name my-test-app \
115+
--app-version 0.0.1 \
116+
my_app_92722156890707.json
117+
```
118+
107119
## Supported entities (object types)
108120

109121
* ASN
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
# Copyright 2025 NetBox Labs Inc
3+
"""NetBox Labs, Diode - Scripts."""
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
# Copyright 2025 NetBox Labs Inc
3+
"""CLI helper to ingest dry-run JSON messages into Diode."""
4+
5+
import argparse
6+
import sys
7+
8+
from netboxlabs.diode.sdk import DiodeClient, load_dryrun_entities
9+
10+
11+
def main() -> None:
12+
"""Ingest JSON files generated by ``DiodeDryRunClient``."""
13+
parser = argparse.ArgumentParser(
14+
description="Load dry-run JSON messages and ingest them into Diode"
15+
)
16+
parser.add_argument(
17+
"-t",
18+
"--target",
19+
required=True,
20+
help="gRPC target of the Diode server, e.g. grpc://localhost:8080/diode",
21+
)
22+
parser.add_argument(
23+
"-a",
24+
"--app-name",
25+
required=True,
26+
help="Application name used when ingesting the dry-run messages",
27+
)
28+
parser.add_argument(
29+
"-v",
30+
"--app-version",
31+
required=True,
32+
help="Application version used when ingesting the dry-run messages",
33+
)
34+
parser.add_argument(
35+
"-c",
36+
"--client-id",
37+
help="OAuth2 client ID. Defaults to the DIODE_CLIENT_ID environment variable if not provided",
38+
)
39+
parser.add_argument(
40+
"-k",
41+
"--client-secret",
42+
help="OAuth2 client secret. Defaults to the DIODE_CLIENT_SECRET environment variable if not provided",
43+
)
44+
parser.add_argument(
45+
"files",
46+
nargs="+",
47+
metavar="FILE",
48+
help="Dry-run JSON files to ingest",
49+
)
50+
51+
args = parser.parse_args()
52+
53+
with DiodeClient(
54+
target=args.target,
55+
app_name=args.app_name,
56+
app_version=args.app_version,
57+
client_id=args.client_id,
58+
client_secret=args.client_secret,
59+
) as client:
60+
has_errors = False
61+
for file_path in args.files:
62+
entities = list(load_dryrun_entities(file_path))
63+
if entities:
64+
response = client.ingest(entities=entities)
65+
if response.errors:
66+
print(f"Errors while ingesting {file_path}: {response.errors}", file=sys.stderr)
67+
has_errors = True
68+
else:
69+
print(f"Ingested {len(entities)} entities from {file_path}")
70+
if has_errors:
71+
sys.exit(1)
72+
73+
74+
if __name__ == "__main__":
75+
main()

‎pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test = ["coverage", "pytest", "pytest-cov==6.0.0"]
3636

3737
[tool.coverage.run]
3838
omit = [
39+
"*/netboxlabs/diode/scripts/*",
3940
"*/netboxlabs/diode/sdk/ingester.py",
4041
"*/netboxlabs/diode/sdk/diode/*",
4142
"*/netboxlabs/diode/sdk/validate/*",
@@ -45,10 +46,12 @@ omit = [
4546
[project.urls] # Optional
4647
"Homepage" = "https://netboxlabs.com/"
4748

48-
[project.scripts] # Optional
49+
[project.scripts]
50+
diode-replay-dryrun = "netboxlabs.diode.scripts.dryrun_replay:main"
4951

5052
[tool.setuptools]
5153
packages = [
54+
"netboxlabs.diode.scripts",
5255
"netboxlabs.diode.sdk",
5356
"netboxlabs.diode.sdk.diode",
5457
"netboxlabs.diode.sdk.diode.v1",

0 commit comments

Comments
 (0)