-
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.
Merge pull request #13 from ermetic-research/feat/import-scenarios
Add functionality to import scenarios from a local directory
- Loading branch information
Showing
5 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
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: "", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "debug", | ||
Usage: "Enable debug mode", | ||
Value: false, | ||
}, | ||
}, | ||
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
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