yttlibrary

package
v0.49.0 Latest Latest
Warning

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

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

Documentation

Overview

Package yttlibrary implements the "Standard Library" of modules that are built-in to the ytt templating engine.

Index

Constants

View Source
const (
	SemverRegex string = `^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)` +
		`(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))` +
		`?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`
)

Variables

View Source
var (
	Base64API = starlark.StringDict{
		"base64": &starlarkstruct.Module{
			Name: "base64",
			Members: starlark.StringDict{
				"encode": starlark.NewBuiltin("base64.encode", core.ErrWrapper(base64Module{}.Encode)),
				"decode": starlark.NewBuiltin("base64.decode", core.ErrWrapper(base64Module{}.Decode)),
			},
		},
	}
)
View Source
var (
	// IPAPI describes the contents of "@ytt:ip" module of the ytt standard library.
	IPAPI = starlark.StringDict{
		"ip": &starlarkstruct.Module{
			Name: "ip",
			Members: starlark.StringDict{
				"parse_addr": starlark.NewBuiltin("ip.parse_addr", core.ErrWrapper(ipModule{}.ParseAddr)),
				"parse_cidr": starlark.NewBuiltin("ip.parse_cidr", core.ErrWrapper(ipModule{}.ParseCIDR)),
			},
		},
	}
)
View Source
var (
	// JSONAPI contains the definition of the @ytt:json module
	JSONAPI = starlark.StringDict{
		"json": &starlarkstruct.Module{
			Name: "json",
			Members: starlark.StringDict{
				"encode": starlark.NewBuiltin("json.encode", core.ErrWrapper(jsonModule{}.Encode)),
				"decode": starlark.NewBuiltin("json.decode", core.ErrWrapper(jsonModule{}.Decode)),
			},
		},
	}
)
View Source
var (
	MD5API = starlark.StringDict{
		"md5": &starlarkstruct.Module{
			Name: "md5",
			Members: starlark.StringDict{
				"sum": starlark.NewBuiltin("md5.sum", core.ErrWrapper(md5Module{}.Sum)),
			},
		},
	}
)
View Source
var (
	ModuleAPI = starlark.StringDict{
		"module": &starlarkstruct.Module{
			Name: "module",
			Members: starlark.StringDict{
				"make": starlark.NewBuiltin("module.make", core.ErrWrapper(starlarkstruct.MakeModule)),
			},
		},
	}
)
View Source
var (
	RegexpAPI = starlark.StringDict{
		"regexp": &starlarkstruct.Module{
			Name: "regexp",
			Members: starlark.StringDict{
				"match":   starlark.NewBuiltin("regexp.match", core.ErrWrapper(regexpModule{}.Match)),
				"replace": starlark.NewBuiltin("regexp.replace", core.ErrWrapper(regexpModule{}.Replace)),
			},
		},
	}
)
View Source
var (
	SHA256API = starlark.StringDict{
		"sha256": &starlarkstruct.Module{
			Name: "sha256",
			Members: starlark.StringDict{
				"sum": starlark.NewBuiltin("sha256.sum", core.ErrWrapper(sha256Module{}.Sum)),
			},
		},
	}
)
View Source
var (
	StructAPI = starlark.StringDict{
		"struct": &starlarkstruct.Module{
			Name: "struct",
			Members: starlark.StringDict{
				"make":          starlark.NewBuiltin("struct.make", core.ErrWrapper(structModule{}.Make)),
				"make_and_bind": starlark.NewBuiltin("struct.make_and_bind", core.ErrWrapper(structModule{}.MakeAndBind)),
				"bind":          starlark.NewBuiltin("struct.bind", core.ErrWrapper(structModule{}.Bind)),

				"encode": starlark.NewBuiltin("struct.encode", core.ErrWrapper(structModule{}.Encode)),
				"decode": starlark.NewBuiltin("struct.decode", core.ErrWrapper(structModule{}.Decode)),
			},
		},
	}
)
View Source
var (
	URLAPI = starlark.StringDict{
		"url": &starlarkstruct.Module{
			Name: "url",
			Members: starlark.StringDict{
				"path_segment_encode": starlark.NewBuiltin("url.path_segment_encode", core.ErrWrapper(urlModule{}.PathSegmentEncode)),
				"path_segment_decode": starlark.NewBuiltin("url.path_segment_decode", core.ErrWrapper(urlModule{}.PathSegmentDecode)),

				"query_param_value_encode": starlark.NewBuiltin("url.query_param_value_encode", core.ErrWrapper(urlModule{}.QueryParamValueEncode)),
				"query_param_value_decode": starlark.NewBuiltin("url.query_param_value_decode", core.ErrWrapper(urlModule{}.QueryParamValueDecode)),

				"query_params_encode": starlark.NewBuiltin("url.query_params_encode", core.ErrWrapper(urlModule{}.QueryParamsEncode)),
				"query_params_decode": starlark.NewBuiltin("url.query_params_decode", core.ErrWrapper(urlModule{}.QueryParamsDecode)),

				"parse": starlark.NewBuiltin("url.parse", core.ErrWrapper(urlModule{}.ParseURL)),
			},
		},
	}
)
View Source
var (
	VersionAPI = starlark.StringDict{
		"version": &starlarkstruct.Module{
			Name: "version",
			Members: starlark.StringDict{
				"require_at_least": starlark.NewBuiltin("version.require_at_least", core.ErrWrapper(versionModule{}.RequireAtLeast)),
			},
		},
	}
)
View Source
var (
	// YAMLAPI contains the definition of the @ytt:yaml module
	YAMLAPI = starlark.StringDict{
		"yaml": &starlarkstruct.Module{
			Name: "yaml",
			Members: starlark.StringDict{
				"encode": starlark.NewBuiltin("yaml.encode", core.ErrWrapper(yamlModule{}.starlarkEncode)),
				"decode": starlark.NewBuiltin("yaml.decode", core.ErrWrapper(yamlModule{}.starlarkDecode)),
			},
		},
	}
)

