-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscription.go
More file actions
49 lines (44 loc) · 1.7 KB
/
subscription.go
File metadata and controls
49 lines (44 loc) · 1.7 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/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Method-Security/methodazure/internal/subscription"
"github.com/spf13/cobra"
)
// InitSubscriptionCommand initializes the `methodazure subscription` subcommand that deals with enumerating Azure Subscription related details.
func (a *MethodAzure) InitSubscriptionCommand() {
subscriptionCmd := &cobra.Command{
Use: "subscription",
Short: "Audit and command Azure Subscriptions",
Long: `Audit and command Azure Subscriptions`,
}
enumerateCmd := &cobra.Command{
Use: "enumerate",
Short: "Enumerate Subscriptions for the provided credentials",
Long: `Enumerate Subscriptions for the provided credentials`,
Run: func(cmd *cobra.Command, args []string) {
var clouds []cloud.Configuration
tryAllClouds, err := cmd.Flags().GetBool("try-all-clouds")
if err != nil {
errorMessage := err.Error()
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
return
}
if tryAllClouds {
clouds = []cloud.Configuration{cloud.AzurePublic, cloud.AzureGovernment, cloud.AzureChina}
} else {
clouds = []cloud.Configuration{a.AzureConfig.CloudConfig}
}
report, err := subscription.EnumerateSubscriptions(cmd.Context(), a.AzureConfig, clouds)
if err != nil {
errorMessage := err.Error()
a.OutputSignal.ErrorMessage = &errorMessage
a.OutputSignal.Status = 1
}
a.OutputSignal.Content = report
},
}
enumerateCmd.PersistentFlags().BoolP("try-all-clouds", "t", false, "Attempt to list subscriptions in AzurePublic, Azure Government, and AzureChina; if true overrides cloud-config flag")
subscriptionCmd.AddCommand(enumerateCmd)
a.RootCmd.AddCommand(subscriptionCmd)
}