service

package
v0.0.0-...-47649f3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 38 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInstanceAlreadyExistsInAPI = errors.New("instance already exists in the service API")
	ErrInstanceNotFoundInAPI      = errors.New("instance does not exist in the service API")
	ErrInstanceNotReady           = errors.New("instance is not ready yet")
)
View Source
var (
	ErrServiceAlreadyExists = errors.New("Service already exists.")
	ErrServiceNotFound      = errors.New("Service not found.")
	ErrMissingPool          = errors.New("Missing pool")
)
View Source
var (
	ErrServiceInstanceNotFound                  = errors.New("service instance not found")
	ErrInvalidInstanceName                      = errors.New("invalid service instance name")
	ErrInstanceNameAlreadyExists                = errors.New("instance name already exists.")
	ErrAccessNotAllowed                         = errors.New("user does not have access to this service instance")
	ErrTeamMandatory                            = errors.New("please specify the team that owns the service instance")
	ErrAppAlreadyBound                          = errors.New("app is already bound to this service instance")
	ErrJobAlreadyBound                          = errors.New("job is already bound to this service instance")
	ErrAppNotBound                              = errors.New("app is not bound to this service instance")
	ErrJobNotBound                              = errors.New("job is not bound to this service instance")
	ErrUnitNotBound                             = errors.New("unit is not bound to this service instance")
	ErrServiceInstanceBound                     = errors.New("This service instance is bound to at least one app. Unbind them before removing it")
	ErrMultiClusterServiceRequiresPool          = errors.New("multi-cluster service instance requires a pool")
	ErrMultiClusterViolatingConstraint          = errors.New("multi-cluster service instance is not allowed in this pool")
	ErrMultiClusterPoolDoesNotMatch             = errors.New("pools between app and multi-cluster service instance does not match")
	ErrRegularServiceInstanceCannotBelongToPool = errors.New("regular (non-multi-cluster) service instance cannot belong to a pool")
	ErrRevokeInstanceTeamOwnerAccess            = errors.New("cannot revoke the instance's team owner access")
)
View Source
var ClientFactory = func(config *osb.ClientConfiguration) (osb.Client, error) {
	return osb.NewClient(config)
}

ClientFactory provides a way to customize the Open Service Broker API client. Should be used in tests to create a fake client.

View Source
var ErrInvalidBrokerData = errors.New("Invalid broker data")

Functions

func BrokerService

func BrokerService() (serviceTypes.ServiceBrokerService, error)

func Create

func Create(s Service) error

func CreateServiceInstance

func CreateServiceInstance(ctx context.Context, instance ServiceInstance, service *Service, evt *event.Event, requestID string) error

func Delete

func Delete(s Service) error

func DeleteInstance

func DeleteInstance(ctx context.Context, si *ServiceInstance, evt *event.Event, requestID string) error

DeleteInstance deletes the service instance from the database.

func Proxy

func Proxy(ctx context.Context, service *Service, path string, evt *event.Event, requestID string, w http.ResponseWriter, r *http.Request) error

Proxy is a proxy between tsuru and the service. This method allow customized service methods.

func ProxyInstance

func ProxyInstance(ctx context.Context, instance *ServiceInstance, path string, evt *event.Event, requestID string, w http.ResponseWriter, r *http.Request) error

ProxyInstance is a proxy between tsuru and the service instance. This method allow customized service instance methods.

func RenameServiceInstanceTeam

func RenameServiceInstanceTeam(ctx context.Context, oldName, newName string) error

func RenameServiceTeam

func RenameServiceTeam(ctx context.Context, oldName, newName string) error

func Update

func Update(s Service) error

Types

type BindAppParameters

type BindAppParameters map[string]interface{}

type BrokerInstanceBind

type BrokerInstanceBind struct {
	// UUID is a v4 UUID generated when binding
	UUID         string
	OperationKey string
	Parameters   map[string]interface{}
}

type BrokerInstanceData

type BrokerInstanceData struct {
	// UUID is a v4 UUID generated for this Instance on creation
	UUID             string
	ServiceID        string
	PlanID           string
	OrgID            string
	SpaceID          string
	LastOperationKey string

	Binds map[string]BrokerInstanceBind
}

