mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix build errors caused by update aws-sdk-go to v1.1.30
This fix tries to fix build errors caused by updating aws-sdk-go to v1.1.30. This fix fixes #22961. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
51f0a04223
commit
46ea8ff75d
2 changed files with 17 additions and 18 deletions
|
@ -14,9 +14,9 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/defaults"
|
||||
"github.com/aws/aws-sdk-go/aws/ec2metadata"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
|
@ -66,11 +66,8 @@ type regionFinder interface {
|
|||
|
||||
type byTimestamp []*cloudwatchlogs.InputLogEvent
|
||||
|
||||
// init registers the awslogs driver and sets the default region, if provided
|
||||
// init registers the awslogs driver
|
||||
func init() {
|
||||
if os.Getenv(regionEnvKey) != "" {
|
||||
defaults.DefaultConfig.Region = aws.String(os.Getenv(regionEnvKey))
|
||||
}
|
||||
if err := logger.RegisterLogDriver(name, New); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -113,7 +110,7 @@ func New(ctx logger.Context) (logger.Logger, error) {
|
|||
// newRegionFinder is a variable such that the implementation
|
||||
// can be swapped out for unit tests.
|
||||
var newRegionFinder = func() regionFinder {
|
||||
return ec2metadata.New(nil)
|
||||
return ec2metadata.New(session.New())
|
||||
}
|
||||
|
||||
// newAWSLogsClient creates the service client for Amazon CloudWatch Logs.
|
||||
|
@ -121,28 +118,30 @@ var newRegionFinder = func() regionFinder {
|
|||
// User-Agent string and automatic region detection using the EC2 Instance
|
||||
// Metadata Service when region is otherwise unspecified.
|
||||
func newAWSLogsClient(ctx logger.Context) (api, error) {
|
||||
config := defaults.DefaultConfig
|
||||
if ctx.Config[regionKey] != "" {
|
||||
config = defaults.DefaultConfig.Merge(&aws.Config{
|
||||
Region: aws.String(ctx.Config[regionKey]),
|
||||
})
|
||||
var region *string
|
||||
if os.Getenv(regionEnvKey) != "" {
|
||||
region = aws.String(os.Getenv(regionEnvKey))
|
||||
}
|
||||
if config.Region == nil || *config.Region == "" {
|
||||
if ctx.Config[regionKey] != "" {
|
||||
region = aws.String(ctx.Config[regionKey])
|
||||
}
|
||||
if region == nil || *region == "" {
|
||||
logrus.Info("Trying to get region from EC2 Metadata")
|
||||
ec2MetadataClient := newRegionFinder()
|
||||
region, err := ec2MetadataClient.Region()
|
||||
r, err := ec2MetadataClient.Region()
|
||||
if err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Error("Could not get region from EC2 metadata, environment, or log option")
|
||||
return nil, errors.New("Cannot determine region for awslogs driver")
|
||||
}
|
||||
config.Region = ®ion
|
||||
region = &r
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"region": *config.Region,
|
||||
"region": *region,
|
||||
}).Debug("Created awslogs client")
|
||||
client := cloudwatchlogs.New(config)
|
||||
|
||||
client := cloudwatchlogs.New(session.New(), aws.NewConfig().WithRegion(*region))
|
||||
|
||||
client.Handlers.Build.PushBackNamed(request.NamedHandler{
|
||||
Name: "DockerUserAgentHandler",
|
||||
|
|
|
@ -47,8 +47,8 @@ func TestNewAWSLogsClientUserAgentHandler(t *testing.T) {
|
|||
},
|
||||
}
|
||||
buildHandlerList.Run(request)
|
||||
expectedUserAgentString := fmt.Sprintf("Docker %s (%s) %s/%s",
|
||||
dockerversion.Version, runtime.GOOS, aws.SDKName, aws.SDKVersion)
|
||||
expectedUserAgentString := fmt.Sprintf("Docker %s (%s) %s/%s (%s; %s; %s)",
|
||||
dockerversion.Version, runtime.GOOS, aws.SDKName, aws.SDKVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
userAgent := request.HTTPRequest.Header.Get("User-Agent")
|
||||
if userAgent != expectedUserAgentString {
|
||||
t.Errorf("Wrong User-Agent string, expected \"%s\" but was \"%s\"",
|
||||
|
|
Loading…
Reference in a new issue