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

chore!: Update SDK to v0.14.1 #1239

Merged
merged 9 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 24 additions & 60 deletions client/config.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,40 @@
package client

import "github.com/cloudquery/cq-provider-sdk/cqproto"

type Account struct {
ID string `yaml:"id" hcl:",label"`
ID string `yaml:"id"`
AccountID string
AccountName string `yaml:"account_name,omitempty" hcl:"account_name,optional"`
LocalProfile string `yaml:"local_profile,omitempty" hcl:"local_profile,optional"`
RoleARN string `yaml:"role_arn,omitempty" hcl:"role_arn,optional"`
RoleSessionName string `yaml:"role_session_name,omitempty" hcl:"role_session_name,optional"`
ExternalID string `yaml:"external_id,omitempty" hcl:"external_id,optional"`
DefaultRegion string `yaml:"default_region,omitempty" hcl:"default_region,optional"`
Regions []string `yaml:"regions,omitempty" hcl:"regions,optional"`
AccountName string `yaml:"account_name,omitempty"`
LocalProfile string `yaml:"local_profile,omitempty"`
RoleARN string `yaml:"role_arn,omitempty"`
RoleSessionName string `yaml:"role_session_name,omitempty"`
ExternalID string `yaml:"external_id,omitempty"`
DefaultRegion string `yaml:"default_region,omitempty"`
Regions []string `yaml:"regions,omitempty"`
source string
}

type AwsOrg struct {
OrganizationUnits []string `yaml:"organization_units,omitempty" hcl:"organization_units,optional"`
AdminAccount *Account `yaml:"admin_account" hcl:"admin_account,block"`
MemberCredentials *Account `yaml:"member_trusted_principal" hcl:"member_trusted_principal,block"`
ChildAccountRoleName string `yaml:"member_role_name,omitempty" hcl:"member_role_name,optional"`
ChildAccountRoleSessionName string `yaml:"member_role_session_name,omitempty" hcl:"member_role_session_name,optional"`
ChildAccountExternalID string `yaml:"member_external_id,omitempty" hcl:"member_external_id,optional"`
ChildAccountRegions []string `yaml:"member_regions,omitempty" hcl:"member_regions,optional"`
OrganizationUnits []string `yaml:"organization_units,omitempty"`
AdminAccount *Account `yaml:"admin_account"`
MemberCredentials *Account `yaml:"member_trusted_principal"`
ChildAccountRoleName string `yaml:"member_role_name,omitempty"`
ChildAccountRoleSessionName string `yaml:"member_role_session_name,omitempty"`
ChildAccountExternalID string `yaml:"member_external_id,omitempty"`
ChildAccountRegions []string `yaml:"member_regions,omitempty"`
}

type Config struct {
Regions []string `yaml:"regions,omitempty" hcl:"regions,optional"`
Accounts []Account `yaml:"accounts" hcl:"accounts,block"`
Organization *AwsOrg `yaml:"org" hcl:"org,block"`
AWSDebug bool `yaml:"aws_debug,omitempty" hcl:"aws_debug,optional"`
MaxRetries int `yaml:"max_retries,omitempty" hcl:"max_retries,optional" default:"10"`
MaxBackoff int `yaml:"max_backoff,omitempty" hcl:"max_backoff,optional" default:"30"`
GlobalRegion string `yaml:"global_region,omitempty" hcl:"global_region,optional" default:"us-east-1"`

requestedFormat cqproto.ConfigFormat
}

func NewConfig(f cqproto.ConfigFormat) *Config {
return &Config{
requestedFormat: f,
}
Regions []string `yaml:"regions,omitempty"`
Accounts []Account `yaml:"accounts"`
Organization *AwsOrg `yaml:"org"`
AWSDebug bool `yaml:"aws_debug,omitempty"`
MaxRetries int `yaml:"max_retries,omitempty" default:"10"`
MaxBackoff int `yaml:"max_backoff,omitempty" default:"30"`
GlobalRegion string `yaml:"global_region,omitempty" default:"us-east-1"`
}

func (c Config) Example() string {
switch c.requestedFormat {
case cqproto.ConfigHCL:
return ` configuration {
// Optional, Repeated. Add an 'accounts' block for every account you want to assume-role into and fetch data from.
// accounts "<UNIQUE ACCOUNT IDENTIFIER>" {
// Optional. Role ARN we want to assume when accessing this account
// role_arn = < YOUR_ROLE_ARN >
// Optional. Named profile in config or credential file from where CQ should grab credentials
// local_profile = < PROFILE_NAME >
// }
// Optional. by default assumes all regions
// regions = ["us-east-1", "us-west-2"]
// Optional. Enable AWS SDK debug logging.
aws_debug = false
// The maximum number of times that a request will be retried for failures. Defaults to 10 retry attempts.
// max_retries = 10
// The maximum back off delay between attempts. The backoff delays exponentially with a jitter based on the number of attempts. Defaults to 30 seconds.
// max_backoff = 30
}
`
default:
return `
func (Config) Example() string {
return `
Optional, Repeated. Add an accounts block for every account you want to assume-role into and fetch data from.
accounts:
- id: <UNIQUE ACCOUNT IDENTIFIER>
Expand All @@ -84,9 +53,4 @@ max_retries: 10
The maximum back off delay between attempts. The backoff delays exponentially with a jitter based on the number of attempts. Defaults to 30 seconds.
max_backoff: 30
`
}
}

func (c Config) Format() cqproto.ConfigFormat {
return c.requestedFormat
}
21 changes: 10 additions & 11 deletions client/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"testing"

"github.com/cloudquery/cq-provider-sdk/cqproto"
"github.com/cloudquery/cq-provider-sdk/logging"
"github.com/cloudquery/cq-provider-sdk/provider"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
Expand All @@ -21,14 +20,14 @@ func AwsMockTestHelper(t *testing.T, table *schema.Table, builder func(*testing.
ctrl := gomock.NewController(t)

cfg := `
regions = ["us-east-1"]
accounts "testAccount" {
role_arn = ""
}
aws_debug = false
max_retries = 3
max_backoff = 60
`
regions: ["us-east-1"]
accounts:
- id: testAccount
role_arn: ""
aws_debug: false
max_retries: 3
max_backoff: 60
`
// accounts := []Account{
// {ID: "testAccount"},
// }
Expand All @@ -48,8 +47,8 @@ func AwsMockTestHelper(t *testing.T, table *schema.Table, builder func(*testing.
ResourceMap: map[string]*schema.Table{
"test_resource": table,
},
Config: func(f cqproto.ConfigFormat) provider.Config {
return NewConfig(f)
Config: func() provider.Config {
return &Config{}
},
},
Config: cfg,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/basgys/goxml2json v1.1.0
github.com/bxcodec/faker v2.0.1+incompatible
github.com/cloudquery/cq-gen v0.0.5
github.com/cloudquery/cq-provider-sdk v0.13.5
github.com/cloudquery/cq-provider-sdk v0.14.0
github.com/cloudquery/faker/v3 v3.7.7
github.com/gocarina/gocsv v0.0.0-20220712153207-8b2118da4570
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -168,7 +168,7 @@ require (
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.11 // indirect
google.golang.org/genproto v0.0.0-20220630174209-ad1d48641aa7 // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading