Skip to content

fix: omitempty on Service.Name so provision references serialize href-only - #19

Open
adityakrishnan142 wants to merge 1 commit into
brian1917:v2from
adityakrishnan142:fix-service-name-omitempty
Open

fix: omitempty on Service.Name so provision references serialize href-only#19
adityakrishnan142 wants to merge 1 commit into
brian1917:v2from
adityakrishnan142:fix-service-name-omitempty

Conversation

@adityakrishnan142

Copy link
Copy Markdown

Problem

Service.Name is tagged json:"name" (no omitempty), while every other provisionable type — RuleSet, IPList, LabelGroup, VirtualService, VirtualServer, EnforcementBoundary — uses json:"name,omitempty".

ProvisionHref builds href-only references:

services = append(services, &Service{Href: h})

Because Name has no omitempty, the unset field serializes into the change_subset as "name":"". The PCE's POST /sec_policy rejects that body:

response status code: 406
[{"token":"invalid_uri","message":"Invalid URI: {{\"href\"=>\"/orgs/…/services/…\", \"name\"=>\"\"}}"}]

Real-world impact: workloader delete --provision of services never commits — the deleted services linger in a pending-delete draft, and a later rule-import then 406s with Can not assign deleted service, leaving rulesets empty. (Other types in the same batch provision fine, which is what pointed at Service specifically.)

Fix

Add omitempty to Service.Name, matching the other provisionable structs. A service provision reference now serializes href-only ({"href":"..."}), while a populated Name still serializes for the normal create/update path.

Tests

Adds services_provision_test.go:

  • TestServiceProvisionHrefOnly&Service{Href: h} marshals to exactly {"href":"..."} with no name.
  • TestServiceNameOmittedWhenEmpty — empty name omitted; non-empty name still serialized.

Both pass (go test), and go build ./... is clean.

Service.Name was tagged `json:"name"` (no omitempty) while every other
provisionable type (RuleSet, IPList, LabelGroup, VirtualService,
VirtualServer, EnforcementBoundary) uses `name,omitempty`.

ProvisionHref builds href-only references (&Service{Href: h}), so the unset
Name serialized as "name":"" in the change_subset. The PCE's
POST /sec_policy rejects that with 406 invalid_uri / not_acceptable, so
`workloader delete --provision` of services never commits — the deleted
services linger in a pending-delete draft and later 406 rule-import with
"Can not assign deleted service".

Adding omitempty makes a service provision reference serialize href-only
({"href":"..."}) like the other types, while a populated Name still
serializes for normal create/update. Adds regression tests.
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.

1 participant