Skip to content

feat: Add measured boot trust approvals#3464

Open
kfelternv wants to merge 4 commits into
NVIDIA:mainfrom
kfelternv:v21-measurables-rest
Open

feat: Add measured boot trust approvals#3464
kfelternv wants to merge 4 commits into
NVIDIA:mainfrom
kfelternv:v21-measurables-rest

Conversation

@kfelternv

@kfelternv kfelternv commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Resolves #2801

What this PR does

Adds Provider Admin REST operations for measured-boot trust approvals that already exist in Core:

  • Create, list, and delete trusted-machine approvals.
  • Create, list, and delete trusted-profile approvals.
  • Route each request through the existing Temporal to SiteAgent to Core gRPC path.
  • Publish the routes and models in the OpenAPI specification and generated Go SDK.

How we verified it

Revision: cc4c71c715133b071ba57c939a2d7d5622e9060c

Environment: kfelter-nico-dev.nvidia.com, Kind context kind-kind, with the integrated local stack from revision 7ea923ea3cca858f53b304f361177721eb3f63b0. Only deployment/nico-rest-api was replaced with an image built from this PR; Core, Temporal, SiteAgent, Keycloak, and PostgreSQL remained on the existing stack.

Hands-on verification:

  • Before replacement, GET /v2/org/test-org/nico/measured-boot/trusted-machine returned 404, confirming that the running baseline did not expose the new route.
  • Built localhost:5000/nico-rest-api:pr3464-cc4c71c, loaded it into Kind, and observed one ready REST API pod with zero restarts and image ID sha256:ed4c0c7254d2112c9d8f80ea0531b3613b81bd08fa7e8c2329fb1109ac456103.
  • Provider Admin empty-list requests returned 200 with [] for both resource types.
  • An invalid approval type returned 400. A Tenant Admin list request returned 403.
  • A trusted-machine Persist approval and a trusted-profile Oneshot approval both returned 201. Follow-up list requests returned the exact approval IDs, targets, PCR registers, and comments.
  • Direct Core database reads showed the matching machine and profile rows. SiteAgent logged code=Ok for all six list, add, and remove gRPC methods, and Core spans reported HTTP 200 with gRPC status code 0.
  • Both REST delete requests returned 200. Final Core counts were zero trusted-machine approvals, zero trusted-profile approvals, and zero temporary system profiles.
  • Restored the original REST API image after the exercise and confirmed the deployment was ready and available.

Supporting checks:

go test -timeout 3m ./api/pkg/api/handler -run 'Test(Create|List|Delete)MeasurementTrusted|TestMeasurementTrust'
ok github.com/NVIDIA/infra-controller/rest-api/api/pkg/api/handler 5.575s

go test -timeout 2m ./api/pkg/api/model -run TestMeasurementTrust
ok github.com/NVIDIA/infra-controller/rest-api/api/pkg/api/model 0.106s

go test -timeout 2m ./api/pkg/api -run TestNewAPIRoutes
ok github.com/NVIDIA/infra-controller/rest-api/api/pkg/api 0.058s

How to reproduce the verification

Prerequisites:

  • Docker, Kind, kubectl, jq, and curl.
  • The integrated local NICo stack running in Kind context kind-kind, including REST, Temporal, SiteAgent, Core, Keycloak, and PostgreSQL.
  • A bearer token for a Provider Admin in the test organization and a bearer token for a Tenant Admin. Do not store either token in the checkout.
  1. Start from a clean checkout of the exact PR revision and build the REST image.
git clone https://github.com/NVIDIA/infra-controller.git infra-controller
cd infra-controller
git fetch origin pull/3464/head:pr-3464
git checkout pr-3464
test "$(git rev-parse HEAD)" = cc4c71c715133b071ba57c939a2d7d5622e9060c
test -z "$(git status --porcelain)"

