deploymentcontext

package
v0.412.6 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabasesFromSecrets

func DatabasesFromSecrets(ctx context.Context, module string, secrets map[string][]byte, types map[string]DBType) (map[string]Database, error)

DatabasesFromSecrets finds DSNs in secrets and creates a map of databases.

Secret keys should be in the format FTL_DSN_<MODULENAME>_<DBNAME>

Types

type Builder

type Builder DeploymentContext

Builder is used to build a DeploymentContext

func NewBuilder

func NewBuilder(module string) *Builder

NewBuilder creates a new blank Builder for the given module.

func NewBuilderFromContext

func NewBuilderFromContext(ctx DeploymentContext) *Builder

func (*Builder) AddAllowedDirectVerb

func (b *Builder) AddAllowedDirectVerb(ref reflection.Ref) *Builder

AddAllowedDirectVerb adds a verb that can be called directly within the current context

func (*Builder) AddConfigs

func (b *Builder) AddConfigs(configs map[string][]byte) *Builder

AddConfigs adds configuration values (as bytes) to the builder

func (*Builder) AddDatabases

func (b *Builder) AddDatabases(databases map[string]Database) *Builder

AddDatabases adds databases to the builder

func (*Builder) AddRoutes

func (b *Builder) AddRoutes(routes map[string]string) *Builder

func (*Builder) AddSecrets

func (b *Builder) AddSecrets(secrets map[string][]byte) *Builder

AddSecrets adds secrets values (as bytes) to the builder

func (*Builder) Build

func (b *Builder) Build() DeploymentContext

func (*Builder) UpdateForTesting

func (b *Builder) UpdateForTesting(mockVerbs map[schema.RefKey]Verb, allowDirectVerbBehavior bool, leaseClient LeaseClient) *Builder

UpdateForTesting marks the builder as part of a test environment and adds mock verbs and flags for other test features.

type Database

type Database struct {
	DSN    string
	DBType DBType
	// contains filtered or unexported fields
}

Database represents a database connection based on a DSN It holds a private field for the database which is accessible through moduleCtx.GetDatabase(name)

func NewDatabase

func NewDatabase(dbType DBType, dsn string) (Database, error)

NewDatabase creates a Database that can be added to DeploymentContext

func NewTestDatabase

func NewTestDatabase(dbType DBType, dsn string) (Database, error)

NewTestDatabase creates a Database that can be added to DeploymentContext

Test databases can be used within module tests

type DeploymentContext

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

DeploymentContext holds the context needed for a module, including configs, secrets and DSNs

DeploymentContext is immutable

func Empty

func Empty(module string) DeploymentContext

func (DeploymentContext) BehaviorForVerb

func (m DeploymentContext) BehaviorForVerb(ref schema.Ref) (optional.Option[VerbBehavior], error)

BehaviorForVerb returns what to do to execute a verb

This allows module context to dictate behavior based on testing options Returning optional.Nil indicates the verb should be executed normally via the controller

func (DeploymentContext) GetConfig

func (m DeploymentContext) GetConfig(name string, value any) error

GetConfig reads a configuration value for the module.

"value" must be a pointer to a Go type that can be unmarshalled from JSON.

func (DeploymentContext) GetDatabase

func (m DeploymentContext) GetDatabase(name string, dbType DBType) (string, bool, error)

GetDatabase gets a database DSN by name and type.

Returns an error if no database with that name is found or it is not the expected type. When in a testing context (via ftltest), an error is returned if the database is not a test database.

func (DeploymentContext) GetSecret

func (m DeploymentContext) GetSecret(name string, value any) error

GetSecret reads a secret value for the module.

"value" must be a pointer to a Go type that can be unmarshalled from JSON.

func (DeploymentContext) MockLeaseClient

func (m DeploymentContext) MockLeaseClient() optional.Option[LeaseClient]

MockLeaseClient provides a mock lease client when testing

func (DeploymentContext) ToProto

ToProto converts a DeploymentContext to a proto response.

type DeploymentContextSupplier

type DeploymentContextSupplier interface {
	Subscribe(ctx context.Context, moduleName string, sink func(ctx context.Context, moduleContext DeploymentContext), errorRetryCallback func(err error) bool)
}

type DirectBehavior

type DirectBehavior struct{}

DirectBehavior indicates that the verb should be executed by calling the function directly (for testing)

func (DirectBehavior) Call

func (DirectBehavior) Call(ctx context.Context, verb Verb, req any) (any, error)

type DynamicDeploymentContext

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

DynamicDeploymentContext provides up-to-date DeploymentContext instances supplied by the controller

func FromContext

func FromContext(ctx context.Context) *DynamicDeploymentContext

FromContext returns the DynamicDeploymentContext attached to a context.

func NewDynamicContext

func NewDynamicContext(ctx context.Context, supplier DeploymentContextSupplier, deploymentName string) (*DynamicDeploymentContext, error)

NewDynamicContext creates a new DynamicDeploymentContext. This operation blocks until the first DeploymentContext is supplied by the controller.

The DynamicDeploymentContext will continually update as updated DeploymentContext's are streamed from the controller. This operation may time out if the first module context is not supplied quickly enough (fixed at 5 seconds).

func (*DynamicDeploymentContext) ApplyToContext

func (m *DynamicDeploymentContext) ApplyToContext(ctx context.Context) context.Context

ApplyToContext returns a Go context.Context with DynamicDeploymentContext added.

func (*DynamicDeploymentContext) CurrentContext

func (m *DynamicDeploymentContext) CurrentContext() DeploymentContext

CurrentContext immediately returns the most recently updated DeploymentContext

type LeaseClient

type LeaseClient interface {
	// Returns ResourceExhausted if the lease is held.
	Acquire(ctx context.Context, module string, key []string, ttl time.Duration) error
	Heartbeat(ctx context.Context, module string, key []string, ttl time.Duration) error
	Release(ctx context.Context, key []string) error
}

LeaseClient is the interface for acquiring, heartbeating and releasing leases

type MockBehavior

type MockBehavior struct {
	Mock Verb
}

MockBehavior indicates the verb has a mock implementation

func (MockBehavior) Call

func (b MockBehavior) Call(ctx context.Context, _ Verb, req any) (any, error)

type Verb

type Verb func(ctx context.Context, req any) (resp any, err error)

Verb is a function that takes a request and returns a response but is not constrained by request/response type like ftl.Verb

It is used for definitions of mock verbs as well as real implementations of verbs to directly execute

type VerbBehavior

type VerbBehavior interface {
	Call(ctx context.Context, verb Verb, request any) (any, error)
}

VerbBehavior indicates how to execute a verb

Jump to

Keyboard shortcuts

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