Functions

func RegisterExt added in v0.48.0

func RegisterExt(mod *starlarkstruct.Module)

RegisterExt adds "mod" to the standard set of ytt library modules as an extension. An "extension" is a Starlark module that has external Go dependencies (as opposed to other Starlark modules in the ytt library that either have no dependencies or depend on the Go standard lib). This enables those using ytt as a Go module to opt-in (rather than be forced) to accept such dependencies. Only Carvel-maintained extensions can be registered; this reserves the `@ytt:` namespace. Integrators who want to write their own extensions should construct their own library.

Types

type API

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

func NewAPI

func NewAPI(
	replaceNodeFunc tplcore.StarlarkFunc,
	dataMod DataModule,
	libraryMod starlark.StringDict,
	ui ui.UI) API

NewAPI builds an API instance to be used in executing a template.

func (API) FindModule added in v0.48.0

func (a API) FindModule(module string) (starlark.StringDict, error)

type AssertModule added in v0.48.0

type AssertModule struct{}

AssertModule contains the definition of the @ytt:assert module.

func NewAssertModule added in v0.48.0

func NewAssertModule() AssertModule

NewAssertModule constructs a new instance of AssertModule, respecting the "validations" experiment flag.

func (AssertModule) AsModule added in v0.48.0

func (m AssertModule) AsModule() starlark.StringDict

AsModule produces the corresponding Starlark module definition suitable for use in running a Starlark program.

func (AssertModule) Equals added in v0.48.0

Equals compares two values for equality

func (AssertModule) Fail added in v0.48.0

Fail is a core.StarlarkFunc that forces a Starlark failure.

func (AssertModule) Max added in v0.48.0

Max is a core.StarlarkFunc wrapping NewAssertMax()

