variables

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package variables contains functions for interacting with variables

Package variables contains functions for interacting with variables

Package variables contains functions for interacting with variables

Package variables contains functions for interacting with variables

Index

Constants

This section is empty.

Variables

View Source
var (
	// IsUppercaseNumberUnderscore is a regex for uppercase, numbers and underscores.
	// https://regex101.com/r/tfsEuZ/1
	IsUppercaseNumberUnderscore = regexp.MustCompile(`^[A-Z0-9_]+$`).MatchString
)

Functions

This section is empty.

Types

type Constant

type Constant struct {
	// The name to be used for the constant
	Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"`
	// The value to set for the constant during deploy
	Value string `json:"value"`
	// A description of the constant to explain its purpose on package create or deploy confirmation prompts
	Description string `json:"description,omitempty"`
	// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_.
	AutoIndent bool `json:"autoIndent,omitempty"`
	// An optional regex pattern that a constant value must match before a package can be created.
	Pattern string `json:"pattern,omitempty"`
}

Constant are constants that can be used to dynamically template K8s resources or run in actions.

func (Constant) Validate

func (c Constant) Validate() error

Validate runs all validation checks on a package constant.

type InteractiveVariable

type InteractiveVariable struct {
	Variable `json:",inline"`
	// A description of the variable to be used when prompting the user a value
	Description string `json:"description,omitempty"`
	// The default value to use for the variable
	Default string `json:"default,omitempty"`
	// Whether to prompt the user for input for this variable
	Prompt bool `json:"prompt,omitempty"`
}

InteractiveVariable is a variable that can be used to prompt a user for more information

type SetVariable

type SetVariable struct {
	Variable `json:",inline"`
	// The value the variable is currently set with
	Value string `json:"value"`
}

SetVariable tracks internal variables that have been set during this run of Zarf

type SetVariableMap

type SetVariableMap map[string]*SetVariable

SetVariableMap represents a map of variable names to their set values

type TextTemplate

type TextTemplate struct {
	Sensitive  bool
	AutoIndent bool
	Type       VariableType
	Value      string
}

TextTemplate represents a value to be templated into a text file.

type Variable

type Variable struct {
	// The name to be used for the variable
	Name string `json:"name" jsonschema:"pattern=^[A-Z0-9_]+$"`
	// Whether to mark this variable as sensitive to not print it in the log
	Sensitive bool `json:"sensitive,omitempty"`
	// Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_.
	AutoIndent bool `json:"autoIndent,omitempty"`
	// An optional regex pattern that a variable value must match before a package deployment can continue.
	Pattern string `json:"pattern,omitempty"`
	// Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB)
	Type VariableType `json:"type,omitempty" jsonschema:"enum=raw,enum=file"`
}

Variable represents a variable that has a value set programmatically

type VariableConfig

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

VariableConfig represents a value to be templated into a text file.

func New

func New(templatePrefix string, prompt func(variable InteractiveVariable) (value string, err error), logger *slog.Logger) *VariableConfig

New creates a new VariableConfig

func (*VariableConfig) CheckVariablePattern

func (vc *VariableConfig) CheckVariablePattern(name, pattern string) error

CheckVariablePattern checks to see if a current variable is set to a value that matches its pattern

func (*VariableConfig) GetAllTemplates

func (vc *VariableConfig) GetAllTemplates() map[string]*TextTemplate

GetAllTemplates gets all of the current templates stored in the VariableConfig

func (*VariableConfig) GetSetVariable

func (vc *VariableConfig) GetSetVariable(name string) (variable *SetVariable, ok bool)

GetSetVariable gets a variable set within a VariableConfig by its name

func (*VariableConfig) PopulateVariables

func (vc *VariableConfig) PopulateVariables(variables []InteractiveVariable, presetVariables map[string]string) error

PopulateVariables handles setting the active variables within a VariableConfig's SetVariableMap

func (*VariableConfig) ReplaceTextTemplate

func (vc *VariableConfig) ReplaceTextTemplate(path string) error

ReplaceTextTemplate loads a file from a given path, replaces text in it and writes it back in place.

func (*VariableConfig) SetApplicationTemplates

func (vc *VariableConfig) SetApplicationTemplates(applicationTemplates map[string]*TextTemplate)

SetApplicationTemplates sets the application-specific templates for the variable config (i.e. ZARF_REGISTRY for Zarf)

func (*VariableConfig) SetConstants

func (vc *VariableConfig) SetConstants(constants []Constant)

SetConstants sets the constants for a variable config (templated as PREFIX_CONST_NAME)

func (*VariableConfig) SetVariable

func (vc *VariableConfig) SetVariable(name, value string, sensitive bool, autoIndent bool, varType VariableType)

SetVariable sets a variable in a VariableConfig's SetVariableMap

type VariableType

type VariableType string

VariableType represents a type of a Zarf package variable

const (
	// RawVariableType is the default type for a Zarf package variable
	RawVariableType VariableType = "raw"
	// FileVariableType is a type for a Zarf package variable that loads its contents from a file
	FileVariableType VariableType = "file"
)

Jump to

Keyboard shortcuts

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