Skip to content

Commit 1ca5dbf

Browse files
committed
Fix bug in role-trusts command around new vendor lookup feature, enabled caching on apigateway commands
1 parent f000446 commit 1ca5dbf

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

aws/role-trusts.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ func (m *RoleTrustsModule) printPrincipalTrusts(outputDirectory string) ([]strin
242242
for _, statement := range role.trustsDoc.Statement {
243243
for _, principal := range statement.Principal.AWS {
244244
//check to see if the accountID is known
245-
accountID := strings.Split(principal, ":")[4]
246-
vendorName := m.vendors.GetVendorNameFromAccountID(accountID)
247-
if vendorName != "" {
248-
principal = fmt.Sprintf("%s (%s)", principal, vendorName)
245+
if strings.Contains(principal, "arn:aws:iam::") || strings.Contains(principal, "root") {
246+
accountID := strings.Split(principal, ":")[4]
247+
vendorName := m.vendors.GetVendorNameFromAccountID(accountID)
248+
if vendorName != "" {
249+
principal = fmt.Sprintf("%s (%s)", principal, vendorName)
250+
}
249251
}
250252

251253
RoleTrustRow := RoleTrustRow{

aws/sdk/apigateway.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/aws/aws-sdk-go-v2/aws"
1010
"github.com/aws/aws-sdk-go-v2/service/apigateway"
1111
apiGatewayTypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types"
12+
"github.com/patrickmn/go-cache"
1213
)
1314

1415
type APIGatewayClientInterface interface {
@@ -66,7 +67,7 @@ func CachedApiGatewayGetRestAPIs(client APIGatewayClientInterface, accountID str
6667
}
6768
PaginationControl = GetRestApis.Position
6869
}
69-
70+
internal.Cache.Set(cacheKey, restAPIs, cache.DefaultExpiration)
7071
return restAPIs, nil
7172
}
7273

@@ -92,6 +93,7 @@ func CachedApiGatewayGetStages(client APIGatewayClientInterface, accountID strin
9293
return apigateway.GetStagesOutput{}, err
9394
}
9495

96+
internal.Cache.Set(cacheKey, GetStages, cache.DefaultExpiration)
9597
return *GetStages, err
9698
}
9799

@@ -129,7 +131,7 @@ func CachedApiGatewayGetResources(client APIGatewayClientInterface, accountID st
129131
}
130132
PaginationControl = GetResources.Position
131133
}
132-
134+
internal.Cache.Set(cacheKey, resources, cache.DefaultExpiration)
133135
return resources, nil
134136
}
135137

@@ -166,7 +168,7 @@ func CachedApiGatewayGetDomainNames(client APIGatewayClientInterface, accountID
166168
}
167169
PaginationControl = GetDomainNames.Position
168170
}
169-
171+
internal.Cache.Set(cacheKey, domainNames, cache.DefaultExpiration)
170172
return domainNames, nil
171173
}
172174

@@ -204,7 +206,7 @@ func CachedApiGatewayGetBasePathMappings(client APIGatewayClientInterface, accou
204206
}
205207
PaginationControl = GetBasePathMappings.Position
206208
}
207-
209+
internal.Cache.Set(cacheKey, basePathMappings, cache.DefaultExpiration)
208210
return basePathMappings, nil
209211
}
210212

@@ -233,6 +235,7 @@ func CachedApiGatewayGetMethod(client APIGatewayClientInterface, accountID strin
233235
return apigateway.GetMethodOutput{}, err
234236
}
235237

238+
internal.Cache.Set(cacheKey, GetMethod, cache.DefaultExpiration)
236239
return *GetMethod, nil
237240

238241
}
@@ -271,6 +274,7 @@ func CachedApiGatewayGetUsagePlans(client APIGatewayClientInterface, accountID s
271274
PaginationControl = GetUsagePlans.Position
272275
}
273276

277+
internal.Cache.Set(cacheKey, usagePlans, cache.DefaultExpiration)
274278
return usagePlans, nil
275279
}
276280

@@ -309,5 +313,6 @@ func CachedApiGatewayGetUsagePlanKeys(client APIGatewayClientInterface, accountI
309313
PaginationControl = GetUsagePlanKeys.Position
310314
}
311315

316+
internal.Cache.Set(cacheKey, usagePlanKeys, cache.DefaultExpiration)
312317
return usagePlanKeys, nil
313318
}

0 commit comments

Comments
 (0)