broker

package
v4.0.0-rc+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2018 License: Apache-2.0 Imports: 8 Imported by: 25

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(service *BrokerService)

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

Types

type BrokerService

type BrokerService struct {
	Name                     string
	DefaultServiceDefinition string
	ProvisionInputVariables  []BrokerVariable
	BindInputVariables       []BrokerVariable
	BindOutputVariables      []BrokerVariable
	PlanVariables            []BrokerVariable
	Examples                 []ServiceExample
	DefaultRoleWhitelist     []string
}

func GetAllServices

func GetAllServices() []*BrokerService

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() []*BrokerService

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

func GetServiceById

func GetServiceById(id string) (*BrokerService, 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 (*BrokerService) CatalogEntry

func (svc *BrokerService) CatalogEntry() (*models.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 (*BrokerService) DefinitionProperty

func (svc *BrokerService) DefinitionProperty() string

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

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

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

service.left-handed-smoke-sifter.definition

func (*BrokerService) EnabledProperty

func (svc *BrokerService) EnabledProperty() string

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

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

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

service.left-handed-smoke-sifter.enabled

func (*BrokerService) GetPlanById

func (svc *BrokerService) GetPlanById(planId string) (*models.ServicePlan, error)

GetPlanById finds a plan in this service by its UUID.

Example
service := BrokerService{
	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 (*BrokerService) IsEnabled

func (svc *BrokerService) IsEnabled() bool

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

Example
service := BrokerService{
	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 (*BrokerService) IsRoleWhitelistEnabled

func (svc *BrokerService) IsRoleWhitelistEnabled() bool

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

Example
service := BrokerService{
	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 (*BrokerService) RoleWhitelist

func (svc *BrokerService) RoleWhitelist() []string

RoleWhitelist returns the whitelist of roles the operator has allowed or the default if it is blank.

Example
service := BrokerService{
	Name:                 "my-service",
	DefaultRoleWhitelist: []string{"a", "b", "c"},
}
viper.Set(service.RoleWhitelistProperty(), "")
fmt.Println(service.RoleWhitelist())

viper.Set(service.RoleWhitelistProperty(), "x,y,z")
fmt.Println(service.RoleWhitelist())
Output:

[a b c]
[x y z]

func (*BrokerService) RoleWhitelistProperty

func (svc *BrokerService) RoleWhitelistProperty() string

RoleWhitelistProperty computes the Viper property name for the boolean the user can set to enable or disable the role whitelist.

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

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

service.left-handed-smoke-sifter.whitelist

func (*BrokerService) ServiceDefinition

func (svc *BrokerService) ServiceDefinition() (*models.Service, error)

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

Example
service := BrokerService{
	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 (*BrokerService) TileUserDefinedPlansVariable

func (svc *BrokerService) TileUserDefinedPlansVariable() string

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

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

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

SPANNER_CUSTOM_PLANS

func (*BrokerService) UserDefinedPlans

func (svc *BrokerService) UserDefinedPlans() ([]models.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 (*BrokerService) UserDefinedPlansProperty

func (svc *BrokerService) UserDefinedPlansProperty() string

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

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

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

service.left-handed-smoke-sifter.plans

type BrokerVariable

type BrokerVariable struct {
	// Is this variable required?
	Required bool
	// The name of the JSON field this variable serializes/deserializes to
	FieldName string
	// The JSONSchema type of the field
	Type JsonType
	// Human readable info about the field.
	Details string
	// The default value of the field.
	Default interface{}
	// 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
}

type JsonType

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

type ServiceExample

type ServiceExample struct {
	// Name is a human-readable name of the example.
	Name string
	// Description is a long-form description of what this example is about.
	Description string
	// PlanId is the plan this example will run against.
	PlanId string

	// ProvisionParams is the JSON object that will be passed to provision.
	ProvisionParams map[string]interface{}

	// 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{}
}

ServiceExample holds example configurations for a service that _should_ work.

Jump to

Keyboard shortcuts

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