-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality to import scenarios from a local directory
- Introduce `import-scenarios` subcommand to import scenarios from a specified local directory. - Implement the `ImportScenarios` method in `registry.go`.
- Loading branch information
1 parent
8d07778
commit 9c142cc
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
cmd/commands/commands/maintenance/commands/import_scenarios.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
cnappgoat "github.com/ermetic-research/CNAPPgoat" | ||
"github.com/ermetic-research/CNAPPgoat/cmd/commands/common" | ||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var ImportScenariosCommand = &cli.Command{ | ||
Name: "import-scenarios", | ||
Usage: "maintenance subcommand to import scenarios from a local directory to the CNAPPgoat registry", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "directory", | ||
Usage: "Directory to import scenarios from", | ||
Aliases: []string{"d"}, | ||
Value: "", | ||
}, | ||
}, | ||
Before: func(c *cli.Context) error { | ||
if err := common.CommandBefore(c); err != nil { | ||
return err | ||
} | ||
|
||
if c.String("directory") == "" { | ||
return fmt.Errorf("directory flag is required in import-scenarios subcommand") | ||
} | ||
|
||
return nil | ||
}, | ||
Action: func(c *cli.Context) error { | ||
registry := c.Context.Value("CNAPPgoatModuleRegistry").(*cnappgoat.Registry) | ||
logrus.Infof("importing scenarios from %s", c.String("directory")) | ||
if _, err := registry.ImportScenarios(c.String("directory")); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters