state

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorEmptyState = errors.New("state is empty")
	ErrorNotFound   = errors.New("key not found in state")
	ErrorKeyExists  = errors.New("key already exists in state")
	ErrorReadOnly   = errors.New("state is read-only")
)

Functions

func ArgumentTypesEqual

func ArgumentTypesEqual(arg Argument, argTypes ...ArgumentType) bool

Types

type ArgMapReader

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

ArgMapReader attempts to read state values from the provided "ArgMap". The ArgMap is provided by the user by using the '-arg={key}={value}' argument. This is typically only used in local executions where some values will not be provided.

func NewArgMapReader

func NewArgMapReader(defaults args.ArgMap) *ArgMapReader

func (*ArgMapReader) Exists

func (s *ArgMapReader) Exists(arg Argument) (bool, error)

func (*ArgMapReader) GetBool

func (s *ArgMapReader) GetBool(arg Argument) (bool, error)

func (*ArgMapReader) GetDirectory

func (s *ArgMapReader) GetDirectory(arg Argument) (fs.FS, error)

func (*ArgMapReader) GetDirectoryString

func (s *ArgMapReader) GetDirectoryString(arg Argument) (string, error)

func (*ArgMapReader) GetFile

func (s *ArgMapReader) GetFile(arg Argument) (*os.File, error)

func (*ArgMapReader) GetFloat64

func (s *ArgMapReader) GetFloat64(arg Argument) (float64, error)

func (*ArgMapReader) GetInt64

func (s *ArgMapReader) GetInt64(arg Argument) (int64, error)

func (*ArgMapReader) GetString

func (s *ArgMapReader) GetString(arg Argument) (string, error)

type Argument

type Argument struct {
	Type ArgumentType
	Key  string
}

An Argument is a pre-defined argument that is used in a typical CI pipeline. This allows the scribe library to define different methods of retrieving the same information on various clients. For example, when running in CLI or Dagger client, getting the git ref might be as simple as running `git rev-parse HEAD`. But in a Drone pipeline, that information may be available before the repository has been cloned in an environment variable. Other arguments may require the user to be prompted if they have not been provided. These arguments can be provided to the CLI by using the flag `-arg`, for example `-arg=workdir=./example` will set the "workdir" argument to "example" in the CLI client. By default, all steps expect a WorkingDir and Repository.

func NewBoolArgument

func NewBoolArgument(key string) Argument

func NewDirectoryArgument

func NewDirectoryArgument(key string) Argument

func NewFileArgument

func NewFileArgument(key string) Argument

func NewFloat64Argument

func NewFloat64Argument(key string) Argument

func NewInt64Argument

func NewInt64Argument(key string) Argument

func NewSecretArgument

func NewSecretArgument(key string) Argument

func NewStringArgument

func NewStringArgument(key string) Argument

func NewUnpackagedDirectoryArgument

func NewUnpackagedDirectoryArgument(key string) Argument

type ArgumentType

type ArgumentType int
const (
	ArgumentTypeString ArgumentType = iota
	ArgumentTypeInt64
	ArgumentTypeFloat64
	ArgumentTypeBool
	ArgumentTypeSecret
	ArgumentTypeFile
	ArgumentTypeFS
	// An ArgumentTypeUnpackagedFS is used for filesystems that are invariably consistent regardless of operating system.
	// Developers can get around packaging and unpackaging of large directories using this argument type.
	// Filesystems and directories used with this argument should always exist on every machine. This basically means that they should be available within the source tree.
	// If this argument type is used for directories outside of the source tree, then expect divergeant behavior between operating systems.
	ArgumentTypeUnpackagedFS
)

func (ArgumentType) String

func (a ArgumentType) String() string

type FilesystemState

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

FilesystemState stores state in a JSON file on the filesystem.

func NewFilesystemState

func NewFilesystemState(path string) (*FilesystemState, error)

func (*FilesystemState) Exists

func (f *FilesystemState) Exists(arg Argument) (bool, error)

func (*FilesystemState) GetBool

func (f *FilesystemState) GetBool(arg Argument) (bool, error)

func (*FilesystemState) GetDirectory

func (f *FilesystemState) GetDirectory(arg Argument) (fs.FS, error)

func (*FilesystemState) GetDirectoryString

func (f *FilesystemState) GetDirectoryString(arg Argument) (string, error)

GetDirectoryString retrieves the original directory path. This can be particularly useful for things stored within the source filesystem.

func (*FilesystemState) GetFile

func (f *FilesystemState) GetFile(arg Argument) (*os.File, error)

func (*FilesystemState) GetFloat64

func (f *FilesystemState) GetFloat64(arg Argument) (float64, error)

func (*FilesystemState) GetInt64

func (f *FilesystemState) GetInt64(arg Argument) (int64, error)

func (*FilesystemState) GetString

func (f *FilesystemState) GetString(arg Argument) (string, error)

func (*FilesystemState) SetBool

func (f *FilesystemState) SetBool(arg Argument, value bool) error

func (*FilesystemState) SetDirectory

func (f *FilesystemState) SetDirectory(arg Argument, value string) error

func (*FilesystemState) SetFile

func (f *FilesystemState) SetFile(arg Argument, value string) error

func (*FilesystemState) SetFileReader

func (f *FilesystemState) SetFileReader(arg Argument, value io.Reader) error

func (*FilesystemState) SetFloat64

func (f *FilesystemState) SetFloat64(arg Argument, value float64) error

func (*FilesystemState) SetInt64

func (f *FilesystemState) SetInt64(arg Argument, value int64) error

func (*FilesystemState) SetString

func (f *FilesystemState) SetString(arg Argument, value string) error

type State

type State struct {
	Handler  StateHandler
	Fallback []StateReader
	Log      logrus.FieldLogger
}

func (*State) Exists

func (s *State) Exists(arg Argument) (bool, error)

Exists checks the state to see if an argument exists in it. It can return an error in the event of a failure to check the state. An error will not be returned if the state could be read and the value was not in it. If a value for argument was not found, then false and a nil error is returned.

func (*State) GetBool

func (s *State) GetBool(arg Argument) (bool, error)

GetBool attempts to get the bool from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) GetDirectory

func (s *State) GetDirectory(arg Argument) (fs.FS, error)

GetDirectory attempts to get the directory from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) GetDirectoryString

func (s *State) GetDirectoryString(arg Argument) (string, error)

GetDirectory attempts to get the directory from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) GetFile

func (s *State) GetFile(arg Argument) (*os.File, error)

GetFile attempts to get the file from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) GetFloat64

func (s *State) GetFloat64(arg Argument) (float64, error)

GetFloat64 attempts to get the int64 from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) GetInt64

func (s *State) GetInt64(arg Argument) (int64, error)

GetInt64 attempts to get the int64 from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) GetString

func (s *State) GetString(arg Argument) (string, error)

GetString attempts to get the string from the state. If there are Fallback readers and the state returned an error, then it will loop through each one, attempting to retrieve the value from the fallback state reader. If no fallback reader returns the value, then the original error is returned.

func (*State) MustGetBool

func (s *State) MustGetBool(arg Argument) bool

func (*State) MustGetDirectory

func (s *State) MustGetDirectory(arg Argument) fs.FS

func (*State) MustGetDirectoryString

func (s *State) MustGetDirectoryString(arg Argument) string

func (*State) MustGetFile

func (s *State) MustGetFile(arg Argument) *os.File

func (*State) MustGetFloat64

func (s *State) MustGetFloat64(arg Argument) float64

func (*State) MustGetInt64

func (s *State) MustGetInt64(arg Argument) int64

func (*State) MustGetString

func (s *State) MustGetString(arg Argument) string

func (*State) SetBool

func (s *State) SetBool(arg Argument, value bool) error

SetBool attempts to set the bool into the state.

func (*State) SetDirectory

func (s *State) SetDirectory(arg Argument, path string) error

SetDirectory attempts to set the directory into the state. The "path" argument should be the path to the directory to be stored.

func (*State) SetFile

func (s *State) SetFile(arg Argument, path string) error

SetFile attempts to set the file into the state. The "path" argument should be the path to the file to be stored.

func (*State) SetFileReader

func (s *State) SetFileReader(arg Argument, r io.Reader) error

SetFileReader attempts to set the reader into the state as a file. This is an easy way to go from downloading a file to setting it into the state without having to write it to disk first.

func (*State) SetFloat64

func (s *State) SetFloat64(arg Argument, value float64) error

SetFloat64 attempts to set the float64 into the state.

func (*State) SetInt64

func (s *State) SetInt64(arg Argument, value int64) error

SetInt64 attempts to set the int64 into the state.

func (*State) SetString

func (s *State) SetString(arg Argument, value string) error

SetString attempts to set the string into the state.

type StateHandler

type StateHandler interface {
	StateReader
	StateWriter
}

type StateHandlerLogWrapper

type StateHandlerLogWrapper struct {
	*StateReaderLogWrapper
	*StateWriterLogWrapper
}

