Skip to content

Commit

Permalink
Correct parameter schema support (openshift#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie authored and jpeeler committed Jun 1, 2017
1 parent 05c6f00 commit f4233a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
26 changes: 19 additions & 7 deletions pkg/brokerapi/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ package brokerapi
// Schemas represents a plan's schemas for service instance and binding create
// and update.
type Schemas struct {
ServiceInstances *Schema `json:"service_instances,omitempty"`
ServiceBindings *Schema `json:"service_bindings,omitempty"`
ServiceInstances *ServiceInstanceSchema `json:"service_instance,omitempty"`
ServiceBindings *ServiceBindingSchema `json:"service_binding,omitempty"`
}

// Schema represents a plan's schemas for a create and update of an API
// resource.
type Schema struct {
Create interface{} `json:"create,omitempty"`
Update interface{} `json:"update,omitempty"`
// ServiceInstanceSchema represents a plan's schemas for a create and update
// of a service instance.
type ServiceInstanceSchema struct {
Create *InputParameters `json:"create,omitempty"`
Update *InputParameters `json:"update,omitempty"`
}

// ServiceBindingSchema represents a plan's schemas for the parameters
// accepted for binding creation.
type ServiceBindingSchema struct {
Create *InputParameters `json:"create,omitempty"`
}

// InputParameters represents a schema for input parameters for creation or
// update of an API resource.
type InputParameters struct {
Parameters interface{} `json:"parameters,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/brokerapi/service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ type ServicePlan struct {
Description string `json:"description"`
Metadata interface{} `json:"metadata,omitempty"`
Free bool `json:"free,omitempty"`
Schemas *Schemas `json:"schemas,omitempty"`
Bindable *bool `json:"bindable,omitempty"`
Schemas *Schemas `json:"schemas,omitempty"`
}
18 changes: 9 additions & 9 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,30 +432,30 @@ func convertServicePlans(plans []brokerapi.ServicePlan) ([]v1alpha1.ServicePlan,

if schemas := plans[i].Schemas; schemas != nil {
if instanceSchemas := schemas.ServiceInstances; instanceSchemas != nil {
if instanceCreateSchema := instanceSchemas.Create; instanceCreateSchema != nil {
schema, err := json.Marshal(instanceCreateSchema)
if instanceCreateSchema := instanceSchemas.Create; instanceCreateSchema != nil && instanceCreateSchema.Parameters != nil {
schema, err := json.Marshal(instanceCreateSchema.Parameters)
if err != nil {
err = fmt.Errorf("Failed to marshal instance create schema \n%+v\n %v", instanceCreateSchema, err)
err = fmt.Errorf("Failed to marshal instance create schema \n%+v\n %v", instanceCreateSchema.Parameters, err)
glog.Error(err)
return nil, err
}
ret[i].AlphaInstanceCreateParameterSchema = &runtime.RawExtension{Raw: schema}
}
if instanceUpdateSchema := instanceSchemas.Update; instanceUpdateSchema != nil {
schema, err := json.Marshal(instanceUpdateSchema)
if instanceUpdateSchema := instanceSchemas.Update; instanceUpdateSchema != nil && instanceUpdateSchema.Parameters != nil {
schema, err := json.Marshal(instanceUpdateSchema.Parameters)
if err != nil {
err = fmt.Errorf("Failed to marshal instance update schema \n%+v\n %v", instanceUpdateSchema, err)
err = fmt.Errorf("Failed to marshal instance update schema \n%+v\n %v", instanceUpdateSchema.Parameters, err)
glog.Error(err)
return nil, err
}
ret[i].AlphaInstanceUpdateParameterSchema = &runtime.RawExtension{Raw: schema}
}
}
if bindingSchemas := schemas.ServiceBindings; bindingSchemas != nil {
if bindingCreateSchema := bindingSchemas.Create; bindingCreateSchema != nil {
schema, err := json.Marshal(bindingCreateSchema)
if bindingCreateSchema := bindingSchemas.Create; bindingCreateSchema != nil && bindingCreateSchema.Parameters != nil {
schema, err := json.Marshal(bindingCreateSchema.Parameters)
if err != nil {
err = fmt.Errorf("Failed to marshal binding create schema \n%+v\n %v", bindingCreateSchema, err)
err = fmt.Errorf("Failed to marshal binding create schema \n%+v\n %v", bindingCreateSchema.Parameters, err)
glog.Error(err)
return nil, err
}
Expand Down
16 changes: 11 additions & 5 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,17 +460,23 @@ const alphaParameterSchemaCatalogBytes = `{
"d": "e"
},
"schemas": {
"service_instances": {
"service_instance": {
"create": {
"foo": "bar"
"parameters": {
"foo": "bar"
}
},
"update": {
"baz": "zap"
"parameters": {
"baz": "zap"
}
}
},
"service_bindings": {
"service_binding": {
"create": {
"zoo": "blu"
"parameters": {
"zoo": "blu"
}
}
}
}
Expand Down

0 comments on commit f4233a0

Please sign in to comment.