utils

package
v0.0.0-...-82678ac Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdentifierFieldName = "identifier"
	ArgsFieldName       = "args"
	CommandFieldName    = "command"
	CwdFieldName        = "cwd"
	ModuleName          = "@module"
	NameName            = "name"
	TimestampMain       = "timestamp"
)

Variables

View Source
var (
	FS  = afero.NewOsFs()
	AFS = &afero.Afero{Fs: FS}
)
View Source
var DebugTransport = &LogTransport{
	transport: http.DefaultTransport,
}

Functions

func CmdSetForeground

func CmdSetForeground(cmd *exec.Cmd)

func ComputeDirHash

func ComputeDirHash(path string) (string, error)

func ComputeFileHash

func ComputeFileHash(filePath string) (string, error)

func ComputeHash

func ComputeHash(t interface{}) (string, error)

func DecryptYaml

func DecryptYaml(ctx context.Context, filename string) ([]byte, error)

decryptYaml takes a filename and returns the decrypted yaml. This command directly calls the sops binary instead of using the go.mozilla.org/sops/v3/decrypt package since that adds numerous dependencies and adds ~19mb to the generated binary

func FilterMap

func FilterMap(data map[string]any, skipKeys []string) map[string]any

func FormatIdentifier

func FormatIdentifier(identifier string) string

func GetTerraformOutputs

func GetTerraformOutputs(ctx context.Context, path string) (cty.Value, error)

func Ref

func Ref[T any](v T) *T

func RenderGoTemplate

func RenderGoTemplate(t string, data any) (string, error)

func RunInteractive

func RunInteractive(ctx context.Context, command string, cwd string, w io.Writer, args ...string) (string, error)

func RunSops

func RunSops(ctx context.Context, cwd string, args ...string) ([]byte, error)

func RunTerraform

func RunTerraform(ctx context.Context, cwd string, args ...string) (string, error)

RunTerraform will execute a terraform command with the given arguments in the given directory.

func StopProcess

func StopProcess(cmd *exec.Cmd) error

func TrimIndent

func TrimIndent(data string) string

Types

type LogTransport

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

func (*LogTransport) RoundTrip

func (c *LogTransport) RoundTrip(request *http.Request) (*http.Response, error)

type OnceMap

type OnceMap[K comparable] map[K]*sync.Once

OnceMap allows for creating a map of sync.Once elements. This allows for running multiple different processes only once.

A use case is for example a list of downloads, where we only want to run every unique download only once.

var downloadFiles = utils.OnceMap{}

for _, file := files {
	downloadFiles.Get(file).Do(func() {
		downloadFile(ctx, file)
	})
}

func (*OnceMap[any]) Get

func (m *OnceMap[any]) Get(key any) *sync.Once

Get will search for an existing key. If it exists the sync.Once will be returned. If not a new sync. Once will be created and set on the map

type StdHook

type StdHook struct {
	Logger zerolog.Logger
}

func (StdHook) Run

func (s StdHook) Run(e *zerolog.Event, level zerolog.Level, message string)

Jump to

Keyboard shortcuts

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