context

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValues

func GetValues(providers []Provider, keys []string) (map[string]any, error)

GetValues extracts the context values from a list of providers

Types

type EnvContextReader

type EnvContextReader struct {
	VarPrefix string
}

EnvContextReader is a context provider that reads context data from environment variables. In order to provide some isolation, values are (optionally but recommended) prefixed with a string (defaults to "AMPEL_").

The envvar context reader will look for the context values by reading an environment variable formed by the prefix, an underscore and uppercasing it all. For example, if the context expects a value called "test", the provider will look for a an environment var called AMPEL_TEST.

func NewEnvContextReader

func NewEnvContextReader() *EnvContextReader

func (*EnvContextReader) GetContextMap

func (ecr *EnvContextReader) GetContextMap(keys []string) (map[string]any, error)

func (*EnvContextReader) GetContextValue

func (ecr *EnvContextReader) GetContextValue(key string) (any, error)

type MapAnyProvider

type MapAnyProvider map[string]any

MapAnyProvider adds the Provider interface functions on top of a standard map the idea is that anything that can provide a map[string]any can create a provider very easy.

func (*MapAnyProvider) GetContextMap

func (mapr *MapAnyProvider) GetContextMap(keys []string) (map[string]any, error)

func (*MapAnyProvider) GetContextValue

func (mapr *MapAnyProvider) GetContextValue(key string) (any, error)

type Provider

type Provider interface {
	GetContextValue(string) (any, error)
	GetContextMap(keys []string) (map[string]any, error)
}

Provider is an interface that abstracts objects that can extract contextual data data from a source. The API contract is pretty simple: If the source has a value ir returns it. If it does not returns nil. When asking for a map with specific keys, the map should not have an entry for a key it doesn't have a value for.

func NewProviderFromJSON

func NewProviderFromJSON(r io.Reader) (Provider, error)

NewProviderFromJSON returns a new context provider from JSON data ingested from a reader.

The data can't be just any JSON though, it needs to be able to be parsed to a map[string]any.

func NewProviderFromJSONFile

func NewProviderFromJSONFile(path string) (Provider, error)

func NewProviderFromYAML added in v1.1.0

func NewProviderFromYAML(r io.Reader) (Provider, error)

NewProviderFromYAML returns a new context provider from YAML data ingested from a reader.

The data needs to be able to be parsed to a map[string]any.

func NewProviderFromYAMLFile added in v1.1.0

func NewProviderFromYAMLFile(path string) (Provider, error)

type StringMapList

type StringMapList []string

StringMapList returns context data from a list of strings where each line has the value preceded by a colon and the value. For example:

"value1:My Value"
"OtherValue:Another value"
"Number:3" // This would be a string "3"

All values returned by the provider are strings.

This provider was created to support context strings passed in the CLI to the ampel verifier.

func (*StringMapList) GetContextMap

func (sml *StringMapList) GetContextMap(keys []string) (map[string]any, error)

func (*StringMapList) GetContextValue

func (sml *StringMapList) GetContextValue(key string) (any, error)

Jump to

Keyboard shortcuts

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