broker

package
v4.2.0-rc2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = BrokerRegistry{}

DefaultRegistry is the broker registry all service broker definitions implicitly register with.

Functions

func ApplyDefaults

func ApplyDefaults(parameters map[string]interface{}, variables []BrokerVariable)

Apply defaults adds default values for missing broker variables.

func Register

func Register(service *ServiceDefinition)

Registers a ServiceDefinition with the service registry that various commands poll to create the catalog, documentation, etc.

func ValidateVariables

func ValidateVariables(parameters map[string]interface{}, variables []BrokerVariable) error

ValidateVariables validates a list of BrokerVariables are adhering to their JSONSchema.

Types

type BrokerRegistry

type BrokerRegistry map[string]*ServiceDefinition

BrokerRegistry holds the list of ServiceDefinitions that can be provisioned by the GCP Service Broker.

func (BrokerRegistry) GetAllServices

func (brokerRegistry BrokerRegistry) GetAllServices() []*ServiceDefinition

func (*BrokerRegistry) GetEnabledServices

func (brokerRegistry *BrokerRegistry) GetEnabledServices() ([]*ServiceDefinition, error)

func (BrokerRegistry) GetServiceById

func (brokerRegistry BrokerRegistry) GetServiceById(id string) (*ServiceDefinition, error)

func (BrokerRegistry) Register

func (brokerRegistry BrokerRegistry) Register(service *ServiceDefinition)

type BrokerVariable

type BrokerVariable struct {
	// Is this variable required?
	Required bool `yaml:"required,omitempty"`
	// The name of the JSON field this variable serializes/deserializes to
	FieldName string `yaml:"field_name" validate:"required"`
	// The JSONSchema type of the field
	Type JsonType `yaml:"type" validate:"required,jsonschema_type"`
	// Human readable info about the field.
	Details string `yaml:"details" validate:"required"`
	// The default value of the field.
	Default interface{} `yaml:"default,omitempty"`
	// If there are a limited number of valid values for this field then
	// Enum will hold them in value:friendly name pairs
	Enum map[interface{}]string `yaml:"enum,omitempty"`
	// Constraints holds JSON Schema validations defined for this variable.
	// Keys are valid JSON Schema validation keywords, and values are their
	// associated values.
	// http://json-schema.org/latest/json-schema-validation.html
	Constraints map[string]interface{} `yaml:"constraints,omitempty"`
}

func (*BrokerVariable) ToSchema

func (bv *BrokerVariable) ToSchema() map[string]interface{}

ToSchema converts the BrokerVariable into the value part of a JSON Schema.

type JsonType

type JsonType string
const (
	JsonTypeString  JsonType = "string"
	JsonTypeNumeric JsonType = "number"
	JsonTypeInteger JsonType = "integer"
	JsonTypeBoolean JsonType = "boolean"
)

type Service

type Service struct {
	brokerapi.Service

	Plans []ServicePlan `json:"plans"`
}

Service overrides the canonical Service Broker service type using a custom type for Plans, everything else is the same.

func (Service) ToPlain

func (s Service) ToPlain() brokerapi.Service

ToPlain converts this service to a plain PCF Service definition.

type ServiceDefinition

type ServiceDefinition struct {
	Name                       string                       `validate:"osbname"`
	DefaultServiceDefinition   string                       `validate:"json"`
	ProvisionInputVariables    []BrokerVariable             `validate:"dive"`
	ProvisionComputedVariables []varcontext.DefaultVariable `validate:"dive"`
	BindInputVariables         []BrokerVariable             `validate:"dive"`
	BindOutputVariables        []BrokerVariable             `validate:"dive"`
	BindComputedVariables      []varcontext.DefaultVariable `validate:"dive"`
	PlanVariables              []BrokerVariable             `validate:"dive"`
	Examples                   []ServiceExample             `validate:"dive"`
	DefaultRoleWhitelist       []string

	// ProviderBuilder creates a new provider given the project, auth, and logger.
	ProviderBuilder func(projectId string, auth *jwt.Config, logger lager.Logger) ServiceProvider
}

