bindings

package
v0.18.8 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const BindingHostnameDisable = "disable"

Variables

This section is empty.

Functions

func NewProviderHCLogger added in v0.18.7

func NewProviderHCLogger(logger *types.Logger, serviceType string) hclog.Logger

NewProviderHCLogger builds the hclog.Logger go-plugin uses on the host side: provider log lines (hclog JSON on the provider's stderr) and go-plugin lifecycle messages are routed into the server's zerolog log.

func ProviderSecureConfig added in v0.18.7

func ProviderSecureConfig(sha256Hex string) (*plugin.SecureConfig, error)

ProviderSecureConfig builds the go-plugin SecureConfig that verifies the executable's sha256 before launch; nil when no checksum is available.

func RegisterRemoteBinding added in v0.18.7

func RegisterRemoteBinding(providerName, serviceType, execPath, sha256Hex string) error

RegisterRemoteBinding registers a service type served by an out-of-process binding provider executable. The builder is cheap: the provider process is launched lazily by InitializeService and killed by CloseService, so dry runs (which build binding instances but open no connections) spawn nothing. Compiled-in bindings always win: registering a service type they serve is an error, as is a type already registered by a different provider. sha256Hex is the expected checksum of the executable, verified by go-plugin before every launch; empty (dev providers) disables the check.

func RegisterServiceBinding

func RegisterServiceBinding(name string, serviceBindingBuilder ServiceBindingBuilder)

RegisterServiceBinding registers a service binding

func ReplaceProviderBindings added in v0.18.7

func ReplaceProviderBindings(providerName string, serviceTypes []string, execPath, sha256Hex string) error

ReplaceProviderBindings atomically replaces the named provider's registrations: service types no longer served are removed, the given types are registered with the new executable and checksum, all under one lock so no caller ever observes a half-registered provider. Conflicts (built-in types, types owned by another provider) fail the whole call before any change is made.

func SetServiceBinding added in v0.18.7

func SetServiceBinding(name string, builder ServiceBindingBuilder)

SetServiceBinding registers a builder for a service type, removing the registration when builder is nil. Used by tests to install fakes and restore the previous state.

func UnregisterProviderBindings added in v0.18.7

func UnregisterProviderBindings(providerName string)

UnregisterProviderBindings removes all service types registered by the named provider. Compiled-in bindings are never unregistered.

Types

type Artifact added in v0.18.0

type Artifact struct {
	Type ArtifactType
	Name string
}

Artifact identifies one object created on the service by GenerateAccount, such as a role/schema (postgres) or user/database (mysql). The caller tracks the created artifacts and passes them back to DeleteArtifact to undo the creation on rollback.

type ArtifactType added in v0.18.0

type ArtifactType string
const (
	ArtifactRole     ArtifactType = "role"
	ArtifactSchema   ArtifactType = "schema"
	ArtifactUser     ArtifactType = "user"
	ArtifactDatabase ArtifactType = "database"
	ArtifactLogin    ArtifactType = "login" // SQL Server server-level login backing a database user
)

type GrantApplyResult added in v0.18.5

type GrantApplyResult struct {
	// GrantsApplied is the set of grants now in effect on the service for the
	// account, to be recorded in the binding metadata. Grants pending revoke are
	// still included; the caller removes them from the metadata after RevokeGrants
	// succeeds.
	GrantsApplied []types.BindingGrant
	// Granted lists the grants newly applied on the service by this call. If the
	// caller's metadata transaction is rolled back, these are the grants to
	// compensate via RevokeGrants.
	Granted []types.BindingGrant
	// PendingRevokes lists grants that are applied on the service but no longer
	// desired. The caller executes them via RevokeGrants after its metadata
	// transaction commits.
	PendingRevokes []types.BindingGrant
}

GrantApplyResult is the outcome of ApplyGrants. ApplyGrants only executes the additive part of a grant change; revokes are computed but not executed, so a caller can defer them until after its metadata transaction commits (a running app may see extra grants during the operation, but never loses a grant from an operation that is later rolled back).

type MysqlServiceBinding added in v0.17.5

type MysqlServiceBinding struct {
	*types.Logger
	// contains filtered or unexported fields
}

func (*MysqlServiceBinding) ApplyGrants added in v0.17.5

func (b *MysqlServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, bindingMetadata types.BindingMetadata,
	derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)

func (*MysqlServiceBinding) CloseService added in v0.17.5

func (b *MysqlServiceBinding) CloseService(ctx context.Context) error

func (*MysqlServiceBinding) DeleteArtifact added in v0.18.0

func (b *MysqlServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error

DeleteArtifact drops one user or database previously reported as created by GenerateAccount. The caller only passes back artifacts created during the current operation; pre-existing databases are never reported as created and so are never dropped here.

func (*MysqlServiceBinding) GenerateAccount added in v0.17.5

func (b *MysqlServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata, derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)

func (*MysqlServiceBinding) GetAccountEnv added in v0.18.7

func (b *MysqlServiceBinding) GetAccountEnv(ctx context.Context) ([]string, []string, error)

func (*MysqlServiceBinding) InitializeService added in v0.17.5

func (b *MysqlServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error

func (*MysqlServiceBinding) RevokeGrants added in v0.18.5

func (b *MysqlServiceBinding) RevokeGrants(ctx context.Context, account map[string]string,
	_ types.BindingMetadata, revokes, regrants []types.BindingGrant) error

func (*MysqlServiceBinding) RunCommand added in v0.17.5

func (b *MysqlServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)

type PostgresServiceBinding

type PostgresServiceBinding struct {
	*types.Logger
	// contains filtered or unexported fields
}

func (*PostgresServiceBinding) ApplyGrants added in v0.17.3

func (b *PostgresServiceBinding) ApplyGrants(ctx context.Context, account map[string]string, bindingMetadata types.BindingMetadata,
	derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)

func (*PostgresServiceBinding) CloseService added in v0.17.4

func (b *PostgresServiceBinding) CloseService(ctx context.Context) error

func (*PostgresServiceBinding) DeleteArtifact added in v0.18.0

func (b *PostgresServiceBinding) DeleteArtifact(ctx context.Context, artifact Artifact) error

DeleteArtifact drops one role or schema previously reported as created by GenerateAccount. The caller only passes back artifacts created during the current operation, so a newly created role cannot own pre-existing objects and a schema drop only removes objects created since the schema itself was created.

func (*PostgresServiceBinding) GenerateAccount

func (b *PostgresServiceBinding) GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata, derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)

func (*PostgresServiceBinding) GetAccountEnv added in v0.18.7

func (b *PostgresServiceBinding) GetAccountEnv(ctx context.Context) ([]string, []string, error)

func (*PostgresServiceBinding) InitializeService added in v0.17.3

func (b *PostgresServiceBinding) InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error

func (*PostgresServiceBinding) RevokeGrants added in v0.18.5

func (b *PostgresServiceBinding) RevokeGrants(ctx context.Context, account map[string]string,
	derivedFromMetadata types.BindingMetadata, revokes, regrants []types.BindingGrant) error

func (*PostgresServiceBinding) RunCommand added in v0.17.4

func (b *PostgresServiceBinding) RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)

type ServiceBinding

type ServiceBinding interface {
	// GetAccountEnv returns the names of the env values included in the
	// account info for this binding: the always-present params first, then the
	// optional params. This is static info: it must be callable on an
	// uninitialized instance, before InitializeService.
	GetAccountEnv(ctx context.Context) ([]string, []string, error)

	// Initialize the service with the given config. This is called when the service binding is created.
	InitializeService(ctx context.Context, logger *types.Logger, serviceConfig map[string]string, runtime ServiceBindingRuntime) error

	// Close the service connection. This is called when the service binding is no longer needed.
	CloseService(ctx context.Context) error

	// Generate the account based on the binding config. This is called once when the binding is created, after the service is initialized.
	// The account and its backing artifacts (role/schema, user/database) are created on the endpoint specified in the service config
	// and are persisted immediately. The artifacts that were created are returned in creation order; pre-existing objects that the
	// account merely references (like the base binding's schema for a derived binding) must not be included. If creation fails
	// partway and already-created artifacts cannot be rolled back internally, they are returned along with the error so the
	// caller can clean them up.
	GenerateAccount(ctx context.Context, bindingId, bindingPath string, bindingMetadata types.BindingMetadata,
		derivedFromMetadata *types.BindingMetadata, isStaging bool) (map[string]string, []Artifact, error)

	// Delete one artifact previously reported as created by GenerateAccount. The caller only passes back artifacts
	// created during the current operation; the implementation must delete only the named artifact.
	DeleteArtifact(ctx context.Context, artifact Artifact) error

	// Apply the grants to the account. This is called when the binding is created, after the account is generated.
	// It can be called again if the grants are changed. Only new grants are executed (and persisted immediately);
	// grants that need to be removed are returned in PendingRevokes without being executed, for the caller to run
	// via RevokeGrants once its metadata transaction commits.
	ApplyGrants(ctx context.Context, account map[string]string,
		bindingMetadata, derivedFromMetadata types.BindingMetadata, reapplyAll bool) (GrantApplyResult, error)

	// Revoke the given grants from the account, then re-apply the regrants. Called with the PendingRevokes of an
	// earlier ApplyGrants after the caller's metadata transaction commits (regrants = the grants that remain
	// desired), or with the Granted list to compensate when the transaction is rolled back (regrants = the grants
	// that were applied before the operation). The regrants restore privileges that an overlapping revoke removes
	// (e.g. revoking read:t1 while read:* remains would otherwise drop SELECT on t1). Revoking a grant that is not
	// currently applied must be harmless.
	RevokeGrants(ctx context.Context, account map[string]string,
		derivedFromMetadata types.BindingMetadata, revokes, regrants []types.BindingGrant) error

	// Run a command on the endpoint specified in the service config as the binding account.
	RunCommand(ctx context.Context, bindingMetadata types.BindingMetadata, command string) (map[string]any, error)
}

func NewMysqlServiceBinding added in v0.17.5

func NewMysqlServiceBinding() ServiceBinding

func NewPostgresServiceBinding

func NewPostgresServiceBinding() ServiceBinding

type ServiceBindingBuilder

type ServiceBindingBuilder func() ServiceBinding

func GetServiceBinding added in v0.18.7

func GetServiceBinding(name string) (ServiceBindingBuilder, bool)

GetServiceBinding returns the builder registered for a service type.

type ServiceBindingRuntime added in v0.18.0

type ServiceBindingRuntime struct {
	LocalhostBindingHostname string
}

Jump to

Keyboard shortcuts

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