variables

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 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 {
	Name  string `json:"name" jsonschema:"description=The name to be used for the constant,pattern=^[A-Z0-9_]+$"`
	Value string `json:"value" jsonschema:"description=The value to set for the constant during deploy"`
	// Include a description that will only be displayed during package create/deploy confirm prompts
	Description string `` /* 155-byte string literal not displayed */
	AutoIndent  bool   `` /* 202-byte string literal not displayed */
	Pattern     string `` /* 141-byte string literal not displayed */
}

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

func (Constant) Validate added in v0.34.0

func (c Constant) Validate() error

Validate runs all validation checks on a package constant.

type InteractiveVariable

type InteractiveVariable struct {
	Variable    `json:",inline"`
	Description string `` /* 126-byte string literal not displayed */
	Default     string `json:"default,omitempty" jsonschema:"description=The default value to use for the variable"`
	Prompt      bool   `json:"prompt,omitempty" jsonschema:"description=Whether to prompt the user for input for this variable"`
}

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

type SetVariable

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

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 {
	Name       string       `json:"name" jsonschema:"description=The name to be used for the variable,pattern=^[A-Z0-9_]+$"`
	Sensitive  bool         `json:"sensitive,omitempty" jsonschema:"description=Whether to mark this variable as sensitive to not print it in the log"`
	AutoIndent bool         `` /* 200-byte string literal not displayed */
	Pattern    string       `` /* 150-byte string literal not displayed */
	Type       VariableType `` /* 223-byte string literal not displayed */
}

Variable represents a variable that has a value set programmatically

func (Variable) Validate added in v0.34.0

func (v Variable) Validate() error

Validate runs all validation checks on a package variable.

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, deprecatedKeys map[string]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