Help us shape the future of Go! Take the 2026 Go Developer Survey

application

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRuntimeAPIURL                   = "https://baseharbor-secrets:8443"
	RuntimeIdentityContainerTokenPath      = "/run/secrets/baseharbor-runtime-token"
	RuntimeIdentityContainerCAPath         = "/run/secrets/baseharbor-runtime-ca"
	RuntimeIdentityContainerClientCertPath = "/run/secrets/baseharbor-runtime-client-cert"
	RuntimeIdentityContainerClientKeyPath  = "/run/secrets/baseharbor-runtime-client-key"
	SecretFileBindingContainerDir          = "/run/baseharbor/bindings/secrets"
)
View Source
const CurrentVersion = 1
View Source
const (
	LastBackupMetadataVersion = 1
)
View Source
const (
	LastRecoveryMetadataVersion = 1
)
View Source
const (
	LastUpdateMetadataVersion = 1
)
View Source
const MaxPostgresBackupBytes int64 = 512 << 20
View Source
const RepositoryManifestName = "baseharbor.yaml"

Variables

View Source
var ErrExists = errors.New("application already exists")
View Source
var ErrNoBackupMetadata = errors.New("no application backup metadata recorded")
View Source
var ErrNoRecoveryMetadata = errors.New("no application recovery metadata recorded")
View Source
var ErrNoUpdateMetadata = errors.New("no application update metadata recorded")
View Source
var ErrRuntimeAPIURL = errors.New("application runtime API URL is invalid")
View Source
var ErrRuntimeDefinitionChanged = errors.New("application runtime definition differs from the BaseHarbor-managed definition")
View Source
var ErrRuntimeNotApplied = errors.New("application runtime has not been applied")
View Source
var ErrUnsupportedService = errors.New("application contains services that are not yet supported by apply")
View Source
var ErrWorkloadComposeAmbiguous = errors.New("multiple application Compose files found")
View Source
var ErrWorkloadComposeNotFound = errors.New("application Compose file not found")

Functions

func ApplicationBackendNetworkName

func ApplicationBackendNetworkName(m Manifest) string

ApplicationBackendNetworkName returns the stable Docker/Podman network name used by BaseHarbor-managed backend services for one application environment.

Application-owned workloads may attach to this network as an additional external network without replacing their own Compose networks. The current Compose provider maps the logical backend network to the deterministic project default network.

func CapabilityBindings added in v0.4.1

func CapabilityBindings(m Manifest) ([]capability.Binding, error)

func CheckManagedRuntimeDefinition

func CheckManagedRuntimeDefinition(files RuntimeFiles, m Manifest) error

CheckManagedRuntimeDefinition prevents destructive operations from trusting a locally modified Compose file. BaseHarbor may only mutate the runtime shape it originally generated and understands for the current manifest.

func CheckRuntimePermissions

func CheckRuntimePermissions(files RuntimeFiles) error

func CheckSupportedRuntimeServices

func CheckSupportedRuntimeServices(m Manifest) error

func ConfiguredRuntimeAPIURL

func ConfiguredRuntimeAPIURL() (string, bool, error)

func EnsureRuntimeIdentity

func EnsureRuntimeIdentity(m Manifest, files RuntimeFiles) (string, error)

func ExpectedPersistentRuntimeResources

func ExpectedPersistentRuntimeResources(m Manifest) []bhruntime.ProjectResource

func ExpectedPostgresRuntimeResources

func ExpectedPostgresRuntimeResources(m Manifest) []bhruntime.ProjectResource

ExpectedPostgresRuntimeResources is kept for compatibility with the first runtime milestone. New lifecycle code should use ExpectedRuntimeResources.

func ExpectedRuntimeResources

func ExpectedRuntimeResources(m Manifest) []bhruntime.ProjectResource

func FindRepositoryManifest

func FindRepositoryManifest(start string) (string, error)

FindRepositoryManifest returns the nearest baseharbor.yaml from start upward. This lets developers run baha from nested directories inside an application repository.

func GenerateSecretValue

func GenerateSecretValue(generation SecretGeneration) ([]byte, error)

func HasExplicitWorkload added in v0.3.0

func HasExplicitWorkload(m Manifest) bool

HasExplicitWorkload reports whether the repository manifest explicitly declares a Compose workload. Workload-only applications must be explicit so validation never guesses based on files outside the manifest.

func HasManagedRuntimeServices added in v0.3.0

func HasManagedRuntimeServices(m Manifest) bool

HasManagedRuntimeServices reports whether BaseHarbor owns a materialized PostgreSQL or Valkey runtime for the application. Managed secrets currently require one of those services and therefore do not form a standalone runtime.

func HasRequiredFileSecrets

