-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnsg.go
More file actions
49 lines (44 loc) · 1.43 KB
/
nsg.go
File metadata and controls
49 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"github.com/Method-Security/methodazure/internal/nsg"
"github.com/spf13/cobra"
)
// InitNSGCommand initializes the `methodazure nsg` subcommand that deals with enumerating Network Security Groups in the Azure environment.
func (a *MethodAzure) InitNSGCommand() {
nsgCmd := &cobra.Command{
Use: "nsg",
Short: "Audit and command Network Security Groups",
Long: `Audit and command Network Security Groups`,
}
enumerateCmd := &cobra.Command{
Use: "enumerate",
Short: "Enumerate Network Security Groups",
Long: `Enumerate Network Security Groups`,
Run: func(cmd *cobra.Command, args []string) {
subscriptionID, err := cmd.Flags().GetString("subscription-id")
if err != nil {
errorMessage := err.Error()
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
return
}
if subscriptionID == "" {
errorMessage := "subscription-id is not set"
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
return
}
a.AzureConfig.SubID = subscriptionID
report, err := nsg.EnumerateNSGs(cmd.Context(), a.AzureConfig)
if err != nil {
errorMessage := err.Error()
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
}
a.OutputSignal.Content = report
},
}
enumerateCmd.PersistentFlags().StringP("subscription-id", "s", "", "Azure subscription ID")
nsgCmd.AddCommand(enumerateCmd)
a.RootCmd.AddCommand(nsgCmd)
}