Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Feat/upgrade sdk (#199)
Browse files Browse the repository at this point in the history
* upgrade sdk
  • Loading branch information
roneli authored Sep 23, 2021
1 parent a58003f commit 6d17773
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
14 changes: 11 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,21 @@ func (c *Client) withAccountID(accountID string) *Client {
maxRetries: c.maxRetries,
maxBackoff: c.maxBackoff,
ServicesManager: c.ServicesManager,
logger: c.logger.With("account_id", accountID),
logger: c.logger.With("account_id", obfuscateAccountId(accountID)),
AccountID: accountID,
Region: c.Region,
}
}

func (c *Client) withAccountIDAndRegion(accountID string, region string) *Client {

return &Client{
regions: c.regions,
logLevel: c.logLevel,
maxRetries: c.maxRetries,
maxBackoff: c.maxBackoff,
ServicesManager: c.ServicesManager,
logger: c.logger.With("account_id", accountID, "Region", region),
logger: c.logger.With("account_id", obfuscateAccountId(accountID), "Region", region),
AccountID: accountID,
Region: region,
}
Expand Down Expand Up @@ -283,7 +284,7 @@ func Configure(logger hclog.Logger, providerConfig interface{}) (schema.ClientMe

if awsConfig.AWSDebug {
awsCfg.ClientLogMode = aws.LogRequest | aws.LogResponse | aws.LogRetries
awsCfg.Logger = AwsLogger{logger.With("account", account)}
awsCfg.Logger = AwsLogger{logger.With("account", obfuscateAccountId(account.ID))}
}
svc := sts.NewFromConfig(awsCfg)
output, err := svc.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{}, func(o *sts.Options) {
Expand Down Expand Up @@ -395,3 +396,10 @@ func (a AwsLogger) Logf(classification logging.Classification, format string, v
a.l.Debug(fmt.Sprintf(format, v...))
}
}

func obfuscateAccountId(accountId string) string {
if len(accountId) <= 4 {
return accountId
}
return accountId[:4] + "xxxxxxxx"
}
7 changes: 7 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"

"github.com/aws/aws-sdk-go-v2/aws"
)

Expand Down Expand Up @@ -100,3 +102,8 @@ func Test_initServices_NoNilValues(t *testing.T) {
t.Errorf("initServices().%s == nil", name)
}
}

func Test_obfuscateAccountId(t *testing.T) {
assert.Equal(t, "1111xxxxxxxx", obfuscateAccountId("1111111111"))
assert.Equal(t, "11", obfuscateAccountId("11"))
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ require (
github.com/aws/aws-sdk-go-v2/service/waf v1.2.1
github.com/aws/aws-sdk-go-v2/service/wafv2 v1.5.1
github.com/aws/smithy-go v1.8.0
github.com/cloudquery/cq-provider-sdk v0.4.4
github.com/cloudquery/cq-provider-sdk v0.4.7
github.com/cloudquery/faker/v3 v3.7.4
github.com/gocarina/gocsv v0.0.0-20210516172204-ca9e8a8ddea8
github.com/golang/mock v1.5.0
github.com/hashicorp/go-hclog v0.16.1
github.com/jackc/pgx/v4 v4.11.0
github.com/mitchellh/mapstructure v1.1.2
github.com/spf13/cast v1.4.0
github.com/stretchr/testify v1.7.0
)

require (
Expand Down Expand Up @@ -111,7 +112,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/thoas/go-funk v0.8.1-0.20210502090430-efae847b30ab // indirect
github.com/tmccombs/hcl2json v0.3.3 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
github.com/cloudquery/cq-provider-sdk v0.4.4 h1:jqV7DMuCinH2qrna75ysfgFYcWZrmlGyamzffJapGgI=
github.com/cloudquery/cq-provider-sdk v0.4.4/go.mod h1:j6TTZ0yX83sp7f39R/FTXAh/QougA1jGXNOzgEZwZqg=
github.com/cloudquery/cq-provider-sdk v0.4.7 h1:QsapCPBrsot95bbUFSN29W3egSvBt6+EfkCvbPyoNvE=
github.com/cloudquery/cq-provider-sdk v0.4.7/go.mod h1:j6TTZ0yX83sp7f39R/FTXAh/QougA1jGXNOzgEZwZqg=
github.com/cloudquery/faker/v3 v3.7.4 h1:cCcU3r0yHpS0gqKj9rRKAGS0/hY33fBxbqCNFtDD4ec=
github.com/cloudquery/faker/v3 v3.7.4/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
Expand Down
2 changes: 2 additions & 0 deletions resources/iam_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func IamRoles() *schema.Table {
Name: "policies",
Description: "List of policies attached to group.",
Type: schema.TypeJSON,
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
Resolver: resolveIamRolePolicies,
},
{
Expand Down Expand Up @@ -154,6 +155,7 @@ func resolveIamRolePolicies(ctx context.Context, meta schema.ClientMeta, resourc
}
return resource.Set("policies", policies)
}

func resolveIamRoleAssumeRolePolicyDocument(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
r := resource.Item.(types.Role)
if r.AssumeRolePolicyDocument != nil {
Expand Down

0 comments on commit 6d17773

Please sign in to comment.