bindings

package
v0.18.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const BindingHostnameDisable = "disable"

Variables

View Source
var (
	ServiceBindings = map[string]ServiceBindingBuilder{}
)

Functions

func RegisterServiceBinding

func RegisterServiceBinding(name string, serviceBindingBuilder ServiceBindingBuilder)

RegisterServiceBinding registers a service binding

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"
)

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) 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) 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 {
	// 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

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