Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(decl): rename declarative commands namespace to suite #283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// Initialize all k8s client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/falcosecurity/event-generator/cmd/declarative"
"github.com/falcosecurity/event-generator/cmd/suite"
// register event collections.
_ "github.com/falcosecurity/event-generator/events/k8saudit"
_ "github.com/falcosecurity/event-generator/events/syscall"
Expand All @@ -49,9 +49,9 @@ func init() {
const (
// envKeysPrefix is used as environment variable prefix configuration for viper.
envKeysPrefix = "falco_event_generator"
// declarativeEnvKey is used to distinguish between command-line invocation of the "declarative run" subcommand and
// the subcommand invoking itself during process chain creation.
declarativeEnvKey = "DECLARATIVE"
// suiteEnvKey is used to distinguish between command-line invocation of the "suite run" subcommand and the
// subcommand invoking itself during process chain creation.
suiteEnvKey = "SUITE"
)

// New instantiates the root command.
Expand Down Expand Up @@ -108,7 +108,7 @@ func New(configOptions *ConfigOptions) *cobra.Command {
rootCmd.AddCommand(NewBench())
rootCmd.AddCommand(NewTest())
rootCmd.AddCommand(NewList())
rootCmd.AddCommand(declarative.New(declarativeEnvKey, envKeysPrefix))
rootCmd.AddCommand(suite.New(suiteEnvKey, envKeysPrefix))

return rootCmd
}
Expand All @@ -117,9 +117,9 @@ func New(configOptions *ConfigOptions) *cobra.Command {
func Execute() {
ctx := WithSignals(context.Background())
rootCmd := New(nil)
// declarativeEnvKey is not mapped on viper and cobra on purpose.
if v := os.Getenv(declarativeEnvKey); v != "" {
rootCmd.SetArgs([]string{"declarative", "run"})
// suiteEnvKey is not mapped on viper and cobra on purpose.
if v := os.Getenv(suiteEnvKey); v != "" {
rootCmd.SetArgs([]string{"suite", "run"})
}

if err := rootCmd.ExecuteContext(ctx); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/declarative/config/config.go → cmd/suite/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const (
TimeoutFlagName = "timeout"
)

// Config represents the configuration shared among declarative commands. Among other shared settings, it also stores
// the values of the shared flags.
// Config represents the configuration shared among `suite` commands. Among other shared settings, it also stores the
// values of the shared flags.
type Config struct {
EnvKeysPrefix string
DeclarativeEnvKey string
EnvKeysPrefix string
SuiteEnvKey string
// DescriptionFileEnvKey is the environment variable key corresponding to DescriptionFileFlagName.
DescriptionFileEnvKey string
// DescriptionDirEnvKey is the environment variable key corresponding to DescriptionDirFlagName.
Expand Down Expand Up @@ -103,9 +103,9 @@ var containerImagePullPolicies = map[builder.ImagePullPolicy][]string{
}

// New creates a new config.
func New(declarativeEnvKey, envKeysPrefix string) *Config {
func New(suiteEnvKey, envKeysPrefix string) *Config {
commonConf := &Config{
DeclarativeEnvKey: declarativeEnvKey,
SuiteEnvKey: suiteEnvKey,
EnvKeysPrefix: envKeysPrefix,
DescriptionFileEnvKey: envKeyFromFlagName(envKeysPrefix, DescriptionFileFlagName),
DescriptionDirEnvKey: envKeyFromFlagName(envKeysPrefix, DescriptionDirFlagName),
Expand Down
4 changes: 2 additions & 2 deletions cmd/declarative/config/doc.go → cmd/suite/config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package config provides the implementation of Config, the configuration shared among declarative commands. Among
// other shared settings, it also stores the values of the shared flags.
// Package config provides the implementation of Config, the configuration shared among suite commands. Among other
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Package config provides the implementation of Config, the configuration shared among suite commands. Among other
// Package config provides the implementation of Config, the configuration shared among suite-related commands. Among other

// shared settings, it also stores the values of the shared flags.
package config
4 changes: 2 additions & 2 deletions cmd/declarative/doc.go → cmd/suite/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package declarative provides the implementation of the "declarative" command.
package declarative
// Package suite provides the implementation of the "suite" command.
package suite
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ documentation for properties enabled only by the presence of that value.
Enum requirements are evaluated in their appearing order, so order matters.
The following examples demonstrate how to specify property path expressions:

event-generator declarative explain tests.context.processes
event-generator suite explain tests.context.processes

event-generator declarative explain tests.steps{type=syscall}{syscall=openat2}.args.how
event-generator suite explain tests.steps{type=syscall}{syscall=openat2}.args.how

Enum requirements can be provided also by using the --with flag (see --with flag documentation for the syntax). It is
not possible to specify enum requirements both with <propertyPathExpr> and the --with flag.`
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/declarative/run/run.go → cmd/suite/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/spf13/cobra"

"github.com/falcosecurity/event-generator/cmd/declarative/config"
"github.com/falcosecurity/event-generator/cmd/declarative/test"
"github.com/falcosecurity/event-generator/cmd/suite/config"
"github.com/falcosecurity/event-generator/cmd/suite/test"
)

const (
Expand Down
22 changes: 11 additions & 11 deletions cmd/declarative/declarative.go → cmd/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package declarative
package suite

import (
"github.com/spf13/cobra"

"github.com/falcosecurity/event-generator/cmd/declarative/config"
"github.com/falcosecurity/event-generator/cmd/declarative/explain"
"github.com/falcosecurity/event-generator/cmd/declarative/run"
"github.com/falcosecurity/event-generator/cmd/declarative/test"
"github.com/falcosecurity/event-generator/cmd/suite/config"
"github.com/falcosecurity/event-generator/cmd/suite/explain"
"github.com/falcosecurity/event-generator/cmd/suite/run"
"github.com/falcosecurity/event-generator/cmd/suite/test"
)

// New creates a new declarative command.
func New(declarativeEnvKey, envKeysPrefix string) *cobra.Command {
// New creates a new suite command.
func New(suiteEnvKey, envKeysPrefix string) *cobra.Command {
c := &cobra.Command{
Use: "declarative",
Short: "Run test(s) specified via a YAML description",
Long: "Run test(s) specified via a YAML description",
Use: "suite",
Short: "Manage everything related to test suites",
Long: "Manage everything related to test suites",
Comment on lines +31 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Manage everything related to test suites",
Long: "Manage everything related to test suites",
Short: "Manage test suites described via YAML files",
Long: "Provide sub-commands to work with test suites described via YAML files",

DisableAutoGenTag: true,
}

commonConf := config.New(declarativeEnvKey, envKeysPrefix)
commonConf := config.New(suiteEnvKey, envKeysPrefix)

runCmd := run.New(commonConf)
testCmd := test.New(commonConf, false).Command
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/declarative/test/test.go → cmd/suite/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/spf13/pflag"
"github.com/thediveo/enumflag"

"github.com/falcosecurity/event-generator/cmd/declarative/config"
"github.com/falcosecurity/event-generator/cmd/suite/config"
"github.com/falcosecurity/event-generator/pkg/alert/retriever/grpcretriever"
"github.com/falcosecurity/event-generator/pkg/baggage"
containerbuilder "github.com/falcosecurity/event-generator/pkg/container/builder"
Expand Down Expand Up @@ -585,7 +585,7 @@ func sendTestReport(ctx context.Context, reportCh chan<- *tester.Report, report
func (cw *CommandWrapper) buildRunnerEnviron(cmd *cobra.Command) []string {
environ := os.Environ()
environ = cw.appendFlags(environ, cmd.PersistentFlags(), cmd.Flags())
environ = append(environ, fmt.Sprintf("%s=1", cw.DeclarativeEnvKey))
environ = append(environ, fmt.Sprintf("%s=1", cw.SuiteEnvKey))
return environ
}

Expand Down
Loading