-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvm.go
More file actions
50 lines (45 loc) · 1.39 KB
/
vm.go
File metadata and controls
50 lines (45 loc) · 1.39 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
50
package cmd
import (
"github.com/Method-Security/methodazure/internal/vm"
"github.com/spf13/cobra"
)
// InitVMCommand initializes the `methodazure vm` subcommand that deals with enumerating Virtual Machines in the
// Azure environment.
func (a *MethodAzure) InitVMCommand() {
vmCmd := &cobra.Command{
Use: "vm",
Short: "Audit and command Virtual Machines",
Long: `Audit and command Virtual Machines`,
}
enumerateCmd := &cobra.Command{
Use: "enumerate",
Short: "Enumerate Virtual Machines",
Long: `Enumerate Virtual Machines`,
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 := vm.EnumerateVMs(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")
vmCmd.AddCommand(enumerateCmd)
a.RootCmd.AddCommand(vmCmd)
}