recipe

package
v1.14.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YAMLExtension          = ".yml"
	RecipeFileName         = "recipe"
	RecipeTemplatesDirName = "templates"
	RecipeTestsDirName     = "tests"
	RecipeTestMetaFileName = "test"
	RecipeTestFilesDirName = "files"
	IgnoreFileName         = ".jalapenoignore"
	ManifestFileName       = "manifest"
)
View Source
const (
	SaucesFileName = "sauces"

	// The directory name which contains all Jalapeno related files
	// in the project directory
	SauceDirName = ".jalapeno"
)
View Source
const (
	HashPrefix = "sha256:"
)
View Source
const LatestTag = "latest"

Variables

View Source
var (
	ErrSauceNotFound  = errors.New("sauce not found")
	ErrAmbiguousSauce = errors.New("multiple sauces found with same recipe")
)
View Source
var (
	ErrNoTestsSpecified    error = errors.New("no tests specified")
	ErrTestWrongFileAmount       = errors.New("recipe rendered different amount of files than expected")
	ErrTestMissingFile           = errors.New("recipe did not render file which was expected")
	ErrTestContentMismatch       = errors.New("the contents of the files did not match")
)
View Source
var (
	ErrorUnauthorized = errors.New("unauthorized")
)
View Source
var TestID uuid.UUID = uuid.Must(uuid.FromString("12345678-1234-5678-1234-567812345678"))

Random hardcoded UUID

Functions

func PushRecipe added in v0.1.26

func PushRecipe(ctx context.Context, path string, opts oci.Repository, replaceLatest bool) error

func SaveRemoteRecipe added in v0.1.26

func SaveRemoteRecipe(ctx context.Context, dest string, opts oci.Repository) error

SaveRemoteRecipe pulls a recipe from repository and saves it to dest directory

func ValidatePath added in v1.10.0

func ValidatePath(basePath, filePath string) error

func ValidateSubpath added in v1.4.0

func ValidateSubpath(path string) error

Types

type File added in v0.1.0

type File struct {
	Checksum string `yaml:"checksum"` // e.g. "sha256:xxxxxxxxx" w. default algo
	Content  []byte `yaml:"-"`
}

func NewFile added in v0.1.26

func NewFile(content []byte) File

func (File) HasBeenModifiedByUser added in v1.5.0

func (f File) HasBeenModifiedByUser() bool

type Manifest added in v1.8.0

type Manifest struct {
	APIVersion string           `yaml:"apiVersion"`
	Recipes    []ManifestRecipe `yaml:"recipes"`
}

func LoadManifest added in v1.8.0

func LoadManifest(path string) (*Manifest, error)

func NewManifest added in v1.8.0

func NewManifest() Manifest

func (*Manifest) Save added in v1.8.0

func (m *Manifest) Save(path string) error

func (*Manifest) Validate added in v1.8.0

func (m *Manifest) Validate() error

type ManifestRecipe added in v1.8.0

type ManifestRecipe struct {
	Name       string         `yaml:"name"`
	Version    string         `yaml:"version"`
	Repository string         `yaml:"repository"`
	Values     VariableValues `yaml:"values,omitempty"`
}

type Metadata

type Metadata struct {
	// Version of the recipe metadata API schema. Currently should have value "v1"
	APIVersion string `yaml:"apiVersion"`

	// Name of the recipe
	Name string `yaml:"name"`

	// Version of the recipe. Must be valid [semver](https://semver.org/)
	Version string `yaml:"version"`

	// Description of what the recipe does
	Description string `yaml:"description"`

	// Changelog of recipe versions
	Changelog map[string]string `yaml:"changelog,omitempty"`

	// URL to source code for this recipe
	Source string `yaml:"source,omitempty"`

	// A message which will be showed to an user after a succesful recipe execution.
	// Can be used to guide the user what should be done next in the project directory.
	InitHelp string `yaml:"initHelp,omitempty"`

	// Glob patterns for ignoring generated files from future recipe upgrades. Ignored
	// files will not be regenerated even if their templates change in future versions
	// of the recipe.
	IgnorePatterns []string `yaml:"ignorePatterns,omitempty"`

	// File extension of files in "templates" directory which should be templated.
	// Files not matched by this extension will be copied as-is.
	// If left empty (the default), all files will be templated.
	TemplateExtension string `yaml:"templateExtension,omitempty"`
}

func (*Metadata) UpdateVersion added in v1.14.0

func (m *Metadata) UpdateVersion(re *Recipe, newVer, msg string)

