Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Support for service binding response schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
luksa committed Feb 5, 2018
1 parent 8c97274 commit a88e490
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 17 deletions.
2 changes: 1 addition & 1 deletion v2/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestBind(t *testing.T) {
version: Version2_12(),
enableAlpha: true,
request: defaultAsyncBindRequest(),
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: must have latest API Version. Current: 2.12, Expected: 2.13",
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: must have latest API Version. Current: 2.12, Expected: 2.14",
},
}

Expand Down
21 changes: 21 additions & 0 deletions v2/get_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,32 @@ func (c *client) GetCatalog() (*CatalogResponse, error) {
}

if !c.APIVersion.AtLeast(Version2_13()) {
// remove ParameterSchemas if broker version is less than 2.13
for ii := range catalogResponse.Services {
for jj := range catalogResponse.Services[ii].Plans {
catalogResponse.Services[ii].Plans[jj].ParameterSchemas = nil
}
}
} else if !c.APIVersion.AtLeast(Version2_14()) {
// remove Response ParameterSchemas if broker version is less than 2.14
for ii := range catalogResponse.Services {
for jj := range catalogResponse.Services[ii].Plans {
parameterSchemas := catalogResponse.Services[ii].Plans[jj].ParameterSchemas
if parameterSchemas != nil {
if parameterSchemas.ServiceInstances != nil {
if parameterSchemas.ServiceInstances.Create != nil {
parameterSchemas.ServiceInstances.Create.Response = nil
}
if parameterSchemas.ServiceInstances.Update != nil {
parameterSchemas.ServiceInstances.Update.Response = nil
}
if parameterSchemas.ServiceBindings.Create != nil {
parameterSchemas.ServiceBindings.Create.Response = nil
}
}
}
}
}
}

return catalogResponse, nil
Expand Down
89 changes: 84 additions & 5 deletions v2/get_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,91 @@ const alphaParameterSchemaCatalogBytes = `{
}]
}`