func StateHandlerWithLogs

func StateHandlerWithLogs(log logrus.FieldLogger, state StateHandler) *StateHandlerLogWrapper

type StateReader

type StateReader interface {
	Exists(Argument) (bool, error)
	GetString(Argument) (string, error)
	GetInt64(Argument) (int64, error)
	GetFloat64(Argument) (float64, error)
	GetBool(Argument) (bool, error)
	GetFile(Argument) (*os.File, error)
	GetDirectory(Argument) (fs.FS, error)
	GetDirectoryString(Argument) (string, error)
}

type StateReaderLogWrapper

type StateReaderLogWrapper struct {
	StateReader
	Log logrus.FieldLogger
}

func StateReaderWithLogs

func StateReaderWithLogs(log logrus.FieldLogger, state StateReader) *StateReaderLogWrapper

func (*StateReaderLogWrapper) Exists

func (s *StateReaderLogWrapper) Exists(arg Argument) (bool, error)

func (*StateReaderLogWrapper) GetDirectory

func (s *StateReaderLogWrapper) GetDirectory(arg Argument) (fs.FS, error)

func (*StateReaderLogWrapper) GetDirectoryString

func (s *StateReaderLogWrapper) GetDirectoryString(arg Argument) (string, error)

func (*StateReaderLogWrapper) GetFile

func (s *StateReaderLogWrapper) GetFile(arg Argument) (*os.File, error)

func (*StateReaderLogWrapper) GetFloat64

func (s *StateReaderLogWrapper) GetFloat64(arg Argument) (float64, error)

func (*StateReaderLogWrapper) GetInt64

func (s *StateReaderLogWrapper) GetInt64(arg Argument) (int64, error)

func (*StateReaderLogWrapper) GetString

func (s *StateReaderLogWrapper) GetString(arg Argument) (string, error)

type StateWriter

type StateWriter interface {
	SetString(Argument, string) error
	SetInt64(Argument, int64) error
	SetFloat64(Argument, float64) error
	SetBool(Argument, bool) error
	SetFile(Argument, string) error
	SetFileReader(Argument, io.Reader) error
	SetDirectory(Argument, string) error
}

type StateWriterLogWrapper

type StateWriterLogWrapper struct {
	StateWriter
	Log logrus.FieldLogger
}

func StateWriterWithLogs

func StateWriterWithLogs(log logrus.FieldLogger, state StateWriter) *StateWriterLogWrapper

func (*StateWriterLogWrapper) SetDirectory

func (s *StateWriterLogWrapper) SetDirectory(arg Argument, val string) error

func (*StateWriterLogWrapper) SetFile

func (s *StateWriterLogWrapper) SetFile(arg Argument, val string) error

func (*StateWriterLogWrapper) SetFileReader

func (s *StateWriterLogWrapper) SetFileReader(arg Argument, val io.Reader) error

func (*StateWriterLogWrapper) SetFloat64

func (s *StateWriterLogWrapper) SetFloat64(arg Argument, val float64) error

func (*StateWriterLogWrapper) SetInt64

func (s *StateWriterLogWrapper) SetInt64(arg Argument, val int64) error

func (*StateWriterLogWrapper) SetString

func (s *StateWriterLogWrapper) SetString(arg Argument, val string) error

type StdinReader

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

func NewStdinReader

func NewStdinReader(in io.Reader, out io.Writer) *StdinReader

func (*StdinReader) Exists

func (s *StdinReader) Exists(arg Argument) (bool, error)

Since the StdinReader can read any state value, it's better if we assume that if it's being used, then it wasn't found in other reasonable state managers.

func (*StdinReader) Get

func (s *StdinReader) Get(arg Argument) (string, error)

func (*StdinReader) GetBool

func (s *StdinReader) GetBool(arg Argument) (bool, error)

func (*StdinReader) GetDirectory

func (s *StdinReader) GetDirectory(arg Argument) (fs.FS, error)

func (*StdinReader) GetDirectoryString

func (s *StdinReader) GetDirectoryString(arg Argument) (string, error)

func (*StdinReader) GetFile

func (s *StdinReader) GetFile(arg Argument) (*os.File, error)

func (*StdinReader) GetFloat64

func (s *StdinReader) GetFloat64(arg Argument) (float64, error)

func (*StdinReader) GetInt64

func (s *StdinReader) GetInt64(arg Argument) (int64, error)

func (*StdinReader) GetString

func (s *StdinReader) GetString(arg Argument) (string, error)

Jump to

Keyboard shortcuts

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