Documentation ¶
Index ¶
- func DatabasesFromSecrets(ctx context.Context, module string, secrets map[string][]byte, ...) (map[string]Database, error)
- type Builder
- func (b *Builder) AddAllowedDirectVerb(ref reflection.Ref) *Builder
- func (b *Builder) AddConfigs(configs map[string][]byte) *Builder
- func (b *Builder) AddDatabases(databases map[string]Database) *Builder
- func (b *Builder) AddRoutes(routes map[string]string) *Builder
- func (b *Builder) AddSecrets(secrets map[string][]byte) *Builder
- func (b *Builder) Build() DeploymentContext
- func (b *Builder) UpdateForTesting(mockVerbs map[schema.RefKey]Verb, allowDirectVerbBehavior bool, ...) *Builder
- type DBType
- type Database
- type DeploymentContext
- func (m DeploymentContext) BehaviorForVerb(ref schema.Ref) (optional.Option[VerbBehavior], error)
- func (m DeploymentContext) GetConfig(name string, value any) error
- func (m DeploymentContext) GetDatabase(name string, dbType DBType) (string, bool, error)
- func (m DeploymentContext) GetSecret(name string, value any) error
- func (m DeploymentContext) MockLeaseClient() optional.Option[LeaseClient]
- func (m DeploymentContext) ToProto() *deploymentpb.GetDeploymentContextResponse
- type DeploymentContextSupplier
- type DirectBehavior
- type DynamicDeploymentContext
- type LeaseClient
- type MockBehavior
- type Verb
- type VerbBehavior
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 ¶
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 ¶
AddConfigs adds configuration values (as bytes) to the builder
func (*Builder) AddDatabases ¶
AddDatabases adds databases to the builder
func (*Builder) AddSecrets ¶
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 DBType ¶
type DBType deploymentpb.GetDeploymentContextResponse_DbType
const ( DBTypeUnspecified DBType = DBType(deploymentpb.GetDeploymentContextResponse_DB_TYPE_UNSPECIFIED) DBTypePostgres DBType = DBType(deploymentpb.GetDeploymentContextResponse_DB_TYPE_POSTGRES) DBTypeMySQL DBType = DBType(deploymentpb.GetDeploymentContextResponse_DB_TYPE_MYSQL) )
func DBTypeFromProto ¶
func DBTypeFromProto(x deploymentpb.GetDeploymentContextResponse_DbType) DBType
func DBTypeFromString ¶
func (DBType) ToProto ¶
func (x DBType) ToProto() deploymentpb.GetDeploymentContextResponse_DbType
type Database ¶
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 ¶
NewDatabase creates a Database that can be added to DeploymentContext
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 FromProto ¶
func FromProto(response *deploymentpb.GetDeploymentContextResponse) (DeploymentContext, error)
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 ¶
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 ¶
func (m DeploymentContext) ToProto() *deploymentpb.GetDeploymentContextResponse
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)
}
func NewDeploymentContextSupplier ¶
func NewDeploymentContextSupplier(client deploymentpbconnect.DeploymentServiceClient) DeploymentContextSupplier
type DirectBehavior ¶
type DirectBehavior struct{}
DirectBehavior indicates that the verb should be executed by calling the function directly (for testing)
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