Documentation ¶
Index ¶
- func ApplyDefaults(parameters map[string]interface{}, variables []BrokerVariable)
- func CreateJsonSchema(schemaVariables []BrokerVariable) map[string]interface{}
- func ValidateVariables(parameters map[string]interface{}, variables []BrokerVariable) error
- func ValidateVariablesAgainstSchema(parameters map[string]interface{}, schema map[string]interface{}) error
- type BrokerRegistry
- func (brokerRegistry BrokerRegistry) GetAllServices() []*ServiceDefinition
- func (brokerRegistry *BrokerRegistry) GetEnabledServices() ([]*ServiceDefinition, error)
- func (brokerRegistry BrokerRegistry) GetServiceById(id string) (*ServiceDefinition, error)
- func (brokerRegistry BrokerRegistry) Register(service *ServiceDefinition)
- type BrokerVariable
- type JsonType
- type Service
- type ServiceDefinition
- func (svc *ServiceDefinition) BindDefaultOverrideProperty() string
- func (svc *ServiceDefinition) BindDefaultOverrides() map[string]interface{}
- func (svc *ServiceDefinition) BindVariables(instance models.ServiceInstanceDetails, bindingID string, ...) (*varcontext.VarContext, error)
- func (svc *ServiceDefinition) CatalogEntry() (*Service, error)
- func (svc *ServiceDefinition) GetPlanById(planId string) (*ServicePlan, error)
- func (svc *ServiceDefinition) IsRoleWhitelistEnabled() bool
- func (svc *ServiceDefinition) ProvisionDefaultOverrideProperty() string
- func (svc *ServiceDefinition) ProvisionDefaultOverrides() map[string]interface{}
- func (svc *ServiceDefinition) ProvisionVariables(instanceId string, details brokerapi.ProvisionDetails, plan ServicePlan) (*varcontext.VarContext, error)
- func (svc *ServiceDefinition) TileUserDefinedPlansVariable() string
- func (svc *ServiceDefinition) UserDefinedPlans() ([]ServicePlan, error)
- func (svc *ServiceDefinition) UserDefinedPlansProperty() string
- func (sd *ServiceDefinition) Validate() (errs *validation.FieldError)
- type ServiceExample
- type ServicePlan
- type ServiceProvider
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyDefaults ¶
func ApplyDefaults(parameters map[string]interface{}, variables []BrokerVariable)
Apply defaults adds default values for missing broker variables.
func CreateJsonSchema ¶
func CreateJsonSchema(schemaVariables []BrokerVariable) map[string]interface{}
CreateJsonSchema outputs a JSONSchema given a list of BrokerVariables
func ValidateVariables ¶
func ValidateVariables(parameters map[string]interface{}, variables []BrokerVariable) error
func ValidateVariablesAgainstSchema ¶
func ValidateVariablesAgainstSchema(parameters map[string]interface{}, schema map[string]interface{}) 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
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 (*BrokerRegistry) GetEnabledServices ¶
func (brokerRegistry *BrokerRegistry) GetEnabledServices() ([]*ServiceDefinition, error)
GetEnabledServices returns a list of all registered brokers that the user has enabled the use of.
func (BrokerRegistry) GetServiceById ¶
func (brokerRegistry BrokerRegistry) 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 (BrokerRegistry) Register ¶
func (brokerRegistry BrokerRegistry) Register(service *ServiceDefinition)
Registers a ServiceDefinition with the service registry that various commands poll to create the catalog, documentation, etc.
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"` // The JSONSchema type of the field Type JsonType `yaml:"type"` // Human readable info about the field. Details string `yaml:"details"` // 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.
func (*BrokerVariable) Validate ¶
func (bv *BrokerVariable) Validate() (errs *validation.FieldError)
Validate implements validation.Validatable.
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.
type ServiceDefinition ¶
type ServiceDefinition struct { Id string Name string Description string DisplayName string ImageUrl string DocumentationUrl string SupportUrl string Tags []string Bindable bool PlanUpdateable bool Plans []ServicePlan ProvisionInputVariables []BrokerVariable ProvisionComputedVariables []varcontext.DefaultVariable BindInputVariables []BrokerVariable BindOutputVariables []BrokerVariable BindComputedVariables []varcontext.DefaultVariable PlanVariables []BrokerVariable Examples []ServiceExample DefaultRoleWhitelist []string // ProviderBuilder creates a new provider given the project, auth, and logger. ProviderBuilder func(projectId string, auth *jwt.Config, logger lager.Logger) ServiceProvider // IsBuiltin is true if the service is built-in to the platform. IsBuiltin bool }
ServiceDefinition holds the necessary details to describe an OSB service and provision it.
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, plan *ServicePlan) (*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. 2. Variables overridden in the plan's `bind_overrides` map. 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.
Example ¶
service := ServiceDefinition{ Id: "00000000-0000-0000-0000-000000000000", Name: "left-handed-smoke-sifter", Plans: []ServicePlan{ {ServicePlan: brokerapi.ServicePlan{ID: "builtin-plan", Name: "Builtin!"}}, }, ProvisionInputVariables: []BrokerVariable{ {FieldName: "location", Type: JsonTypeString, Default: "us"}, }, BindInputVariables: []BrokerVariable{ {FieldName: "name", Type: JsonTypeString, Default: "name"}, }, } srvc, err := service.CatalogEntry() if err != nil { panic(err) } // Schemas should be nil by default fmt.Println("schemas with flag off:", srvc.ToPlain().Plans[0].Schemas) viper.Set("compatibility.enable-catalog-schemas", true) defer viper.Reset() srvc, err = service.CatalogEntry() if err != nil { panic(err) } eq := reflect.DeepEqual(srvc.ToPlain().Plans[0].Schemas, service.createSchemas()) fmt.Println("schema was generated?", eq)
Output: schemas with flag off: <nil> schema was generated? true
func (*ServiceDefinition) GetPlanById ¶
func (svc *ServiceDefinition) GetPlanById(planId string) (*ServicePlan, error)
GetPlanById finds a plan in this service by its UUID.
Example ¶
service := ServiceDefinition{ Id: "00000000-0000-0000-0000-000000000000", Name: "left-handed-smoke-sifter", Plans: []ServicePlan{ {ServicePlan: brokerapi.ServicePlan{ID: "builtin-plan", Name: "Builtin!"}}, }, } viper.Set(service.UserDefinedPlansProperty(), `[{"id":"custom-plan", "name": "Custom!"}]`) defer viper.Reset() 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) 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{ Id: "00000000-0000-0000-0000-000000000000", 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. Variables overridden in the plan's `provision_overrides` map. 4. User defined variables (in `provision_input_variables` or `bind_input_variables`) 5. Operator default variables loaded from the environment. 6. 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) TileUserDefinedPlansVariable ¶
func (svc *ServiceDefinition) TileUserDefinedPlansVariable() string
TileUserDefinedPlansVariable returns the name of the user defined plans variable for the broker tile.
Example ¶
service := ServiceDefinition{ Id: "00000000-0000-0000-0000-000000000000", 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{ Id: "00000000-0000-0000-0000-000000000000", Name: "left-handed-smoke-sifter", } fmt.Println(service.UserDefinedPlansProperty())
Output: service.left-handed-smoke-sifter.plans
func (*ServiceDefinition) Validate ¶
func (sd *ServiceDefinition) Validate() (errs *validation.FieldError)
Validate implements validation.Validatable.
type ServiceExample ¶
type ServiceExample struct { // Name is a human-readable name of the example. Name string `json:"name" yaml:"name"` // Description is a long-form description of what this example is about. Description string `json:"description" yaml:"description"` // PlanId is the plan this example will run against. PlanId string `json:"plan_id" yaml:"plan_id"` // ProvisionParams is the JSON object that will be passed to provision. ProvisionParams map[string]interface{} `json:"provision_params" yaml:"provision_params"` // 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.
func (*ServiceExample) Validate ¶
func (action *ServiceExample) Validate() (errs *validation.FieldError)
Validate implements validation.Validatable.
type ServicePlan ¶
type ServicePlan struct { brokerapi.ServicePlan ServiceProperties map[string]string `json:"service_properties"` ProvisionOverrides map[string]interface{} `json:"provision_overrides,omitempty"` BindOverrides map[string]interface{} `json:"bind_overrides,omitempty"` }
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.