-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvpc.go
More file actions
57 lines (49 loc) · 1.46 KB
/
vpc.go
File metadata and controls
57 lines (49 loc) · 1.46 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
51
52
53
54
55
56
57
package cmd
import (
// Generated
vpcfern "github.com/Method-Security/methodaws/generated/go/vpc"
// Internal
"github.com/Method-Security/methodaws/internal/vpc"
"github.com/Method-Security/methodaws/utils"
// External
"github.com/spf13/cobra"
)
// InitVPCCommand initializes the `methodaws vpc` subcommand that deals with enumerating VPCs and related resources in
// the AWS account.
func (a *MethodAws) InitVPCCommand() {
// vpc command
// Subcommands:
// - enumerate
vpcCmd := &cobra.Command{
Use: "vpc",
Short: "Audit and manage VPC services",
Long: `Audit and manage VPC services`,
}
enumerateCmd := &cobra.Command{
Use: "enumerate",
Short: "Enumerate all VPCs",
Long: `Enumerate all VPCs in your AWS account.`,
Run: func(cmd *cobra.Command, args []string) {
// Account ID
accountID, err := utils.GetAccountID(cmd.Context(), *a.AwsConfig)
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Config
config := getVPCEnumerateConfig(a.RootFlags.Regions, accountID)
// Genate Report
report := vpc.EnumerateVPC(cmd.Context(), *a.AwsConfig, config)
a.OutputSignal.Content = report
},
}
vpcCmd.AddCommand(enumerateCmd)
a.RootCmd.AddCommand(vpcCmd)
}
// getVPCEnumerateConfig returns the configuration for the VPC enumerate command.
func getVPCEnumerateConfig(regions []string, accountID string) vpcfern.VpcEnumerateConfig {
return vpcfern.VpcEnumerateConfig{
AccountId: accountID,
Regions: regions,
}
}