func (*Metadata) Validate

func (m *Metadata) Validate() error

type MultiSelectValue added in v1.12.0

type MultiSelectValue []string

func (*MultiSelectValue) FromString added in v1.12.0

func (v *MultiSelectValue) FromString(s string, delimiter rune)

func (MultiSelectValue) ToString added in v1.12.0

func (v MultiSelectValue) ToString(delimiter rune) string

type Recipe

type Recipe struct {
	Metadata  `yaml:",inline"`
	Variables []Variable      `yaml:"vars,omitempty"`
	Templates map[string]File `yaml:"-"`
	Tests     []Test          `yaml:"-"`
}

func LoadRecipe added in v0.1.0

func LoadRecipe(path string) (*Recipe, error)

LoadRecipe reads a recipe from a given path

func NewRecipe added in v0.1.0

func NewRecipe() Recipe

func PullRecipe added in v0.1.26

func PullRecipe(ctx context.Context, repo oci.Repository) (*Recipe, error)

func (*Recipe) Execute added in v0.1.0

func (re *Recipe) Execute(engine RenderEngine, values VariableValues, id uuid.UUID) (*Sauce, error)

Execute executes the recipe and returns a sauce

func (*Recipe) RunTests added in v0.1.0

func (re *Recipe) RunTests() []error

func (*Recipe) Save

func (re *Recipe) Save(dest string) error

Save saves recipe to given destination

func (*Recipe) Validate

func (re *Recipe) Validate() error

type RecipeConflict added in v0.1.0

type RecipeConflict struct {
	Path           string
	Sha256Sum      string
	OtherSha256Sum string
}

type RenderEngine

type RenderEngine interface {
	Render(templates map[string][]byte, values map[string]interface{}) (map[string][]byte, error)
}

type Sauce added in v0.1.0

type Sauce struct {
	// Version of the sauce API schema. Currently should have value "v1"
	APIVersion string `yaml:"apiVersion"`

	// The recipe which was used to render the sauce
	Recipe Recipe `yaml:"recipe"`

	// Values which was used to execute the recipe
	Values VariableValues `yaml:"values,omitempty"`

	// Files genereated from the recipe
	Files map[string]File `yaml:"files"`

	// Random unique ID whose value is determined on first render and stays the same
	// on subsequent re-renders (upgrades) of the sauce. Can be used for example as a seed
	// for template random functions to provide same result on each template
	ID uuid.UUID `yaml:"id"`

	// SubPath is used as a prefix when saving and loading the files rendered by the sauce.
	// This is useful for example in monorepos where the sauce is rendered to a subdirectory of the project directory.
	SubPath string `yaml:"subPath,omitempty"`

	// CheckFrom defines the repository where updates should be checked for the recipe
	CheckFrom string `yaml:"from,omitempty"`
}

Sauce represents a rendered recipe

func LoadSauceByID added in v1.4.0

func LoadSauceByID(projectDir string, id uuid.UUID) (*Sauce, error)

func LoadSauceByRecipe added in v1.4.0

func LoadSauceByRecipe(projectDir, recipeName string) (*Sauce, error)

func LoadSauces added in v0.1.0

func LoadSauces(projectDir string) ([]*Sauce, error)

Load all sauces from a project directory. Returns empty slice if the project directory did not contain any sayces

func NewSauce added in v0.1.0

func NewSauce() *Sauce

func (*Sauce) Conflicts added in v0.1.0

func (s *Sauce) Conflicts(other *Sauce) []RecipeConflict

Check if the recipe conflicts with another recipe. Recipes conflict if they touch the same files.

func (*Sauce) CreateTemplateContext added in v1.4.0

func (s *Sauce) CreateTemplateContext() (map[string]interface{}, error)

func (*Sauce) RenderInitHelp added in v1.4.0

func (s *Sauce) RenderInitHelp() (string, error)

func (*Sauce) Save added in v0.1.0

func (s *Sauce) Save(dest string) error

Save saves sauce to given destination

func (*Sauce) Validate added in v0.1.0

func (s *Sauce) Validate() error

type TableValue added in v1.1.1

type TableValue struct {
	Columns []string   `yaml:"columns"`
	Rows    [][]string `yaml:"rows,flow"`
}

func (*TableValue) FromCSV added in v1.1.1

func (t *TableValue) FromCSV(columns []string, input string, delimiter rune) error

func (TableValue) ToCSV added in v1.1.1

func (t TableValue) ToCSV(delimiter rune) (string, error)

