modules

package
v4.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StdoutSuccess is the standard message indicating a successful module execution.
	StdoutSuccess = "success"
	// StdoutFailed is the standard message indicating a failed module execution.
	StdoutFailed = "failed"
	// StdoutSkip is the standard message indicating a skipped module execution.
	StdoutSkip = "skip"

	// StderrGetConnector is returned when the connector cannot be obtained.
	StderrGetConnector = "failed to get connector"
	// StderrGetHostVariable is returned when host variables cannot be retrieved.
	StderrGetHostVariable = "failed to get host variable"
	// StderrParseArgument is returned when module arguments cannot be parsed.
	StderrParseArgument = "failed to parse argument"
	// StderrUnsupportArgs is returned when the provided arguments are not supported.
	StderrUnsupportArgs = "unsupport args"
	// StderrGetPlaybook is returned when get playbook error
	StderrGetPlaybook = "failed to get playbook"
)

Variables

View Source
var ConnKey = &key{}

ConnKey is the context key for storing/retrieving a connector in context.Context.

Functions

func EncodeCertPEM

func EncodeCertPEM(cert *x509.Certificate) []byte

EncodeCertPEM encodes the given certificate into PEM format.

func ModuleAddHostvars

func ModuleAddHostvars(ctx context.Context, options ExecOptions) (string, string, error)

ModuleAddHostvars handles the "add_hostvars" module, merging variables into the specified hosts. Returns empty stdout and stderr on success, or error message in stderr on failure.

func ModuleAssert

func ModuleAssert(ctx context.Context, options ExecOptions) (string, string, error)

ModuleAssert handles the "assert" module, evaluating boolean conditions and returning appropriate messages

func ModuleCommand

func ModuleCommand(ctx context.Context, options ExecOptions) (string, string, error)

ModuleCommand handles the "command" module, executing shell commands on remote hosts

func ModuleCopy

func ModuleCopy(ctx context.Context, options ExecOptions) (string, string, error)

ModuleCopy handles the "copy" module, copying files or content to remote hosts.

func ModuleDebug

func ModuleDebug(_ context.Context, options ExecOptions) (string, string, error)

ModuleDebug handles the "debug" module, printing debug information

func ModuleFetch

func ModuleFetch(ctx context.Context, options ExecOptions) (string, string, error)

ModuleFetch handles the "fetch" module, retrieving files from remote hosts

func ModuleGenCert

func ModuleGenCert(ctx context.Context, options ExecOptions) (string, string, error)

ModuleGenCert is the entry point for the "gen_cert" module, responsible for generating SSL/TLS certificates.

func ModuleImage

func ModuleImage(ctx context.Context, options ExecOptions) (string, string, error)

ModuleImage handles the "image" module, managing container image operations including pulling and pushing images

func ModuleIncludeVars

func ModuleIncludeVars(ctx context.Context, options ExecOptions) (string, string, error)

ModuleIncludeVars handle the "include_vars" module ,add other var files into playbook

func ModulePrometheus

func ModulePrometheus(ctx context.Context, options ExecOptions) (string, string, error)

ModulePrometheus handles the "prometheus" module, using prometheus connector to execute PromQL queries

func ModuleResult

func ModuleResult(ctx context.Context, options ExecOptions) (string, string, error)

ModuleResult handles the "result" module, setting result variables during playbook execution

func ModuleSetFact

func ModuleSetFact(_ context.Context, options ExecOptions) (string, string, error)

ModuleSetFact handles the "set_fact" module, setting variables during playbook execution

func ModuleSetup

func ModuleSetup(ctx context.Context, options ExecOptions) (string, string, error)

ModuleSetup establishes a connection to a remote host and gathers facts about it. It returns StdoutSuccess if successful, or an error message if any step fails.

func ModuleTemplate

func ModuleTemplate(ctx context.Context, options ExecOptions) (string, string, error)

ModuleTemplate handles the "template" module, processing files with Go templates

func NewSelfSignedCACert

func NewSelfSignedCACert(cfg cgutilcert.Config, after time.Duration, key crypto.Signer) (*x509.Certificate, error)

NewSelfSignedCACert creates a new self-signed CA certificate.

func NewSignedCert

func NewSignedCert(cfg cgutilcert.Config, after time.Duration, key crypto.Signer, caCert *x509.Certificate, caKey crypto.Signer, isCA bool) (*x509.Certificate, error)

NewSignedCert creates a certificate signed by the given CA certificate and key.

func RegisterModule

func RegisterModule(moduleName string, exec ModuleExecFunc) error

RegisterModule registers a module execution function under the given module name. Returns an error if the module name is already registered.

func RemoveDuplicateAltNames

func RemoveDuplicateAltNames(altNames *cgutilcert.AltNames)

RemoveDuplicateAltNames eliminates duplicate entries from the AltNames struct.

func TryLoadCertChainFromDisk

func TryLoadCertChainFromDisk(rootCert string) ([]*x509.Certificate, error)

TryLoadCertChainFromDisk loads a certificate chain from the specified file.

func TryLoadKeyFromDisk

func TryLoadKeyFromDisk(rootKey string) (crypto.Signer, error)

TryLoadKeyFromDisk attempts to load and validate a private key from disk.

func ValidateCertPeriod

func ValidateCertPeriod(cert *x509.Certificate, offset time.Duration) error

ValidateCertPeriod checks whether the certificate is currently valid, considering the given offset.

func VerifyCertChain

func VerifyCertChain(cert *x509.Certificate, intermediates []*x509.Certificate, root *x509.Certificate) error

VerifyCertChain ensures that a certificate has a valid chain of trust back to the root CA.

func WriteCert

func WriteCert(outCert string, cert *x509.Certificate, policy string) error

WriteCert writes the given certificate to the specified file path.

func WriteKey

func WriteKey(outKey string, key crypto.Signer, policy string) error

WriteKey writes the given private key to the specified file path.

Types

type ExecOptions

type ExecOptions struct {
	// Args contains the defined arguments for the module.
	Args runtime.RawExtension
	// Host specifies which host to execute the module on.
	Host string
	// Variable provides the variables needed by the module.
	variable.Variable
	// Task is the task to be executed.
	Task kkcorev1alpha1.Task
	// Playbook is the playbook to be executed.
	Playbook kkcorev1.Playbook
	// LogOutput is the output writer for module logs.
	LogOutput io.Writer
}

ExecOptions represents options for module execution.

type ModuleExecFunc

type ModuleExecFunc func(ctx context.Context, options ExecOptions) (stdout string, stderr string, err error)

ModuleExecFunc defines the function signature for executing a module. It takes a context and ExecOptions, and returns stdout and stderr strings.

func FindModule

func FindModule(moduleName string) ModuleExecFunc

FindModule retrieves a registered module execution function by its name. Returns nil if the module is not found.

Jump to

Keyboard shortcuts

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