Skip to content

Commit

Permalink
fixing cluster agent entry point into the check subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
modernplumbing committed Jan 11, 2023
1 parent a7d9edd commit 173908a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cmd/cluster-agent/app/compliance_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package app
import (
"github.com/spf13/cobra"

"github.com/DataDog/datadog-agent/cmd/security-agent/app/subcommands/check"
"github.com/DataDog/datadog-agent/cmd/security-agent/subcommands/check"
"github.com/DataDog/datadog-agent/comp/core"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log"
Expand All @@ -34,6 +34,7 @@ func init() {
LogParams: log.LogForOneShot(string(loggerName), "off", true),
}

complianceCmd.AddCommand(check.Commands(bundleParams)...)
// TODO: The SecAgent Check package should be a component
complianceCmd.AddCommand(check.CommandsWrapped(bundleParams)...)
ClusterAgentCmd.AddCommand(complianceCmd)
}
14 changes: 10 additions & 4 deletions cmd/security-agent/subcommands/check/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ type CliParams struct {

// Commands returns a cobra command to run security agent checks
func Commands(globalParams *command.GlobalParams) []*cobra.Command {
bundleParams := core.BundleParams{
ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths),
LogParams: log.LogForOneShot(command.LoggerName, "info", true),
}

return CommandsWrapped(bundleParams)
}

// CommandsWrapped exists to allow for an entry point from the Cluster-Agent. We should remove this and refactor once Check becomes a component that both the Cluster Agent and the Security Agent can use.
func CommandsWrapped(bundleParams core.BundleParams) []*cobra.Command {
checkArgs := &CliParams{}

cmd := &cobra.Command{
Expand All @@ -57,10 +67,6 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
checkArgs.args = args
bundleParams := core.BundleParams{
ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths),
LogParams: log.LogForOneShot(command.LoggerName, "info", true),
}
if checkArgs.verbose {
bundleParams.LogParams = log.LogForOneShot(bundleParams.LogParams.LoggerName(), "trace", true)
}
Expand Down

0 comments on commit 173908a

Please sign in to comment.