injecuet

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 9 Imported by: 0

README

status PkgGoDev

injecuet

injecuet (ɪndʒékjuːt) = inject + CUE

The injecuet injects concrete values and emits new CUE document.

You can pass emitted new CUE document as cue eval or cue export argument to generate unified CUE document or other format such as JSON or YAML. (See CUE integrations)

Current supported injection sources:

  • environment variables
  • Terraform state

Concept

The injecuet neither have type conversion mechanism nor data validation mechanism by design.

The CUE has Types are values concept, so you already get data validation mechanism from CUE.

For example, if you expected the injected values must not be empty, you just write != "" restriction and cue eval fails if injected value is empty.

You can also use CUE modules such as strconv to parse injected string as integers.

Synopsis

Environment variables
cat src.cue
# name: string @inject(env,name=USER_NAME)

env USER_NAME=aereal injecuet ./src.cue
# name: "aereal" @inject(env,name=USER_NAME)
cat complex.cue
# import "strconv"
# 
# #varAge: string @inject(env,name=AGE)
# age: strconv.Atoi(#varAge)

env AGE=17 injecuet -output ./out.gen.cue ./src.cue

cat out.gen.cue
# #varAge: "123"
# age:     123

cue export ./out.gen.cue
# {
#     "age": 123
# }

You can use injecuet with ssmwrap:

cat src.cue
# secretKey: string @inject(env,name=APP_SECRET_KEY)

ssmwrap -env-prefix APP_ -recursive injecuet ./src.cue
# secretKey: "<value from SSM parameter store>" @inject(env=APP_SECRET_KEY)
Terraform state

You can pass file path or URL to stateURL. Supported URL formats are described on tfstate-lookup.

See examples.

Installation

go get github.com/aereal/injecuet/cmd/injecuet

Library usage

The injecuet also provides library interface.

See pkg.go.dev

License

See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Injector

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

Injector is used for injecting provided values. The injection values are given from several constructors.

func NewEnvironmentInjector deprecated

func NewEnvironmentInjector(match func(name string) bool) *Injector

NewEnvironmentInjector returns an new Injector that injects environment variables.

Deprecated: use NewInjector

func NewInjector added in v0.3.0

func NewInjector(options ...Option) *Injector

NewInjector creates new Injector.

func (*Injector) Inject

func (i *Injector) Inject(srcPath string) (cue.Value, error)

Inject injects provided injection values to CUE document in srcPath.

type Option added in v0.3.0

type Option func(i *Injector)

func WithEnvironmentVariables added in v0.3.0

func WithEnvironmentVariables(filterEnv func(name string) bool) Option

func WithTFState added in v0.3.0

func WithTFState() Option

Directories

Path Synopsis
cmd
internal
cli

Jump to

Keyboard shortcuts

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