fixed flag and cloud env support

This commit is contained in:
David Wertenteil
2022-01-13 14:19:26 +02:00
committed by GitHub
4 changed files with 15 additions and 22 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ func init() {
cobra.OnInitialize(frameworkInitConfig)
rootCmd.AddCommand(scanCmd)
rootCmd.PersistentFlags().StringVarP(&scanInfo.KubeContext, "--kube-context", "", "", "Kube context. Default will use the current-context")
rootCmd.PersistentFlags().StringVarP(&scanInfo.KubeContext, "kube-context", "", "", "Kube context. Default will use the current-context")
scanCmd.PersistentFlags().StringVar(&scanInfo.ControlsInputs, "controls-config", "", "Path to an controls-config obj. If not set will download controls-config from ARMO management portal")
scanCmd.PersistentFlags().StringVar(&scanInfo.UseExceptions, "exceptions", "", "Path to an exceptions obj. If not set will download exceptions from ARMO management portal")
scanCmd.PersistentFlags().StringVarP(&scanInfo.ExcludedNamespaces, "exclude-namespaces", "e", "", "Namespaces to exclude from scanning. Recommended: kube-system,kube-public")
+12 -19
View File
@@ -2,6 +2,7 @@ package resourcehandler
import (
"os"
"strings"
"github.com/armosec/k8s-interface/cloudsupport"
"github.com/armosec/k8s-interface/k8sinterface"
@@ -22,32 +23,24 @@ type ICloudProvider interface {
}
func initCloudProvider() ICloudProvider {
var provider string
if isEnvVars() {
provider = getCloudProviderFromEnvVar()
switch provider {
case "gke":
return NewGKEProviderEnvVar()
case "eks":
return NewEKSProviderEnvVar()
}
} else {
provider = getCloudProviderFromContext()
switch provider {
case "gke":
return NewGKEProviderContext()
case "eks":
return NewEKSProviderContext()
}
switch getCloudProvider() {
case "gke", "gcp":
return NewGKEProviderContext()
case "eks", "aws":
return NewEKSProviderContext()
}
return NewEmptyCloudProvider()
}
func getCloudProvider() string {
var provider string
if isEnvVars() {
return getCloudProviderFromEnvVar()
provider = getCloudProviderFromEnvVar()
} else {
provider = getCloudProviderFromContext()
}
return getCloudProviderFromContext()
return strings.ToLower(provider)
}
func getCloudProviderFromContext() string {
@@ -45,7 +45,7 @@ func (report *ReportEventReceiver) ActionSendReport(opaSessionObj *cautils.OPASe
return nil
}
if report.clusterName == "" {
report.message = "WARNING: Failed to publish results. Reason: Unknown cluster name. Run kubescape with the '--kube-context <cluster name>' flag"
report.message = "WARNING: Failed to publish results because the cluster name is Unknown. If you are scanning YAML files the results are not submitted to the Kubescape SaaS"
return nil
}
@@ -46,7 +46,7 @@ func (report *ReportEventReceiver) ActionSendReport(opaSessionObj *cautils.OPASe
return nil
}
if report.clusterName == "" {
report.message = "WARNING: Failed to publish results. Reason: Unknown cluster name. Run kubescape with the '--kube-context <cluster name>' flag"
report.message = "WARNING: Failed to publish results because the cluster name is Unknown. If you are scanning YAML files the results are not submitted to the Kubescape SaaS"
return nil
}
opaSessionObj.Report.ReportID = uuid.NewV4().String()