ServiceDefinition holds the necessary details to describe an OSB service and provision it.

func GetAllServices

func GetAllServices() []*ServiceDefinition

GetAllServices returns a list of all registered brokers whether or not the user has enabled them. The brokers are sorted in lexocographic order based on name.

func GetEnabledServices

func GetEnabledServices() ([]*ServiceDefinition, error)

GetEnabledServices returns a list of all registered brokers that the user has enabled the use of.

func GetServiceById

func GetServiceById(id string) (*ServiceDefinition, error)

GetServiceById returns the service with the given ID, if it does not exist or one of the services has a parse error then an error is returned.

func (*ServiceDefinition) BindDefaultOverrideProperty

func (svc *ServiceDefinition) BindDefaultOverrideProperty() string

BindDefaultOverrideProperty returns the Viper property name for the object users can set to override the default values on bind.

func (*ServiceDefinition) BindDefaultOverrides

func (svc *ServiceDefinition) BindDefaultOverrides() map[string]interface{}

BindDefaultOverrides returns the deserialized JSON object for the operator-provided property overrides.

func (*ServiceDefinition) BindVariables

func (svc *ServiceDefinition) BindVariables(instance models.ServiceInstanceDetails, bindingID string, details brokerapi.BindDetails) (*varcontext.VarContext, error)

BindVariables gets the variable resolution context for a bind request. Variables have a very specific resolution order, and this function populates the context to preserve that. The variable resolution order is the following:

1. Variables defined in your `computed_variables` JSON list. 3. User defined variables (in `bind_input_variables`) 4. Operator default variables loaded from the environment. 5. Default variables (in `bind_input_variables`).

func (*ServiceDefinition) CatalogEntry

func (svc *ServiceDefinition) CatalogEntry() (*Service, error)

CatalogEntry returns the service broker catalog entry for this service, it has metadata about the service so operators and programmers know which service and plan will work best for their purposes.

func (*ServiceDefinition) DefinitionProperty

func (svc *ServiceDefinition) DefinitionProperty() string

DefinitionProperty computes the Viper property name for the JSON service definition.

Example
service := ServiceDefinition{
	Name: "left-handed-smoke-sifter",
}

fmt.Println(service.DefinitionProperty())
Output:

service.left-handed-smoke-sifter.definition

func (*ServiceDefinition) EnabledProperty

func (svc *ServiceDefinition) EnabledProperty() string

EnabledProperty computes the Viper property name for the boolean the user can set to disable or enable this service.

Example
service := ServiceDefinition{
	Name: "left-handed-smoke-sifter",
}

fmt.Println(service.EnabledProperty())
Output:

service.left-handed-smoke-sifter.enabled

func (*ServiceDefinition) GetPlanById

func (svc *ServiceDefinition) GetPlanById(planId string) (*ServicePlan, error)

GetPlanById finds a plan in this service by its UUID.

Example
service := ServiceDefinition{
	Name:                     "left-handed-smoke-sifter",
	DefaultServiceDefinition: `{"id":"abcd-efgh-ijkl", "plans": [{"id": "builtin-plan", "name": "Builtin!"}]}`,
}

viper.Set(service.UserDefinedPlansProperty(), `[{"id":"custom-plan", "name": "Custom!"}]`)
defer viper.Set(service.UserDefinedPlansProperty(), nil)

plan, err := service.GetPlanById("builtin-plan")
fmt.Printf("builtin-plan: %q %v\n", plan.Name, err)

plan, err = service.GetPlanById("custom-plan")
fmt.Printf("custom-plan: %q %v\n", plan.Name, err)

_, err = service.GetPlanById("missing-plan")
fmt.Printf("missing-plan: %s\n", err)
Output:

builtin-plan: "Builtin!" <nil>
custom-plan: "Custom!" <nil>
missing-plan: Plan ID "missing-plan" could not be found

func (*ServiceDefinition) IsEnabled

func (svc *ServiceDefinition) IsEnabled() bool

IsEnabled returns false if the operator has explicitly disabled this service or true otherwise.

