Repository navigation
refactor(environments, snapshot): go through the Kosli API client - #1271
dangrondahl wants to merge 5 commits into
Conversation
…ough the Kosli API client
|
Claude finished @dangrondahl's task in 1m 28s —— View job Follow-up review of
|
…recated fields The method calls create_or_update_environment and overwrites an existing environment, so its name now says so. IncludeScaling and RequireProvenance are deprecated on the server (accepted, ignored); the deprecated flags that set them keep working, behind a reasoned nolint.
|
Thanks. Here's what happened to each suggestion, in 8438f1d:
Also in this commit,
|
Stacked on #1249, next to #1269 (the two don't depend on each other). This adds the Environments endpoints to
internal/kosliand moves every caller of them onto the client:get environment,create environment, auto-environment, and the snapshot reporter that all 11snapshotcommands share.internal/kosli/environments.goGetEnvironment(ctx, name)returns*Response[Environment].Environmentonly hasNameandTypefor now, because those are all any caller reads.Value()decodes lazily, soget environment -o jsonstill prints the raw body.CreateOrUpdateEnvironment(ctx, CreateOrUpdateEnvironmentRequest)returns*Result. The name follows the operation and makes the overwrite visible at call sites. The request type moves here fromcmd, where it wasCreateEnvironmentPayload.OpenAPIContractTestSuitenow checks the moved type againstCreateEnvironmentPutInput.IncludeScalingandRequireProvenanceare markedDeprecated:. On the server, both aredeprecated=TrueinCreateEnvironmentPutInput, accepted and ignored. Scaling is never recorded, andrequire_provenancewas replaced by policies. The deprecated CLI flags still set them, behind a//nolint:staticcheckwith the reason. The model forbids extra fields, so the server can only drop them once the CLI stops sending them. The CLI should therefore remove the fields and the flags together.ReportSnapshot(ctx, name, envType, payload)returns*Result. The payload staysany: eachsnapshotcommand still builds its own per-type body.get environmentandcreate environmentnow go throughkosliAPI(). Requests with the deprecated flags were compared too, and their bodies are unchanged.getEnvironmentTypeIfExistsusesGetEnvironment. As before, only a genuine 404 means the environment doesn't exist; that is now checked withkosli.IsNotFound.createEnvironmentForSnapshotusesCreateEnvironment.snapshotReporter*kosli.Clientinstead of client, host, org and token. ItsdryRunfield now only controls whether the success message is printed, because the dry-run sender already stops the PUT.reportandensuretake ctx.snapshotcommands takerun(ctx, args), andRunEpassescmd.Context(). ctx also goes through the K8S multi-environment loop and the--watchpath loops. This PR doesn't add any new cancellation behaviour.operationIds
GetEnvironmentget_environmentCreateOrUpdateEnvironmentcreate_or_update_environmentReportSnapshotreport_<type>_environment, e.g.report_k8s_environment,report_ecs_environmentThere is one report operation per environment type. I couldn't confirm the ids for docker, lambda and server, because my view of the published spec was cut off. So the godoc only names the two I saw.
Verification
internal/koslihas 5 new httptest tests:TypeIsNotFoundsnapshotReportertests pass under-race. They now build the reporter around akosli.Client, wrapped inDryRunfor the dry-run case.make lintis clean.get environment: table, json and 404create environment, including--exclude-scaling, a logical environment with--included-environments, and--dry-runsnapshot serverwithout auto-environmentsnapshot serverwith--auto-environmentin these situations:--environment-descriptionand--include-scaling-A--dry-runSnapshotAutoEnvironmentTestSuite, theSnapshot*suites, theget/create environmentsuites andOpenAPIContractTestSuite.Not in this PR
Conflict to expect
#1269 also adds a field to the test fake server's
receivedstruct ininternal/kosli/client_test.go. Whichever of the two PRs is rebased second will hit a small conflict there.Checklist
Docs are autogenerated from CLI help — make sure the help text reflects your changes(no help text changes)Helm chart ((n/a)charts/k8s-reporter/) updated, if needed. Note: these changes live in a separate PRTerraform provider and related changes (terraform-provider-kosli, terraform-aws-evidence-reporter, terraform-aws-kosli-reporter) updated, if needed(n/a)