utils

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const MondooClientSecret = "mondoo-client"

Variables

View Source
var (
	CreateArgs                        = []string{"create", "-f"}
	CreateFromStdinArgs               = append(CreateArgs, "-")
	DeleteArgs                        = []string{"delete", "-f"}
	DeleteArgsIgnoreNotFound          = []string{"delete", "--ignore-not-found=true", "-f"}
	DeleteFromStdinArgs               = append(DeleteArgs, "-")
	DeleteIngoreNotFoundFromStdinArgs = append(DeleteArgsIgnoreNotFound, "-")
)

Functions

func DefaultAuditConfig

func DefaultAuditConfig(ns string, workloads, nodes, admission bool) mondoov2.MondooAuditConfig

DefaultAuditConfig returns a new Mondoo audit config with some default settings to make sure a tests passes (e.g. setting the correct secret name).

func ExitStatus

func ExitStatus(err error) (int, bool)

func FindRootFolder

func FindRootFolder() (string, error)

func GenerateTLSCerts

func GenerateTLSCerts(dnsNames []string) (*bytes.Buffer, *bytes.Buffer, *bytes.Buffer, error)

GenerateTLSCerts will return create a CA and return the CA certificate, the Server certificate, and the Server private key for the provided list of dnsNames

func LabelSelectorListOptions

func LabelSelectorListOptions(labelSelector string) (*client.ListOptions, error)

func ReadFile

func ReadFile(filename string) string

Types

type CommandArgs

type CommandArgs struct {
	Command             string
	CmdArgs             []string
	PipeToStdIn         string
	EnvironmentVariable []string
}

CommandArgs is a warpper for cmd args

type CommandExecutor

type CommandExecutor struct {
}

CommandExecutor is the type of the Executor

func (*CommandExecutor) ExecuteCommand

func (c *CommandExecutor) ExecuteCommand(command string, arg ...string) error

ExecuteCommand starts a process and wait for its completion

func (*CommandExecutor) ExecuteCommandWithCombinedOutput

func (*CommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)

ExecuteCommandWithCombinedOutput executes a command with combined output

func (*CommandExecutor) ExecuteCommandWithEnv

func (*CommandExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error

ExecuteCommandWithEnv starts a process with env variables and wait for its completion

func (*CommandExecutor) ExecuteCommandWithOutput

func (*CommandExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)

ExecuteCommandWithOutput executes a command with output

func (*CommandExecutor) ExecuteCommandWithOutputFile

func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string, arg ...string) (string, error)

ExecuteCommandWithOutputFile executes a command with output on a file #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close

func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout

func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout(timeout time.Duration,
	command, outfileArg string, arg ...string) (string, error)

ExecuteCommandWithOutputFileTimeout Same as ExecuteCommandWithOutputFile but with a timeout limit. #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close

func (*CommandExecutor) ExecuteCommandWithTimeout

func (*CommandExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)

ExecuteCommandWithTimeout starts a process and wait for its completion with timeout.

type CommandOut

type CommandOut struct {
	StdOut   string
	StdErr   string
	ExitCode int
	Err      error
}

CommandOut is a wrapper for cmd out returned after executing command args

func ExecuteCommand

func ExecuteCommand(cmdStruct CommandArgs) CommandOut

ExecuteCommand executes a os command with stdin and returns output

type K8sHelper

type K8sHelper struct {
	Clientset        client.Client
	RunningInCluster bool
	// contains filtered or unexported fields
}

func CreateK8sHelper

func CreateK8sHelper() (*K8sHelper, error)

CreateK8sHelper creates a instance of k8sHelper

func (*K8sHelper) DeleteResourceIfExists

func (k8sh *K8sHelper) DeleteResourceIfExists(r client.Object) error

DeleteResourceIfExists Deletes the requested resource if it exists. If the resource does not exist, the function does nothing (return no error).

func (*K8sHelper) GetEventsFromNamespace

func (k8sh *K8sHelper) GetEventsFromNamespace(namespace, testName string)

func (*K8sHelper) GetLogsFromNamespace

func (k8sh *K8sHelper) GetLogsFromNamespace(namespace, testName string)

GetLogsFromNamespace collects logs for all containers in all pods in the namespace

func (*K8sHelper) GetPodDescribeFromNamespace

func (k8sh *K8sHelper) GetPodDescribeFromNamespace(namespace, testName string)

func (*K8sHelper) IsPodReady

func (k8sh *K8sHelper) IsPodReady(labelSelector, namespace string) bool

IsPodInExpectedState waits for a pod to be in a Ready state If the pod is in expected state within the time retry limit true is returned, if not false

func (*K8sHelper) Kubectl

func (k8sh *K8sHelper) Kubectl(args ...string) (string, error)

Kubectl is wrapper for executing kubectl commands

func (*K8sHelper) KubectlWithStdin

func (k8sh *K8sHelper) KubectlWithStdin(stdin string, args ...string) (string, error)

KubectlWithStdin is wrapper for executing kubectl commands in stdin

func (*K8sHelper) PrintPodDescribe

func (k8sh *K8sHelper) PrintPodDescribe(namespace string, args ...string)

func (*K8sHelper) WaitForResourceDeletion

func (k8sh *K8sHelper) WaitForResourceDeletion(r client.Object) error

WaitForResourceDeletion waits for a resource deletion

Jump to

Keyboard shortcuts

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