IMAGE=localhost:5000/nico-rest-api:pr3464-cc4c71c
docker build -t "$IMAGE" -f rest-api/docker/local/Dockerfile.nico-rest-api rest-api
kind load docker-image --name kind "$IMAGE"
ORIGINAL_IMAGE=$(kubectl --context kind-kind -n nico-rest get deployment nico-rest-api \
  -o jsonpath='{.spec.template.spec.containers[0].image}')
kubectl --context kind-kind -n nico-rest set image deployment/nico-rest-api api="$IMAGE"
kubectl --context kind-kind -n nico-rest rollout status deployment/nico-rest-api --timeout=120s
  1. In a separate terminal, forward the REST API service, then set the test values.
kubectl --context kind-kind -n nico-rest port-forward service/nico-rest-api 18388:8388
API=http://localhost:18388
ORG=test-org
ADMIN_TOKEN='<provider-admin bearer token>'
TENANT_TOKEN='<tenant-admin bearer token>'

SITE_ID=$(curl -fsS "$API/v2/org/$ORG/nico/site" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -er '.[0].id')
PROFILE_ID=$(kubectl --context kind-kind -n postgres exec postgres-0 -- \
  psql -U postgres -d nico -Atqc \
  "insert into measurement_system_profiles (name) select gen_random_uuid()::text returning profile_id")
  1. Confirm both lists are initially empty, invalid input is rejected, and Tenant Admin access is denied.
curl -fsS "$API/v2/org/$ORG/nico/measured-boot/trusted-machine?siteId=$SITE_ID" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -e 'length == 0'
curl -fsS "$API/v2/org/$ORG/nico/measured-boot/trusted-profile?siteId=$SITE_ID" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -e 'length == 0'

status=$(curl -sS -o /dev/null -w '%{http_code}' \
  -X POST "$API/v2/org/$ORG/nico/measured-boot/trusted-machine" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
  -d "$(jq -nc --arg site "$SITE_ID" '{siteId:$site,machineId:"*",approvalType:"Invalid"}')")
test "$status" = 400

status=$(curl -sS -o /dev/null -w '%{http_code}' \
  "$API/v2/org/$ORG/nico/measured-boot/trusted-machine?siteId=$SITE_ID" \
  -H "Authorization: Bearer $TENANT_TOKEN")
test "$status" = 403
  1. Create and list both approval types.
machine=$(curl -fsS -X POST "$API/v2/org/$ORG/nico/measured-boot/trusted-machine" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
  -d "$(jq -nc --arg site "$SITE_ID" \
    '{siteId:$site,machineId:"*",approvalType:"Persist",pcrRegisters:"0,2,7",comments:"measured boot runtime machine"}')")
MACHINE_APPROVAL_ID=$(jq -er '.approvalId' <<<"$machine")

profile=$(curl -fsS -X POST "$API/v2/org/$ORG/nico/measured-boot/trusted-profile" \
  -H "Authorization: Bearer $ADMIN_TOKEN" -H 'Content-Type: application/json' \
  -d "$(jq -nc --arg site "$SITE_ID" --arg profile "$PROFILE_ID" \
    '{siteId:$site,profileId:$profile,approvalType:"Oneshot",pcrRegisters:"0,2,7",comments:"measured boot runtime profile"}')")
PROFILE_APPROVAL_ID=$(jq -er '.approvalId' <<<"$profile")

curl -fsS "$API/v2/org/$ORG/nico/measured-boot/trusted-machine?siteId=$SITE_ID" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -e --arg id "$MACHINE_APPROVAL_ID" \
  'length == 1 and .[0].approvalId == $id and .[0].machineId == "*" and .[0].approvalType == "Persist"'
curl -fsS "$API/v2/org/$ORG/nico/measured-boot/trusted-profile?siteId=$SITE_ID" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -e --arg id "$PROFILE_APPROVAL_ID" --arg profile "$PROFILE_ID" \
  'length == 1 and .[0].approvalId == $id and .[0].profileId == $profile and .[0].approvalType == "Oneshot"'
  1. Delete the approvals through REST, remove the temporary profile, and confirm the Core tables are clean.
