Repository navigation
asn-risk: add /api/asn-risk and /api/asn/{asn}/risk to the client and CLI - #12
Merged
Merged
Conversation
… CLI (#340)
The two ASN risk endpoints shipped in honeydb-web#332 were documented in
honeydb-api-docs but absent here, so Python consumers had to bypass the
library -- re-implementing the auth headers, the retry policy and the
error mapping -- to reach a flagship dataset.
Client:
asn_risk(*, period=None, limit=None, scanners=None) -> the monthly
ranked report; asn_risk_history(as_number) -> one ASN's latest row plus
six months of history. Both pass the body through untouched: the two
report generations (methodology.version 1.0 and 2.0) carry different
fields, and normalizing them here would create a second source of truth
for scoring semantics that already live in the API and honeydb-ops.
CLI:
`honeydb asn-risk [--period] [--limit] [--scanners]`, and `--risk` on
the existing `asn` command. --prefixes and --risk are now mutually
exclusive members of one view group, mirroring `ip --geo|--netinfo|...`;
--prefixes behaviour is unchanged and its existing test passes
unmodified.
period/limit/scanners are validated client-side against the API's own
validator regexes, so a malformed value raises ValueError before any
request goes out. Note --limit must accept digit *strings*, not just int:
the parser types it as a string so that "all" stays valid, and forwards
it unconverted. limit=0 is rejected rather than passed on -- the API
floors it to 1, and returning one row to a caller who asked for none
would mislead them. bool is excluded explicitly, since it subclasses int
and limit=True would otherwise become limit=1.
main() now catches ValueError alongside HoneyDBError so client-side
validation exits 1 with a message instead of a traceback. This also fixes
`monitors create --json '{bad'`, since JSONDecodeError subclasses
ValueError; there is a test pinning that.
Two unrelated-looking hunks, both deliberate:
- README.md's create_monitors example is reformatted. `ruff` was
unpinned and current ruff formats Python blocks inside Markdown, so
`ruff format --check .` -- which CI runs on every PR -- already failed
on a clean master. ruff is now pinned to >=0.16,<0.17 and the tree is
actually clean.
- ASN_RISK_SCANNERS is added to three __all__ lists, not one;
honeydb.api is a documented public surface.
Version bumped to 2.1.0 (additive, backward compatible). Not published.
83 tests pass (46 pre-existing, untouched -- both test files have zero
deleted lines), ruff check and ruff format --check clean. Verified
end-to-end against a live stub server, not only mocks: query-string
construction, the 200 [] no-data contract, the HTML-404 path, every
validation rejection sending no request, and the CLI dispatch.
Design: honeydb-web design/asn-risk-python-client-{prd,techspec}.md
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01WybGWSMuPJEuRG4Pz9EfWN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes honeydbio/honeydb-web#340.
The two ASN risk endpoints shipped in honeydb-web#332 are documented in
honeydb-api-docsbut were absent from this library, so Python consumers had to bypass it entirely — re-implementing the auth headers, the retry policy and the error mapping — to reach a flagship dataset.Client
asn_risk(*, period=None, limit=None, scanners=None)— the monthly ranked report.asn_risk_history(as_number)— one ASN's latest row plus six months of history.ASN_RISK_SCANNERS— the acceptedscannersvalues, exported from all three public surfaces.Both pass the response body through untouched. Reports come in two generations (
methodology.version1.0 and 2.0) with different row fields; normalizing them here would create a second source of truth for scoring semantics that already live in the API and inhoneydb-ops.CLI
--prefixesand--riskare now mutually exclusive members of one view group, mirroringip --geo|--netinfo|….--prefixesbehaviour is unchanged and its existing test passes unmodified.Validation
period/limit/scannersare checked client-side against the API's own validator regexes, so a malformed value raisesValueErrorbefore any request goes out. Three details worth a reviewer's eye:--limitmust accept digit strings, not justint. The parser types it as a string soallstays valid and forwards it unconverted; anint-only validator would makehoneydb asn-risk --limit 25— the most likely invocation of the feature — raise before issuing a request.limit=0is rejected rather than forwarded. The API accepts it and silently floors it to 1; returning one row to a caller who asked for none would mislead them.boolis excluded explicitly, since it subclassesintandlimit=Truewould otherwise becomelimit=1.main()now catchesValueErroralongsideHoneyDBError, so client-side validation exits 1 with a message instead of a traceback. That also fixesmonitors create --json '{bad'(JSONDecodeErrorsubclassesValueError); there is a test pinning it as intended.Two hunks that look unrelated — both deliberate
README.md'screate_monitorsexample is reformatted.ruffwas unpinned, and current ruff formats Python blocks inside Markdown, soruff format --check .— which CI runs on every PR — already failed on a cleanmaster. The last green run was 2026-07-07 on an older ruff. ruff is now pinned to>=0.16,<0.17and the tree is actually clean, so this PR's CI is green for its own reasons.ASN_RISK_SCANNERSis added to three__all__lists, not one.honeydb.apiis a documented public surface; a test now covers all three.Version bumped to 2.1.0 (additive, backward compatible). Not published —
make build && make publishstays manual.Verification
46 pre-existing tests untouched — both test files have zero deleted lines.
Beyond the mocked suite, verified end-to-end against a live stub HTTP server: query-string construction for every parameter combination, the
200 []no-data contract on both endpoints, the HTML-404 path for a non-numeric ASN, every validation rejection sending no request, and CLI dispatch including the mutual-exclusion rejection. 21/21 passed.Design docs:
design/asn-risk-python-client-{prd,techspec}.mdin honeydb-web (PR #342).🤖 Generated with Claude Code
https://claude.ai/code/session_01WybGWSMuPJEuRG4Pz9EfWN