func (AssertModule) MaxLen added in v0.48.0

MaxLen is a core.StarlarkFunc wrapping NewAssertMaxLen()

func (AssertModule) Min added in v0.48.0

Min is a core.StarlarkFunc wrapping NewAssertMin()

func (AssertModule) MinLen added in v0.48.0

MinLen is a core.StarlarkFunc wrapping NewAssertMinLen()

func (AssertModule) NotNull added in v0.48.0

func (m AssertModule) NotNull(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error)

NotNull is a core.StarlarkFunc wrapping NewAssertNotNull()

func (AssertModule) OneNotNull added in v0.48.0

OneNotNull is a core.StarlarkFunc wrapping NewAssertOneNotNull()

func (AssertModule) OneOf added in v0.48.0

OneOf is a core.StarlarkFunc wrapping NewAssertOneOf()

func (AssertModule) TryTo added in v0.48.0

TryTo is a core.StarlarkFunc that attempts to invoke the passed in starlark.Callable, converting any error into an error message.

type Assertion added in v0.48.0

type Assertion struct {
	*core.StarlarkStruct
	// contains filtered or unexported fields
}

Assertion encapsulates a rule (a predicate) that can be accessed in a Starlark expression (via the "check" attribute) or in Go (via CheckFunc()).

func NewAssertMax added in v0.48.0

func NewAssertMax(max starlark.Value) *Assertion

NewAssertMax produces an Assertion that a given value is at most "maximum".

see also:https://github.com/google/starlark-go/blob/master/doc/spec.md#comparisons

func NewAssertMaxLen added in v0.48.0

func NewAssertMaxLen(maximum starlark.Int) *Assertion

NewAssertMaxLen produces an Assertion that a given sequence is at most "maximum" in length.

see also: https://github.com/google/starlark-go/blob/master/doc/spec.md#len

func NewAssertMin added in v0.48.0

func NewAssertMin(min starlark.Value) *Assertion

NewAssertMin produces an Assertion that a given value is at least "minimum".

see also:https://github.com/google/starlark-go/blob/master/doc/spec.md#comparisons

func NewAssertMinLen added in v0.48.0

func NewAssertMinLen(minimum starlark.Int) *Assertion

NewAssertMinLen produces an Assertion that a given sequence is at least "minimum" in length.

see also: https://github.com/google/starlark-go/blob/master/doc/spec.md#len

func NewAssertNotNull added in v0.48.0

func NewAssertNotNull() *Assertion

NewAssertNotNull produces an Assertion that a given value is not null.

func NewAssertOneNotNull added in v0.48.0

func NewAssertOneNotNull(keys starlark.Sequence) *Assertion

NewAssertOneNotNull produces an Assertion that a given value is a map having exactly one item with a non-null value.

func NewAssertOneOf added in v0.48.0

func NewAssertOneOf(enum starlark.Sequence) *Assertion

NewAssertOneOf produces an Assertion that a given value is one of a pre-defined set.

see also:https://github.com/google/starlark-go/blob/master/doc/spec.md#membership-tests

func NewAssertionFromSource added in v0.48.0

func NewAssertionFromSource(funcName, checkSrc string, env starlark.StringDict) *Assertion

NewAssertionFromSource creates an Assertion whose "check" attribute is the lambda expression defined in "checkSrc".

func NewAssertionFromStarlarkFunc added in v0.48.0

func NewAssertionFromStarlarkFunc(funcName string, checkFunc core.StarlarkFunc) *Assertion

NewAssertionFromStarlarkFunc creates an Assertion whose "check" attribute is "checkFunc".

func (*Assertion) CheckFunc added in v0.48.0

func (a *Assertion) CheckFunc() starlark.Callable

CheckFunc returns the function that — given a value — makes this assertion on it.

func (*Assertion) ConversionHint added in v0.48.0

func (a *Assertion) ConversionHint() string

