-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapigateway.go
More file actions
55 lines (47 loc) · 1.65 KB
/
apigateway.go
File metadata and controls
55 lines (47 loc) · 1.65 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
package cmd
import (
apigatewayfern "github.com/Method-Security/methodaws/generated/go/apigateway"
apigateway "github.com/Method-Security/methodaws/internal/apigateway/enumerate"
"github.com/Method-Security/methodaws/utils"
"github.com/spf13/cobra"
)
func (a *MethodAws) InitAPIGatewayCommand() {
apiGatewayCmd := &cobra.Command{
Use: "api-gateway",
Short: "Audit and manage api gateways",
Long: `Audit and manage api gateways`,
Aliases: []string{"agw"},
}
enumerateCmd := &cobra.Command{
Use: "enumerate",
Short: "Enumerate api gateways",
Long: `Enumerate api gateways in your AWS account.`,
Run: func(cmd *cobra.Command, args []string) {
accountID, err := utils.GetAccountID(cmd.Context(), *a.AwsConfig)
if err != nil {
a.OutputSignal.AddError(err)
return
}
// Get Config - default to both versions if not specified
config := getAPIGatewayEnumerateConfig(a.RootFlags.Regions, accountID)
// Get Report
report := apigateway.EnumerateAPIGateway(cmd.Context(), *a.AwsConfig, config)
a.OutputSignal.Content = report
},
}
apiGatewayCmd.AddCommand(enumerateCmd)
a.RootCmd.AddCommand(apiGatewayCmd)
}
// getAPIGatewayEnumerateConfig returns an ApiGatewayEnumerateConfig with the given regions and account ID
func getAPIGatewayEnumerateConfig(regions []string, accountID string) apigatewayfern.ApiGatewayEnumerateConfig {
// Default to both V1 and V2 if not specified
versions := []apigatewayfern.ApiGatewayVersion{
apigatewayfern.ApiGatewayVersionV1,
apigatewayfern.ApiGatewayVersionV2,
}
return apigatewayfern.ApiGatewayEnumerateConfig{
Regions: regions,
AccountId: accountID,
Versions: versions,
}
}