From 606995adada48dd6a1f8c5c79ebf9745dca21bcf Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Sun, 17 Nov 2024 11:36:27 +0100 Subject: [PATCH] fix build --- pkg/security/resolvers/cgroup/model/model.go | 51 ---------------- pkg/security/resolvers/cgroup/model/types.go | 63 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 51 deletions(-) create mode 100644 pkg/security/resolvers/cgroup/model/types.go diff --git a/pkg/security/resolvers/cgroup/model/model.go b/pkg/security/resolvers/cgroup/model/model.go index 15a90465103635..8abaf74cd47bbb 100644 --- a/pkg/security/resolvers/cgroup/model/model.go +++ b/pkg/security/resolvers/cgroup/model/model.go @@ -9,8 +9,6 @@ package model import ( - "errors" - "fmt" "sync" "go.uber.org/atomic" @@ -20,55 +18,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/security/utils" ) -var ( - ErrNoImageProvided = errors.New("no image name provided") // ErrNoImageProvided is returned when no image name is provided -) - -// WorkloadSelector is a selector used to uniquely indentify the image of a workload -type WorkloadSelector struct { - Image string - Tag string -} - -// NewWorkloadSelector returns an initialized instance of a WorkloadSelector -func NewWorkloadSelector(image string, tag string) (WorkloadSelector, error) { - if image == "" { - return WorkloadSelector{}, ErrNoImageProvided - } else if tag == "" { - tag = "latest" - } - return WorkloadSelector{ - Image: image, - Tag: tag, - }, nil -} - -// IsReady returns true if the selector is ready -func (ws *WorkloadSelector) IsReady() bool { - return len(ws.Image) != 0 -} - -// Match returns true if the input selector matches the current selector -func (ws *WorkloadSelector) Match(selector WorkloadSelector) bool { - if ws.Tag == "*" || selector.Tag == "*" { - return ws.Image == selector.Image - } - return ws.Image == selector.Image && ws.Tag == selector.Tag -} - -// String returns a string representation of a workload selector -func (ws WorkloadSelector) String() string { - return fmt.Sprintf("[image_name:%s image_tag:%s]", ws.Image, ws.Tag) -} - -// ToTags returns a string array representation of a workload selector -func (ws WorkloadSelector) ToTags() []string { - return []string{ - "image_name:" + ws.Image, - "image_tag:" + ws.Tag, - } -} - // CacheEntry cgroup resolver cache entry type CacheEntry struct { model.CGroupContext diff --git a/pkg/security/resolvers/cgroup/model/types.go b/pkg/security/resolvers/cgroup/model/types.go new file mode 100644 index 00000000000000..d07f94be041217 --- /dev/null +++ b/pkg/security/resolvers/cgroup/model/types.go @@ -0,0 +1,63 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build linux || windows + +// Package model holds model related files +package model + +import ( + "errors" + "fmt" +) + +var ( + ErrNoImageProvided = errors.New("no image name provided") // ErrNoImageProvided is returned when no image name is provided +) + +// WorkloadSelector is a selector used to uniquely indentify the image of a workload +type WorkloadSelector struct { + Image string + Tag string +} + +// NewWorkloadSelector returns an initialized instance of a WorkloadSelector +func NewWorkloadSelector(image string, tag string) (WorkloadSelector, error) { + if image == "" { + return WorkloadSelector{}, ErrNoImageProvided + } else if tag == "" { + tag = "latest" + } + return WorkloadSelector{ + Image: image, + Tag: tag, + }, nil +} + +// IsReady returns true if the selector is ready +func (ws *WorkloadSelector) IsReady() bool { + return len(ws.Image) != 0 +} + +// Match returns true if the input selector matches the current selector +func (ws *WorkloadSelector) Match(selector WorkloadSelector) bool { + if ws.Tag == "*" || selector.Tag == "*" { + return ws.Image == selector.Image + } + return ws.Image == selector.Image && ws.Tag == selector.Tag +} + +// String returns a string representation of a workload selector +func (ws WorkloadSelector) String() string { + return fmt.Sprintf("[image_name:%s image_tag:%s]", ws.Image, ws.Tag) +} + +// ToTags returns a string array representation of a workload selector +func (ws WorkloadSelector) ToTags() []string { + return []string{ + "image_name:" + ws.Image, + "image_tag:" + ws.Tag, + } +}