envset

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//HashSHA256 is the default hash algorithm
	HashSHA256 = "sha256"
	//HashHMAC is the algorithm used with a secret
	HashHMAC = "hmac"
	//HashMD5 used md5 hash
	HashMD5 = "md5"
)
View Source
const DefaultSection = ini.DEFAULT_SECTION

DefaultSection is the name of the default ini section

Variables

This section is empty.

Functions

func CompareMetadataFiles added in v0.4.1

func CompareMetadataFiles(a, b *EnvFile) (bool, error)

CompareMetadataFiles will compare two EnvFile instances

func DocumentTemplate

func DocumentTemplate(name, template string, overwrite, print bool) error

DocumentTemplate will create or update a document template e.g. envset.tpl that we use to document and to check in our repo so we can keep track of the variables and sections.

func FileFinder

func FileFinder(filename string) (string, error)

FileFinder will find the file and return its full path

func InterpolateKVStrings

func InterpolateKVStrings(args []string, context EnvMap, expand bool) []string

InterpolateKVStrings replace ${VAR} in the executable cmd arguments

func IsErrorRunningCommand

func IsErrorRunningCommand(v interface{}) bool

IsErrorRunningCommand will return true if v is section not found

func IsFileNotFound

func IsFileNotFound(v interface{}) bool

IsFileNotFound will return true if v is file not found

func IsSectionNotFound

func IsSectionNotFound(v interface{}) bool

IsSectionNotFound will return true if v is section not found

func Print

func Print(environment string, options RunOptions) error

Print will show the current environment We don't need to do variable replacement if we print since the idea is to use it as a source

func Run

func Run(environment string, options RunOptions) error

Run will run the given command after loading the environment

Types

type EnvFile

type EnvFile struct {
	//TODO: make relative to executable
	Path      string        `json:"-"`
	File      *ini.File     `json:"-"`
	Filename  string        `json:"envfile,omitempty"`
	Project   string        `json:"project,omitempty"` //TODO: should we have https, git and id? if someone checks using https and other ssh this will change!!
	Algorithm string        `json:"algorithm"`
	Date      time.Time     `json:"date"`
	Sections  []*EnvSection `json:"sections"` //TODO: make custom marshaller to ignore DEFAULT section
	// contains filtered or unexported fields
}

EnvFile struct

func CreateMetadataFile

func CreateMetadataFile(o MetadataOptions) (EnvFile, error)

CreateMetadataFile will create or update metadata file

func LoadMetadataFile added in v0.4.1

func LoadMetadataFile(path string) (*EnvFile, error)

LoadMetadataFile will load a metadata file from the provided path

func (*EnvFile) AddSection

func (e *EnvFile) AddSection(name string) *EnvSection

AddSection will add a section to a EnvFile

func (*EnvFile) FromJSON

func (e *EnvFile) FromJSON(path string) error

FromJSON load from json file

func (*EnvFile) FromStdin

func (e *EnvFile) FromStdin() error

FromStdin read from stdin

func (*EnvFile) GetSection

func (e *EnvFile) GetSection(name string) (*EnvSection, error)

GetSection will return a EnvSection by name or an error if is not found

func (EnvFile) Load

func (e EnvFile) Load(path string) error

Load will load the ini file

func (EnvFile) ToJSON

func (e EnvFile) ToJSON() (string, error)

ToJSON will print the JSON representation for a envfile

type EnvKey

type EnvKey struct {
	Name    string `json:"key"`
	Value   string `json:"value,omitempty"`
	Hash    string `json:"hash"`
	Comment string `json:"comment,omitempty"`
}

EnvKey is a single entry in our file

type EnvMap

type EnvMap map[string]string

EnvMap type to hold envset map

func LoadIniSection

func LoadIniSection(sec *ini.Section) EnvMap

LoadIniSection returns a new EnvMap from a ini section

func LoadJSON

func LoadJSON(b []byte) (EnvMap, error)

LoadJSON will load a json environment definition

func LocalEnv

func LocalEnv() EnvMap

LocalEnv will return the local env

func NewEnvMap

func NewEnvMap() EnvMap

NewEnvMap returns a new EnvMap

func (EnvMap) Expand

func (e EnvMap) Expand(osExpand bool) error

Expand ${VAR} and $(command) in values

func (EnvMap) GetMissingKeys

func (e EnvMap) GetMissingKeys(keys []string) []string

GetMissingKeys will compare the keys present in `keys` with the keys present in the EnvMap instance and return a list of missing keys.

func (EnvMap) ToExpandedKVStrings

func (e EnvMap) ToExpandedKVStrings(osExpand bool) []string

ToExpandedKVStrings returns an expanded list of key=value strings

func (EnvMap) ToKVStrings

func (e EnvMap) ToKVStrings() []string

ToKVStrings will return an slice of `key=values`

type EnvSection

type EnvSection struct {
	Name    string    `json:"name"`
	Comment string    `json:"comment,omitempty"`
	Keys    []*EnvKey `json:"values"`
	// contains filtered or unexported fields
}

EnvSection is a top level section

func CompareSections

func CompareSections(s1, s2 EnvSection, ignored []string) EnvSection

CompareSections will compare two sections and return diff

func (*EnvSection) AddKey

func (e *EnvSection) AddKey(key, value string) (*EnvKey, error)

AddKey adds a new key to the section

func (*EnvSection) IsEmpty

func (e *EnvSection) IsEmpty() bool

IsEmpty will return true if we have no keys in our section

func (*EnvSection) ToJSON added in v0.0.9

func (e *EnvSection) ToJSON() (string, error)

ToJSON returns a JSON representation of a section

type EnvSlice

type EnvSlice []string

EnvSlice type to hold envset entries

func (EnvSlice) Add

func (e EnvSlice) Add(k, v string)

type ErrorRunningCommand

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

func (ErrorRunningCommand) Error

func (e ErrorRunningCommand) Error() string

type ErrorWrongAlgorithm added in v0.6.2

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

ErrorWrongAlgorithm generated when source and target have different algorithms

func (*ErrorWrongAlgorithm) Error added in v0.6.2

func (e *ErrorWrongAlgorithm) Error() string

type MetadataOptions

type MetadataOptions struct {
	Name          string
	Filepath      string
	Algorithm     string
	Project       string
	GlobalSection string
	Overwrite     bool
	Globals       bool
	Print         bool
	Values        bool
	Secret        string
}

MetadataOptions are the command options

type RunOptions added in v0.0.5

type RunOptions struct {
	Filename            string
	Cmd                 string
	Args                []string
	Isolated            bool
	Expand              bool
	Required            []string
	Inherit             []string
	Ignored             []string
	ExportEnvName       string
	CommentSectionNames []string
	Restart             bool
	MaxRestarts         int
}

RunOptions is used to configure a run command

Jump to

Keyboard shortcuts

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