ConversionHint helps the user get unstuck if they accidentally left an Assertion as a value in a YAML being encoded.

func (*Assertion) Type added in v0.48.0

func (a *Assertion) Type() string

Type reports the name of this type in the Starlark type system.

type DataLoader added in v0.48.0

type DataLoader interface {
	FilePaths(string) ([]string, error)
	FileData(string) ([]byte, error)
}

type DataModule added in v0.48.0

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

func NewDataModule

func NewDataModule(values *yamlmeta.Document, loader DataLoader) DataModule

func (DataModule) AsModule added in v0.48.0

func (b DataModule) AsModule() starlark.StringDict

func (DataModule) List added in v0.48.0

func (b DataModule) List(thread *starlark.Thread, f *starlark.Builtin,
	args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

func (DataModule) Read added in v0.48.0

func (b DataModule) Read(thread *starlark.Thread, f *starlark.Builtin,
	args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

type IPAddrValue added in v0.48.0

type IPAddrValue struct {
	*core.StarlarkStruct // TODO: keep authorship of the interface by delegating instead of embedding
	// contains filtered or unexported fields
}

IPAddrValue stores a parsed IP

func (*IPAddrValue) AsStarlarkValue added in v0.48.0

func (av *IPAddrValue) AsStarlarkValue() starlark.Value

AsStarlarkValue converts this instance into a value suitable for use in a Starlark program.

func (*IPAddrValue) ConversionHint added in v0.48.0

func (av *IPAddrValue) ConversionHint() string

ConversionHint provides a hint on how the user can explicitly convert this value to a type that can be automatically encoded.

func (*IPAddrValue) IsIPv4 added in v0.48.0

IsIPv4 is a core.StarlarkFunc that reveals whether this value is an IPv4 address.

func (*IPAddrValue) IsIPv6 added in v0.48.0

IsIPv6 is a core.StarlarkFunc that reveals whether this value is an IPv6 address.

func (*IPAddrValue) Type added in v0.48.0

func (av *IPAddrValue) Type() string

Type reports the name of this type as seen from a Starlark program (i.e. via the `type()` built-in)

type IPNetValue added in v0.48.0

type IPNetValue struct {
	*core.StarlarkStruct // TODO: keep authorship of the interface by delegating instead of embedding
	// contains filtered or unexported fields
}

IPNetValue holds the data for an instance of an IP Network value

func (*IPNetValue) Addr added in v0.48.0

Addr is a core.StarlarkFunc that returns the masked address portion of the network value

func (*IPNetValue) AsStarlarkValue added in v0.48.0

func (inv *IPNetValue) AsStarlarkValue() starlark.Value

AsStarlarkValue converts this instance into a value suitable for use in a Starlark program.

func (*IPNetValue) ConversionHint added in v0.48.0

func (inv *IPNetValue) ConversionHint() string

ConversionHint provides a hint on how the user can explicitly convert this value to a type that can be automatically encoded.

func (*IPNetValue) Type added in v0.48.0

func (inv *IPNetValue) Type() string

Type reports the name of this type as seen from a Starlark program (i.e. via the `type()` built-in)

type MathModule added in v0.48.0

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

MathModule contains the definition of the @ytt:math module. It contains math-related functions and constants. The module defines the following functions:

ceil(x) - Returns the ceiling of x, the smallest integer greater than or equal to x.
copysign(x, y) - Returns a value with the magnitude of x and the sign of y.
fabs(x) - Returns the absolute value of x as float.
floor(x) - Returns the floor of x, the largest integer less than or equal to x.
mod(x, y) - Returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.
pow(x, y) - Returns x**y, the base-x exponential of y.
remainder(x, y) - Returns the IEEE 754 floating-point remainder of x/y.
round(x) - Returns the nearest integer, rounding half away from zero.

exp(x) - Returns e raised to the power x, where e = 2.718281… is the base of natural logarithms.
sqrt(x) - Returns the square root of x.

acos(x) - Returns the arc cosine of x, in radians.
asin(x) - Returns the arc sine of x, in radians.
atan(x) - Returns the arc tangent of x, in radians.
atan2(y, x) - Returns atan(y / x), in radians.
              The result is between -pi and pi.
              The vector in the plane from the origin to point (x, y) makes this angle with the positive X axis.
              The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct
              quadrant for the angle.
              For example, atan(1) and atan2(1, 1) are both pi/4, but atan2(-1, -1) is -3*pi/4.
cos(x) - Returns the cosine of x, in radians.
hypot(x, y) - Returns the Euclidean norm, sqrt(x*x + y*y). This is the length of the vector from the origin to point (x, y).
sin(x) - Returns the sine of x, in radians.
tan(x) - Returns the tangent of x, in radians.

degrees(x) - Converts angle x from radians to degrees.
radians(x) - Converts angle x from degrees to radians.

acosh(x) - Returns the inverse hyperbolic cosine of x.
asinh(x) - Returns the inverse hyperbolic sine of x.
atanh(x) - Returns the inverse hyperbolic tangent of x.
cosh(x) - Returns the hyperbolic cosine of x.
sinh(x) - Returns the hyperbolic sine of x.
tanh(x) - Returns the hyperbolic tangent of x.

log(x, base) - Returns the logarithm of x in the given base, or natural logarithm by default.

gamma(x) - Returns the Gamma function of x.

All functions accept both int and float values as arguments.

The module also defines approximations of the following constants:

e - The base of natural logarithms, approximately 2.71828.
pi - The ratio of a circle's circumference to its diameter, approximately 3.14159.

func NewMathModule added in v0.48.0

func NewMathModule(ui ui.UI) MathModule

NewMathModule constructs a new instance of MathModule with the configured UI (to enable displaying a warning).

func (MathModule) AsModule added in v0.48.0

func (m MathModule) AsModule() starlark.StringDict

AsModule produces the corresponding Starlark module definition suitable for use in running a Starlark program.

type TemplateModule added in v0.48.0

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

func NewTemplateModule

func NewTemplateModule(replaceNodeFunc core.StarlarkFunc) TemplateModule

func (TemplateModule) AsModule added in v0.48.0

func (b TemplateModule) AsModule() starlark.StringDict

type URLUser added in v0.48.0

type URLUser struct {
	*core.StarlarkStruct // TODO: keep authorship of the interface by delegating instead of embedding
	// contains filtered or unexported fields
}

URLUser stores the user information

func (*URLUser) ConversionHint added in v0.48.0

func (uu *URLUser) ConversionHint() string

func (*URLUser) Type added in v0.48.0

func (uu *URLUser) Type() string

Type reports the fully-qualified name of type of this custom struct.

type URLValue added in v0.48.0

type URLValue struct {
	*core.StarlarkStruct // TODO: keep authorship of the interface by delegating instead of embedding
	// contains filtered or unexported fields
}

URLValue stores a parsed URL

func (*URLValue) AsStarlarkValue added in v0.48.0

func (uv *URLValue) AsStarlarkValue() starlark.Value

func (*URLValue) ConversionHint added in v0.48.0

func (uv *URLValue) ConversionHint() string

func (*URLValue) Hostname added in v0.48.0

func (uv *URLValue) Hostname(thread *starlark.Thread, f *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

func (*URLValue) Type added in v0.48.0

func (uv *URLValue) Type() string

Type reports the fully-qualified name of type of this custom struct.

func (*URLValue) User added in v0.48.0

func (uv *URLValue) User() starlark.Value

func (*URLValue) WithoutUser added in v0.48.0

func (uv *URLValue) WithoutUser(thread *starlark.Thread, f *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Directories

Path Synopsis
Package overlay implements YAML patching via ytt annotations.
Package overlay implements YAML patching via ytt annotations.

Jump to

Keyboard shortcuts

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