forked from kubernetes-retired/service-catalog
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a continuation of kubernetes-retired#533, and is a pre-requisite for kubernetes-retired#923
- Loading branch information
Showing
69 changed files
with
6,264 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// BindRequest is the struct to contain details of a bind request | ||
type BindRequest struct { | ||
InstanceID string | ||
BindingID string | ||
Details brokerapi.BindDetails | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package server | ||
|
||
import ( | ||
pkgbrokerapi "github.com/kubernetes-incubator/service-catalog/pkg/brokerapi" | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// ConvertCatalog converts a (github.com/kubernetes-incubator/service-catalog/pkg/brokerapi).Catalog | ||
// to an array of brokerapi.Services | ||
func ConvertCatalog(cat *pkgbrokerapi.Catalog) []brokerapi.Service { | ||
ret := make([]brokerapi.Service, len(cat.Services)) | ||
for i, svc := range cat.Services { | ||
ret[i] = convertService(svc) | ||
} | ||
return ret | ||
} | ||
|
||
func convertService(svc *pkgbrokerapi.Service) brokerapi.Service { | ||
return brokerapi.Service{ | ||
ID: svc.ID, | ||
Name: svc.Name, | ||
Description: svc.Description, | ||
Bindable: svc.Bindable, | ||
Tags: svc.Tags, | ||
PlanUpdatable: svc.PlanUpdateable, | ||
Plans: convertPlans(svc.Plans), | ||
// TODO: convert Requires, Metadata, DashboardClient | ||
} | ||
} | ||
|
||
func convertPlans(plans []pkgbrokerapi.ServicePlan) []brokerapi.ServicePlan { | ||
ret := make([]brokerapi.ServicePlan, len(plans)) | ||
for i, plan := range plans { | ||
ret[i] = brokerapi.ServicePlan{ | ||
ID: plan.ID, | ||
Name: plan.Name, | ||
Description: plan.Description, | ||
Free: &plan.Free, | ||
Bindable: plan.Bindable, | ||
// TODO: convert Metadata | ||
} | ||
} | ||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package server | ||
|
||
import ( | ||
"net/http/httptest" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/pkg/brokerapi" | ||
"github.com/kubernetes-incubator/service-catalog/pkg/brokerapi/openservicebroker" | ||
) | ||
|
||
// NewCreateFunc creates a new brokerapi.CreateFunc according to a broker server running | ||
// in srv | ||
func NewCreateFunc(srv *httptest.Server, user, pass string) brokerapi.CreateFunc { | ||
// type CreateFunc func(name, url, username, password string) BrokerClient | ||
return brokerapi.CreateFunc(func(name, url, username, password string) brokerapi.BrokerClient { | ||
return openservicebroker.NewClient("testclient", srv.URL, user, pass) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// DeprovisionRequest is the struct to contain details of a single deprovision request | ||
type DeprovisionRequest struct { | ||
InstanceID string | ||
Details brokerapi.DeprovisionDetails | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// Handler is a fake implementation oif a brokerapi.ServiceBroker | ||
type Handler struct { | ||
Catalog []brokerapi.Service | ||
CatalogRequests int | ||
|
||
ProvisionResp brokerapi.ProvisionedServiceSpec | ||
ProvisionRespError error | ||
ProvisionRequests []ProvisionRequest | ||
|
||
DeprovisionResp brokerapi.DeprovisionServiceSpec | ||
DeprovisonRespErr error | ||
DeprovisionRequests []DeprovisionRequest | ||
|
||
BindResp brokerapi.Binding | ||
BindRespErr error | ||
BindRequests []BindRequest | ||
|
||
UnbindRespErr error | ||
UnbindRequests []UnbindRequest | ||
|
||
UpdateResp brokerapi.UpdateServiceSpec | ||
UpdateRespErr error | ||
UpdateRequests []UpdateRequest | ||
|
||
LastOperationResp brokerapi.LastOperation | ||
LastOperationRespErr error | ||
LastOperationRequests []LastOperationRequest | ||
} | ||
|
||
// NewHandler creates a new fake server handler | ||
func NewHandler() *Handler { | ||
return &Handler{} | ||
} | ||
|
||
// Services is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) Services(ctx context.Context) []brokerapi.Service { | ||
h.CatalogRequests++ | ||
return h.Catalog | ||
} | ||
|
||
// Provision is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) Provision( | ||
ctx context.Context, | ||
instanceID string, | ||
details brokerapi.ProvisionDetails, | ||
asyncAllowed bool, | ||
) (brokerapi.ProvisionedServiceSpec, error) { | ||
h.ProvisionRequests = append(h.ProvisionRequests, ProvisionRequest{ | ||
InstanceID: instanceID, | ||
Details: details, | ||
AsyncAllowed: asyncAllowed, | ||
}) | ||
return h.ProvisionResp, h.ProvisionRespError | ||
} | ||
|
||
// Deprovision is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) Deprovision(context context.Context, instanceID string, details brokerapi.DeprovisionDetails, asyncAllowed bool) (brokerapi.DeprovisionServiceSpec, error) { | ||
h.DeprovisionRequests = append(h.DeprovisionRequests, DeprovisionRequest{ | ||
InstanceID: instanceID, | ||
Details: details, | ||
}) | ||
return h.DeprovisionResp, h.DeprovisonRespErr | ||
} | ||
|
||
// Bind is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) Bind(context context.Context, instanceID, bindingID string, details brokerapi.BindDetails) (brokerapi.Binding, error) { | ||
h.BindRequests = append(h.BindRequests, BindRequest{ | ||
InstanceID: instanceID, | ||
BindingID: bindingID, | ||
Details: details, | ||
}) | ||
return h.BindResp, h.BindRespErr | ||
} | ||
|
||
// Unbind is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) Unbind(context context.Context, instanceID, bindingID string, details brokerapi.UnbindDetails) error { | ||
h.UnbindRequests = append(h.UnbindRequests, UnbindRequest{ | ||
InstanceID: instanceID, | ||
BindingID: bindingID, | ||
Details: details, | ||
}) | ||
return h.UnbindRespErr | ||
} | ||
|
||
// Update is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) Update(context context.Context, instanceID string, details brokerapi.UpdateDetails, asyncAllowed bool) (brokerapi.UpdateServiceSpec, error) { | ||
h.UpdateRequests = append(h.UpdateRequests, UpdateRequest{ | ||
InstanceID: instanceID, | ||
Details: details, | ||
AsyncAllowed: asyncAllowed, | ||
}) | ||
return h.UpdateResp, h.UpdateRespErr | ||
} | ||
|
||
// LastOperation is the interface implementation of brokerapi.ServiceBroker | ||
func (h *Handler) LastOperation(context context.Context, instanceID, operationData string) (brokerapi.LastOperation, error) { | ||
h.LastOperationRequests = append(h.LastOperationRequests, LastOperationRequest{ | ||
InstanceID: instanceID, | ||
OperationData: operationData, | ||
}) | ||
return h.LastOperationResp, h.LastOperationRespErr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package server | ||
|
||
import ( | ||
"code.cloudfoundry.org/lager" | ||
) | ||
|
||
var ( | ||
logger = lager.NewLogger("server") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package server | ||
|
||
type LastOperationRequest struct { | ||
InstanceID string | ||
OperationData string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// ProvisionRequest is the struct to house details of a single provision request | ||
type ProvisionRequest struct { | ||
InstanceID string | ||
Details brokerapi.ProvisionDetails | ||
AsyncAllowed bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package server | ||
|
||
import ( | ||
"net/http/httptest" | ||
|
||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// Run runs a new test server from the given broker handler and auth credentials | ||
func Run(hdl *Handler, username, password string) *httptest.Server { | ||
httpHandler := brokerapi.New(hdl, logger, brokerapi.BrokerCredentials{ | ||
Username: username, | ||
Password: password, | ||
}) | ||
|
||
srv := httptest.NewServer(httpHandler) | ||
return srv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// UnbindRequest is the struct to house details of a single unbind request | ||
type UnbindRequest struct{ | ||
InstanceID string | ||
BindingID string | ||
Details brokerapi.UnbindDetails | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
// UpdateRequest is the struct that contains details of a single update request | ||
type UpdateRequest struct { | ||
InstanceID string | ||
Details brokerapi.UpdateDetails | ||
AsyncAllowed bool | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.