Example
service := ServiceDefinition{
	Name: "left-handed-smoke-sifter",
}

viper.Set(service.EnabledProperty(), true)
fmt.Println(service.IsEnabled())

viper.Set(service.EnabledProperty(), false)
fmt.Println(service.IsEnabled())
Output:

true
false

func (*ServiceDefinition) IsRoleWhitelistEnabled

func (svc *ServiceDefinition) IsRoleWhitelistEnabled() bool

IsRoleWhitelistEnabled returns false if the service has no default whitelist meaning it does not allow any roles.

Example
service := ServiceDefinition{
	Name:                 "left-handed-smoke-sifter",
	DefaultRoleWhitelist: []string{"a", "b", "c"},
}
fmt.Println(service.IsRoleWhitelistEnabled())

service.DefaultRoleWhitelist = nil
fmt.Println(service.IsRoleWhitelistEnabled())
Output:

true
false

func (*ServiceDefinition) ProvisionDefaultOverrideProperty

func (svc *ServiceDefinition) ProvisionDefaultOverrideProperty() string

ProvisionDefaultOverrideProperty returns the Viper property name for the object users can set to override the default values on provision.

func (*ServiceDefinition) ProvisionDefaultOverrides

func (svc *ServiceDefinition) ProvisionDefaultOverrides() map[string]interface{}

ProvisionDefaultOverrides returns the deserialized JSON object for the operator-provided property overrides.

func (*ServiceDefinition) ProvisionVariables

func (svc *ServiceDefinition) ProvisionVariables(instanceId string, details brokerapi.ProvisionDetails, plan ServicePlan) (*varcontext.VarContext, error)

ProvisionVariables gets the variable resolution context for a provision request. Variables have a very specific resolution order, and this function populates the context to preserve that. The variable resolution order is the following:

1. Variables defined in your `computed_variables` JSON list. 2. Variables defined by the selected service plan in its `service_properties` map. 3. User defined variables (in `provision_input_variables` or `bind_input_variables`) 4. Operator default variables loaded from the environment. 5. Default variables (in `provision_input_variables` or `bind_input_variables`).

Loading into the map occurs slightly differently. Default variables and computed_variables get executed by interpolation. User defined varaibles are not to prevent side-channel attacks. Default variables may reference user provided variables. For example, to create a default database name based on a user-provided instance name. Therefore, they get executed conditionally if a user-provided variable does not exist. Computed variables get executed either unconditionally or conditionally for greater flexibility.

func (*ServiceDefinition) ServiceDefinition

func (svc *ServiceDefinition) ServiceDefinition() (*Service, error)

ServiceDefinition extracts service definition from the environment, failing if the definition was not valid JSON.

Example
service := ServiceDefinition{
	Name:                     "left-handed-smoke-sifter",
	DefaultServiceDefinition: `{"id":"abcd-efgh-ijkl"}`,
}

// Default definition
defn, err := service.ServiceDefinition()
fmt.Printf("%q %v\n", defn.ID, err)

// Override
viper.Set(service.DefinitionProperty(), `{"id":"override-id"}`)
defn, err = service.ServiceDefinition()
fmt.Printf("%q %v\n", defn.ID, err)

// Bad Value
viper.Set(service.DefinitionProperty(), "nil")
_, err = service.ServiceDefinition()
fmt.Printf("%v\n", err)

// Cleanup
viper.Set(service.DefinitionProperty(), nil)
Output:

"abcd-efgh-ijkl" <nil>
"override-id" <nil>
Error parsing service definition for "left-handed-smoke-sifter": invalid character 'i' in literal null (expecting 'u')

func (*ServiceDefinition) TileUserDefinedPlansVariable

func (svc *ServiceDefinition) TileUserDefinedPlansVariable() string

TileUserDefinedPlansVariable returns the name of the user defined plans variable for the broker tile.

Example
service := ServiceDefinition{
	Name: "google-spanner",
}

fmt.Println(service.TileUserDefinedPlansVariable())
Output:

SPANNER_CUSTOM_PLANS

func (*ServiceDefinition) UserDefinedPlans

