Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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)