envsource

package
v0.0.0-...-611bec0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 32 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Builtin = "builtin"
	Dotenv  = "dotenv"
)
View Source
const (
	RootRegistrations records.Root = "envsources"
	RootStatus        records.Root = "envsourcestatus"
	RootDigestKey     records.Root = "envsourcedigestkey"
)
View Source
const FolderPlaceholder = "{folder}"
View Source
const VariableNamePattern = `^[^#\x00-\x1f\x7f]*$`

Variables

View Source
var (
	ErrExists = errors.New("envsource: the env source already has that key")

	ErrReadOnly = errors.New("envsource: ocel may not write into the env source")

	ErrAwaitingApproval = errors.New("envsource: the env source queued the write for approval")

	ErrChangedSinceRead = errors.New("envsource: the value changed in the env source since ocel last read it")

	ErrNotInFolder = errors.New("envsource: the env source keeps no such key in that folder itself")
)

Functions

func ClearProvenance

func ClearProvenance(ctx context.Context, store variablestore.Store, scope variablestore.Scope) error

func DedupeKey

func DedupeKey(ctx context.Context, store variablestore.Store, scope variablestore.Scope, descriptor Descriptor) (string, error)

func ForgetDigestKey

func ForgetDigestKey(ctx context.Context, store records.Store, tier environment.Tier) error

func ForgetProject

func ForgetProject(ctx context.Context, store variablestore.Store, tier environment.Tier, project string) error

func ReadCredentials

func ReadCredentials(ctx context.Context, store variablestore.Store, scope variablestore.Scope, descriptor Descriptor) ([]string, error)

func RestoreRegistration

func RestoreRegistration(ctx context.Context, store variablestore.Store, tier environment.Tier, replacing Registration, previous *Registration) error

func ScheduledProjects

func ScheduledProjects(ctx context.Context, store records.Store, tier environment.Tier) ([]string, error)

func SetCommand

func SetCommand(tier environment.Tier, name string) string

func Unregister

func Unregister(ctx context.Context, store variablestore.Store, tier environment.Tier, project string) error

Types

type Config

type Config struct {
	Doc     string
	Options any
	// contains filtered or unexported fields
}

func (*Config) NamedAlone

func (c *Config) NamedAlone() bool

type CopyResult

type CopyResult struct {
	EnvSource string
	Present   []variablestore.Cell
	Written   []variablestore.Cell
	Unchanged []variablestore.Cell
	Removed   []variablestore.Cell
	Refused   map[variablestore.Cell]string
	// contains filtered or unexported fields
}

func CopyValues

func CopyValues(ctx context.Context, store variablestore.Store, scope variablestore.Scope, listed []variablestore.Metadata, key DigestKey, envSource string, readAt time.Time, read map[variablestore.Cell]Value, folders []string, keep []variablestore.Cell) (CopyResult, error)

type Credential

type Credential interface {
	// contains filtered or unexported methods
}

func AccessToken

func AccessToken(token string) Credential

func IdentityCredential

func IdentityCredential(identityID string, proveIdentity func(ctx context.Context, audience string) (IdentityProof, error)) Credential

func UniversalCredential

func UniversalCredential(clientID, clientSecret string) Credential

type CredentialError

type CredentialError struct {
	Variable string
	Unset    bool
	Reason   string
}

func (*CredentialError) Error

func (e *CredentialError) Error() string

type Descriptor

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

func NewDescriptor

func NewDescriptor(kind string, options json.RawMessage) (Descriptor, error)

func NewDevDescriptor

func NewDevDescriptor(kind string, options json.RawMessage) (Descriptor, error)

func (Descriptor) CanCreate

func (d Descriptor) CanCreate() bool

func (Descriptor) CanUpdate

func (d Descriptor) CanUpdate() bool

func (Descriptor) CredentialVariables

func (d Descriptor) CredentialVariables() []string

func (Descriptor) ID

func (d Descriptor) ID() string

func (Descriptor) Kind

func (d Descriptor) Kind() string

func (Descriptor) MarshalJSON

func (d Descriptor) MarshalJSON() ([]byte, error)

func (Descriptor) Open

func (d Descriptor) Open(dir string, lookupEnv func(string) (string, bool)) (Source, error)

func (Descriptor) Options

func (d Descriptor) Options() json.RawMessage

func (Descriptor) Reading

func (d Descriptor) Reading() Reading

func (Descriptor) RefuseLogin

func (d Descriptor) RefuseLogin(login Login) error

func (*Descriptor) UnmarshalJSON

func (d *Descriptor) UnmarshalJSON(data []byte) error

type DigestKey

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

func EnsureDigestKey

func EnsureDigestKey(ctx context.Context, store variablestore.Store, tier environment.Tier) (DigestKey, error)

type ExecOptions

type ExecOptions struct {
	Command []string `json:"command" doc:"The command and its arguments. {folder} in an argument becomes the variables folder being read."`
	Format  Format   `json:"format" enum:"json,dotenv" doc:"What the command prints: a JSON object of names to values, or KEY=VALUE lines."`
}

func (ExecOptions) Doc

func (ExecOptions) Doc() string

type Format

type Format string
const (
	FormatJSON   Format = "json"
	FormatDotenv Format = "dotenv"
)

type IdentityAuth

type IdentityAuth struct {
	IdentityID string `json:"identityId" doc:"The id of the Infisical machine identity to sign in as."`
}

func (IdentityAuth) Doc

func (IdentityAuth) Doc() string

type IdentityProof

type IdentityProof struct {
	SignedRequest *SignedRequest
	IDToken       string
}

type InfisicalAuth

type InfisicalAuth struct {
	Universal *UniversalAuth `json:"universal,omitempty" doc:"Universal Auth: a client id and client secret, each an ocel variable."`
	Identity  *IdentityAuth  `json:"identity,omitempty" doc:"This target's own cloud identity signs in, so no secret is stored."`
}

func (InfisicalAuth) Doc

func (InfisicalAuth) Doc() string

func (InfisicalAuth) Shorthands

func (InfisicalAuth) Shorthands() []string

func (*InfisicalAuth) Variables

func (a *InfisicalAuth) Variables() []string

type InfisicalOptions

type InfisicalOptions struct {
	Project     string         `json:"project" doc:"The id of the Infisical project the values live in."`
	Environment string         `json:"environment" doc:"The slug of the Infisical environment this tier reads, such as prod."`
	Path        string         `json:"path,omitempty" doc:"The Infisical folder the project's values sit under. Left off, the environment's root, /."`
	Host        string         `json:"host,omitempty" doc:"The base URL of a self-hosted Infisical. Left off, https://app.infisical.com."`
	Auth        *InfisicalAuth `` /* 136-byte string literal not displayed */
	Write       WritePolicy    `` /* 182-byte string literal not displayed */
}

func (InfisicalOptions) Doc

func (InfisicalOptions) Doc() string

func (InfisicalOptions) ID

func (o InfisicalOptions) ID() string

func (InfisicalOptions) Normalize

func (o InfisicalOptions) Normalize() InfisicalOptions

type Kind

type Kind struct {
	Name     string
	Deployed *Config
	Dev      *Config
}

func Kinds

func Kinds() []Kind

type Login

type Login struct {
	ProveIdentity func(ctx context.Context, audience string) (IdentityProof, error)
	Client        *http.Client
}

type OptionError

type OptionError struct {
	Field  string
	Reason string
}

func (*OptionError) Error

func (e *OptionError) Error() string

type Reading

type Reading int
const (
	ReadingOwnStore Reading = iota
	ReadingWhereOcelRuns
	ReadingOnSchedule
)

type Registration

type Registration struct {
	Project    string     `json:"project"`
	Descriptor Descriptor `json:"descriptor"`
	Folders    []string   `json:"folders"`
	DedupeKey  string     `json:"dedupeKey"`
}

func Register

func Register(ctx context.Context, store variablestore.Store, tier environment.Tier, registration Registration) (Registration, error)

func Registered

func Registered(ctx context.Context, store records.Store, tier environment.Tier, project string) (Registration, bool, error)

func Registrations

func Registrations(ctx context.Context, store records.Store, tier environment.Tier) ([]Registration, error)

func (Registration) Credentials

func (r Registration) Credentials() []variablestore.Cell

type SignedRequest

type SignedRequest struct {
	Method string
	URL    string
	Header http.Header
	Body   []byte
}

type Source

type Source interface {
	ID() string
	Read(ctx context.Context, folders []string) (map[variablestore.Cell]Value, error)
	Create(ctx context.Context, at variablestore.Cell, value []byte, description string) error
	Update(ctx context.Context, at variablestore.Cell, value []byte, copiedVersion string) error
	URL(at variablestore.Cell) string
}

func NewFixed

func NewFixed(id string, values map[variablestore.Cell]Value) Source

func NewInfisical

func NewInfisical(options InfisicalOptions, credential Credential, client *http.Client) Source

type Status

type Status struct {
	EnvSource           string            `json:"envSource"`
	LastAttemptAt       time.Time         `json:"lastAttemptAt,omitzero"`
	LastSuccessAt       time.Time         `json:"lastSuccessAt,omitzero"`
	LastError           string            `json:"lastError,omitempty"`
	ConsecutiveFailures int               `json:"consecutiveFailures,omitempty"`
	RetryAt             time.Time         `json:"retryAt,omitzero"`
	URLs                map[string]string `json:"urls,omitempty"`
}

func StatusOf

func StatusOf(ctx context.Context, store variablestore.Store, tier environment.Tier, registration Registration) (Status, error)

type Sync

type Sync struct {
	Store    variablestore.Store
	Tier     environment.Tier
	Login    Login
	Now      func() time.Time
	Interval time.Duration
	// contains filtered or unexported fields
}

func (*Sync) CopyProject

func (s *Sync) CopyProject(ctx context.Context, registration Registration) (CopyResult, error)

func (*Sync) CopyProjectFrom

func (s *Sync) CopyProjectFrom(ctx context.Context, registration Registration, source Source) (CopyResult, error)

func (*Sync) CopyScheduled

func (s *Sync) CopyScheduled(ctx context.Context) error

func (*Sync) CopyScheduledEveryInterval

func (s *Sync) CopyScheduledEveryInterval(ctx context.Context, report func(error))

func (*Sync) Open

func (s *Sync) Open(ctx context.Context, registration Registration) (Source, error)

type Tiers

type Tiers struct {
	Production Descriptor
	Preview    Descriptor
	Dev        Descriptor
}

func DefaultTiers

func DefaultTiers() Tiers

type UndecodableRegistrationError

type UndecodableRegistrationError struct {
	Project string
	Kind    string
	Err     error
}

func (*UndecodableRegistrationError) Error

func (*UndecodableRegistrationError) Unwrap

func (e *UndecodableRegistrationError) Unwrap() error

type UniversalAuth

type UniversalAuth struct {
	ClientID     Variable `json:"clientId" doc:"The ocel variable containing the Universal Auth client id."`
	ClientSecret Variable `json:"clientSecret" doc:"The ocel variable containing the Universal Auth client secret."`
}

func (UniversalAuth) Doc

func (UniversalAuth) Doc() string

type Value

type Value struct {
	Plaintext []byte
	Version   string
}

type Variable

type Variable struct {
	Name string `json:"$env"`
}

type WritePolicy

type WritePolicy string
const (
	WriteNever   WritePolicy = "never"
	WriteMissing WritePolicy = "missing"
	WriteValues  WritePolicy = "values"
)

Jump to

Keyboard shortcuts

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