Documentation ¶
Overview ¶
Package broker implements some helpers needed for brokerapi
Index ¶
- Constants
- func ApplyDefaults(parameters map[string]any, variables []BrokerVariable)
- func CreateJSONSchema(schemaVariables []BrokerVariable) map[string]any
- func ProvisionGlobalDefaults() (map[string]any, error)
- func ValidateVariables(parameters map[string]any, variables []BrokerVariable) error
- func ValidateVariablesAgainstSchema(parameters map[string]any, schema map[string]any) 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, maintenanceInfo *domain.MaintenanceInfo) error
- func (brokerRegistry BrokerRegistry) Validate() (errs *validation.FieldError)
- type BrokerVariable
- type ImportVariable
- type JSONType
- type Service
- type ServiceDefinition
- func (svc *ServiceDefinition) AllowedUpdate(params map[string]any) bool
- func (svc *ServiceDefinition) BindDefaultOverrideProperty() string
- func (svc *ServiceDefinition) BindDefaultOverrides() map[string]any
- func (svc *ServiceDefinition) BindVariables(instance storage.ServiceInstanceDetails, bindingID string, ...) (*varcontext.VarContext, error)
- func (svc *ServiceDefinition) CatalogEntry() *Service
- func (svc *ServiceDefinition) GetPlanByID(planID string) (*ServicePlan, error)
- func (svc *ServiceDefinition) IsRoleWhitelistEnabled() bool
- func (svc *ServiceDefinition) ProvisionDefaultOverrideProperty() string
- func (svc *ServiceDefinition) ProvisionDefaultOverrides() (map[string]any, error)
- func (svc *ServiceDefinition) ProvisionVariables(instanceID string, details paramparser.ProvisionDetails, plan ServicePlan, ...) (*varcontext.VarContext, error)
- func (svc *ServiceDefinition) TileUserDefinedPlansVariable() string
- func (svc *ServiceDefinition) UpdateVariables(instanceID string, details paramparser.UpdateDetails, ...) (*varcontext.VarContext, error)
- func (svc *ServiceDefinition) UserDefinedPlans(maintenanceInfo *domain.MaintenanceInfo) ([]ServicePlan, error)
- func (svc *ServiceDefinition) UserDefinedPlansProperty() string
- func (svc *ServiceDefinition) UserDefinedPlansVariable() string
- func (svc *ServiceDefinition) Validate() (errs *validation.FieldError)
- type ServiceExample
- type ServicePlan
- type ServiceProvider
- type ServiceProviderStorage
Examples ¶
Constants ¶
const GlobalProvisionDefaults = "provision.defaults"
GlobalProvisionDefaults viper key for global provision defaults
Variables ¶
This section is empty.
Functions ¶
func ApplyDefaults ¶
func ApplyDefaults(parameters map[string]any, variables []BrokerVariable)
ApplyDefaults adds default values for missing broker variables.
func CreateJSONSchema ¶
func CreateJSONSchema(schemaVariables []BrokerVariable) map[string]any
CreateJSONSchema outputs a JSONSchema given a list of BrokerVariables
func ProvisionGlobalDefaults ¶
func ValidateVariables ¶
func ValidateVariables(parameters map[string]any, variables []BrokerVariable) error
Types ¶
type BrokerRegistry ¶
type BrokerRegistry map[string]*ServiceDefinition
BrokerRegistry holds the list of ServiceDefinitions that can be provisioned by the 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, maintenanceInfo *domain.MaintenanceInfo) error
Register registers a ServiceDefinition with the service registry that various commands poll to create the catalog, documentation, etc.
func (BrokerRegistry) Validate ¶
func (brokerRegistry BrokerRegistry) Validate() (errs *validation.FieldError)
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"` // Whether the value can be set to 'null' Nullable bool `yaml:"nullable,omitempty"` // Human-readable info about the field. Details string `yaml:"details"` // The default value of the field. Default any `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[any]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]any `yaml:"constraints,omitempty"` ProhibitUpdate bool `yaml:"prohibit_update,omitempty"` TFAttribute string `yaml:"tf_attribute,omitempty"` TFAttributeSkip string `yaml:"tf_attribute_skip,omitempty"` }
func (*BrokerVariable) ToSchema ¶
func (bv *BrokerVariable) ToSchema() map[string]any
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 ImportVariable ¶
type ImportVariable struct { Name string `yaml:"field_name"` Type string `yaml:"type"` Details string `yaml:"details"` TfResource string `yaml:"tf_resource"` }
ImportVariable Variable definition for TF import support
type Service ¶
type Service struct { domain.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) Validate ¶
func (s *Service) Validate() (errs *validation.FieldError)
type ServiceDefinition ¶
type ServiceDefinition struct { ID string Name string Description string DisplayName string ImageURL string DocumentationURL string ProviderDisplayName string SupportURL string Tags []string Bindable bool PlanUpdateable bool Plans []ServicePlan ProvisionInputVariables []BrokerVariable ImportInputVariables []ImportVariable 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(plogger lager.Logger, store ServiceProviderStorage) ServiceProvider GlobalLabels map[string]string }
ServiceDefinition holds the necessary details to describe an OSB service and provision it.
func (*ServiceDefinition) AllowedUpdate ¶
func (svc *ServiceDefinition) AllowedUpdate(params map[string]any) bool
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]any
BindDefaultOverrides returns the deserialized JSON object for the operator-provided property overrides.
func (*ServiceDefinition) BindVariables ¶
func (svc *ServiceDefinition) BindVariables(instance storage.ServiceInstanceDetails, bindingID string, details paramparser.BindDetails, plan *ServicePlan, originatingIdentity map[string]any) (*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
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: domain.ServicePlan{ID: "builtin-plan", Name: "Builtin!"}}, }, ProvisionInputVariables: []BrokerVariable{ {FieldName: "location", Type: JSONTypeString, Default: "us"}, }, BindInputVariables: []BrokerVariable{ {FieldName: "name", Type: JSONTypeString, Default: "name"}, }, } srvc := service.CatalogEntry() // 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 = service.CatalogEntry() 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: domain.ServicePlan{ID: "test-plan", Name: "Builtin!"}}, }, } plan, err := service.GetPlanByID("test-plan") fmt.Printf("test-plan: %q %v\n", plan.Name, err) _, err = service.GetPlanByID("missing-plan") fmt.Printf("missing-plan: %s\n", err)
Output: test-plan: "Builtin!" <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]any, error)
ProvisionDefaultOverrides returns the deserialized JSON object for the operator-provided property overrides.
func (*ServiceDefinition) ProvisionVariables ¶
func (svc *ServiceDefinition) ProvisionVariables(instanceID string, details paramparser.ProvisionDetails, plan ServicePlan, originatingIdentity map[string]any) (*varcontext.VarContext, error)
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) UpdateVariables ¶
func (svc *ServiceDefinition) UpdateVariables(instanceID string, details paramparser.UpdateDetails, mergedUserProvidedParameters map[string]any, plan ServicePlan, originatingIdentity map[string]any) (*varcontext.VarContext, error)
func (*ServiceDefinition) UserDefinedPlans ¶
func (svc *ServiceDefinition) UserDefinedPlans(maintenanceInfo *domain.MaintenanceInfo) ([]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) UserDefinedPlansVariable ¶
func (svc *ServiceDefinition) UserDefinedPlansVariable() string
func (*ServiceDefinition) Validate ¶
func (svc *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]any `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]any `json:"bind_params" yaml:"bind_params"` BindCanFail bool `json:"bind_can_fail,omitempty" yaml:"bind_can_fail,omitempty"` }
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 { domain.ServicePlan ServiceProperties map[string]any `json:"service_properties"` ProvisionOverrides map[string]any `json:"provision_overrides,omitempty"` BindOverrides map[string]any `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]any
GetServiceProperties gets the plan settings variables as a string->interface map.
func (*ServicePlan) Validate ¶
func (sp *ServicePlan) Validate() (errs *validation.FieldError)
Validate implements validation.Validatable.
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) error // Update makes necessary updates to resources so they match new desired configuration Update(ctx context.Context, updateContext *varcontext.VarContext) error UpgradeInstance(ctx context.Context, instanceContext *varcontext.VarContext) (*sync.WaitGroup, error) UpgradeBindings(ctx context.Context, instanceContext *varcontext.VarContext, bindingContexts []*varcontext.VarContext) error // GetImportedProperties extracts properties that should have been saved as part of subsume operation GetImportedProperties(ctx context.Context, instanceGUID string, inputVariables []BrokerVariable, initialProperties map[string]any) (map[string]any, 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]any, error) // Unbind deprovisions the resources created with Bind. Unbind(ctx context.Context, instanceGUID, bindingID string, vc *varcontext.VarContext) 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, instanceGUID string, vc *varcontext.VarContext) (*string, error) PollInstance(ctx context.Context, instanceGUID string) (bool, string, string, error) GetTerraformOutputs(ctx context.Context, instanceGUID string) (storage.JSONObject, error) DeleteInstanceData(ctx context.Context, instanceGUID string) error DeleteBindingData(ctx context.Context, instanceGUID, bindingID string) error ClearOperationType(ctx context.Context, instanceGUID string) error CheckUpgradeAvailable(deploymentID string) error CheckOperationConstraints(deploymentID string, operationType string) 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.
type ServiceProviderStorage ¶
type ServiceProviderStorage interface { StoreTerraformDeployment(t storage.TerraformDeployment) error GetTerraformDeployment(id string) (storage.TerraformDeployment, error) DeleteTerraformDeployment(id string) error ExistsTerraformDeployment(id string) (bool, error) GetServiceBindingIDsForServiceInstance(serviceInstanceID string) ([]string, error) WriteLockFile(guid string) error RemoveLockFile(guid string) error }