Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow HIL parser to parse CF request context by dropping annotation keys #1087

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/brokerpak-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ The order of combining all plan properties before invoking OpenTofu is as follow
* `request.default_labels.pcf-organization-guid` - _string_ Mapped from [cloudfoundry context](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#cloud-foundry-context-object) `organization_guid` (provision only).
* `request.default_labels.pcf-space-guid` - _string_ Mapped from [cloudfoundry context](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#cloud-foundry-context-object) `space_guid` (provision only).
* `request.default_labels.pcf-instance-id` - _string_ Mapped from the ID of the requested instance.
* `request.context` - _map[string]any_ Mapped from [cloudfoundry context](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#cloud-foundry-context-object) (provision only).
* `request.context` - _map[string]any_ Mapped from [cloudfoundry context](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#cloud-foundry-context-object) (provision only). Does not include `organization_annotation` and `space_annotation` keys; see [issue](https://github.com/cloudfoundry/cloud-service-broker/issues/1086).
* `request.x_broker_api_originating_identity` - _map[string]any_ Mapped from [cloudfoundry `x_broker_api_originating_identity` header](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#originating-identity-header)

#### Bind/Unbind
Expand All @@ -571,7 +571,7 @@ The order of combining all plan properties before invoking OpenTofu is as follow
* `request.app_guid` - _string_ The ID of the application this binding is for. (bind only)
* `instance.name` - _string_ The name of the instance.
* `instance.details` - _map[string]any_ Output variables of the instance as specified by ProvisionOutputVariables.
* `request.context` - _map[string]any_ Mapped from [cloudfoundry context](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#cloud-foundry-context-object) (bind only).
* `request.context` - _map[string]any_ Mapped from [cloudfoundry context](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#cloud-foundry-context-object) (bind only). Does not include `organization_annotation` and `space_annotation` keys; see [issue](https://github.com/cloudfoundry/cloud-service-broker/issues/1086).
* `request.x_broker_api_originating_identity` - _map[string]any_ Mapped from [cloudfoundry `x_broker_api_originating_identity` header](https://github.com/openservicebrokerapi/servicebroker/blob/master/profile.md#originating-identity-header)

## File format
Expand Down
10 changes: 10 additions & 0 deletions internal/paramparser/parse_provision_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ func ParseProvisionDetails(input domain.ProvisionDetails) (ProvisionDetails, err
}
}

// Special case: These two values are maps and must be removed so the HIL parser
// can access the rest of the values, which are strings.
// See: https://github.com/cloudfoundry/cloud-service-broker/issues/1086
if s, ok := result.RequestContext["platform"].(string); ok {
if s == "cloudfoundry" {
delete(result.RequestContext, "organization_annotations")
delete(result.RequestContext, "space_annotations")
}
}

if s, ok := result.RequestContext["organization_guid"].(string); ok {
result.OrganizationGUID = s
}
Expand Down
42 changes: 42 additions & 0 deletions internal/paramparser/parse_provision_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,46 @@ var _ = Describe("ParseProvisionDetails", func() {
Expect(pd.SpaceGUID).To(Equal("fake-space-guid-1"))
})
})

When("a cloudfoundry context contains space_annotations or organization_annotations keys", func() {
ctx := `{"platform": "cloudfoundry", "space_guid": "fake-space-guid", "space_annotations": {"a": "b"}, "organization_guid": "fake-org-guid", "organization_annotations": {"a": "b"}}`
It("removes the annotation keys", func() {
pd, err := paramparser.ParseProvisionDetails(domain.ProvisionDetails{
RawContext: []byte(ctx),
})

Expect(err).NotTo(HaveOccurred())
Expect(pd.RequestContext).ToNot(HaveKey("organization_annotations"))
Expect(pd.RequestContext).ToNot(HaveKey("space_annotations"))
})

It("ignores all other keys and their values", func() {
pd, err := paramparser.ParseProvisionDetails(domain.ProvisionDetails{
RawContext: []byte(ctx),
})

Expect(err).NotTo(HaveOccurred())
Expect(pd.RequestContext).To(HaveKey("platform"))
Expect(pd.RequestContext["platform"]).To(Equal("cloudfoundry"))
Expect(pd.RequestContext).To(HaveKey("space_guid"))
Expect(pd.RequestContext["space_guid"]).To(Equal("fake-space-guid"))
Expect(pd.RequestContext).To(HaveKey("organization_guid"))
Expect(pd.RequestContext["organization_guid"]).To(Equal("fake-org-guid"))
})
})

When("non-cloudfoundry context contains space_annotations or organization_annotations keys", func() {
ctx := `{"platform": "kubernetes", "space_guid": "fake-space-guid", "space_annotations": {"a": "b"}, "organization_guid": "fake-org-guid", "organization_annotations": {"a": "b"}}`
It("ignores the annotation keys and their values", func() {
pd, err := paramparser.ParseProvisionDetails(domain.ProvisionDetails{
RawContext: []byte(ctx),
})

Expect(err).NotTo(HaveOccurred())
Expect(pd.RequestContext).To(HaveKey("organization_annotations"))
Expect(pd.RequestContext["organization_annotations"]).To(HaveKey("a"))
Expect(pd.RequestContext).To(HaveKey("space_annotations"))
Expect(pd.RequestContext["space_annotations"]).To(HaveKey("a"))
})
})
})
Loading