type Plan

type Plan struct {
	Name        string
	Description string
	Schemas     *osb.Schemas `json:",omitempty"`
}

Plan represents a service plan

func GetPlanByServiceAndPlanName

func GetPlanByServiceAndPlanName(ctx context.Context, svc Service, pool, planName, requestID string) (Plan, error)

func GetPlansByService

func GetPlansByService(ctx context.Context, svc Service, pool, requestID string) ([]Plan, error)

type ProxyOpts

type ProxyOpts struct {
	Instance  *ServiceInstance
	Path      string
	Event     *event.Event
	RequestID string
	Writer    http.ResponseWriter
	Request   *http.Request
}

type Service

type Service struct {
	Name         string `bson:"_id"`
	Username     string
	Password     string
	Endpoint     map[string]string
	OwnerTeams   []string `bson:"owner_teams"`
	Teams        []string
	Doc          string
	IsRestricted bool `bson:"is_restricted"`
	// IsMultiCluster indicates whether Service Instances (children of this Service)
	// run within the user's Cluster (same pool of Tsuru Apps). When enabled, creating
	// a Service Instance must require a valid Pool.
	//
	// This field is immutable (after creating Service).
	IsMultiCluster bool `bson:"is_multi_cluster"`
	// contains filtered or unexported fields
}

func Get

func Get(ctx context.Context, service string) (Service, error)

func GetServices

func GetServices(ctx context.Context) ([]Service, error)

func GetServicesByOwnerTeamsAndServices

func GetServicesByOwnerTeamsAndServices(ctx context.Context, teams []string, services []string) ([]Service, error)

func GetServicesByTeamsAndServices

func GetServicesByTeamsAndServices(ctx context.Context, teams []string, services []string) ([]Service, error)

func (*Service) GrantAccess

func (s *Service) GrantAccess(team *authTypes.Team) error

func (*Service) HasTeam

func (s *Service) HasTeam(team *authTypes.Team) bool

func (*Service) RevokeAccess

func (s *Service) RevokeAccess(team *authTypes.Team) error

type ServiceClient

type ServiceClient interface {
	Create(ctx context.Context, instance *ServiceInstance, evt *event.Event, requestID string) error
	Update(ctx context.Context, instance *ServiceInstance, evt *event.Event, requestID string) error
	Destroy(ctx context.Context, instance *ServiceInstance, evt *event.Event, requestID string) error
	BindApp(ctx context.Context, instance *ServiceInstance, app bind.App, params BindAppParameters, evt *event.Event, requestID string) (map[string]string, error)
	BindJob(ctx context.Context, instance *ServiceInstance, job *jobTypes.Job, evt *event.Event, requestID string) (map[string]string, error)
	UnbindApp(ctx context.Context, instance *ServiceInstance, app bind.App, evt *event.Event, requestID string) error
	UnbindJob(ctx context.Context, instance *ServiceInstance, job *jobTypes.Job, evt *event.Event, requestID string) error
	Status(ctx context.Context, instance *ServiceInstance, requestID string) (string, error)
	Info(ctx context.Context, instance *ServiceInstance, requestID string) ([]map[string]string, error)
	Plans(ctx context.Context, pool, requestID string) ([]Plan, error)
	Proxy(ctx context.Context, opts *ProxyOpts) error
}

TODO: use requestID inside the context

type ServiceInstance

type ServiceInstance struct {
	Name        string                 `json:"name"`
	Id          int                    `json:"id"`
	ServiceName string                 `bson:"service_name" json:"service_name"`
	PlanName    string                 `bson:"plan_name" json:"plan_name"`
	Apps        []string               `json:"apps"`
	Jobs        []string               `json:"jobs"`
	Teams       []string               `json:"teams"`
	TeamOwner   string                 `json:"team_owner"`
	Description string                 `json:"description"`
	Tags        []string               `json:"tags"`
	Parameters  map[string]interface{} `json:"parameters,omitempty"`
	// Pool is the pool name which the Service Instance should run into.
	// This field is mandatory iff the parent Service is running in
	// multi-cluster mode (see Service.IsMultiCluster field)
	//
	// NOTE: after the service instance is created, this field turns immutable.
	Pool string `json:"pool,omitempty"`

	// BrokerData stores data used by Instances provisioned by Brokers
	BrokerData *BrokerInstanceData `json:"broker_data,omitempty" bson:"broker_data"`

	// ForceRemove indicates whether service instance should be removed even the
	// related call to service API fails.
	ForceRemove bool `bson:"-" json:"-"`
	// contains filtered or unexported fields
}

