utils

package
v0.0.0-...-be2e3c8 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package utils contains utilities common to all units of the Operator

The package includes:

- Common utilities

- Common test utilities, like constructors for test doubles etc

Index

Constants

View Source
const ArgdContainerToImageIds = "containerToImageIDs"
View Source
const ArgsContainerData = "containerData"
View Source
const ArgsName = "name"
View Source
const ArgsNamespace = "namespace"
View Source
const ArgsPod = "pod"
View Source
const CommandScanApplicationProfile = "scanApplicationProfile"
View Source
const KubescapeRequestPathV1 = "v1/scan"
View Source
const KubescapeRequestStatusV1 = "v1/status"
View Source
const KubescapeScanV1 = "scanV1"

Variables

This section is empty.

Functions

func AddCommandToChannel

func AddCommandToChannel(ctx context.Context, config config.IConfig, cmd *apis.Command, workerPool *ants.PoolWithFunc) error

func ExtractContainersToImageIDsFromPod

func ExtractContainersToImageIDsFromPod(pod *corev1.Pod) map[string]string

func ExtractImageID

func ExtractImageID(imageID string) string

func GetApplicationProfileForRelevancyScan

func GetApplicationProfileForRelevancyScan(ctx context.Context, storageClient kssc.Interface, slug, namespace string) *v1beta1.ApplicationProfile

GetApplicationProfileForRelevancyScan retrieves an application profile from the storage client based on the provided slug and namespace If the application profile is found, and it should not be skipped (i.e. correct status, InstanceID and WLID annotations), it is returned, otherwise nil

func GetApplicationProfileScanCommand

func GetApplicationProfileScanCommand(appProfile *v1beta1.ApplicationProfile, pod *corev1.Pod) *apis.Command

func GetRequestHeaders

func GetRequestHeaders(accessKey string) map[string]string

func InitHttpClient

func InitHttpClient(url string) httputils.IHttpClient

func MapToString

func MapToString(m map[string]interface{}) []string

func NewK8sInterfaceFake

func NewK8sInterfaceFake(k8sClient k8s.Interface) *k8sinterface.KubernetesApi

NewK8sInterfaceFake returns a new K8sInterface with a fake Kubernetes Client attached

This function is a Dependency Injection-friendly version for the `KubernetesApi` constructor that allows to inject any Kubernetes Clients. For example, the official fake Kubernetes client, so unit tests would have a suitable test double instead of trying to talk to a real cluster

func SkipApplicationProfile

func SkipApplicationProfile(annotations map[string]string) (bool, error)

func WithError

func WithError(err error) func(*patchStatus)

func WithMultipleErrors

func WithMultipleErrors(errors []error) func(*patchStatus)

func WithPayload

func WithPayload(payload []byte) func(*patchStatus)

func WithSuccess

func WithSuccess() func(*patchStatus)

Types

type ClientMock

type ClientMock struct {
}

func (*ClientMock) Do

func (c *ClientMock) Do(req *http.Request) (*http.Response, error)

type ContainerData

type ContainerData struct {
	ImageTag      string // imageTag (from container.Image)
	ImageID       string // imageID (from containerStatus.ImageID)
	InstanceID    string // instanceID.GetStringFormatted()
	ContainerName string // containerName
	ContainerType string // containerType (init or regular)
	Slug          string // represent the unique identifier of the container
	Wlid          string // workloadID
}

func PodToContainerData

func PodToContainerData(k8sAPI *k8sinterface.KubernetesApi, pod *corev1.Pod, instanceID instanceidhandler.IInstanceID, clusterName string) (*ContainerData, error)

type CredStruct

type CredStruct struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Customer string `json:"customer"`
}

CredStruct holds the various credentials needed to do login into CA BE

type Job

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

func (*Job) Context

func (j *Job) Context() context.Context

func (*Job) Obj

func (j *Job) Obj() SessionObj

func (*Job) SetContext

func (j *Job) SetContext(ctx context.Context)

func (*Job) SetObj

func (j *Job) SetObj(sessionObj SessionObj)

type OperatorCommandDetails

type OperatorCommandDetails struct {
	Command   *v1alpha1.OperatorCommand
	StartedAt time.Time
	Client    *k8sinterface.KubernetesApi
}

type SessionObj

type SessionObj struct {
	CustomerGUID string
	JobID        string
	Timestamp    time.Time
	Command      *apis.Command `json:"command"`
	ParentJobID  string
	// optional - if command was created by an OperatorCommand CRD
	ParentCommandDetails *OperatorCommandDetails `json:"parentCommandDetails,omitempty"`
}

Commands list of commands received from websocket

func NewSessionObj

func NewSessionObj(ctx context.Context, config config.IConfig, command *apis.Command, parentJobId, jobID string) *SessionObj

func (*SessionObj) SetOperatorCommandDetails

func (s *SessionObj) SetOperatorCommandDetails(opcmd *OperatorCommandDetails)

func (*SessionObj) SetOperatorCommandStatus

func (s *SessionObj) SetOperatorCommandStatus(ctx context.Context, options ...func(*patchStatus))

Jump to

Keyboard shortcuts

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