func HasRequiredFileSecrets(m Manifest) bool

func InspectOwnedRuntimeResources

func InspectOwnedRuntimeResources(ctx context.Context, compose bhruntime.Compose, m Manifest) ([]bhruntime.ProjectResource, error)

func MaterializeRuntimeIdentityWorkloadOverride

func MaterializeRuntimeIdentityWorkloadOverride(m Manifest, workload WorkloadFiles, files RuntimeFiles, plan WorkloadBindingPlan) (string, bool, error)

MaterializeRuntimeIdentityWorkloadOverride adds only the protected bindings that selected application services actually consume. Runtime identity is injected through ordinary environment file paths plus Compose secret mounts; applications do not configure certificates, keys or broker topology.

func PostgresInstanceNames

func PostgresInstanceNames(m Manifest) []string

func ReallocateRuntimePorts

func ReallocateRuntimePorts(m Manifest, files RuntimeFiles) error

ReallocateRuntimePorts replaces only the generated host-port assignments for an already materialized application runtime. Credentials, databases, volumes and other persisted runtime values are left unchanged. This is used when the container runtime proves that a probed loopback port was claimed between allocation and the actual container bind.

func ReconcileReferenceProviderRegistry added in v0.4.2

func ReconcileReferenceProviderRegistry(m Manifest) error

func RedisInstanceNames

func RedisInstanceNames(m Manifest) []string

func ReleaseApplicationProviderRegistry added in v0.4.2

func ReleaseApplicationProviderRegistry(m Manifest) error

func RequiredSecretNames

func RequiredSecretNames(m Manifest) []string

func RequiredSecretUsesFileBinding

func RequiredSecretUsesFileBinding(name string) bool

func ResolveCapabilityResources added in v0.4.1

func ResolveCapabilityResources(contract PortableContract) ([]capability.Resource, error)

func ResolveWorkloadCompose

func ResolveWorkloadCompose(repositoryRoot string, m Manifest) (string, bool, error)

func ResourceExists

func ResourceExists(resources []bhruntime.ProjectResource, kind string) bool

func ResourceNamedExists

func ResourceNamedExists(resources []bhruntime.ProjectResource, wanted bhruntime.ProjectResource) bool

func RestorePostgresInstances

func RestorePostgresInstances(ctx context.Context, runtime PostgresBackupRuntime, m Manifest, files RuntimeFiles, backups []PostgresBackup) error

func RevokeRuntimeIdentity

func RevokeRuntimeIdentity(m Manifest, files RuntimeFiles) error

func RotateRuntimeIdentity

func RotateRuntimeIdentity(m Manifest, files RuntimeFiles) error

func RuntimeComposeYAML

func RuntimeComposeYAML(m Manifest) (string, error)

func RuntimeIdentityRevoked

func RuntimeIdentityRevoked(files RuntimeFiles) bool

func RuntimeIdentityRevokedPath

func RuntimeIdentityRevokedPath(files RuntimeFiles) string

func RuntimeIdentityTokenPath

func RuntimeIdentityTokenPath(files RuntimeFiles) string

func RuntimeMTLSHostDir

func RuntimeMTLSHostDir(files RuntimeFiles) string

func RuntimeProjectName

func RuntimeProjectName(m Manifest) string

func SecretFileContainerPath

func SecretFileContainerPath(name string) string

func SecretFileHostDir

func SecretFileHostDir(files RuntimeFiles) string

func SecretFileHostPath

func SecretFileHostPath(files RuntimeFiles, name string) string

func ValidatePostgresBackupSet

func ValidatePostgresBackupSet(m Manifest, backups []PostgresBackup) error

func VerifyPostgresRuntime

func VerifyPostgresRuntime(ctx context.Context, compose bhruntime.Compose, m Manifest, files RuntimeFiles) error

func VerifyValkeyRuntime

func VerifyValkeyRuntime(ctx context.Context, compose bhruntime.Compose, m Manifest, files RuntimeFiles) error

func WorkloadProjectName

func WorkloadProjectName(m Manifest) string

Types

type Action

type Action struct {
	Kind        string
	Resource    string
	Description string
}

type BackupMetadata added in v0.3.0

type BackupMetadata struct {
	Version           int       `json:"version"`
	Application       string    `json:"application"`
	Environment       string    `json:"environment"`
	CreatedAt         time.Time `json:"created_at"`
	ArchivePath       string    `json:"archive_path"`
	PostgresResources []string  `json:"postgres_resources,omitempty"`
	IncludesSecrets   bool      `json:"includes_secrets"`
}

func (BackupMetadata) Validate added in v0.3.0

func (m BackupMetadata) Validate() error

type CapabilityKind added in v0.4.0

type CapabilityKind = capability.Kind