func GetServiceInstance

func GetServiceInstance(ctx context.Context, serviceName string, instanceName string) (*ServiceInstance, error)

func GetServiceInstancesBoundToApp

func GetServiceInstancesBoundToApp(appName string) ([]ServiceInstance, error)

func GetServiceInstancesBoundToJob

func GetServiceInstancesBoundToJob(jobName string) ([]ServiceInstance, error)

func GetServiceInstancesByServices

func GetServiceInstancesByServices(services []Service) ([]ServiceInstance, error)

func GetServicesInstancesByTeamsAndNames

func GetServicesInstancesByTeamsAndNames(teams []string, names []string, appName, serviceName string) ([]ServiceInstance, error)

func (*ServiceInstance) BindApp

func (si *ServiceInstance) BindApp(app bind.App, params BindAppParameters, shouldRestart bool, writer io.Writer, evt *event.Event, requestID string) error

BindApp makes the bind between the service instance and an app.

func (*ServiceInstance) BindJob

func (si *ServiceInstance) BindJob(job *jobTypes.Job, writer io.Writer, evt *event.Event, requestID string) error

BindJob makes the bind between the service instance and a job.

func (*ServiceInstance) FindApp

func (si *ServiceInstance) FindApp(appName string) int

func (*ServiceInstance) FindJob

func (si *ServiceInstance) FindJob(jobName string) int

func (*ServiceInstance) GetIdentifier

func (si *ServiceInstance) GetIdentifier() string

func (*ServiceInstance) Grant

func (si *ServiceInstance) Grant(teamName string) error

func (*ServiceInstance) Info

func (si *ServiceInstance) Info(requestID string) (map[string]string, error)

func (*ServiceInstance) Revoke

func (si *ServiceInstance) Revoke(teamName string) error

func (*ServiceInstance) Status

func (si *ServiceInstance) Status(requestID string) (string, error)

Status returns the service instance status.

func (*ServiceInstance) ToInfo

ToInfo returns the service instance as a struct compatible with the return of the service info api call.

func (*ServiceInstance) UnbindApp

func (si *ServiceInstance) UnbindApp(unbindArgs UnbindAppArgs) error

UnbindApp makes the unbind between the service instance and an app.

func (*ServiceInstance) UnbindJob

func (si *ServiceInstance) UnbindJob(unbindArgs UnbindJobArgs) error

UnbindJob makes the unbind between the service instance and a job.

func (*ServiceInstance) Update

func (si *ServiceInstance) Update(service Service, updateData ServiceInstance, evt *event.Event, requestID string) error

Update changes informations of the service instance.

type ServiceInstanceWithInfo

type ServiceInstanceWithInfo struct {
	Id          int
	Name        string
	Pool        string
	Teams       []string
	PlanName    string
	Apps        []string
	Jobs        []string
	ServiceName string
	Info        map[string]string
	TeamOwner   string
}

type ServiceModel

type ServiceModel struct {
	Service          string            `json:"service"`
	Instances        []string          `json:"instances"`
	Plans            []string          `json:"plans"`
	ServiceInstances []ServiceInstance `json:"service_instances"`
}

type UnbindAppArgs

type UnbindAppArgs struct {
	App         bind.App
	Restart     bool
	ForceRemove bool
	Event       *event.Event
	RequestID   string
}

type UnbindJobArgs

type UnbindJobArgs struct {
	Job         *jobTypes.Job
	ForceRemove bool
	Event       *event.Event
	RequestID   string
}

Jump to

Keyboard shortcuts

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