utils

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const REPLACE_CHAR_DEFAULT = " "

Variables

View Source
var ErrInvalidOptionsEnvFile = errors.New("invalid options on envfile")

Functions

func ConvertEnv

func ConvertEnv(env map[string]string) []string

ConvertEnv converts map representing the environment to array of strings in the form "key=value"

func ConvertFromEnv

func ConvertFromEnv(env []string) map[string]string

ConvertFromEnv takes a string array and coverts it to a map of strings since an env variable can only really be a string it's safe to convert to string and not interface downstream programs need to cast values to what they expect

func ConvertStringToHumanFriendly

func ConvertStringToHumanFriendly(str string) string

ConvertStringToHumanFriendly takes a ConvertStringToMachineFriendly generated string and and converts it back to its original human friendly form

func ConvertStringToMachineFriendly

func ConvertStringToMachineFriendly(str string) string

ConvertStringToMachineFriendly takes astring and replaces any occurrence of non machine friendly chars with machine friendly ones

func ConvertToMapOfStrings

func ConvertToMapOfStrings(m map[string]interface{}) map[string]string

ConvertToMapOfStrings converts map of interfaces to map of strings

func FileExists

func FileExists(file string) bool

FileExists checks if the file exists

func GetFullPath

func GetFullPath(path string) string

GetFullPath

func IsExitError

func IsExitError(err error) bool

IsExitError checks if given error is an instance of exec.ExitError

func IsURL

func IsURL(s string) bool

IsURL checks if given string is a valid URL

func LastLine

func LastLine(r io.Reader) (l string)

LastLine returns last line from provided reader

func MapKeys

func MapKeys(m interface{}) (keys []string)

MapKeys returns an array of map's keys

func MustGetUserHomeDir

func MustGetUserHomeDir() string

MustGetUserHomeDir returns current working directory. Panics is os.UserHomeDir() returns error

func MustGetwd

func MustGetwd() string

MustGetwd returns current working directory. Panics is os.Getwd() returns error

func ReadEnvFile

func ReadEnvFile(r io.ReadCloser) (map[string]string, error)

ReadEnvFile reads env file inv `k=v` format

func RenderString

func RenderString(tmpl string, variables map[string]interface{}) (string, error)

RenderString parses given string as a template and executes it with provided params

Types

type Binary

type Binary struct {
	IsContainer bool `jsonschema:"-"`
	// Bin is the name of the executable to run
	// it must exist on the path
	// If using a default mvdn.sh context then
	// ensure it is on your path as symlink if you are only using aliases.
	Bin  string   `mapstructure:"bin" yaml:"bin" json:"bin"`
	Args []string `mapstructure:"args" yaml:"args,omitempty" json:"args,omitempty"`
	// contains filtered or unexported fields
}

Binary is a structure for storing binary file path and arguments that should be passed on binary's invocation

func (*Binary) BuildArgsWithEnvFile

func (b *Binary) BuildArgsWithEnvFile(envfilePath string) []string

BuildArgsWithEnvFile returns all args with correctly placed --env-file parameter for context binary

func (*Binary) GetArgs added in v1.7.1

func (b *Binary) GetArgs() []string

func (*Binary) WithBaseArgs

func (b *Binary) WithBaseArgs(args []string) *Binary

func (*Binary) WithContainerArgs

func (b *Binary) WithContainerArgs(args []string) *Binary

func (*Binary) WithShellArgs

func (b *Binary) WithShellArgs(args []string) *Binary

type EnvFileOpts

type EnvFileOpts func(*Envfile)

Opts is a task runner configuration function.

type Envfile

type Envfile struct {
	// Generate will toggle the creation of the envFile
	// this "envFile" is only used in executables of type `docker|podman`
	Generate bool `mapstructure:"generate" yaml:"generate,omitempty" json:"generate,omitempty"`
	// list of variables to be excluded
	// from the injection into container runtimes
	//
	// Currently this is based on a prefix
	//
	// Example:
	// HOME=foo,HOMELAB=bar
	//
	// Both of these will be skipped
	Exclude []string `mapstructure:"exclude" yaml:"exclude,omitempty" json:"exclude,omitempty"`
	Include []string `mapstructure:"include" yaml:"include,omitempty" json:"include,omitempty"`
	// Path is generated using task name and current timestamp
	// TODO: include additional graph info about the execution
	// e.g. owning pipeline (if any) execution number
	Path        string `mapstructure:"path" yaml:"path,omitempty" json:"path,omitempty"`
	ReplaceChar string `mapstructure:"replace_char" yaml:"replace_char,omitempty" json:"replace_char,omitempty"`
	Quote       bool   `mapstructure:"quote" yaml:"quote,omitempty" json:"quote,omitempty"`
	// Modify specifies the modifications to make to each env var and whether it meets the criteria
	// example:
	// - pattern: "^(?P<keyword>TF_VAR_)(?P<varname>.*)"
	// 	 operation: lower
	// the inputs are validated at task/pipeline build time and will fail if the
	// <keyword> and <varname> sub expressions are not present in the `pattern`
	Modify []ModifyEnv `mapstructure:"modify" yaml:"modify,omitempty" json:"modify,omitempty"`
	// defaults to .taskctl in the current directory
	// again this should be hidden from the user...
	GeneratedDir string `mapstructure:"generated_dir" yaml:"generated_dir,omitempty" json:"generated_dir,omitempty"`
}

Envile is a structure for storing the information required to generate an envfile which can be consumed by the specified binary

func NewEnvFile

func NewEnvFile(opts ...EnvFileOpts) *Envfile

NewEnvFile creates a new instance of the EnvFile initializes it with some defaults

func (*Envfile) Validate

func (e *Envfile) Validate() error

Validate checks input is correct

This will be added to later

type ModifyEnv

type ModifyEnv struct {
	Pattern   string `mapstructure:"pattern" yaml:"pattern" json:"pattern"`
	Operation string `mapstructure:"operation" yaml:"operation" json:"operation" jsonschema:"enum=upper,enum=lower"`
}

func (ModifyEnv) IsValid

func (me ModifyEnv) IsValid() bool

Jump to

Keyboard shortcuts

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