-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping.go
56 lines (48 loc) · 1.28 KB
/
mapping.go
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
package main
import (
_ "embed"
"encoding/json"
"log"
"strings"
)
//go:embed map.json
var bIAMMap []byte
func loadMap() {
// Load API method -> IAM permission mapping
err := json.Unmarshal(bIAMMap, &iamMap)
if err != nil {
log.Fatal(err)
}
}
// sdkMethodToAction looks up the IAM action for a given AWS SDK call or returns
// an empty string if there is no match (not all calls require permissions)
func sdkMethodToAction(apiMethod string) string {
for iamMethodName, iamMethods := range iamMap.SDKMethodIAMMappings {
if strings.EqualFold(iamMethodName, apiMethod) {
for _, priv := range iamMethods {
return priv.Action
}
}
}
return ""
}
// actionToSDKMethods finds looks up all SDK calls that requires a specific
// IAM action to make. Returns and empty list if no matches are found
func actionToSDKMethods(action string) []string {
var sdkCalls []string
for iamMethodName, iamMethods := range iamMap.SDKMethodIAMMappings {
for _, priv := range iamMethods {
if strings.EqualFold(priv.Action, action) {
sdkCalls = append(sdkCalls, iamMethodName)
}
}
}
return sdkCalls
}
type iamMapMethod struct {
Action string `json:"action"`
}
type iamMapBase struct {
SDKMethodIAMMappings map[string][]iamMapMethod `json:"sdk_method_iam_mappings"`
}
var iamMap iamMapBase