recipe

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YAMLExtension          = ".yml"
	RecipeFileName         = "recipe"
	RecipeTemplatesDirName = "templates"
	RecipeTestsDirName     = "tests"
	RecipeTestMetaFileName = "test"
	RecipeTestFilesDirName = "files"
	IgnoreFileName         = ".jalapenoignore"
)
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 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 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"`

	// 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) Validate

func (m *Metadata) Validate() error

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"`

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

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

func (Test) Validate added in v0.1.0

func (t Test) Validate() error

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"`

	// 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 (
	VariableTypeUndefined VariableType = iota
	VariableTypeString
	VariableTypeTable
	VariableTypeSelect
	VariableTypeBoolean
)

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"`
}

func (*VariableValidator) CreateValidatorFunc added in v0.1.12

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

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

Jump to

Keyboard shortcuts

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