hook

package
v3.57.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package hook provides management and execution of hook scripts, and the ability to capture environment variable changes caused by scripts.

It is intended for internal use by buildkite-agent only.

Index

Constants

View Source
const (
	TypeShell   = "shell"
	TypeBinary  = "binary"
	TypeScript  = "script" // Something with a shebang that isn't a shell script, but is an interpretable something-or-other
	TypeUnknown = "unknown"
)

Variables

View Source
var (
	// Linux and many other Unix-like systems use ELF binaries
	ELFMagic = []byte{0x7F, 0x45, 0x4C, 0x46}

	// Windows uses MS-DOS MZ-style executables. This includes PE32 and PE32+ (which is 64-bit 🙃) binaries,
	// which are what modern windowses tend to use.
	MZMagic = []byte{0x4D, 0x5A}

	// For "fat" binaries, which contain multiple architectures
	MachOFatMagic = []byte{0xCA, 0xFE, 0xBA, 0xBE}

	// For "thin" binaries, which contain a single architecture
	// (ie 32 and 64 bit variants, on top of different processor architectures)
	MachOThin32Magic = []byte{0xFE, 0xED, 0xFA, 0xCE}
	MachOThin64Magic = []byte{0xFE, 0xED, 0xFA, 0xCF}

	// Mach-O thin binaries can also be in reverse byte order, apparently?
	// I think this is for big endian processors like PowerPC, in which case we don't need these here,
	// but we might as well include them for completeness.
	MachOThin32ReverseMagic = []byte{0xCE, 0xFA, 0xED, 0xFE}
	MachOThin64ReverseMagic = []byte{0xCF, 0xFA, 0xED, 0xFE}

	BinaryMagicks = [][]byte{
		ELFMagic,
		MZMagic,
		MachOFatMagic,
		MachOThin32Magic,
		MachOThin64Magic,
		MachOThin32ReverseMagic,
		MachOThin64ReverseMagic,
	}
)

Magic numbers for various types of executable files

Functions

func Find

func Find(hookDir string, name string) (string, error)

Find returns the absolute path to the best matching hook file in a path, or os.ErrNotExist if none is found

func Type added in v3.47.0

func Type(path string) (string, error)

func WithHookPath added in v3.38.0

func WithHookPath(path string) scriptWrapperOpt

func WithOS added in v3.38.0

func WithOS(os string) scriptWrapperOpt

Types

type HookExitError added in v3.33.3

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

func (*HookExitError) Error added in v3.33.3

func (e *HookExitError) Error() string

type HookScriptChanges added in v3.33.0

type HookScriptChanges struct {
	Diff env.Diff
	// contains filtered or unexported fields
}

func (*HookScriptChanges) GetAfterWd added in v3.33.3

func (changes *HookScriptChanges) GetAfterWd() (string, error)

type ScriptWrapper

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

ScriptWrapper wraps a hook script with env collection and then provides a way to get the difference between the environment before the hook is run and after it

func NewScriptWrapper added in v3.38.0

func NewScriptWrapper(opts ...scriptWrapperOpt) (*ScriptWrapper, error)

NewScriptWrapper creates and configures a ScriptWrapper. Writes temporary files to the filesystem.

func (*ScriptWrapper) Changes

func (wrap *ScriptWrapper) Changes() (HookScriptChanges, error)

Changes returns the changes in the environment and working dir after the hook script runs

func (*ScriptWrapper) Close

func (wrap *ScriptWrapper) Close()

Close cleans up the wrapper script and the environment files

func (*ScriptWrapper) Path

func (wrap *ScriptWrapper) Path() string

Path returns the path to the wrapper script, this is the one that should be executed

Jump to

Keyboard shortcuts

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