Skip to content

Commit 5dd0187

Browse files
committed
Add extra flag to override map file
1 parent fb5041e commit 5dd0187

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ You can optionally also include the following arguments to the `iamlive` command
7878

7979
**--account-id:** the AWS account ID to use in policy outputs within proxy mode (_default: 123456789012 unless detected_) (_AWS only_)
8080

81+
**--override-aws-map:** overrides the embedded AWS mapping JSON file with the filepath provided (_AWS only_)
82+
8183
**--debug:** dumps associated HTTP requests when set in proxy mode (_default: false_)
8284

8385
_Basic Example (CSM Mode)_

iamlivecore/logger.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"log"
99
"net/url"
10+
"os"
1011
"reflect"
1112
"regexp"
1213
"sort"
@@ -88,11 +89,22 @@ type AzureIAMPolicy struct {
8889

8990
func loadMaps() {
9091
if *providerFlag == "aws" {
91-
err := json.Unmarshal(bIAMMap, &iamMap)
92-
if err != nil {
93-
log.Fatal(err)
92+
if *overrideAwsMapFlag != "" {
93+
bIAMMap, err := os.ReadFile(*overrideAwsMapFlag)
94+
if err != nil {
95+
log.Fatal(err)
96+
}
97+
err = json.Unmarshal(bIAMMap, &iamMap)
98+
if err != nil {
99+
log.Fatal(err)
100+
}
101+
} else {
102+
err := json.Unmarshal(bIAMMap, &iamMap)
103+
if err != nil {
104+
log.Fatal(err)
105+
}
94106
}
95-
err = json.Unmarshal(bIAMSAR, &iamDef)
107+
err := json.Unmarshal(bIAMSAR, &iamDef)
96108
if err != nil {
97109
panic(err)
98110
}

iamlivecore/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var caBundleFlag *string
2727
var caKeyFlag *string
2828
var accountIDFlag *string
2929
var backgroundFlag *bool
30+
var overrideAwsMapFlag *string
3031
var debugFlag *bool
3132
var forceWildcardResourceFlag *bool
3233
var cpuProfileFlag = flag.String("cpu-profile", "", "write a CPU profile to this file (for performance testing purposes)")
@@ -48,6 +49,7 @@ func parseConfig() {
4849
caKey := "~/.iamlive/ca.key"
4950
accountID := ""
5051
background := false
52+
overrideAwsMap := ""
5153
debug := false
5254
forceWildcardResource := false
5355
csmPort := 31000
@@ -99,6 +101,9 @@ func parseConfig() {
99101
if cfg.Section("").HasKey("background") {
100102
background, _ = cfg.Section("").Key("background").Bool()
101103
}
104+
if cfg.Section("").HasKey("override-aws-map") {
105+
overrideAwsMap = cfg.Section("").Key("override-aws-map").String()
106+
}
102107
if cfg.Section("").HasKey("debug") {
103108
debug, _ = cfg.Section("").Key("debug").Bool()
104109
}
@@ -126,6 +131,7 @@ func parseConfig() {
126131
caKeyFlag = flag.String("ca-key", caKey, "the CA certificate key to use for proxy mode")
127132
accountIDFlag = flag.String("account-id", accountID, "the AWS account ID to use in policy outputs within proxy mode")
128133
backgroundFlag = flag.Bool("background", background, "when set, the process will return the current PID and run in the background without output")
134+
overrideAwsMapFlag = flag.String("override-aws-map", overrideAwsMap, "overrides the embedded AWS mapping JSON file with the filepath provided")
129135
debugFlag = flag.Bool("debug", debug, "dumps associated HTTP requests when set in proxy mode")
130136
forceWildcardResourceFlag = flag.Bool("force-wildcard-resource", forceWildcardResource, "when set, the Resource will always be a wildcard")
131137
csmPortFlag = flag.Int("csm-port", csmPort, "port to listen on for CSM")

0 commit comments

Comments
 (0)