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

Commit

Permalink
Add Version 2.14 (#146)
Browse files Browse the repository at this point in the history
* Add version 2.14

- Graduate previously alpha features

* Fix incorrect version in comment for 2.14

* Update comments for graduated features to show required client version
  • Loading branch information
edwardecook committed May 26, 2020
1 parent f23a52c commit 6c426d2
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 182 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func GetBrokerCatalog(URL string) (*osb.CatalogResponse, error) {
This client library supports the following versions of the
[Open Service Broker API](https://github.com/openservicebrokerapi/servicebroker):

- [v2.14](https://github.com/openservicebrokerapi/servicebroker/tree/v2.14)
- [v2.13](https://github.com/openservicebrokerapi/servicebroker/tree/v2.13)
- [v2.12](https://github.com/openservicebrokerapi/servicebroker/tree/v2.12)
- [v2.11](https://github.com/openservicebrokerapi/servicebroker/tree/v2.11)
Expand Down
2 changes: 1 addition & 1 deletion v2/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (

func (c *client) Bind(r *BindRequest) (*BindResponse, error) {
if r.AcceptsIncomplete {
if err := c.validateAlphaAPIMethodsAllowed(); err != nil {
if err := c.validateClientVersionIsAtLeast(Version2_14()); err != nil {
return nil, AsyncBindingOperationsNotAllowedError{
reason: err.Error(),
}
Expand Down
19 changes: 5 additions & 14 deletions v2/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ func TestBind(t *testing.T) {
expectedResponse: successBindResponse(),
},
{
name: "success - asynchronous",
version: LatestAPIVersion(),
enableAlpha: true,
request: defaultAsyncBindRequest(),
name: "success - asynchronous",
version: Version2_14(),
request: defaultAsyncBindRequest(),
httpChecks: httpChecks{
params: map[string]string{
AcceptsIncomplete: "true",
Expand Down Expand Up @@ -265,19 +264,11 @@ func TestBind(t *testing.T) {
},
expectedResponse: successBindResponse(),
},
{
name: "async with alpha features disabled",
version: LatestAPIVersion(),
enableAlpha: false,
request: defaultAsyncBindRequest(),
expectedErrMessage: "Asynchronous binding operations are not allowed: alpha API methods not allowed: alpha features must be enabled",
},
{
name: "async with unsupported API version",
version: Version2_12(),
enableAlpha: true,
version: Version2_13(),
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: operation not allowed: must have API version >= 2.14. Current: 2.13",
},
}

Expand Down
16 changes: 16 additions & 0 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@ func (c *client) validateAlphaAPIMethodsAllowed() error {
return nil
}

// validateClientVersionIsAtLeast returns an error if client version is not at
// least the specified version
func (c *client) validateClientVersionIsAtLeast(version APIVersion) error {
if !c.APIVersion.AtLeast(version) {
return OperationNotAllowedError{
reason: fmt.Sprintf(
"must have API version >= %s. Current: %s",
version,
c.APIVersion.label,
),
}
}

return nil
}

// drainReader reads and discards the remaining data in reader (for example
// response body data) For HTTP this ensures that the http connection
// could be reused for another request if the keepalive is enabled.
Expand Down
28 changes: 0 additions & 28 deletions v2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,6 @@ func testHTTPStatusCodeError() error {
}
}

func testGetInstanceNotAllowedErrorUnsupportedAPIVersion() error {
e := AlphaAPIMethodsNotAllowedError{
reason: fmt.Sprintf(
"must have latest API Version. Current: %s, Expected: %s",
Version2_11().label,
LatestAPIVersion().label,
),
}

return GetInstanceNotAllowedError{
reason: e.Error(),
}
}

func testGetBindingNotAllowedErrorUnsupportedAPIVersion() error {
e := AlphaAPIMethodsNotAllowedError{
reason: fmt.Sprintf(
"must have latest API Version. Current: %s, Expected: %s",
Version2_11().label,
LatestAPIVersion().label,
),
}

return GetBindingNotAllowedError{
reason: e.Error(),
}
}

func truePtr() *bool {
b := true
return &b
Expand Down
15 changes: 14 additions & 1 deletion v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func IsConcurrencyError(err error) bool {
}

// AlphaAPIMethodsNotAllowedError is an error type signifying that alpha API
// methods are not allowed for this client's API Version.
// methods are not allowed for this client's API Version or alpha opt-in.
type AlphaAPIMethodsNotAllowedError struct {
reason string
}
Expand All @@ -198,6 +198,19 @@ func (e AlphaAPIMethodsNotAllowedError) Error() string {
)
}

// OperationNotAllowedError is an error type signifying that an operation
// is not allowed for this client.
type OperationNotAllowedError struct {
reason string
}

func (e OperationNotAllowedError) Error() string {
return fmt.Sprintf(
"operation not allowed: %s",
e.reason,
)
}

// GetInstanceNotAllowedError is an error type signifying that doing a GET to
// fetch a service instance is not allowed for this client.
type GetInstanceNotAllowedError struct {
Expand Down
2 changes: 1 addition & 1 deletion v2/get_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func (c *client) GetBinding(r *GetBindingRequest) (*GetBindingResponse, error) {
if err := c.validateAlphaAPIMethodsAllowed(); err != nil {
if err := c.validateClientVersionIsAtLeast(Version2_14()); err != nil {
return nil, GetBindingNotAllowedError{
reason: err.Error(),
}
Expand Down
27 changes: 8 additions & 19 deletions v2/get_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,59 +55,48 @@ func TestGetBinding(t *testing.T) {
expectedErr error
}{
{
name: "success",
enableAlpha: true,
name: "success",
httpReaction: httpReaction{
status: http.StatusOK,
body: okBindingBytes,
},
expectedResponse: okGetBindingResponse(),
},
{
name: "http error",
enableAlpha: true,
name: "http error",
httpReaction: httpReaction{
err: fmt.Errorf("http error"),
},
expectedErrMessage: "http error",
},
{
name: "200 with malformed response",
enableAlpha: true,
name: "200 with malformed response",
httpReaction: httpReaction{
status: http.StatusOK,
body: malformedResponse,
},
expectedErrMessage: "Status: 200; ErrorMessage: <nil>; Description: <nil>; ResponseError: unexpected end of JSON input",
},
{
name: "500 with malformed response",
enableAlpha: true,
name: "500 with malformed response",
httpReaction: httpReaction{
status: http.StatusInternalServerError,
body: malformedResponse,
},
expectedErrMessage: "Status: 500; ErrorMessage: <nil>; Description: <nil>; ResponseError: unexpected end of JSON input",
},
{
name: "500 with conventional response",
enableAlpha: true,
name: "500 with conventional response",
httpReaction: httpReaction{
status: http.StatusInternalServerError,
body: conventionalFailureResponseBody,
},
expectedErr: testHTTPStatusCodeError(),
},
{
name: "alpha features disabled",
enableAlpha: false,
expectedErrMessage: "GetBinding not allowed: alpha API methods not allowed: alpha features must be enabled",
},
{
name: "unsupported API version",
enableAlpha: true,
APIVersion: Version2_11(),
expectedErr: testGetBindingNotAllowedErrorUnsupportedAPIVersion(),
name: "unsupported API version",
APIVersion: Version2_13(),
expectedErrMessage: "GetBinding not allowed: operation not allowed: must have API version >= 2.14. Current: 2.13",
},
}

Expand Down
2 changes: 1 addition & 1 deletion v2/get_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func (c *client) GetInstance(r *GetInstanceRequest) (*GetInstanceResponse, error) {
if err := c.validateAlphaAPIMethodsAllowed(); err != nil {
if err := c.validateClientVersionIsAtLeast(Version2_14()); err != nil {
return nil, GetInstanceNotAllowedError{
reason: err.Error(),
}
Expand Down
27 changes: 8 additions & 19 deletions v2/get_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,59 +53,48 @@ func TestGetInstance(t *testing.T) {
expectedErr error
}{
{
name: "success",
enableAlpha: true,
name: "success",
httpReaction: httpReaction{
status: http.StatusOK,
body: okInstanceBytes,
},
expectedResponse: okGetInstanceResponse(),
},
{
name: "http error",
enableAlpha: true,
name: "http error",
httpReaction: httpReaction{
err: fmt.Errorf("http error"),
},
expectedErrMessage: "http error",
},
{
name: "200 with malformed response",
enableAlpha: true,
name: "200 with malformed response",
httpReaction: httpReaction{
status: http.StatusOK,
body: malformedResponse,
},
expectedErrMessage: "Status: 200; ErrorMessage: <nil>; Description: <nil>; ResponseError: unexpected end of JSON input",
},
{
name: "500 with malformed response",
enableAlpha: true,
name: "500 with malformed response",
httpReaction: httpReaction{
status: http.StatusInternalServerError,
body: malformedResponse,
},
expectedErrMessage: "Status: 500; ErrorMessage: <nil>; Description: <nil>; ResponseError: unexpected end of JSON input",
},
{
name: "500 with conventional response",
enableAlpha: true,
name: "500 with conventional response",
httpReaction: httpReaction{
status: http.StatusInternalServerError,
body: conventionalFailureResponseBody,
},
expectedErr: testHTTPStatusCodeError(),
},
{
name: "alpha features disabled",
enableAlpha: false,
expectedErrMessage: "GetInstance not allowed: alpha API methods not allowed: alpha features must be enabled",
},
{
name: "unsupported API version",
enableAlpha: true,
APIVersion: Version2_11(),
expectedErr: testGetInstanceNotAllowedErrorUnsupportedAPIVersion(),
name: "unsupported API version",
APIVersion: Version2_13(),
expectedErrMessage: "GetInstance not allowed: operation not allowed: must have API version >= 2.14. Current: 2.13",
},
}

Expand Down
12 changes: 3 additions & 9 deletions v2/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ type Client interface {
// there are special semantics for PollLastOperation when checking the
// status of deprovision operations; see the doc for that method.
DeprovisionInstance(r *DeprovisionRequest) (*DeprovisionResponse, error)
// GetInstance is an ALPHA API method and may change. Alpha features must
// be enabled and the client must be using the latest API Version in
// order to use this method.
// GetInstance requires a client API version >= 2.14.
//
// GetInstance returns information about an existing instance.
// GetInstance calls GET on the Broker's endpoint for the requested
Expand All @@ -171,9 +169,7 @@ type Client interface {
// asynchronous deprovision, callers should test the value of the returned
// error with IsGoneError.
PollLastOperation(r *LastOperationRequest) (*LastOperationResponse, error)
// PollBindingLastOperation is an ALPHA API method and may change.
// Alpha features must be enabled and the client must be using the
// latest API Version in order to use this method.
// PollBindingLastOperation requires a client API version >= 2.14.
//
// PollBindingLastOperation sends a request to query the last operation
// for a service binding to the broker and returns information about the
Expand All @@ -199,9 +195,7 @@ type Client interface {
// error. Unbind does a DELETE on the Broker's endpoint for the requested
// instance and binding IDs (/v2/service_instances/instance-id/service_bindings/binding-id).
Unbind(r *UnbindRequest) (*UnbindResponse, error)
// GetBinding is an ALPHA API method and may change. Alpha features must
// be enabled and the client must be using the latest API Version in
// order to use this method.
// GetBinding requires a client API version >= 2.14.
//
// GetBinding returns configuration and credential information
// about an existing binding. GetBindings calls GET on the Broker's
Expand Down
2 changes: 1 addition & 1 deletion v2/poll_binding_last_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func (c *client) PollBindingLastOperation(r *BindingLastOperationRequest) (*LastOperationResponse, error) {
if err := c.validateAlphaAPIMethodsAllowed(); err != nil {
if err := c.validateClientVersionIsAtLeast(Version2_14()); err != nil {
return nil, AsyncBindingOperationsNotAllowedError{
reason: err.Error(),
}
Expand Down
Loading

0 comments on commit 6c426d2

Please sign in to comment.