Skip to content

Commit

Permalink
move selector functions to the cgroup model package
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannGh committed Mar 20, 2024
1 parent c51639a commit aa60982
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@

//go:build linux

// Package selector holds selector related files
package selector
// Package model holds model related files
package model

import (
proto "github.com/DataDog/agent-payload/v5/cws/dumpsv1"

cgroupModel "github.com/DataDog/datadog-agent/pkg/security/resolvers/cgroup/model"
)

// ProtoToWorkloadSelector decodes a Selector structure
func ProtoToWorkloadSelector(selector *proto.ProfileSelector) cgroupModel.WorkloadSelector {
func ProtoToWorkloadSelector(selector *proto.ProfileSelector) WorkloadSelector {
if selector == nil {
return cgroupModel.WorkloadSelector{}
return WorkloadSelector{}
}

return cgroupModel.WorkloadSelector{
return WorkloadSelector{
Image: selector.GetImageName(),
Tag: selector.GetImageTag(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

//go:build linux

// Package selector holds selector related files
package selector
// Package model holds model related files
package model

import (
proto "github.com/DataDog/agent-payload/v5/cws/dumpsv1"

cgroupModel "github.com/DataDog/datadog-agent/pkg/security/resolvers/cgroup/model"
)

// WorkloadSelectorToProto incode a WorkloadSelector to its protobuf representation
func WorkloadSelectorToProto(input *cgroupModel.WorkloadSelector) *proto.ProfileSelector {
func WorkloadSelectorToProto(input *WorkloadSelector) *proto.ProfileSelector {
if input == nil {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

proto "github.com/DataDog/agent-payload/v5/cws/dumpsv1"

cgroupModel "github.com/DataDog/datadog-agent/pkg/security/resolvers/cgroup/model"
timeResolver "github.com/DataDog/datadog-agent/pkg/security/resolvers/time"
activity_tree "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree"
mtdt "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree/metadata"
"github.com/DataDog/datadog-agent/pkg/security/security_profile/profile/selector"
)

// ActivityDumpToSecurityProfileProto serializes an Activity Dump to a Security Profile protobuf representation
Expand All @@ -35,7 +35,7 @@ func ActivityDumpToSecurityProfileProto(input *ActivityDump) (*proto.SecurityPro
Metadata: mtdt.ToProto(&input.Metadata),
ProfileContexts: make(map[string]*proto.ProfileContext),
Tree: activity_tree.ToProto(input.ActivityTree),
Selector: selector.WorkloadSelectorToProto(wSelector),
Selector: cgroupModel.WorkloadSelectorToProto(wSelector),
}
timeResolver, err := timeResolver.NewResolver()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/security/security_profile/profile/profile_proto_dec_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ package profile
import (
proto "github.com/DataDog/agent-payload/v5/cws/dumpsv1"

cgroupModel "github.com/DataDog/datadog-agent/pkg/security/resolvers/cgroup/model"
"github.com/DataDog/datadog-agent/pkg/security/secl/model"
activity_tree "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree"
mtdt "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree/metadata"
"github.com/DataDog/datadog-agent/pkg/security/security_profile/profile/selector"
)

// ProtoToSecurityProfile decodes a Security Profile from its protobuf representation
Expand All @@ -24,7 +24,7 @@ func ProtoToSecurityProfile(output *SecurityProfile, pathsReducer *activity_tree
}

output.Metadata = mtdt.ProtoMetadataToMetadata(input.Metadata)
output.selector = selector.ProtoToWorkloadSelector(input.Selector)
output.selector = cgroupModel.ProtoToWorkloadSelector(input.Selector)

for key, ctx := range input.ProfileContexts {
outCtx := &VersionContext{
Expand Down
4 changes: 2 additions & 2 deletions pkg/security/security_profile/profile/profile_proto_enc_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ package profile
import (
proto "github.com/DataDog/agent-payload/v5/cws/dumpsv1"

cgroupModel "github.com/DataDog/datadog-agent/pkg/security/resolvers/cgroup/model"
activity_tree "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree"
mtdt "github.com/DataDog/datadog-agent/pkg/security/security_profile/activity_tree/metadata"
"github.com/DataDog/datadog-agent/pkg/security/security_profile/profile/selector"
)

// SecurityProfileToProto incode a Security Profile to its protobuf representation
Expand All @@ -26,7 +26,7 @@ func SecurityProfileToProto(input *SecurityProfile) *proto.SecurityProfile {
Metadata: mtdt.ToProto(&input.Metadata),
ProfileContexts: make(map[string]*proto.ProfileContext),
Tree: activity_tree.ToProto(input.ActivityTree),
Selector: selector.WorkloadSelectorToProto(&input.selector),
Selector: cgroupModel.WorkloadSelectorToProto(&input.selector),
}

for key, ctx := range input.versionContexts {
Expand Down

0 comments on commit aa60982

Please sign in to comment.