Skip to content

Commit

Permalink
Updated v7 folder
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisiaM committed Dec 15, 2020
1 parent 7d156de commit e10bf38
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions v7/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
10 changes: 10 additions & 0 deletions v7/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 v7/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 e10bf38

Please sign in to comment.