broker

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyAtlasClient contextKey = "atlas-client"
	ContextKeyGroupID     contextKey = "group-id"
)

ContextKeyAtlasClient is the key used to store the Atlas client in the request context.

View Source
const (
	OperationProvision   = "provision"
	OperationDeprovision = "deprovision"
	OperationUpdate      = "update"
	InstanceSizeNameM2   = "M2"
	InstanceSizeNameM5   = "M5"
)

The different async operations that can be performed. These constants are returned during provisioning, deprovisioning, and updates and are subsequently included in async polls from the platform.

Variables

This section is empty.

Functions

func NormalizeClusterName

func NormalizeClusterName(name string) string

NormalizeClusterName will sanitize a name to make sure it will be accepted by the Atlas API. Atlas has different name length requirements depending on which environment it's running in. A length of 23 is a safe choice and truncates UUIDs nicely.

Types

type Broker

type Broker struct {
	// contains filtered or unexported fields
}

Broker is responsible for translating OSB calls to Atlas API calls. Implements the domain.ServiceBroker interface making it easy to spin up an API server.

func New

func New(
	logger *zap.SugaredLogger,
	credentials *credentials.Credentials,
	atlasURL string,
	realmURL string,
	whitelist Whitelist,
	userAgent string,
) *Broker

New creates a new Broker with a logger.

func (*Broker) AuthMiddleware

func (b *Broker) AuthMiddleware() mux.MiddlewareFunc

func (Broker) Bind

func (b Broker) Bind(ctx context.Context, instanceID string, bindingID string, details domain.BindDetails, asyncAllowed bool) (spec domain.Binding, err error)

Bind will create a new database user with a username matching the binding ID and a randomly generated password. The user credentials will be returned back.

func (Broker) Deprovision

func (b Broker) Deprovision(ctx context.Context, instanceID string, details domain.DeprovisionDetails, asyncAllowed bool) (spec domain.DeprovisionServiceSpec, err error)

Deprovision will destroy an Atlas cluster asynchronously.

func (Broker) GetBinding

func (b Broker) GetBinding(ctx context.Context, instanceID string, bindingID string) (spec domain.GetBindingSpec, err error)

GetBinding is currently not supported as specified by the BindingsRetrievable setting in the service catalog.

func (*Broker) GetDashboardURL

func (b *Broker) GetDashboardURL(groupID, clusterName string) string

func (Broker) GetInstance

func (b Broker) GetInstance(ctx context.Context, instanceID string) (spec domain.GetInstanceDetailsSpec, err error)

GetInstance should fetch the stored instance from state storage

func (Broker) LastBindingOperation

func (b Broker) LastBindingOperation(ctx context.Context, instanceID string, bindingID string, details domain.PollDetails) (domain.LastOperation, error)

LastBindingOperation should fetch the status of the last creation/deletion of a database user.

func (Broker) LastOperation

func (b Broker) LastOperation(ctx context.Context, instanceID string, details domain.PollDetails) (resp domain.LastOperation, err error)

LastOperation should fetch the state of the provision/deprovision of a cluster.

func (Broker) Provision

func (b Broker) Provision(ctx context.Context, instanceID string, details domain.ProvisionDetails, asyncAllowed bool) (spec domain.ProvisionedServiceSpec, err error)

Provision will create a new Atlas cluster with the instance ID as its name. The process is always async.

func (*Broker) Services

func (b *Broker) Services(ctx context.Context) ([]domain.Service, error)

Services generates the service catalog which will be presented to consumers of the API.

func (Broker) Unbind

func (b Broker) Unbind(ctx context.Context, instanceID string, bindingID string, details domain.UnbindDetails, asyncAllowed bool) (spec domain.UnbindSpec, err error)

Unbind will delete the database user for a specific binding. The database user should have the binding ID as its username.

func (Broker) Update

func (b Broker) Update(ctx context.Context, instanceID string, details domain.UpdateDetails, asyncAllowed bool) (spec domain.UpdateServiceSpec, err error)

Update will change the configuration of an existing Atlas cluster asynchronously.

type ConnectionDetails

type ConnectionDetails struct {
	Username         string `json:"username"`
	Password         string `json:"password"`
	URI              string `json:"uri"`
	ConnectionString string `json:"connectionString"`
	Database         string `json:"database"`
}

ConnectionDetails will be returned when a new binding is created.

type StateStorage

type StateStorage interface {
	Put(ctx context.Context, key string, value *domain.GetInstanceDetailsSpec) error
	Get(ctx context.Context, key string) (*domain.GetInstanceDetailsSpec, error)
	Update(ctx context.Context, key string, value *domain.GetInstanceDetailsSpec) error
	Delete(ctx context.Context, key string) error
}

func NewMongoStorage

func NewMongoStorage(client *mongo.Client) StateStorage

type Whitelist

type Whitelist map[string][]string

func ReadWhitelistFile

func ReadWhitelistFile(path string) (Whitelist, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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