curl -fsS -X DELETE \
  "$API/v2/org/$ORG/nico/measured-boot/trusted-machine/$MACHINE_APPROVAL_ID?siteId=$SITE_ID&selector=ApprovalId" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -e --arg id "$MACHINE_APPROVAL_ID" '.approvalId == $id'
curl -fsS -X DELETE \
  "$API/v2/org/$ORG/nico/measured-boot/trusted-profile/$PROFILE_ID?siteId=$SITE_ID&selector=ProfileId" \
  -H "Authorization: Bearer $ADMIN_TOKEN" | jq -e --arg id "$PROFILE_APPROVAL_ID" '.approvalId == $id'

kubectl --context kind-kind -n postgres exec postgres-0 -- psql -U postgres -d nico -v ON_ERROR_STOP=1 -qc \
  "delete from measurement_system_profiles where profile_id = '$PROFILE_ID'::uuid"
test "$(kubectl --context kind-kind -n postgres exec postgres-0 -- psql -U postgres -d nico -Atqc \
  'select count(*) from measurement_approved_machines')" = 0
test "$(kubectl --context kind-kind -n postgres exec postgres-0 -- psql -U postgres -d nico -Atqc \
  'select count(*) from measurement_approved_profiles')" = 0

kubectl --context kind-kind -n nico-rest set image deployment/nico-rest-api api="$ORIGINAL_IMAGE"
kubectl --context kind-kind -n nico-rest rollout status deployment/nico-rest-api --timeout=120s

Signed-off-by: Kyle Felter <kfelter@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added Measured Boot trusted approval management for machines and profiles via new Provider Admin REST endpoints (create, list, delete).
    • Supports one-time and persistent approval types, optional PCR registers and comments, and returns stored approval records with creation timestamps.
    • Delete supports flexible selection by approval ID or entity ID (machine/profile), with request validation and proper authorization errors.
  • Documentation
    • Added OpenAPI specs for the new endpoints, schemas, and approval type enums.
  • Tests
    • Added handler, routing, model, and authorization test coverage for create/list/delete flows and input validation.

Walkthrough

Adds REST API support for creating, listing, and deleting measured-boot trusted machine and profile approvals, including models, validation, Core integration, authorization, routes, OpenAPI documentation, and automated tests.

Changes

Measurement trust API

Layer / File(s) Summary
Trust approval models and conversions
rest-api/api/pkg/api/model/measurementtrust.go, rest-api/api/pkg/api/model/measurementtrust_test.go
Defines machine and profile approval models, validates request fields and approval types, converts requests and records to and from Core protobufs, and supports selector-based removal requests.
Trust approval handlers
rest-api/api/pkg/api/handler/measurementtrust.go
Adds authorized create, list, and delete handlers for machine and profile approvals, with tracing, Core calls, error mapping, and response conversion.
Handler integration and validation coverage
rest-api/api/pkg/api/handler/measurementtrust_test.go
Tests handler wiring, proxied Core workflow requests, response mapping, invalid-input rejection, and provider-admin authorization.
Routes and API specification
rest-api/api/pkg/api/routes.go, rest-api/api/pkg/api/routes_test.go, rest-api/openapi/spec.yaml
Registers six measured-boot trust approval routes and documents their operations, selectors, request schemas, response schemas, and error responses.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant MeasurementTrustHandler
  participant CoreGrpcProxy
  APIClient->>MeasurementTrustHandler: Create, list, or delete approval
  MeasurementTrustHandler->>MeasurementTrustHandler: Validate request and authorize site
  MeasurementTrustHandler->>CoreGrpcProxy: Execute measurement trust operation
  CoreGrpcProxy-->>MeasurementTrustHandler: Return approval record or records
  MeasurementTrustHandler-->>APIClient: Return HTTP response
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR covers the REST API and OpenAPI parts of #2801, but it does not address the nicocli support requested in the linked issue. Add the nicocli parity work or split it into a separately linked follow-up if it is intentionally deferred.
Docstring Coverage ⚠️ Warning Docstring coverage is 35.48% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding measured boot trust approvals.
Description check ✅ Passed The description is on-topic and matches the PR’s REST API, OpenAPI, and testing changes.
Out of Scope Changes check ✅ Passed The changes stay focused on measured-boot trust approvals, routes, models, tests, and spec updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@kfelternv kfelternv requested a review from thossain-nv July 14, 2026 00:43
@kfelternv kfelternv marked this pull request as ready for review July 14, 2026 01:38
@kfelternv kfelternv requested a review from a team as a code owner July 14, 2026 01:38
@github-actions

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
nico-flow 15 1 3 3 0 8
nico-nsm 7 0 1 5 0 1
nico-psm 15 1 3 3 0 8
nico-rest-api 17 1 4 4 0 8
nico-rest-cert-manager 14 1 3 3 0 7
nico-rest-db 15 1 3 3 0 8
nico-rest-site-agent 15 1 3 3 0 8
nico-rest-site-manager 14 1 3 3 0 7
nico-rest-workflow 15 1 3 3 0 8
TOTAL 127 8 26 30 0 63

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

