pass info in call

This commit is contained in:
dwertent
2022-03-10 17:13:51 +02:00
parent 2d59ba0943
commit 66196c0d56
9 changed files with 30 additions and 31 deletions

View File

@@ -38,7 +38,7 @@ func GetConfigCmd() *cobra.Command {
configCmd.AddCommand(getDeleteCmd())
configCmd.AddCommand(getSetCmd())
configCmd.AddCommand(getSetCmd())
configCmd.AddCommand(getViewCmd())
return configCmd
}

View File

@@ -54,16 +54,6 @@ func Execute() {
}
func init() {
rootCmd.AddCommand(scan.GetScanCommand())
rootCmd.AddCommand(download.GeDownloadCmd())
rootCmd.AddCommand(delete.GetDeleteCmd())
rootCmd.AddCommand(list.GetListCmd())
rootCmd.AddCommand(submit.GetSubmitCmd())
rootCmd.AddCommand(completion.GetCompletionCmd())
rootCmd.AddCommand(version.GetVersionCmd())
rootCmd.AddCommand(config.GetConfigCmd())
cobra.OnInitialize(initLogger, initLoggerLevel, initEnvironment, initCacheDir)
rootCmd.PersistentFlags().StringVar(&armoBEURLsDep, "environment", "", envFlagUsage)
@@ -79,6 +69,14 @@ func init() {
rootCmd.PersistentFlags().StringVar(&rootInfo.CacheDir, "cache-dir", getter.DefaultLocalStore, "Cache directory [$KS_CACHE_DIR]")
rootCmd.PersistentFlags().BoolVarP(&rootInfo.DisableColor, "disable-color", "", false, "Disable Color output for logging")
rootCmd.AddCommand(scan.GetScanCommand())
rootCmd.AddCommand(download.GeDownloadCmd())
rootCmd.AddCommand(delete.GetDeleteCmd())
rootCmd.AddCommand(list.GetListCmd())
rootCmd.AddCommand(submit.GetSubmitCmd())
rootCmd.AddCommand(completion.GetCompletionCmd())
rootCmd.AddCommand(version.GetVersionCmd())
rootCmd.AddCommand(config.GetConfigCmd())
}
func initLogger() {

View File

@@ -32,7 +32,7 @@ var (
)
// controlCmd represents the control command
func getControlCmd() *cobra.Command {
func getControlCmd(scanInfo *cautils.ScanInfo) *cobra.Command {
return &cobra.Command{
Use: "control <control names list>/<control ids list>",
Short: "The controls you wish to use. Run 'kubescape list controls' for the list of supported controls",
@@ -53,7 +53,6 @@ func getControlCmd() *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
var scanInfo cautils.ScanInfo
// flagValidationControl(scanInfo)
scanInfo.PolicyIdentifier = []reporthandling.PolicyIdentifier{}
@@ -85,7 +84,7 @@ func getControlCmd() *cobra.Command {
scanInfo.FrameworkScan = false
results, err := clihandler.Scan(&scanInfo)
results, err := clihandler.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}

View File

@@ -34,7 +34,7 @@ var (
`
)
func getFrameworkCmd() *cobra.Command {
func getFrameworkCmd(scanInfo *cautils.ScanInfo) *cobra.Command {
return &cobra.Command{
Use: "framework <framework names list> [`<glob pattern>`/`-`] [flags]",
@@ -57,9 +57,8 @@ func getFrameworkCmd() *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
var scanInfo cautils.ScanInfo
flagValidationFramework(&scanInfo)
flagValidationFramework(scanInfo)
scanInfo.FrameworkScan = true
var frameworks []string
@@ -94,7 +93,7 @@ func getFrameworkCmd() *cobra.Command {
scanInfo.SetPolicyIdentifiers(frameworks, reporthandling.KindFramework)
results, err := clihandler.Scan(&scanInfo)
results, err := clihandler.Scan(scanInfo)
if err != nil {
logger.L().Fatal(err.Error())
}

View File

@@ -39,7 +39,7 @@ func GetScanCommand() *cobra.Command {
if len(args) > 0 {
if args[0] != "framework" && args[0] != "control" {
scanInfo.ScanAll = true
return getFrameworkCmd().RunE(cmd, append([]string{"all"}, args...))
return getFrameworkCmd(&scanInfo).RunE(cmd, append([]string{"all"}, args...))
}
}
return nil
@@ -48,7 +48,7 @@ func GetScanCommand() *cobra.Command {
if len(args) == 0 {
scanInfo.ScanAll = true
return getFrameworkCmd().RunE(cmd, []string{"all"})
return getFrameworkCmd(&scanInfo).RunE(cmd, []string{"all"})
}
return nil
},
@@ -56,7 +56,7 @@ func GetScanCommand() *cobra.Command {
k8sinterface.SetClusterContextName(scanInfo.KubeContext)
},
PostRun: func(cmd *cobra.Command, args []string) {
k8sinterface.SetClusterContextName(scanInfo.KubeContext)
// TODO - revert context
},
}
@@ -91,8 +91,8 @@ func GetScanCommand() *cobra.Command {
hostF.NoOptDefVal = "true"
hostF.DefValue = "false, for no TTY in stdin"
scanCmd.AddCommand(getControlCmd())
scanCmd.AddCommand(getFrameworkCmd())
scanCmd.AddCommand(getControlCmd(&scanInfo))
scanCmd.AddCommand(getFrameworkCmd(&scanInfo))
return scanCmd
}

View File

@@ -5,10 +5,11 @@ import (
"github.com/armosec/kubescape/cautils/logger"
"github.com/armosec/kubescape/clihandler"
"github.com/armosec/kubescape/clihandler/cliobjects"
"github.com/spf13/cobra"
)
func getExceptionsCmd() *cobra.Command {
func getExceptionsCmd(submitInfo *cliobjects.Submit) *cobra.Command {
return &cobra.Command{
Use: "exceptions <full path to exceptins file>",
Short: "Submit exceptions to the Kubescape SaaS version",

View File

@@ -8,13 +8,14 @@ import (
"github.com/armosec/kubescape/cautils/logger/helpers"
"github.com/armosec/kubescape/clihandler"
"github.com/armosec/kubescape/clihandler/cliinterfaces"
"github.com/armosec/kubescape/clihandler/cliobjects"
reporterv1 "github.com/armosec/kubescape/resultshandling/reporter/v1"
"github.com/armosec/rbac-utils/rbacscanner"
"github.com/spf13/cobra"
)
// getRBACCmd represents the RBAC command
func getRBACCmd() *cobra.Command {
func getRBACCmd(submitInfo *cliobjects.Submit) *cobra.Command {
return &cobra.Command{
Use: "rbac \nExample:\n$ kubescape submit rbac",
Short: "Submit cluster's Role-Based Access Control(RBAC)",

View File

@@ -11,6 +11,7 @@ import (
"github.com/armosec/kubescape/cautils/logger/helpers"
"github.com/armosec/kubescape/clihandler"
"github.com/armosec/kubescape/clihandler/cliinterfaces"
"github.com/armosec/kubescape/clihandler/cliobjects"
"github.com/armosec/kubescape/resultshandling/reporter"
reporterv1 "github.com/armosec/kubescape/resultshandling/reporter/v1"
reporterv2 "github.com/armosec/kubescape/resultshandling/reporter/v2"
@@ -54,7 +55,7 @@ func (resultsObject *ResultsObject) ListAllResources() (map[string]workloadinter
return map[string]workloadinterface.IMetadata{}, nil
}
func getResultsCmd() *cobra.Command {
func getResultsCmd(submitInfo *cliobjects.Submit) *cobra.Command {
var resultsCmd = &cobra.Command{
Use: "results <json file>\nExample:\n$ kubescape submit results path/to/results.json --format-version v2",
Short: "Submit a pre scanned results file. The file must be in json format",

View File

@@ -5,13 +5,13 @@ import (
"github.com/spf13/cobra"
)
var submitInfo cliobjects.Submit
var submitCmdExamples = `
`
func GetSubmitCmd() *cobra.Command {
var submitInfo cliobjects.Submit
submitCmd := &cobra.Command{
Use: "submit <command>",
Short: "Submit an object to the Kubescape SaaS version",
@@ -21,9 +21,9 @@ func GetSubmitCmd() *cobra.Command {
}
submitCmd.PersistentFlags().StringVarP(&submitInfo.Account, "account", "", "", "Armo portal account ID. Default will load account ID from configMap or config file")
submitCmd.AddCommand(getExceptionsCmd())
submitCmd.AddCommand(getResultsCmd())
submitCmd.AddCommand(getRBACCmd())
submitCmd.AddCommand(getExceptionsCmd(&submitInfo))
submitCmd.AddCommand(getResultsCmd(&submitInfo))
submitCmd.AddCommand(getRBACCmd(&submitInfo))
return submitCmd
}