CapabilityKind and CapabilityRequirement remain aliases in the application package so existing v0.4 callers keep their source-compatible contract while the reusable capability domain moves into the shared core.

const (
	CapabilitySQL      CapabilityKind = capability.SQL
	CapabilityKeyValue CapabilityKind = capability.KeyValue
)

type CapabilityRequirement added in v0.4.0

type CapabilityRequirement = capability.Requirement

type Manifest

type Manifest struct {
	Version     int
	Name        string
	Environment string
	Services    Services
	Secrets     SecretRequirements
	Workload    WorkloadConfig
}

Manifest is the declarative application backend request understood by BaseHarbor.

func LoadManifestFile

func LoadManifestFile(path string) (Manifest, error)

func New

func New(name, environment string, postgres, redis, secrets bool) Manifest

func ParseYAML

func ParseYAML(input string) (Manifest, error)

ParseYAML parses the intentionally small v1 manifest grammar without adding a runtime dependency.

func WithGeneratedSecret

func WithGeneratedSecret(m Manifest, name, generationType string, size int) Manifest

func WithPostgresInstances

func WithPostgresInstances(m Manifest, names ...string) Manifest

func WithRedisInstances

func WithRedisInstances(m Manifest, names ...string) Manifest

func WithRequiredSecrets

func WithRequiredSecrets(m Manifest, names ...string) Manifest

func WithWorkload

func WithWorkload(m Manifest, compose string, services ...string) Manifest

func (Manifest) Validate

func (m Manifest) Validate() error

func (Manifest) YAML

func (m Manifest) YAML() string

type Plan

type Plan struct {
	Application string
	Environment string
	Actions     []Action
}

func BuildPlan

func BuildPlan(m Manifest) (Plan, error)

type PortableContract added in v0.4.0

type PortableContract struct {
	Application  string
	Capabilities []CapabilityRequirement
	Secrets      SecretContract
}

PortableContract is the provider-neutral application requirement view used as the seam between manifest compatibility and runtime/capability providers.

Deployment context such as environment, Compose paths, host ports, TLS source directories and provider object names must not be added here. Those belong to deployment state or provider-specific configuration.

func PortableContractFromManifest added in v0.4.0

func PortableContractFromManifest(m Manifest) (PortableContract, error)

PortableContractFromManifest translates the current manifest v1 compatibility surface into provider-neutral requirements without changing manifest behavior. The translation is deliberately one-way for now: v0.4 can evolve a future contract schema while existing v0.3 manifests continue to load unchanged.

type PostgresBackup

type PostgresBackup struct {
	Instance string
	SQL      []byte
}

func DumpPostgresInstances

func DumpPostgresInstances(ctx context.Context, runtime PostgresBackupRuntime, m Manifest, files RuntimeFiles) ([]PostgresBackup, error)

type PostgresBackupRuntime

type PostgresBackupRuntime interface {
	ExecProject(ctx context.Context, project, composeFile, envFile, service string, args ...string) (string, error)
	ExecProjectInput(ctx context.Context, project, composeFile, envFile string, input []byte, service string, args ...string) (string, error)
}

type RecoveryMetadata added in v0.3.0

type RecoveryMetadata struct {
	Version         int       `json:"version"`
	Application     string    `json:"application"`
	Environment     string    `json:"environment"`
	RestoredAt      time.Time `json:"restored_at"`
	BackupCreatedAt time.Time `json:"backup_created_at"`
	ArchivePath     string    `json:"archive_path"`
}

func (RecoveryMetadata) Validate added in v0.3.0

func (m RecoveryMetadata) Validate() error

type RuntimeContract

type RuntimeContract struct {
	Env         string
	BindingsDir string
	Metadata    string
}

func EnsureRuntimeContract

func EnsureRuntimeContract(m Manifest, files RuntimeFiles) (RuntimeContract, error)

type RuntimeFiles

type RuntimeFiles struct {
	Dir            string
	Compose        string
	Env            string
	ApplicationEnv string
	Bindings       string
}

func EnsurePostgresRuntime

func EnsurePostgresRuntime(store Store, m Manifest) (RuntimeFiles, error)

EnsurePostgresRuntime is kept for callers from the first runtime milestone.

func EnsureRuntime

func EnsureRuntime(store Store, m Manifest) (RuntimeFiles, error)

func ExistingRuntimeFiles

func ExistingRuntimeFiles(store Store, m Manifest) (RuntimeFiles, error)

type SecretContract added in v0.4.0

type SecretContract struct {
	Managed  bool
	Required []SecretRequirement
}

SecretContract describes secret intent without selecting a concrete secret backend or delivery mechanism. Required values remain names/generation intent only; provider credentials and provider object identifiers never belong here.

type SecretGeneration

type SecretGeneration struct {
	Type   string
	Length int
	Bytes  int
}

type SecretRequirement

type SecretRequirement struct {
	Name     string
	Generate *SecretGeneration
}

func GeneratedSecretRequirements

func GeneratedSecretRequirements(m Manifest) []SecretRequirement

func SecretRequirementByName

func SecretRequirementByName(m Manifest, name string) (SecretRequirement, bool)

type SecretRequirements

type SecretRequirements struct {
	Required []SecretRequirement
}

SecretRequirements declares application-owned secret requirements. Values never belong in the manifest. Generate only expresses explicit intent for BaseHarbor to create a missing value directly in the managed secret backend.

type ServiceBinding added in v0.3.0

type ServiceBinding struct {
	Kind     string
	Instance string
	Host     string
	Port     string
	Database string
	Username string
	Password string
	URI      string
}

ServiceBinding is the provider-neutral information needed by developer access actions. Callers should prefer these fields over runtime/container names so a later provider can satisfy the same action model.

func ResolveServiceBinding added in v0.3.0

func ResolveServiceBinding(files RuntimeFiles, kind, instance string) (ServiceBinding, error)

ResolveServiceBinding loads an already-materialized owner-only service binding. It never creates or rotates credentials.

type ServiceInstance

type ServiceInstance struct{}

ServiceInstance is the stable logical identity of one requested backend service. The empty v1 shape is intentional: topology remains a BaseHarbor implementation detail and future intent such as availability can evolve here.

type Services

type Services struct {
	Postgres          bool
	Redis             bool
	Secrets           bool
	PostgresInstances map[string]ServiceInstance
	RedisInstances    map[string]ServiceInstance
}

type Store

type Store struct {
	Root string
}

func DefaultStore

func DefaultStore() Store

func (Store) Create

func (s Store) Create(m Manifest) (string, error)

func (Store) Delete

func (s Store) Delete(name string) error

func (Store) LastBackup added in v0.3.0

func (s Store) LastBackup(applicationName string) (BackupMetadata, error)

func (Store) LastRecovery added in v0.3.0

func (s Store) LastRecovery(applicationName string) (RecoveryMetadata, error)

func (Store) LastUpdate added in v0.3.0

func (s Store) LastUpdate(applicationName string) (UpdateMetadata, error)

func (Store) List

func (s Store) List() ([]Manifest, error)

func (Store) Load

func (s Store) Load(name string) (Manifest, string, error)

func (Store) RecordLastBackup added in v0.3.0

func (s Store) RecordLastBackup(metadata BackupMetadata) error

func (Store) RecordLastRecovery added in v0.3.0

func (s Store) RecordLastRecovery(metadata RecoveryMetadata) error

func (Store) RecordLastUpdate added in v0.3.0

func (s Store) RecordLastUpdate(metadata UpdateMetadata) error

func (Store) Sync

func (s Store) Sync(m Manifest) (string, error)

Sync stores a canonical internal copy of a repository manifest while preserving already materialized runtime state. The repository file remains authoritative.

type UpdateMetadata added in v0.3.0

type UpdateMetadata struct {
	Version         int       `json:"version"`
	Application     string    `json:"application"`
	Environment     string    `json:"environment"`
	UpdatedAt       time.Time `json:"updated_at"`
	Branch          string    `json:"branch"`
	Upstream        string    `json:"upstream"`
	FromRevision    string    `json:"from_revision"`
	ToRevision      string    `json:"to_revision"`
	Result          string    `json:"result"`
	BackupPath      string    `json:"backup_path,omitempty"`
	BackupCreatedAt time.Time `json:"backup_created_at,omitempty"`
}

func (UpdateMetadata) Validate added in v0.3.0

func (m UpdateMetadata) Validate() error

type WorkloadBindingPlan

type WorkloadBindingPlan struct {
	RuntimeIdentityServices []string
	FileSecretsByService    map[string][]string
}

func (WorkloadBindingPlan) Empty

func (p WorkloadBindingPlan) Empty() bool

type WorkloadConfig

type WorkloadConfig struct {
	Compose  string
	Services []string
}

WorkloadConfig optionally disambiguates an existing application Compose workload. Empty values keep the common case convention-based: BaseHarbor may detect one unambiguous Compose file and attach all of its services.

type WorkloadFiles

type WorkloadFiles struct {
	RepositoryRoot string
	Compose        string
	Override       string
	Services       []string
	Project        string
	Partial        bool
}

func MaterializeWorkload

func MaterializeWorkload(repositoryRoot string, m Manifest, runtime RuntimeFiles) (WorkloadFiles, bool, error)

Jump to

Keyboard shortcuts

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