Skip to content

Commit

Permalink
Move aws/external to config as its own Go submodule
Browse files Browse the repository at this point in the history
Moves the aws/external package out of the aws core module and into the
config submodule at the root of the repository.
  • Loading branch information
jasdel authored and skmcgrail committed Sep 24, 2020
1 parent b891b7a commit b64d21d
Show file tree
Hide file tree
Showing 31 changed files with 117 additions and 74 deletions.
8 changes: 4 additions & 4 deletions aws/signer/v4/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"github.com/aws/aws-sdk-go-v2/internal/awstesting/unit"
"github.com/awslabs/smithy-go/middleware"
smithyhttp "github.com/awslabs/smithy-go/transport/http"
)
Expand Down Expand Up @@ -108,11 +109,10 @@ func TestSignHTTPRequestMiddleware(t *testing.T) {
for i, tt := range cases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
c := &SignHTTPRequestMiddleware{
credentialsProvider: aws.StaticCredentialsProvider{
Value: aws.Credentials{AccessKeyID: "key", SecretAccessKey: "secret"},
},
credentialsProvider: unit.StubCredentialsProvider{},
signer: httpSignerFunc(func(ctx context.Context, credentials aws.Credentials, r *http.Request, payloadHash string, service string, region string, signingTime time.Time) error {
if e, a := (aws.Credentials{AccessKeyID: "key", SecretAccessKey: "secret", Source: "StaticCredentialsProvider"}), credentials; e != a {
expectCreds, _ := unit.StubCredentialsProvider{}.Retrieve(context.Background())
if e, a := expectCreds, credentials; e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := tt.hash, payloadHash; e != a {
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions aws/external/config.go → config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -124,7 +124,7 @@ func (cs Configs) ResolveConfig(f func(configs []interface{}) error) error {
// The custom configurations must satisfy the respective providers for their data
// or the custom data will be ignored by the resolvers and config loaders.
//
// cfg, err := external.LoadDefaultAWSConfig(
// cfg, err := config.LoadDefaultAWSConfig(
// WithSharedConfigProfile("test-profile"),
// )
// if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions aws/external/config_test.go → config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package external
package config

import (
"context"
"reflect"
"testing"

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

func TestConfigs_SharedConfigOptions(t *testing.T) {
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestConfigs_AppendFromLoaders(t *testing.T) {
func TestConfigs_ResolveAWSConfig(t *testing.T) {
configSources := Configs{
WithRegion("mock-region"),
WithCredentialsProvider{aws.StaticCredentialsProvider{
WithCredentialsProvider{credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: "AKID", SecretAccessKey: "SECRET",
Source: "provider",
Expand Down
2 changes: 1 addition & 1 deletion aws/external/env_config.go → config/env_config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"os"
Expand Down
17 changes: 9 additions & 8 deletions aws/external/example_test.go → config/example_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external_test
package config_test

import (
"context"
Expand All @@ -7,17 +7,18 @@ import (
"path/filepath"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
)

func ExampleWithSharedConfigProfile() {
cfg, err := external.LoadDefaultAWSConfig(
cfg, err := config.LoadDefaultAWSConfig(
// Specify the shared configuration profile to load.
external.WithSharedConfigProfile("exampleProfile"),
config.WithSharedConfigProfile("exampleProfile"),

// Optionally specify the specific shared configuraiton
// files to load the profile from.
external.WithSharedConfigFiles([]string{
config.WithSharedConfigFiles([]string{
filepath.Join("testdata", "shared_config"),
}),
)
Expand All @@ -34,10 +35,10 @@ func ExampleWithSharedConfigProfile() {
}

func ExampleWithCredentialsProvider() {
cfg, err := external.LoadDefaultAWSConfig(
cfg, err := config.LoadDefaultAWSConfig(
// Hard coded credentials.
external.WithCredentialsProvider{
CredentialsProvider: aws.StaticCredentialsProvider{
config.WithCredentialsProvider{
CredentialsProvider: credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "SESSION",
Source: "example hard coded credentials",
Expand Down
2 changes: 1 addition & 1 deletion aws/external/generate.go → config/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

//go:generate go run -tags codegen ./codegen -output=provider_assert_test.go
//go:generate gofmt -s -w ./
14 changes: 14 additions & 0 deletions config/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/aws/aws-sdk-go-v2/config

go 1.15

require github.com/aws/aws-sdk-go-v2 v0.24.0

require (
github.com/aws/aws-sdk-go-v2/credentials v0.0.0-20200915195926-9dd18af694c4
github.com/awslabs/smithy-go v0.0.0-20200828214850-b1c39f43623b
)

replace github.com/aws/aws-sdk-go-v2 => ../

replace github.com/aws/aws-sdk-go-v2/credentials => ../credentials
19 changes: 19 additions & 0 deletions config/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
github.com/aws/aws-sdk-go-v2 v0.24.0 h1:R0lL0krk9EyTI1vmO1ycoeceGZotSzCKO51LbPGq3rU=
github.com/aws/aws-sdk-go-v2 v0.24.0/go.mod h1:2LhT7UgHOXK3UXONKI5OMgIyoQL6zTAw/jwIeX6yqzw=
github.com/awslabs/smithy-go v0.0.0-20200828214850-b1c39f43623b h1:M0bB5T+OssNGuilG69j2aOcTt58DhrvD+R4+RfETW+c=
github.com/awslabs/smithy-go v0.0.0-20200828214850-b1c39f43623b/go.mod h1:hPOQwnmBLHsUphH13tVSjQhTAFma0/0XoZGbBcOuABI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2 changes: 1 addition & 1 deletion aws/external/local.go → config/local.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion aws/external/local_test.go → config/local_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"fmt"
Expand Down
28 changes: 14 additions & 14 deletions aws/external/provider.go → config/provider.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package external
package config

import (
"time"

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

// SharedConfigProfileProvider provides access to the shared config profile
Expand Down Expand Up @@ -225,25 +225,25 @@ func (w WithAssumeRoleDuration) GetAssumeRoleDuration() (time.Duration, bool, er
return time.Duration(w), true, nil
}

// ProcessCredentialProviderOptions is an interface for retrieving a function for setting
// the processcreds.ProviderOptions.
type ProcessCredentialProviderOptions interface {
GetProcessCredentialProviderOptions() (func(*processcreds.ProviderOptions), bool, error)
// ProcessCredentialOptions is an interface for retrieving a function for setting
// the processcreds.Options.
type ProcessCredentialOptions interface {
GetProcessCredentialOptions() (func(*processcreds.Options), bool, error)
}

// WithProcessCredentialProviderOptions wraps a function and satisfies the EC2RoleCredentialProviderOptions interface
type WithProcessCredentialProviderOptions func(*processcreds.ProviderOptions)
// WithProcessCredentialOptions wraps a function and satisfies the EC2RoleCredentialOptions interface
type WithProcessCredentialOptions func(*processcreds.Options)

// GetProcessCredentialProviderOptions returns the wrapped function
func (w WithProcessCredentialProviderOptions) GetProcessCredentialProviderOptions() (func(*processcreds.ProviderOptions), bool, error) {
// GetProcessCredentialOptions returns the wrapped function
func (w WithProcessCredentialOptions) GetProcessCredentialOptions() (func(*processcreds.Options), bool, error) {
return w, true, nil
}

// GetProcessCredentialProviderOptions searches the slice of configs and returns the first function found
func GetProcessCredentialProviderOptions(configs Configs) (f func(*processcreds.ProviderOptions), found bool, err error) {
// GetProcessCredentialOptions searches the slice of configs and returns the first function found
func GetProcessCredentialOptions(configs Configs) (f func(*processcreds.Options), found bool, err error) {
for _, config := range configs {
if p, ok := config.(ProcessCredentialProviderOptions); ok {
f, found, err = p.GetProcessCredentialProviderOptions()
if p, ok := config.(ProcessCredentialOptions); ok {
f, found, err = p.GetProcessCredentialOptions()
if err != nil {
return nil, false, err
}
Expand Down
8 changes: 3 additions & 5 deletions aws/external/provider_assert_test.go → config/provider_assert_test.go
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aws/external/resolve.go → config/resolve.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"crypto/tls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package external
package config

import (
"fmt"
"net/url"

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

const (
Expand Down Expand Up @@ -74,7 +75,7 @@ func ResolveCredentialChain(cfg *aws.Config, configs Configs) (err error) {
case sharedProfileSet:
err = resolveCredsFromProfile(cfg, envConfig, sharedConfig, other)
case envConfig.Credentials.HasKeys():
cfg.Credentials = aws.StaticCredentialsProvider{Value: envConfig.Credentials}
cfg.Credentials = credentials.StaticCredentialsProvider{Value: envConfig.Credentials}
case len(envConfig.WebIdentityTokenFilePath) > 0:
err = assumeWebIdentity(cfg, envConfig.WebIdentityTokenFilePath, envConfig.RoleARN, envConfig.RoleSessionName, configs)
default:
Expand All @@ -92,7 +93,7 @@ func resolveCredsFromProfile(cfg *aws.Config, envConfig *EnvConfig, sharedConfig

case sharedConfig.Credentials.HasKeys():
// Static Credentials from Shared Config/Credentials file.
cfg.Credentials = aws.StaticCredentialsProvider{
cfg.Credentials = credentials.StaticCredentialsProvider{
Value: sharedConfig.Credentials,
}

Expand Down Expand Up @@ -134,9 +135,9 @@ func ecsContainerURI(path string) string {
}

func processCredentials(cfg *aws.Config, sharedConfig *SharedConfig, configs Configs) error {
var opts []func(*processcreds.ProviderOptions)
var opts []func(*processcreds.Options)

options, found, err := GetProcessCredentialProviderOptions(configs)
options, found, err := GetProcessCredentialOptions(configs)
if err != nil {
return err
}
Expand Down Expand Up @@ -182,7 +183,7 @@ func resolveCredsFromSource(cfg *aws.Config, envConfig *EnvConfig, sharedCfg *Sh
return resolveEC2RoleCredentials(cfg, configs)

case credSourceEnvironment:
cfg.Credentials = aws.StaticCredentialsProvider{Value: envConfig.Credentials}
cfg.Credentials = credentials.StaticCredentialsProvider{Value: envConfig.Credentials}

case credSourceECSContainer:
if len(envConfig.ContainerCredentialsRelativePath) == 0 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"fmt"
Expand Down
7 changes: 4 additions & 3 deletions aws/external/resolve_test.go → config/resolve_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"context"
Expand All @@ -7,6 +7,7 @@ import (
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/internal/awstesting"
"github.com/aws/aws-sdk-go-v2/internal/awstesting/unit"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestResolveRegion(t *testing.T) {

func TestResolveCredentialsProvider(t *testing.T) {
configs := Configs{
WithCredentialsProvider{aws.StaticCredentialsProvider{
WithCredentialsProvider{credentials.StaticCredentialsProvider{
Value: aws.Credentials{
AccessKeyID: "AKID",
SecretAccessKey: "SECRET",
Expand All @@ -127,7 +128,7 @@ func TestResolveCredentialsProvider(t *testing.T) {
t.Fatalf("expected %v, got %v", e, a)
}

p := cfg.Credentials.(aws.StaticCredentialsProvider)
p := cfg.Credentials.(credentials.StaticCredentialsProvider)
if e, a := "AKID", p.Value.AccessKeyID; e != a {
t.Errorf("expect %v key, got %v", e, a)
}
Expand Down
2 changes: 1 addition & 1 deletion aws/external/shared_config.go → config/shared_config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package external
package config

import (
"os"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion credentials/processcreds/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ retrieve credentials. NOTE: If there are credentials in the profile you are
using, the credential process will not be used.
// Initialize a session to load credentials.
cfg, _ := external.LoadDefaultAWSConfig()
cfg, _ := config.LoadDefaultAWSConfig()
// Create S3 service client to use the credentials.
svc := s3.NewFromConfig(cfg)
Expand Down
Loading

0 comments on commit b64d21d

Please sign in to comment.