@@ -12,6 +12,7 @@ import (
1212 v1 "github.com/secureCodeBox/secureCodeBox/operator/apis/execution/v1"
1313 kubernetes "github.com/secureCodeBox/secureCodeBox/scbctl/pkg"
1414 "github.com/spf13/cobra"
15+ metav2 "k8s.io/apimachinery/pkg/api/errors"
1516 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617 "k8s.io/apimachinery/pkg/runtime"
1718 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -29,30 +30,26 @@ func init() {
2930}
3031
3132var ScanCmd = & cobra.Command {
32- Use : "scan [name] [target ]" ,
33+ Use : "scan [name] -- [parameters... ]" ,
3334 Short : "Create a new scanner" ,
3435 Long : `Create a new execution (Scan) in the default namespace if no namespace is provided` ,
3536 Example : `
3637 # Create a new scan
3738 scbctl scan nmap
3839 # Create in a different namespace
39- scbctl scan nmap scanme.nmap.org --namespace foobar
40+ scbctl scan --namespace foobar nmap -- scanme.nmap.org -p 90
4041 ` ,
42+ SilenceUsage : true ,
4143 RunE : func (cmd * cobra.Command , args []string ) error {
42- if len (args ) < 2 {
43- return errors .New ("You must specify the name of the scan and the target" )
44- }
4544
4645 scanName := args [0 ]
4746 paramIndex := cmd .ArgsLenAtDash ()
4847 if paramIndex == - 1 {
4948 return errors .New ("You must use '--' to separate scan parameters" )
5049 }
5150
52-
5351 parameters := args [paramIndex :]
54-
55-
52+
5653 fmt .Println ("🎬 Initializing Kubernetes client" )
5754
5855 kubeclient , namespace , err := clientProvider .GetClient (kubeconfigArgs )
@@ -76,7 +73,7 @@ var ScanCmd = &cobra.Command{
7673 Namespace : namespace ,
7774 },
7875 Spec : v1.ScanSpec {
79- ScanType : scanName ,
76+ ScanType : scanName ,
8077 Parameters : parameters ,
8178 },
8279 }
@@ -85,6 +82,9 @@ var ScanCmd = &cobra.Command{
8582
8683 err = kubeclient .Create (context .TODO (), scan )
8784 if err != nil {
85+ if metav2 .IsNotFound (err ) {
86+ return fmt .Errorf ("failed to create Scan: namespace '%s' not found" , namespace )
87+ }
8888 return fmt .Errorf ("Failed to create Scan: %s" , err )
8989 }
9090
0 commit comments