Documentation
¶
Index ¶
- Constants
- Variables
- func InstallHookScripts(dir string, hookPod *pods.Pod, manifest manifest.Manifest, ...) error
- func NewContext(dirpath string, podRoot string, logger *logging.Logger, ...) *hookContext
- type AuditLogger
- type ErrHookTimeout
- type FileAuditLogger
- type HookEnv
- func (h *HookEnv) Config() (*config.Config, error)
- func (h *HookEnv) ConfigDirPath() string
- func (h *HookEnv) EnvPath() string
- func (h *HookEnv) Event() (HookType, error)
- func (h *HookEnv) ExitUnlessEvent(types ...HookType) HookType
- func (h *HookEnv) Manifest() (manifest.Manifest, error)
- func (h *HookEnv) Node() (types.NodeName, error)
- func (h *HookEnv) Pod() (*pods.Pod, error)
- func (h *HookEnv) PodFromDisk() (*pods.Pod, error)
- func (h *HookEnv) PodHome() (string, error)
- func (h *HookEnv) PodID() (types.PodID, error)
- type HookExecContext
- type HookExecutionEnvironment
- type HookType
- type Pod
- type SQLiteAuditLogger
Constants ¶
const ( HookEnvVar = "HOOK" HookEventEnvVar = "HOOK_EVENT" HookedNodeEnvVar = "HOOKED_NODE" HookedPodIDEnvVar = "HOOKED_POD_ID" HookedPodHomeEnvVar = "HOOKED_POD_HOME" HookedPodManifestEnvVar = "HOOKED_POD_MANIFEST" HookedConfigPathEnvVar = "HOOKED_CONFIG_PATH" HookedEnvPathEnvVar = "HOOKED_ENV_PATH" HookedConfigDirPathEnvVar = "HOOKED_CONFIG_DIR_PATH" HookedSystemPodRootEnvVar = "HOOKED_SYSTEM_POD_ROOT" HookedPodUniqueKeyEnvVar = "HOOKED_POD_UNIQUE_KEY" HookedPodReadOnly = "HOOKED_POD_READ_ONLY" DefaultTimeout = 120 * time.Second )
Variables ¶
var ( // BeforeInstall hooks run before the artifact is downloaded and extracted BeforeInstall = HookType("before_install") // AfterInstall hooks run after we have installed but before we have disabled the old version AfterInstall = HookType("after_install") // BeforeUninstall happens after shutdown but before uninstall BeforeUninstall = HookType("before_uninstall") // BeforeLaunch occurs after we have disabled the old version BeforeLaunch = HookType("before_launch") // AfterLaunch occurs after launch AfterLaunch = HookType("after_launch") // AfterAuth occurs conditionally when artifact authorization fails AfterAuthFail = HookType("after_auth_fail") )
var DefaultPath = "/usr/local/p2hooks.d"
DefaultPath is a directory on disk where hooks are installed by default.
Functions ¶
func InstallHookScripts ¶
func InstallHookScripts(dir string, hookPod *pods.Pod, manifest manifest.Manifest, logger logging.Logger) error
Populates the given directory with executor scripts for each launch script of the given pod, which must be installed. Any orphaned executor scripts (from a past install, but no longer present in this pod) will be cleaned out.
func NewContext ¶
func NewContext(dirpath string, podRoot string, logger *logging.Logger, auditLogger AuditLogger) *hookContext
Types ¶
type AuditLogger ¶
type AuditLogger interface { // LogSuccess should be invoked on successful events. LogSuccess(env *HookExecContext) // LogFailure should be called in case of error or timeout. The second parameter may be null. LogFailure(env *HookExecContext, err error) // Close any references held by this AuditLogger Close() error }
AuditLogger defines a mechanism for logging hook success or failure to a store, such as a file or SQLite
type ErrHookTimeout ¶
type ErrHookTimeout struct {
Hook HookExecContext
}
ErrHookTimeout is returned when a Hook's execution times out
func (ErrHookTimeout) Error ¶
func (e ErrHookTimeout) Error() string
type FileAuditLogger ¶
type FileAuditLogger struct {
// contains filtered or unexported fields
}
func NewFileAuditLogger ¶
func NewFileAuditLogger(logger *logging.Logger) *FileAuditLogger
Returns a FileAuditLogger using the given logger
func (*FileAuditLogger) Close ¶
func (al *FileAuditLogger) Close() error
func (*FileAuditLogger) LogFailure ¶
func (al *FileAuditLogger) LogFailure(env *HookExecContext, err error)
func (*FileAuditLogger) LogSuccess ¶
func (al *FileAuditLogger) LogSuccess(env *HookExecContext)
type HookEnv ¶
type HookEnv struct{}
Hook env is a utility for hook writers using Go. This provides useful access to objects exported by the hooks package.
func CurrentEnv ¶
func CurrentEnv() *HookEnv
func (*HookEnv) ConfigDirPath ¶
func (*HookEnv) ExitUnlessEvent ¶
func (*HookEnv) PodFromDisk ¶
Initializes a pod from the current_manifest.yaml file in the pod's home directory. This function will error or return an old manifest if run during an inappropriate hook event, use of this function is discouraged in most cases
type HookExecContext ¶
type HookExecContext struct { Path string // path to hook's executable Name string // human-readable name of Hook Timeout time.Duration // contains filtered or unexported fields }
func NewHookExecContext ¶
func NewHookExecContext(path string, name string, timeout time.Duration, env HookExecutionEnvironment, logger logging.Logger) *HookExecContext
func (*HookExecContext) Close ¶
func (hec *HookExecContext) Close()
Close any references held by this HookExecContext
func (*HookExecContext) Run ¶
func (h *HookExecContext) Run(logger logging.Logger)
Run executes the hook in the context of its environment and logs the output
func (*HookExecContext) RunWithTimeout ¶
func (h *HookExecContext) RunWithTimeout(logger logging.Logger) error
RunWithTimeout runs the hook but returns a HookTimeoutError when it exceeds its timeout
Necessary because Run() hangs if the command double-forks without properly re-opening its fd's and exec.Start() will dutifully wait on any unclosed fd
NB: in the event of a timeout this will leak descriptors
type HookExecutionEnvironment ¶
type HookExecutionEnvironment struct { HookEnvVar, HookEventEnvVar, HookedNodeEnvVar, HookedPodIDEnvVar, HookedPodHomeEnvVar, HookedPodManifestEnvVar, HookedConfigPathEnvVar, HookedEnvPathEnvVar, HookedConfigDirPathEnvVar, HookedSystemPodRootEnvVar, HookedPodUniqueKeyEnvVar, HookedPodReadOnly string }
The set of environment variables exposed to the hook as it runs TODO Need this be public?
func (*HookExecutionEnvironment) Env ¶
func (hee *HookExecutionEnvironment) Env() []string
The set of UNIX environment variables for the hook's execution
type HookType ¶
type HookType string
HookType represents the stage in the Hook lifecycle
func AsHookType ¶
type Pod ¶
type Pod interface { ConfigDir() string EnvDir() string Node() types.NodeName Home() string UniqueKey() types.PodUniqueKey ReadOnly() bool }
Pod is the minimum set of functions needed for a hook to operate on a Pod
type SQLiteAuditLogger ¶
type SQLiteAuditLogger struct {
// contains filtered or unexported fields
}
func NewSQLiteAuditLogger ¶
func NewSQLiteAuditLogger(sqliteDBPath string, logger *logging.Logger) (*SQLiteAuditLogger, error)
func (*SQLiteAuditLogger) Close ¶
func (al *SQLiteAuditLogger) Close() error
Close will terminate this AuditLogger. Re-establishing the connection is not supported, use the constructor.
func (*SQLiteAuditLogger) LogFailure ¶
func (al *SQLiteAuditLogger) LogFailure(ctx *HookExecContext, err error)
func (*SQLiteAuditLogger) LogSuccess ¶
func (al *SQLiteAuditLogger) LogSuccess(ctx *HookExecContext)