Skip to content

Commit

Permalink
Merge pull request #984 from aws/jasdel/refactor/EC2IMDS
Browse files Browse the repository at this point in the history
feature/ec2/imds: Move the ec2imds module
  • Loading branch information
jasdel authored Dec 16, 2020
2 parents 2902dda + ec76446 commit 2ba5cce
Show file tree
Hide file tree
Showing 39 changed files with 85 additions and 57 deletions.
9 changes: 9 additions & 0 deletions .changes/next-release/config-feature-1608146507258154000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ID": "config-feature-1608146507258154000",
"SchemaVersion": 1,
"Module": "config",
"Type": "feature",
"Description": "Update to use moved feature/ec2/imds module",
"MinVersion": "",
"AffectedModules": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ID": "credentials-feature-1608146309206308000",
"SchemaVersion": 1,
"Module": "credentials",
"Type": "feature",
"Description": "Update ec2rolecreds to depend on /feature/ec2/imds module",
"MinVersion": "",
"AffectedModules": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ID": "feature.ec2.imds-feature-1608146342526841000",
"SchemaVersion": 1,
"Module": "feature/ec2/imds",
"Type": "feature",
"Description": "Move ec2imds module to feature/ec2/imds",
"MinVersion": "",
"AffectedModules": null
}
4 changes: 2 additions & 2 deletions config/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.15
require (
github.com/aws/aws-sdk-go-v2 v0.30.0
github.com/aws/aws-sdk-go-v2/credentials v0.1.5
github.com/aws/aws-sdk-go-v2/ec2imds v0.1.5
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v0.0.0-20201216182737-05d6a8e2a8df
github.com/aws/aws-sdk-go-v2/service/sts v0.30.0
github.com/awslabs/smithy-go v0.4.1-0.20201208232924-b8cdbaa577ff
github.com/google/go-cmp v0.5.4
Expand All @@ -14,6 +14,6 @@ require (
replace (
github.com/aws/aws-sdk-go-v2 => ../
github.com/aws/aws-sdk-go-v2/credentials => ../credentials/
github.com/aws/aws-sdk-go-v2/ec2imds => ../ec2imds/
github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../feature/ec2/imds/
github.com/aws/aws-sdk-go-v2/service/sts => ../service/sts/
)
9 changes: 5 additions & 4 deletions config/load_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package config

import (
"context"
"github.com/aws/aws-sdk-go-v2/ec2imds"
"io"

"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go-v2/credentials/endpointcreds"
Expand Down Expand Up @@ -211,7 +212,7 @@ func WithCustomCABundle(v io.Reader) LoadOptionsFunc {
// from the EC2 Metadata service.
type UseEC2IMDSRegion struct {
// If unset will default to generic EC2 IMDS client.
Client *ec2imds.Client
Client *imds.Client
}

// getRegion attempts to retrieve the region from EC2 Metadata service.
Expand All @@ -222,7 +223,7 @@ func (p *UseEC2IMDSRegion) getRegion(ctx context.Context) (string, bool, error)

client := p.Client
if client == nil {
client = ec2imds.New(ec2imds.Options{})
client = imds.New(imds.Options{})
}

result, err := p.Client.GetRegion(ctx, nil)
Expand All @@ -235,7 +236,7 @@ func (p *UseEC2IMDSRegion) getRegion(ctx context.Context) (string, bool, error)
return "", false, nil
}

// getEC2IMDSRegion returns the value of ec2imds region.
// getEC2IMDSRegion returns the value of EC2 IMDS region.
func (o LoadOptions) getEC2IMDSRegion(ctx context.Context) (string, bool, error) {
if o.UseEC2IMDSRegion == nil {
return "", false, nil
Expand Down
4 changes: 2 additions & 2 deletions config/resolve_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/aws/aws-sdk-go-v2/credentials/endpointcreds"
"github.com/aws/aws-sdk-go-v2/credentials/processcreds"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/ec2imds"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/aws/aws-sdk-go-v2/service/sts"
)

Expand Down Expand Up @@ -258,7 +258,7 @@ func resolveEC2RoleCredentials(ctx context.Context, cfg *aws.Config, configs con
optFns = append(optFns, func(o *ec2rolecreds.Options) {
// Only define a client from config if not already defined.
if o.Client != nil {
o.Client = ec2imds.New(ec2imds.Options{
o.Client = imds.New(imds.Options{
HTTPClient: cfg.HTTPClient,
Retryer: cfg.Retryer,
})
Expand Down
12 changes: 6 additions & 6 deletions credentials/ec2rolecreds/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
// it with the CredentialsCache before assigning the provider to the Amazon S3 API
// client's Credentials option.
//
// provider := ec2imds.New(ec2imds.Options{})
// provider := imds.New(imds.Options{})
//
// // Create the service client value configured for credentials.
// svc := s3.New(s3.Options{
// Credentials: &aws.CredentialsCache{Provider: provider},
// })
//
// If you need more control, you can set the configuration options on the
// credentials provider using the ec2imds.Options type to configure the EC2 IMDS
// credentials provider using the imds.Options type to configure the EC2 IMDS
// API Client and ExpiryWindow of the retrieved credentials.
//
// provider := ec2imds.New(ec2imds.Options{
// // See ec2imds.Options type's documentation for more options available.
// Client: ec2imds.New(Options{
// provider := imds.New(imds.Options{
// // See imds.Options type's documentation for more options available.
// Client: imds.New(Options{
// HTTPClient: customHTTPClient,
// }),
//
Expand All @@ -53,6 +53,6 @@
//
// EC2 IMDS API Client
//
// See the github.com/aws/aws-sdk-go-v2/ec2imds module for more details on
// See the github.com/aws/aws-sdk-go-v2/feature/ec2/imds module for more details on
// configuring the client, and options available.
package ec2rolecreds
14 changes: 7 additions & 7 deletions credentials/ec2rolecreds/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/ec2imds"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/awslabs/smithy-go"
)

Expand All @@ -20,7 +20,7 @@ const ProviderName = "EC2RoleProvider"
// GetMetadataAPIClient provides the interface for an EC2 IMDS API client for the
// GetMetadata operation.
type GetMetadataAPIClient interface {
GetMetadata(context.Context, *ec2imds.GetMetadataInput, ...func(*ec2imds.Options)) (*ec2imds.GetMetadataOutput, error)
GetMetadata(context.Context, *imds.GetMetadataInput, ...func(*imds.Options)) (*imds.GetMetadataOutput, error)
}

// A Provider retrieves credentials from the EC2 service, and keeps track if
Expand All @@ -29,7 +29,7 @@ type GetMetadataAPIClient interface {
// The New function must be used to create the Provider.
//
// p := &ec2rolecreds.New(ec2rolecreds.Options{
// Client: ec2imds.New(ec2imds.Options{}),
// Client: imds.New(imds.Options{}),
//
// // Expire the credentials 10 minutes before IAM states they should.
// // Proactively refreshing the credentials.
Expand All @@ -44,7 +44,7 @@ type Options struct {
// The API client that will be used by the provider to make GetMetadata API
// calls to EC2 IMDS.
//
// If nil, the provider will default to the ec2imds client.
// If nil, the provider will default to the EC2 IMDS client.
Client GetMetadataAPIClient
}

Expand All @@ -58,7 +58,7 @@ func New(optFns ...func(*Options)) *Provider {
}

if options.Client == nil {
options.Client = ec2imds.New(ec2imds.Options{})
options.Client = imds.New(imds.Options{})
}

return &Provider{
Expand Down Expand Up @@ -119,7 +119,7 @@ const iamSecurityCredsPath = "/iam/security-credentials/"
// there are no credentials, or there is an error making or receiving the
// request
func requestCredList(ctx context.Context, client GetMetadataAPIClient) ([]string, error) {
resp, err := client.GetMetadata(ctx, &ec2imds.GetMetadataInput{
resp, err := client.GetMetadata(ctx, &imds.GetMetadataInput{
Path: iamSecurityCredsPath,
})
if err != nil {
Expand All @@ -145,7 +145,7 @@ func requestCredList(ctx context.Context, client GetMetadataAPIClient) ([]string
// If the credentials cannot be found, or there is an error reading the response
// and error will be returned.
func requestCred(ctx context.Context, client GetMetadataAPIClient, credsName string) (ec2RoleCredRespBody, error) {
resp, err := client.GetMetadata(ctx, &ec2imds.GetMetadataInput{
resp, err := client.GetMetadata(ctx, &imds.GetMetadataInput{
Path: path.Join(iamSecurityCredsPath, credsName),
})
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions credentials/ec2rolecreds/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/ec2imds"
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/aws/aws-sdk-go-v2/internal/sdk"
"github.com/awslabs/smithy-go"
)
Expand Down Expand Up @@ -38,13 +38,13 @@ type mockClient struct {
}

func (c mockClient) GetMetadata(
ctx context.Context, params *ec2imds.GetMetadataInput, optFns ...func(*ec2imds.Options),
ctx context.Context, params *imds.GetMetadataInput, optFns ...func(*imds.Options),
) (
*ec2imds.GetMetadataOutput, error,
*imds.GetMetadataOutput, error,
) {
switch params.Path {
case iamSecurityCredsPath:
return &ec2imds.GetMetadataOutput{
return &imds.GetMetadataOutput{
Content: ioutil.NopCloser(strings.NewReader(c.roleName)),
}, nil

Expand All @@ -55,7 +55,7 @@ func (c mockClient) GetMetadata(
} else {
fmt.Fprintf(&w, credsRespTmpl, c.expireOn)
}
return &ec2imds.GetMetadataOutput{
return &imds.GetMetadataOutput{
Content: ioutil.NopCloser(strings.NewReader(w.String())),
}, nil
default:
Expand Down
4 changes: 2 additions & 2 deletions credentials/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.15

require (
github.com/aws/aws-sdk-go-v2 v0.30.0
github.com/aws/aws-sdk-go-v2/ec2imds v0.1.5
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v0.0.0-20201216182737-05d6a8e2a8df
github.com/aws/aws-sdk-go-v2/service/sts v0.30.0
github.com/awslabs/smithy-go v0.4.1-0.20201208232924-b8cdbaa577ff
)

replace (
github.com/aws/aws-sdk-go-v2 => ../
github.com/aws/aws-sdk-go-v2/ec2imds => ../ec2imds/
github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../feature/ec2/imds/
github.com/aws/aws-sdk-go-v2/service/sts => ../service/sts/
)
2 changes: 1 addition & 1 deletion example/service/s3/listObjects/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ replace github.com/aws/aws-sdk-go-v2 => ../../../../

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

replace github.com/aws/aws-sdk-go-v2/ec2imds => ../../../../ec2imds/
replace github.com/aws/aws-sdk-go-v2/feature/ec2/imds => ../../../../feature/ec2/imds/

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

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ec2imds/api_client.go → feature/ec2/imds/api_client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions ec2imds/doc.go → feature/ec2/imds/doc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package ec2imds provides the API client for interacting with the Amazon EC2
// Package imds provides the API client for interacting with the Amazon EC2
// Instance Metadata Service.
//
// See the EC2 IMDS user guide for more information on using the API.
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
package ec2imds
package imds
4 changes: 2 additions & 2 deletions ec2imds/go.mod → feature/ec2/imds/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/aws/aws-sdk-go-v2/ec2imds
module github.com/aws/aws-sdk-go-v2/feature/ec2/imds

go 1.15

Expand All @@ -8,4 +8,4 @@ require (
github.com/google/go-cmp v0.5.4
)

replace github.com/aws/aws-sdk-go-v2 => ../
replace github.com/aws/aws-sdk-go-v2 => ../../../
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// +build integration,ec2env

package ec2imds
package imds

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ec2imds
package imds

import (
"context"
Expand Down
Loading

0 comments on commit 2ba5cce

Please sign in to comment.