func alphaParameterCatalogResponse() *CatalogResponse {
const alphaParameterAndResponseSchemaCatalogBytes = `{
"services": [{
"name": "fake-service",
"id": "acb56d7c-XXXX-XXXX-XXXX-feb140a59a66",
"description": "fake service",
"tags": ["tag1", "tag2"],
"requires": ["route_forwarding"],
"bindable": true,
"binding_retrievable": true,
"metadata": {
"a": "b",
"c": "d"
},
"dashboard_client": {
"id": "398e2f8e-XXXX-XXXX-XXXX-19a71ecbcf64",
"secret": "277cabb0-XXXX-XXXX-XXXX-7822c0a90e5d",
"redirect_uri": "http://localhost:1234"
},
"plan_updateable": true,
"plans": [{
"name": "fake-plan-1",
"id": "d3031751-XXXX-XXXX-XXXX-a42377d3320e",
"description": "description1",
"metadata": {
"b": "c",
"d": "e"
},
"schemas": {
"service_instance": {
"create": {
"parameters": {
"foo": "bar"
}
},
"update": {
"parameters": {
"baz": "zap"
}
}
},
"service_binding": {
"create": {
"parameters": {
"zoo": "blu"
},
"response": {
"qux": "qax"
}
}
}
}
}]
}]
}`

func alphaParameterCatalogResponse(includeResponseSchema bool) *CatalogResponse {
catalog := okCatalogResponse()
catalog.Services[0].Plans[0].ParameterSchemas = &ParameterSchemas{
ServiceInstances: &ServiceInstanceSchema{
Create: &InputParameters{
Create: &JsonSchema{
Parameters: map[string]interface{}{
"foo": "bar",
},
},
Update: &InputParameters{
Update: &JsonSchema{
Parameters: map[string]interface{}{
"baz": "zap",
},
},
},
ServiceBindings: &ServiceBindingSchema{
Create: &InputParameters{
Create: &JsonSchema{
Parameters: map[string]interface{}{
"zoo": "blu",
},
},
},
}

if includeResponseSchema {
catalog.Services[0].Plans[0].ParameterSchemas.ServiceBindings.Create.Response = map[string]interface{}{
"qux": "qax",
}
}

return catalog
}

Expand Down Expand Up @@ -258,7 +319,7 @@ func TestGetCatalog(t *testing.T) {
status: http.StatusOK,
body: alphaParameterSchemaCatalogBytes,
},
expectedResponse: alphaParameterCatalogResponse(),
expectedResponse: alphaParameterCatalogResponse(false),
},
{
name: "schemas not included if API version < 2.13",
Expand All @@ -269,6 +330,24 @@ func TestGetCatalog(t *testing.T) {
},
expectedResponse: okCatalogResponse(),
},
{
name: "response schemas included if API version >= 2.14",
version: Version2_14(),
httpReaction: httpReaction{
status: http.StatusOK,
body: alphaParameterAndResponseSchemaCatalogBytes,
},
expectedResponse: alphaParameterCatalogResponse(true),
},
{
name: "response schemas not included if API version < 2.14",
version: Version2_13(),
httpReaction: httpReaction{
status: http.StatusOK,
body: alphaParameterAndResponseSchemaCatalogBytes,
},
expectedResponse: alphaParameterCatalogResponse(false),
},
}

for _, tc := range cases {
Expand Down
2 changes: 1 addition & 1 deletion v2/poll_binding_last_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestPollBindingLastOperation(t *testing.T) {
name: "unsupported API version",
enableAlpha: true,
APIVersion: Version2_12(),
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: must have latest API Version. Current: 2.12, Expected: 2.13",
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: must have latest API Version. Current: 2.12, Expected: 2.14",
},
}

Expand Down
13 changes: 7 additions & 6 deletions v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,25 @@ type ParameterSchemas struct {
// ServiceInstanceSchema represents a plan's schemas for creation and
// update of an API resource.
type ServiceInstanceSchema struct {
Create *InputParameters `json:"create,omitempty"`
Update *InputParameters `json:"update,omitempty"`
Create *JsonSchema `json:"create,omitempty"`
Update *JsonSchema `json:"update,omitempty"`
}

// ServiceBindingSchema requires a client API version >=2.13.
//
// ServiceBindingSchema represents a plan's schemas for the parameters
// accepted for binding creation.
type ServiceBindingSchema struct {
Create *InputParameters `json:"create,omitempty"`
Create *JsonSchema `json:"create,omitempty"`
}

// InputParameters requires a client API version >=2.13.
// JsonSchema requires a client API version >=2.13.
//
// InputParameters represents a schema for input parameters for creation or
// JsonSchema represents a schema for input parameters for creation or
// update of an API resource.
type InputParameters struct {
type JsonSchema struct {
Parameters interface{} `json:"parameters,omitempty"`
Response interface{} `json:"response,omitempty"`
}

// OriginatingIdentity requires a client API version >=2.13.
Expand Down
2 changes: 1 addition & 1 deletion v2/unbind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestUnbind(t *testing.T) {
version: Version2_12(),
enableAlpha: true,
request: defaultAsyncUnbindRequest(),
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: must have latest API Version. Current: 2.12, Expected: 2.13",
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: must have latest API Version. Current: 2.12, Expected: 2.14",
},
}

Expand Down
11 changes: 10 additions & 1 deletion v2/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const (
// internalAPIVersion2_13 represents the 2.13 version of the Open Service
// Broker API.
internalAPIVersion2_13 = "2.13"

// internalAPIVersion2_13 represents the 2.14 version of the Open Service
// Broker API.
internalAPIVersion2_14 = "2.14"
)

//Version2_11 returns an APIVersion struct with the internal API version set to "2.11"
Expand All @@ -47,8 +51,13 @@ func Version2_13() APIVersion {
return APIVersion{label: internalAPIVersion2_13, order: 2}
}

//Version2_14 returns an APIVersion struct with the internal API version set to "2.14"
func Version2_14() APIVersion {
return APIVersion{label: internalAPIVersion2_14, order: 3}
}

// LatestAPIVersion returns the latest supported API version in the current
// release of this library.
func LatestAPIVersion() APIVersion {
return Version2_13()
return Version2_14()
}
4 changes: 2 additions & 2 deletions v2/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAtLeast(t *testing.T) {

func TestLatestAPIVersion(t *testing.T) {

if LatestAPIVersion() != Version2_13() {
t.Error("Unexpected Latest API Version--expected 2.13")
if LatestAPIVersion() != Version2_14() {
t.Error("Unexpected Latest API Version--expected 2.14")
}
}

0 comments on commit a88e490

Please sign in to comment.