Documentation
¶
Index ¶
- Variables
- func CopyFile(fs afero.Fs, sourcePath, targetPath string) error
- func CopyFileFsToFs(sourceFs afero.Fs, targetFs afero.Fs, sourcePath, targetPath string) error
- func CopyFilesByConfig(fs afero.Fs, configs []CopyConfig, sourceBasePath, targetBasePath string) error
- func DefaultTemplateContext(data Data, targetName string) any
- func ReplaceSecret(data Data, secret *Secret) error
- func ReplaceVariables(data Data, classFiles []*Class, predefinedVariables map[string]interface{}) (err error)
- func WriteFile(fs afero.Fs, targetPath string, data []byte, mode fs.FileMode) error
- func YamlFileLoader(fileSystem afero.Fs, basePath string, loader YamlFileLoaderFunc) error
- type Call
- type CallFunc
- type Class
- type ComponentConfig
- type CopyConfig
- type Data
- func (d Data) Bytes() []byte
- func (d Data) FindValues(valueFunc FindValueFunc, target *[]interface{}) (err error)
- func (d Data) Get(key string) Data
- func (d Data) GetPath(path ...interface{}) (tree interface{}, err error)
- func (d Data) HasKey(key string) bool
- func (d Data) MergeReplace(data Data) Data
- func (d *Data) SetPath(value interface{}, path ...interface{}) (err error)
- func (d Data) String() string
- type File
- type FindValueFunc
- type Inventory
- func (inv *Inventory) AddExternalClass(data map[string]any, classFilePath string) error
- func (inv *Inventory) Data(targetName string, predefinedVariables map[string]interface{}, ...) (data Data, err error)
- func (inv *Inventory) GetAllClasses() []*Class
- func (inv *Inventory) GetAllTargets() []*Target
- func (inv *Inventory) GetClass(name string) *Class
- func (inv *Inventory) GetSkipperConfig(targetName string) (config *SkipperConfig, err error)
- func (inv *Inventory) GetTarget(name string) *Target
- func (inv *Inventory) GetUsedClasses(targetName string) ([]*Class, error)
- type RenameConfig
- type Secret
- type SecretFile
- type SecretFileData
- type SecretFileList
- type SkipperConfig
- type Target
- type TargetConfig
- type TargetSecretConfig
- type Templater
- func (t *Templater) DiscoverPartials()
- func (t *Templater) Execute(template *File, data any, allowNoValue bool, renameConfig []RenameConfig) error
- func (t *Templater) ExecuteAll(data any, allowNoValue bool, renameConfig []RenameConfig) error
- func (t *Templater) ExecuteComponents(data any, components []ComponentConfig, allowNoValue bool) error
- type Variable
- type YamlFile
- type YamlFileLoaderFunc
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmptyFunctionName error = fmt.Errorf("empty function name")
)
var (
ErrFilePathEmpty = fmt.Errorf("file path is empty")
)
Functions ¶
func CopyFile ¶
CopyFile will copy the given sourcePath to the targetPath inside the passed afero.Fs.
func CopyFileFsToFs ¶
CopyFileFsToFs will copy a file from the given sourceFs and sourcePath to the targetFs and targetPath
func CopyFilesByConfig ¶
func CopyFilesByConfig(fs afero.Fs, configs []CopyConfig, sourceBasePath, targetBasePath string) error
CopyFilesByConfig uses a list of CopyConfigs and calls the CopyFile func on them.
func DefaultTemplateContext ¶
DefaultTemplateContext returns the default template context with an 'Inventory' field where the Data is located. Additionally it adds the 'TargetName' field for convenience.
func ReplaceSecret ¶
ReplaceSecret will replace the given secret inside Data with the actual secret value.
func ReplaceVariables ¶
func ReplaceVariables(data Data, classFiles []*Class, predefinedVariables map[string]interface{}) (err error)
ReplaceVariables searches and replaces variables defined in data. The classFiles are used for local referencing variables (class internal references). predefinedVariables can be used to provide global user-defined variables.
func WriteFile ¶
WriteFile ensures that `targetPath` exists in the `fs` and then writes `data` into it.
func YamlFileLoader ¶
func YamlFileLoader(fileSystem afero.Fs, basePath string, loader YamlFileLoaderFunc) error
YamlFileLoader is used to load Skipper specific yaml files from the inventory. It searches the basePath inside the given fileSystem for yaml files and loads them. Empty files are skipped. A path relative to the given pasePath is constructed. The loaded yaml file and the relative path are then passed to the given YamlFileLoaderFunc which is responsible for creating specific types from the YamlFile.
Types ¶
type Call ¶
type Class ¶
type Class struct { // File is the underlying file in the filesystem. File *YamlFile // Name is the relative path of the file inside the inventory which uniquely identifies this class. // Because the name is path based, no two classes with the same name can exist. // For the name, the path-separator is replaced with '.' and the file extension is stripped. // Example: 'something/foo/bar.yaml' will have the name 'something.foo.bar' // // The Name is also what is used to reference classes throughout Skpper. Name string // Configuration holds Skipper-relevant configuration inside the class Configuration *SkipperConfig }
Class represents a single file containing a YAML struct which makes up the inventory.
func NewClass ¶
NewClass will create a new class, given a raw YamlFile and the relative filePath from inside the inventory. If your class file is at `foo/bar/inventory/classes/myClass.yaml`, the relativeClassPath will be `myClass.yaml`
func (*Class) NameAsIdentifier ¶
func (c *Class) NameAsIdentifier() (id []interface{})
NameAsIdentifier returns the class name as an identifier used by skipper. The name is a dot-separated list of values (e.g. 'foo.bar.baz'). The returned identifier is a []interface which the values and can be used to address the class in Data.
type ComponentConfig ¶
type ComponentConfig struct { OutputPath string `yaml:"output_path"` InputPaths []string `yaml:"input_paths"` Renames []RenameConfig `yaml:"rename,omitempty"` }
type CopyConfig ¶
type Data ¶
type Data map[string]interface{}
Data is an arbitrary map of values which makes up the inventory.
func NewData ¶
NewData attempts to convert any given interface{} into Data. This is done by first using `yaml.Marshal` and then `yaml.Unmarshal`. If the given interface is compatible with Data, these steps will succeed.
func (Data) FindValues ¶
func (d Data) FindValues(valueFunc FindValueFunc, target *[]interface{}) (err error)
FindValues can be used to find specific 'leaf' nodes, aka values. The Data is iterated recursively and once a plain value is found, the given FindValueFunc is called. It's the responsibility of the FindValueFunc to determine if the value is what is searched for. The FindValueFunc can return any data, which is aggregated and written into the passed `*[]interface{}`. The callee is then responsible of handling the returned value and ensuring the correct types were returned.
func (Data) Get ¶
Get returns the value at `Data[key]` as Data. Note that his function does not support paths like `HasKey("foo.bar.baz")`. For that you can use [GetPath]
func (Data) GetPath ¶
GetPath allows path based indexing into Data. A path is a slice of interfaces which are used as keys in order. Supports array indexing (arrays start at 0) Examples of valid paths:
- ["foo", "bar"]
- ["foo", "bar", 0]
func (Data) HasKey ¶
HasKey returns true if Data[key] exists. Note that his function does not support paths like `HasKey("foo.bar.baz")`. For that you can use [GetPath]
func (Data) MergeReplace ¶
MergeReplace merges the existing Data with the given. If a key already exists, the passed data has precedence and it's value will be used.
type File ¶
File is just an arbitrary description of a path and the data of the File to which Path points to. Note that the used filesystem is not relevant, only at the time of loading a File.
type FindValueFunc ¶
FindValueFunc is a callback used to find values inside a Data map. `value` is the actual found value; `path` are the path segments which point to that value The function returns the extracted value and an error (if any).
type Inventory ¶
type Inventory struct {
// contains filtered or unexported fields
}
Inventory is the collection of classes and targets. The inventory wraps everything together and is capable of producing a single, coherent Data which can then be used inside the templates.
func NewInventory ¶
NewInventory creates a new Inventory with the given afero.Fs. At least one extension must be provided, otherwise an error is returned.
func (*Inventory) AddExternalClass ¶
AddExternalClass can be used to dynamically create class files. The given data will be written into `classFilePath`, overwriting any existing file.
The class path is first normalized to match the existing `Inventory.classPath`.
After that, the root-key of the data is adjusted to match the fileName which is extracted from `classFilePath`. This has to be done in order to comply Skipper rules where the class-filename must also be the root-key of any given class.
A new file inside the Skipper class path is created which makes it available for loading. In order to prevent confusion, a file header is added to indicate that the class was generated.
func (*Inventory) Data ¶
func (inv *Inventory) Data(targetName string, predefinedVariables map[string]interface{}, skipSecretHandling, revealSecrets bool) (data Data, err error)
Data loads the required inventory data map given the target. This is where variables and secrets are handled and eventually replaced. The resulting Data is what can be passed to the templates.
func (*Inventory) GetAllClasses ¶
GetAllClasses returns all discovered Classes
func (*Inventory) GetAllTargets ¶
GetAllTargets returns all discovered Targets
func (*Inventory) GetClass ¶
GetClass attempts to return a Class, given a name. If the class does not exist, nil is returned.
func (*Inventory) GetSkipperConfig ¶
func (inv *Inventory) GetSkipperConfig(targetName string) (config *SkipperConfig, err error)
GetSkipperConfig merges SkipperConfig of the target and it's used classes into one effective configuration.
type RenameConfig ¶
type Secret ¶
type Secret struct { *SecretFile Driver secret.Driver DriverName string AlternativeCall *Call Identifier []interface{} }
func FindOrCreateSecrets ¶
func FindOrCreateSecrets(data Data, secretFiles SecretFileList, secretPath string, fs afero.Fs) ([]*Secret, error)
FindSecrets will leverage the `FindValues` function of Data to recursively search for secrets. All returned values are converted to *Secret and then returned as []*Secret.
func NewSecret ¶
func NewSecret(secretFile *SecretFile, driver string, alternative *Call, path []interface{}) (*Secret, error)
func (Secret) FullName ¶
FullName returns the full secret name as it would be expected to ocurr in a class/target.
type SecretFile ¶
type SecretFile struct { *YamlFile Data SecretFileData RelativePath string }
func NewSecretFile ¶
func NewSecretFile(file *YamlFile, relativeSecretPath string) (*SecretFile, error)
func (*SecretFile) LoadSecretFileData ¶
func (sf *SecretFile) LoadSecretFileData(fs afero.Fs) error
type SecretFileData ¶
type SecretFileData struct { Data string `yaml:"data"` Type string `yaml:"type"` Key string `yaml:"key"` }
SecretFileData describes the generic structure of secret files.
func NewSecretData ¶
func NewSecretData(data string, driver string, key string) (*SecretFileData, error)
NewSecretData constructs a Data map as it is required for secrets.
type SecretFileList ¶
type SecretFileList []*SecretFile
func (SecretFileList) GetSecretFile ¶
func (sfl SecretFileList) GetSecretFile(path string) *SecretFile
type SkipperConfig ¶
type SkipperConfig struct { Classes []string `yaml:"use,omitempty"` Components []ComponentConfig `mapstructure:"components,omitempty"` Copies []CopyConfig `yaml:"copy,omitempty"` IgnoreRegex []string `yaml:"ignore_regex,omitempty"` Renames []RenameConfig `yaml:"rename,omitempty"` }
func LoadSkipperConfig ¶
func LoadSkipperConfig(file *YamlFile, rootKey string) (*SkipperConfig, error)
LoadSkipperConfig attempts to load a SkipperConfig from the given YamlFile with the passed rootKey
func MergeSkipperConfig ¶
func MergeSkipperConfig(merge ...*SkipperConfig) (mergedConfig *SkipperConfig)
MergeSkipperConfig merges a list of configs into one
func (*SkipperConfig) IsSet ¶
func (config *SkipperConfig) IsSet() bool
IsSet returns true if the config is not nil. The function is useful because LoadSkipperConfig can return nil.
type Target ¶
type Target struct { File *YamlFile // Name is the relative path of the file inside the inventory // where '/' is replaced with '.' and without file extension. Name string // UsedWildcardClasses holds all resolved wildcard class imports as specified in the `targets.skipper.use` key. UsedWildcardClasses []string // Configuration is the skipper-internal configuration which needs to be present on every target. Configuration TargetConfig // SkipperConfig is the generic Skipper configuration which can be use throughout targets and classes SkipperConfig *SkipperConfig }
Target defines which classes to use for the compilation.
func (*Target) ReloadConfiguration ¶
func (t *Target) ReloadConfiguration()
type TargetConfig ¶
type TargetConfig struct {
Secrets TargetSecretConfig `mapstructure:"secrets,omitempty"`
}
type TargetSecretConfig ¶
type TargetSecretConfig struct {
Drivers map[string]interface{} `mapstructure:"drivers"`
}
type Templater ¶
type Templater struct { Files []*File IgnoreRegex []*regexp.Regexp // contains filtered or unexported fields }
func NewTemplater ¶
func (*Templater) DiscoverPartials ¶ added in v0.2.0
func (t *Templater) DiscoverPartials()
DiscoverPartials will iterate over all registered files and check each of them whether an additional template is defined (e.g. using the 'define' directive). If so, the file is added to the list of partial templates which is made available during template execution. This ensures that every template can access partial templates. Subsequent calls to this method will reset the 'partialTemplates' field.
func (*Templater) Execute ¶
func (t *Templater) Execute(template *File, data any, allowNoValue bool, renameConfig []RenameConfig) error
Execute is responsible of parsing and executing the given template, using the passed data context. If execution is successful, the template is written to it's desired target location. If allowNoValue is true, the template is rendered even if it contains variables which are not defined.
func (*Templater) ExecuteAll ¶
func (t *Templater) ExecuteAll(data any, allowNoValue bool, renameConfig []RenameConfig) error
ExecuteAll is just a convenience function to execute all templates in `Templater.Files`
func (*Templater) ExecuteComponents ¶
func (t *Templater) ExecuteComponents(data any, components []ComponentConfig, allowNoValue bool) error
ExecuteComponents will only execute the templates as they are defined in the given components.
type Variable ¶
type Variable struct { // Name of the variable is whatever string is between ${}. // + For dynamic variables, this can be a ':' separated string which points somewhere into the Data map. // The reason we use ':' is to improve readability between curly braces. // + For predefined variables, this can be any string and must not be a path into the Data map. Name string // Identifier is the list of keys which point to the variable itself within the data set in which it is used. Identifier []interface{} }
Variable is a keyword which self-references the Data map it is defined in. A Variable has the form ${key:key}.
func FindVariables ¶
FindVariables leverages the [FindValues] function of the given Data to extract all variables by using the [variableFindValueFunc] as callback.
func (Variable) NameAsIdentifier ¶
func (v Variable) NameAsIdentifier() (id []interface{})
type YamlFile ¶
YamlFile is what is used for all inventory-relevant files (classes, secrets and targets).
func CreateNewYamlFile ¶
CreateNewFile can be used to manually create a File inside the given filesystem. This is useful for dynamically creating classes or targets.
The given path is attempted to be created and a file written.
func DiscoverYamlFiles ¶
DiscoverYamlFiles iterates over a given rootPath recursively, filters out all files with the appropriate file fileExtensions and finally creates a YamlFile slice which is then returned.
func NewYamlFile ¶
NewYamlFile returns a newly initialized `YamlFile`.
func (*YamlFile) Load ¶
Load will first load the underlying raw file-data and then attempt to `yaml.Unmarshal` it into `Data` The resulting Data is stored in `YamlFile.Data`.
func (*YamlFile) UnmarshalPath ¶
UnmarshalPath can be used to unmarshall only a sub-map of the Data inside YamlFile. The function errors if the file has not been loaded.
type YamlFileLoaderFunc ¶
YamlFileLoaderFunc is a function used to create specific types from a YamlFile and a relative path to that file.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
external_classes
Module
|
|
keyvault
Module
|
|
secrets
Module
|
|
terraform_azure
Module
|
|