func (svc *ServiceDefinition) UserDefinedPlans() ([]ServicePlan, error)

UserDefinedPlans extracts user defined plans from the environment, failing if the plans were not valid JSON or were missing required properties/variables.

func (*ServiceDefinition) UserDefinedPlansProperty

func (svc *ServiceDefinition) UserDefinedPlansProperty() string

UserDefinedPlansProperty computes the Viper property name for the JSON list of user-defined service plans.

Example
service := ServiceDefinition{
	Name: "left-handed-smoke-sifter",
}

fmt.Println(service.UserDefinedPlansProperty())
Output:

service.left-handed-smoke-sifter.plans

type ServiceExample

type ServiceExample struct {
	// Name is a human-readable name of the example.
	Name string `json:"name" yaml:"name" validate:"required"`
	// Description is a long-form description of what this example is about.
	Description string `json:"description" yaml:"description" validate:"required"`
	// PlanId is the plan this example will run against.
	PlanId string `json:"plan_id" yaml:"plan_id" validate:"required"`

	// ProvisionParams is the JSON object that will be passed to provision.
	ProvisionParams map[string]interface{} `json:"provision_params" yaml:"provision_params" validate:"required"`

	// BindParams is the JSON object that will be passed to bind. If nil,
	// this example DOES NOT include a bind portion.
	BindParams map[string]interface{} `json:"bind_params" yaml:"bind_params"`
}

ServiceExample holds example configurations for a service that _should_ work.

type ServicePlan

type ServicePlan struct {
	brokerapi.ServicePlan

	ServiceProperties map[string]string `json:"service_properties"`
}

ServicePlan extends the OSB ServicePlan by including a map of key/value pairs that can be used to pass additional information to the back-end.

func (*ServicePlan) GetServiceProperties

func (sp *ServicePlan) GetServiceProperties() map[string]interface{}

GetServiceProperties gets the plan settings variables as a string->interface map.

type ServiceProvider

type ServiceProvider interface {
	// Provision creates the necessary resources that an instance of this service
	// needs to operate.
	Provision(ctx context.Context, provisionContext *varcontext.VarContext) (models.ServiceInstanceDetails, error)

	// Bind provisions the necessary resources for a user to be able to connect to the provisioned service.
	// This may include creating service accounts, granting permissions, and adding users to services e.g. a SQL database user.
	// It stores information necessary to access the service _and_ delete the binding in the returned map.
	Bind(ctx context.Context, vc *varcontext.VarContext) (map[string]interface{}, error)
	BuildInstanceCredentials(ctx context.Context, bindRecord models.ServiceBindingCredentials, instance models.ServiceInstanceDetails) (map[string]interface{}, error)
	// Unbind deprovisions the resources created with Bind.
	Unbind(ctx context.Context, instance models.ServiceInstanceDetails, details models.ServiceBindingCredentials) error
	// Deprovision deprovisions the service.
	// If the deprovision is asynchronous (results in a long-running job), then operationId is returned.
	// If no error and no operationId are returned, then the deprovision is expected to have been completed successfully.
	Deprovision(ctx context.Context, instance models.ServiceInstanceDetails, details brokerapi.DeprovisionDetails) (operationId *string, err error)
	PollInstance(ctx context.Context, instance models.ServiceInstanceDetails) (bool, error)
	ProvisionsAsync() bool
	DeprovisionsAsync() bool

	// UpdateInstanceDetails updates the ServiceInstanceDetails with the most recent state from GCP.
	// This function is optional, but will be called after async provisions, updates, and possibly
	// on broker version changes.
	// Return a nil error if you choose not to implement this function.
	UpdateInstanceDetails(ctx context.Context, instance *models.ServiceInstanceDetails) error
}

ServiceProvider performs the actual provisoning/deprovisioning part of a service broker request. The broker will handle storing state and validating inputs while a ServiceProvider changes GCP to match the desired state. ServiceProviders are expected to interact with the state of the system entirely through their inputs and outputs. Specifically, they MUST NOT modify any general state of the broker in the database.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL