Documentation
¶
Overview ¶
Package cueenv builds the environment slice a cue/load or mod/modconfig call consults when the caller wants to override CUE_REGISTRY or CUE_CACHE_DIR for that one operation.
The override is a fresh copy of the process environment with the chosen variables replaced or appended; the process environment itself is never written (no os.Setenv), so a long-running consumer can run overlapping loads with different registries. When nothing is overridden the result is nil, which both load.Config.Env and modconfig.Config.Env document as "use the process environment", so the SDK reads it exactly as it would without the kernel in between.
It also owns the kernel's shared registry client (Registry): one resolver and OCI transport per Kernel, with a fresh module cache for each operation (Registry.Operation), so a fetch failure is never remembered past the operation that saw it.
This package is under opm/internal/ so every package under opm/ that touches cue/load (the file and registry loaders, the schema loader and the render stage) shares one implementation.
Index ¶
- func NewClient(env []string) (*modregistry.Client, error)
- func Override(registry, cacheDir string) []string
- type Operation
- func (o *Operation) Env() []string
- func (o *Operation) Fetch(ctx context.Context, mv module.Version) (module.SourceLoc, error)
- func (o *Operation) FetchFromCache(mv module.Version) (module.SourceLoc, error)
- func (o *Operation) Init() error
- func (o *Operation) ModFile(ctx context.Context, mv module.Version) (*modfile.File, error)
- func (o *Operation) ModuleVersions(ctx context.Context, mpath string) ([]string, error)
- type Registry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(env []string) (*modregistry.Client, error)
NewClient builds a registry client the way modconfig.NewRegistry builds the one inside its module cache: a resolver for env (nil reads the process environment) and a modregistry client over it. It is the constructor a Registry uses unless a test replaces it.
func Override ¶
Override returns nil when both registry and cacheDir are empty, and otherwise a copy of os.Environ() in which each non-empty argument replaces the existing CUE_REGISTRY / CUE_CACHE_DIR entry or is appended when the variable is not set. An empty argument leaves its variable as the process has it.
Types ¶
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation is one kernel operation's registry: a modconfig.CachedRegistry over the Registry's shared client and a module cache of its own. Its setup runs once, on first use; an error from it is that operation's alone. It is safe for concurrent use within the operation.
func (*Operation) Env ¶
Env returns the environment slice this operation was started with: nil when the Registry has no mapping (the process environment), else a copy of the process environment with CUE_REGISTRY replaced. A caller passes it as load.Config.Env beside the registry, so one operation reads one environment.
func (*Operation) FetchFromCache ¶
FetchFromCache implements modconfig.CachedRegistry. A miss is an error here and is normal during resolution, so no error drops the client.
func (*Operation) Init ¶
Init sets the operation up: it takes the shared client (building it when there is none) and opens the module cache. The error, a client construction error or an unusable cache directory, is the one modconfig.NewRegistry would return for the same environment.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a Kernel's one registry client: the resolver and the OCI transport behind it (a *modregistry.Client), built on first use and shared by every operation started from it. It holds no module cache. Each operation gets its own (Registry.Operation), because CUE's module cache keeps every fetch error with the module version it was for, and a cache shared for the life of a long-running process would serve one transient failure to every later fetch of that version.
The client is built from the registry mapping the Registry was given (an empty mapping reads CUE_REGISTRY from the process environment) and the credentials configuration, both read when the client is built. A construction error is returned to the operation that needed the client and is not kept: the next operation tries again. A registry call that fails (Fetch, ModFile or ModuleVersions; not a FetchFromCache miss, which is normal during resolution) drops the client, so the next operation builds a fresh resolver and transport and nothing the transport remembered (it keeps a credentials read error per host) outlives that operation.
A Registry is safe for concurrent use.
func NewRegistry ¶
NewRegistry returns a Registry for mapping (CUE_REGISTRY syntax; empty reads the process CUE_REGISTRY). It builds nothing and reads nothing.
func (*Registry) Operation ¶
Operation starts one operation: its environment is read now (Override of the mapping), and the returned registry is what that operation hands to every load and fetch it runs. On its first use it takes the shared client, building it if needed, and wraps it in a fresh module cache over the cache directory that environment names (CUE_CACHE_DIR, else the user cache directory's cue subdirectory, the rule cue itself uses).
func (*Registry) SetHooksForTest ¶
func (r *Registry) SetHooksForTest(newClient func(env []string) (*modregistry.Client, error), wrapOp func(modconfig.CachedRegistry) modconfig.CachedRegistry)
SetHooksForTest replaces the client constructor and wraps each operation's registry, so a test can count constructions and calls. Either may be nil to keep the real behaviour. It is for tests only and must be called before the Registry is used.