Skip to content

Commit

Permalink
Add metadata parameter to provisioning response body (#131)
Browse files Browse the repository at this point in the history
* Add metadata parameter to provisioning response body

* Updated nameing

Co-authored-by: Felisia Martini <fmartini@pivotal.io>
  • Loading branch information
jasiu001 and FelisiaM committed Dec 15, 2020
1 parent 906dc79 commit 7d156de
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions domain/apiresponses/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type CatalogResponse struct {
}

type ProvisioningResponse struct {
DashboardURL string `json:"dashboard_url,omitempty"`
OperationData string `json:"operation,omitempty"`
DashboardURL string `json:"dashboard_url,omitempty"`
OperationData string `json:"operation,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
}

type GetInstanceResponse struct {
Expand Down
14 changes: 14 additions & 0 deletions domain/apiresponses/responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ var _ = Describe("Provisioning Response", func() {
Expect(json.Marshal(provisioningResponse)).To(MatchJSON(jsonString))
})
})

Context("when the metadata is present", func() {
It("returns it in the JSON", func() {
provisioningResponse := apiresponses.ProvisioningResponse{
Metadata: domain.InstanceMetadata{
Labels: map[string]string{"key1": "value1"},
Attributes: map[string]string{"key1": "value1"},
},
}
jsonString := `{"metadata":{"labels":{"key1":"value1"}, "attributes":{"key1":"value1"}}}`

Expect(json.Marshal(provisioningResponse)).To(MatchJSON(jsonString))
})
})
})
})

Expand Down
10 changes: 10 additions & 0 deletions domain/service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ type ProvisionedServiceSpec struct {
AlreadyExists bool
DashboardURL string
OperationData string
Metadata InstanceMetadata
}

type InstanceMetadata struct {
Labels map[string]string `json:"labels,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
}

type DeprovisionDetails struct {
Expand Down Expand Up @@ -205,6 +211,10 @@ func (d BindDetails) GetRawParameters() json.RawMessage {
return d.RawParameters
}

func (m InstanceMetadata) IsEmpty() bool {
return len(m.Attributes) == 0 && len(m.Labels) == 0
}

func (d UpdateDetails) GetRawContext() json.RawMessage {
return d.RawContext
}
Expand Down
8 changes: 8 additions & 0 deletions handlers/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,26 @@ func (h *APIHandler) Provision(w http.ResponseWriter, req *http.Request) {
return
}

var metadata interface{}
if !provisionResponse.Metadata.IsEmpty() {
metadata = provisionResponse.Metadata
}

if provisionResponse.AlreadyExists {
h.respond(w, http.StatusOK, apiresponses.ProvisioningResponse{
DashboardURL: provisionResponse.DashboardURL,
Metadata: metadata,
})
} else if provisionResponse.IsAsync {
h.respond(w, http.StatusAccepted, apiresponses.ProvisioningResponse{
DashboardURL: provisionResponse.DashboardURL,
OperationData: provisionResponse.OperationData,
Metadata: metadata,
})
} else {
h.respond(w, http.StatusCreated, apiresponses.ProvisioningResponse{
DashboardURL: provisionResponse.DashboardURL,
Metadata: metadata,
})
}
}

0 comments on commit 7d156de

Please sign in to comment.