utils

package
v0.0.0-...-13c9884 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 GetTerraformOutputs

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

func RenderGoTemplate

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

func RunInteractive

func RunInteractive(ctx context.Context, catchOutputs bool, command string, cwd string, 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, catchOutputs bool, 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

Jump to

Keyboard shortcuts

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