@github-actions

Copy link
Copy Markdown

🔐 TruffleHog Secret Scan

No secrets or credentials found!

Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉

🔗 View scan details

🕐 Last updated: 2026-07-14 01:42:37 UTC | Commit: cc4c71c

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc4c71c715

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_RemoveMeasurementTrustedMachine_FullMethodName, coreReq, coreResp, siteID)
if apiErr != nil {
logAPIError(logger, apiErr, "failed to delete machine trust approval")
return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return 404 for absent trust approvals

When the requested approval or target ID is syntactically valid but no approval row exists, Core's delete path (crates/api-core/src/measured_boot/rpc/site.rs) calls fetch_one and wraps RowNotFound as an internal error, so ExecuteCoreGRPC yields a 500 and this line forwards it. The new DELETE REST contract advertises 404 for missing IDs; map that not-found case before returning here (and in the analogous trusted-profile delete handler) so normal absent-resource deletes do not surface as server failures.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
rest-api/api/pkg/api/model/measurementtrust.go (1)

17-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Model approval-type as a named type with receiver methods instead of raw string + free helpers.

approvalType is currently a bare string validated via a hand-rolled switch (validateMeasurementTrustApprovalType) and converted via free functions (measurementTrustApprovalTypeToProto/FromProto). Per coding guidelines, this should be a named type with receiver methods, and validation should prefer ozzo's built-in validation.In rule (or a func(interface{}) error validator usable with validation.By) rather than a bespoke switch.

♻️ Suggested refactor
-const (
-	MeasurementTrustApprovalTypeOneshot = "Oneshot"
-	MeasurementTrustApprovalTypePersist = "Persist"
-)
+type MeasurementTrustApprovalType string
+
+const (
+	MeasurementTrustApprovalTypeOneshot MeasurementTrustApprovalType = "Oneshot"
+	MeasurementTrustApprovalTypePersist MeasurementTrustApprovalType = "Persist"
+)
+
+func (t MeasurementTrustApprovalType) ToProto() corev1.MeasurementApprovedTypePb {
+	if t == MeasurementTrustApprovalTypePersist {
+		return corev1.MeasurementApprovedTypePb_Persist
+	}
+	return corev1.MeasurementApprovedTypePb_Oneshot
+}

Then use validation.Field(&r.ApprovalType, validation.Required, validation.In(MeasurementTrustApprovalTypeOneshot, MeasurementTrustApprovalTypePersist)) inside ValidateStruct.

Also applies to the wildcard MachineID != "*" check at Lines 81-85, which could become validation.When(r.MachineID != "*", validationis.UUID.Error(...)) inside ValidateStruct for a single-pass validation.

Also applies to: 72-99, 231-252

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rest-api/api/pkg/api/model/measurementtrust.go` around lines 17 - 20,
Refactor approvalType in the measurement-trust model into a named type with
receiver methods for proto conversion, replacing
validateMeasurementTrustApprovalType and the free conversion helpers. Update
ValidateStruct to validate ApprovalType with validation.Required and
validation.In using the two approval constants, and express the MachineID
wildcard exception with validation.When and the UUID rule in the same validation
pass.

Source: Coding guidelines

rest-api/openapi/spec.yaml (1)

1296-1329: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Missing pagination on the two new list endpoints.

Both get-all-measurement-trusted-machine and get-all-measurement-trusted-profile only accept siteId and omit pageNumber/pageSize/orderBy plus the X-Pagination response header, unlike essentially every other get-all-* endpoint in this spec — including other Site-scoped resources such as get-all-sku. Persist-type approvals have no forced expiry, so this list can grow unbounded at a busy Site, and callers have no way to page through results.

♻️ Suggested pagination addition (apply to both list operations)
       parameters:
         - schema:
             type: string
             format: uuid
           name: siteId
           in: query
           required: true
           description: ID of the Site
+        - schema:
+            type: integer
+            example: 1
+            default: 1
+            minimum: 1
+          in: query
+          name: pageNumber
+          description: Page number for pagination query
+        - schema:
+            type: integer
+            minimum: 1
+            maximum: 100
+            example: 20
+          in: query
+          name: pageSize
+          description: Page size for pagination query
       responses:
         '200':
           description: Measured Boot trusted Machine approvals
           content:
             application/json:
               schema:
                 type: array
                 items:
                   $ref: '`#/components/schemas/MeasurementTrustedMachine`'
+          headers:
+            X-Pagination:
+              schema:
+                type: string
+                example: '{"pageNumber":1,"pageSize":20,"total":30}'
+              description: Pagination result in JSON format

Also applies to: 1423-1456

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rest-api/openapi/spec.yaml` around lines 1296 - 1329, Update both list
operations, get-all-measurement-trusted-machine and
get-all-measurement-trusted-profile, to accept the standard pageNumber,
pageSize, and orderBy query parameters used by comparable get-all endpoints such
as get-all-sku. Add the X-Pagination response header to each 200 response while
preserving the existing siteId parameter and response schemas.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rest-api/api/pkg/api/model/measurementtrust.go`:
- Around line 126-180: Move the protobuf conversion logic from the free
functions APIMeasurementTrustedMachineFromProto and
APIMeasurementTrustedProfileFromProto onto FromProto receiver methods of their
respective API model structs. Replace the plural helpers
APIMeasurementTrustedMachinesFromProto and
APIMeasurementTrustedProfilesFromProto with named slice types and corresponding
FromProto receiver methods, preserving nil handling and element conversion
behavior.
- Around line 182-229: Replace MeasurementTrustedMachineRemoveProto and
MeasurementTrustedProfileRemoveProto with delete request DTOs containing
selector and path-derived ID fields, plus Validate and error-free ToProto
methods matching the existing create-request pattern. Populate these DTOs in the
handlers, run authorization before validation/conversion, then call Validate
followed by ToProto; preserve wildcard machine-ID handling and selector-specific
protobuf mapping.

---

Nitpick comments:
In `@rest-api/api/pkg/api/model/measurementtrust.go`:
- Around line 17-20: Refactor approvalType in the measurement-trust model into a
named type with receiver methods for proto conversion, replacing
validateMeasurementTrustApprovalType and the free conversion helpers. Update
ValidateStruct to validate ApprovalType with validation.Required and
validation.In using the two approval constants, and express the MachineID
wildcard exception with validation.When and the UUID rule in the same validation
pass.

In `@rest-api/openapi/spec.yaml`:
- Around line 1296-1329: Update both list operations,
get-all-measurement-trusted-machine and get-all-measurement-trusted-profile, to
accept the standard pageNumber, pageSize, and orderBy query parameters used by
comparable get-all endpoints such as get-all-sku. Add the X-Pagination response
header to each 200 response while preserving the existing siteId parameter and
response schemas.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c9957257-ea84-4d0f-b9bf-31302c09ffd4

📥 Commits

Reviewing files that changed from the base of the PR and between 69cd51c and cc4c71c.

⛔ Files ignored due to path filters (7)
  • rest-api/sdk/standard/api_measured_boot_trusted_machine.go is excluded by !rest-api/sdk/standard/api_*.go
  • rest-api/sdk/standard/api_measured_boot_trusted_profile.go is excluded by !rest-api/sdk/standard/api_*.go
  • rest-api/sdk/standard/client.go is excluded by !rest-api/sdk/standard/client.go
  • rest-api/sdk/standard/model_measurement_trusted_machine.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_measurement_trusted_machine_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_measurement_trusted_profile.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_measurement_trusted_profile_create_request.go is excluded by !rest-api/sdk/standard/model_*.go
📒 Files selected for processing (7)
  • rest-api/api/pkg/api/handler/measurementtrust.go
  • rest-api/api/pkg/api/handler/measurementtrust_test.go
  • rest-api/api/pkg/api/model/measurementtrust.go
  • rest-api/api/pkg/api/model/measurementtrust_test.go
  • rest-api/api/pkg/api/routes.go
  • rest-api/api/pkg/api/routes_test.go
  • rest-api/openapi/spec.yaml

Comment thread rest-api/api/pkg/api/model/measurementtrust.go Outdated
Comment thread rest-api/api/pkg/api/model/measurementtrust.go Outdated
Signed-off-by: Kyle Felter <kfelter@nvidia.com>
Signed-off-by: Kyle Felter <kfelter@nvidia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rest-api/api/pkg/api/model/measurementtrust.go (1)

85-99: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use named validation.By validators for the cross-field ID rules.
MachineID != "*" and the matching delete-path selector logic should live in receiver methods, then be composed through validation.Field(..., validation.By(...)) instead of inline branching. That keeps the validation reusable and consistent with the rest of the model package.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rest-api/api/pkg/api/model/measurementtrust.go` around lines 85 - 99,
Refactor APIMeasurementTrustedMachineCreateRequest.Validate to move the
MachineID wildcard/UUID rule into a named receiver validator method and apply it
through validation.Field with validation.By. Apply the same pattern to the
matching delete-path selector logic, preserving the existing "*" allowance and
UUID validation behavior while removing inline branching.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@rest-api/api/pkg/api/model/measurementtrust.go`:
- Around line 85-99: Refactor APIMeasurementTrustedMachineCreateRequest.Validate
to move the MachineID wildcard/UUID rule into a named receiver validator method
and apply it through validation.Field with validation.By. Apply the same pattern
to the matching delete-path selector logic, preserving the existing "*"
allowance and UUID validation behavior while removing inline branching.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b876a0c1-d3a2-4ebe-8d70-719e0c2c86f2

📥 Commits

Reviewing files that changed from the base of the PR and between d886233 and 6e0eee3.

📒 Files selected for processing (4)
  • rest-api/api/pkg/api/handler/measurementtrust.go
  • rest-api/api/pkg/api/handler/measurementtrust_test.go
  • rest-api/api/pkg/api/model/measurementtrust.go
  • rest-api/api/pkg/api/model/measurementtrust_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • rest-api/api/pkg/api/handler/measurementtrust_test.go
  • rest-api/api/pkg/api/handler/measurementtrust.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add REST API support for measurables / trust approve rules (admin-cli measurables parity)

1 participant