feat(platform): add BIOC support#33
Open
olli-kauppinen-wolt wants to merge 3 commits into
Open
Conversation
Models the JSON shapes of /public_api/v1/bioc/{insert,get,delete}:
* BIOC: ten writable fields accepted by /insert, plus four read-only
fields surfaced by /get (creation_time, modification_time, source,
number_of_issues). The Indicator field is json.RawMessage to support
its polymorphic payload — a JSON string when is_xql=true, a JSON
object (filter AST) otherwise.
* BIOCFilter, ListBIOCsRequest, DeleteBIOCsRequest.
* InsertBIOCsResponse with added_objects, updated_objects, and errors
(the live API returns errors as objects with {index, status}, not
strings as documented).
* Listing and delete response wrappers.
Adds an enums package mirror with BIOCType, BIOCSeverity, and BIOCStatus
typed-string aliases plus canonical-set helpers. The severity set
includes SEV_050_CRITICAL, accepted by the live API despite being
absent from the documented enum.
Adds three endpoint constants and Client methods for /public_api/v1/
bioc/{insert,get,delete}:
* InsertBIOCs is the upsert path — submit with no rule_id to create,
or include rule_id to overwrite a matching record. Per-record
failures surface in resp.Errors[{index, status}]. Unlike
/indicators/insert, /bioc/insert returns HTTP 400 (not 200) on
per-record validation failure but the body still uses the success
shape; InsertBIOCs recovers the typed response from that body so
callers can inspect resp.Errors without first handling an HTTP
error.
* ListBIOCs is the filter-bodied read.
* DeleteBIOCs is the filter-bodied delete; returns the deleted
rule_ids, and is idempotent (empty slice on no match, no error).
* FindBIOCByID and FindBIOCByName are convenience helpers. BIOC names
are not unique per tenant — FindBIOCByName returns the first match
only and is unsafe for stateful flows; FindBIOCByID is the canonical
single-record lookup. The rule_id filter field these helpers rely
on is undocumented in the OpenAPI filter enum but accepted by the
live API on EQ for both /bioc/get and /bioc/delete.
Success responses are top-level (no `reply` wrapper); failure responses
that aren't per-record validation errors come back with the usual
`reply.err_extra` wrapper.
* biocs_test.go: 16 sub-tests covering Insert (create/update/HTTP 400
with success-shape body recovery/HTTP 200 with errors/transport-
level failures/top-level body/polymorphic indicator), List (read-
only fields, empty result), Delete (returns ids, idempotent), and
FindBIOCBy{ID,Name}.
* biocs_acc_test.go: five //go:build acceptance tests against a live
tenant — full lifecycle (create→read by id/name→in-place update→
delete by rule_id), idempotent delete, structured-indicator round-
trip, SEV_050_CRITICAL round-trip, and non-unique-name invariant.
Acceptance tests follow the existing env-var contract
(TEST_CORTEX_API_URL, TEST_CORTEX_API_KEY, TEST_CORTEX_API_KEY_ID) and
reuse setupAcceptanceTest from asset_group_acc_test.go.
5 tasks
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.
Summary
Adds first-class support for
/public_api/v1/bioc/{insert,get,delete}to the platform module:BIOCandBIOCFiltertypes with the ten write-allowed fields plus four read-only fields the live API returns (creation_time,modification_time,source,number_of_issues).BIOC.Indicatorisjson.RawMessageto keep the SDK schema-agnostic over the polymorphic payload (JSON string whenis_xql=true, structured filter AST otherwise).Client.InsertBIOCs(upsert viarule_id),Client.ListBIOCs,Client.DeleteBIOCs, and convenience helpersClient.FindBIOCByName/Client.FindBIOCByID. Unlike/indicators/insert,/bioc/insertreturns HTTP 400 with the success-shape body on per-record validation failure —InsertBIOCsrecovers the typed response so callers don't need to special-case that path.enumspackage additions:BIOCType(16 values),BIOCSeverity, andBIOCStatus(string-aliased) with canonical-set helpers. IncludesSEV_050_CRITICAL, which the live API accepts even though the OpenAPI insert enum omits it.BIOC names are not unique per tenant —
FindBIOCByIDis the only safe identity-based lookup;FindBIOCByNamereturns the first match and is reserved for ad-hoc CLI work.Test plan
go test ./platform/...— 16 unit sub-tests covering the three endpoints, the structurederrors[{index,status}]shape on both HTTP 200 and HTTP 400, the no-replywrapper on success, the polymorphic indicator round-trip, and bothFindBIOCBy*helpers.go test -tags=acceptance -run TestAccBIOC ./platform/...— five lifecycle / structured-indicator /SEV_050_CRITICAL/ idempotent-delete / non-unique-name tests against a live tenant; all green, tenant left clean.go vet ./platform/... ./types/... ./enums/...clean.