func (TableValue) ToMapSlice added in v1.1.1

func (t TableValue) ToMapSlice() []map[string]string

type TemplateContext added in v1.4.0

type TemplateContext struct {
	ID     string
	Recipe struct {
		APIVersion string
		Name       string
		Version    string
		Source     string
	}
	Variables VariableValues
}

TemplateContext defines the context that is passed to the template engine

type Test added in v0.1.0

type Test struct {
	// Name of the test case. Defined by directory name of the test case
	Name string `yaml:"-"`

	// Values to use to render the recipe templates
	Values VariableValues `yaml:"values"`

	// Expected initHelp of the recipe when rendered with the values specified in the test
	ExpectedInitHelp string `yaml:"expectedInitHelp,omitempty"`

	// If true, test will not fail if the templates generates more files than the test specifies
	IgnoreExtraFiles bool `yaml:"ignoreExtraFiles,omitempty"`

	// Snapshots of the rendered templates which were rendered with the values specified in the test
	Files map[string]File `yaml:"-"`
}

func (Test) Validate added in v0.1.0

func (t Test) Validate() error

type URLType added in v1.8.0

type URLType int
const (
	UnknownType URLType = iota
	LocalType
	ManifestType
	OCIType
)

func DetermineRecipeURLType added in v1.8.0

func DetermineRecipeURLType(url string) URLType

type Variable

type Variable struct {
	// The name of the variable. It is also used as unique identifier.
	Name        string `yaml:"name"`
	Description string `yaml:"description,omitempty"`

	// Default value of the variable
	Default string `yaml:"default,omitempty"`

	// If set to true, the prompt will be yes/no question, and the value type will be boolean
	Confirm bool `yaml:"confirm,omitempty"`

	// If set to true, the variable can be left empty
	Optional bool `yaml:"optional,omitempty"`

	// The user selects the value from a list of options
	Options []string `yaml:"options,omitempty"`

	// If set to true, the user can select multiple values from the list of options
	Multi bool `yaml:"multi,omitempty"`

	// Validators for the variable
	Validators []VariableValidator `yaml:"validators,omitempty"`

	// Makes the variable conditional based on the result of the expression. The result of the evaluation needs to be a boolean value. Uses https://github.com/expr-lang/expr
	If string `yaml:"if,omitempty"`

	// Set the variable as a table type with columns defined by this property
	Columns []string `yaml:"columns,omitempty"`
}

func (Variable) DetermineType added in v1.3.0

func (v Variable) DetermineType() VariableType

func (Variable) ParseDefaultValue added in v1.3.0

func (v Variable) ParseDefaultValue() (interface{}, error)

func (*Variable) Validate

func (v *Variable) Validate() error

type VariableType added in v1.3.0

type VariableType uint8
const (
	VariableTypeUnknown VariableType = iota
	VariableTypeString
	VariableTypeBoolean
	VariableTypeSelect
	VariableTypeMultiSelect
	VariableTypeTable
)

type VariableValidator added in v0.1.12

type VariableValidator struct {
	// Regular expression pattern to match the input against
	Pattern string `yaml:"pattern,omitempty"`

	// If the regular expression validation fails, this help message will be shown to the user
	Help string `yaml:"help,omitempty"`

	// Apply the validator to a column if the variable type is table
	Column string `yaml:"column,omitempty"`

	// When targeting table columns, set this to true to make sure that the values in the column are unique
	Unique bool `yaml:"unique,omitempty"`
}

func (*VariableValidator) CreateTableValidatorFunc added in v1.9.0

func (r *VariableValidator) CreateTableValidatorFunc() (func(cols []string, rows [][]string, input string) error, error)

func (*VariableValidator) CreateValidatorFunc added in v0.1.12

func (r *VariableValidator) CreateValidatorFunc() (func(input string) error, error)

func (*VariableValidator) RequiresTableContext added in v1.10.1

func (r *VariableValidator) RequiresTableContext() bool

RequiresTableContext returns true if the validator function should be created with CreateTableValidatorFunc

type VariableValues

type VariableValues map[string]interface{}

VariableValues stores values for each variable

func (*VariableValues) UnmarshalYAML added in v1.2.0

func (vv *VariableValues) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler interface

func (VariableValues) Validate added in v1.8.0

func (val VariableValues) Validate() error

NOTE: This function does note validate the values against the variable definitions. It only checks if the name of the values are not empty and the values are of supported types.

Jump to

Keyboard shortcuts

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