diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go')
-rw-r--r-- | vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go index 5b4379d..ef5f732 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go | |||
@@ -1,5 +1,10 @@ | |||
1 | // Package ec2metadata provides the client for making API calls to the | 1 | // Package ec2metadata provides the client for making API calls to the |
2 | // EC2 Metadata service. | 2 | // EC2 Metadata service. |
3 | // | ||
4 | // This package's client can be disabled completely by setting the environment | ||
5 | // variable "AWS_EC2_METADATA_DISABLED=true". This environment variable set to | ||
6 | // true instructs the SDK to disable the EC2 Metadata client. The client cannot | ||
7 | // be used while the environemnt variable is set to true, (case insensitive). | ||
3 | package ec2metadata | 8 | package ec2metadata |
4 | 9 | ||
5 | import ( | 10 | import ( |
@@ -7,17 +12,21 @@ import ( | |||
7 | "errors" | 12 | "errors" |
8 | "io" | 13 | "io" |
9 | "net/http" | 14 | "net/http" |
15 | "os" | ||
16 | "strings" | ||
10 | "time" | 17 | "time" |
11 | 18 | ||
12 | "github.com/aws/aws-sdk-go/aws" | 19 | "github.com/aws/aws-sdk-go/aws" |
13 | "github.com/aws/aws-sdk-go/aws/awserr" | 20 | "github.com/aws/aws-sdk-go/aws/awserr" |
14 | "github.com/aws/aws-sdk-go/aws/client" | 21 | "github.com/aws/aws-sdk-go/aws/client" |
15 | "github.com/aws/aws-sdk-go/aws/client/metadata" | 22 | "github.com/aws/aws-sdk-go/aws/client/metadata" |
23 | "github.com/aws/aws-sdk-go/aws/corehandlers" | ||
16 | "github.com/aws/aws-sdk-go/aws/request" | 24 | "github.com/aws/aws-sdk-go/aws/request" |
17 | ) | 25 | ) |
18 | 26 | ||
19 | // ServiceName is the name of the service. | 27 | // ServiceName is the name of the service. |
20 | const ServiceName = "ec2metadata" | 28 | const ServiceName = "ec2metadata" |
29 | const disableServiceEnvVar = "AWS_EC2_METADATA_DISABLED" | ||
21 | 30 | ||
22 | // A EC2Metadata is an EC2 Metadata service Client. | 31 | // A EC2Metadata is an EC2 Metadata service Client. |
23 | type EC2Metadata struct { | 32 | type EC2Metadata struct { |
@@ -75,6 +84,21 @@ func NewClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegio | |||
75 | svc.Handlers.Validate.Clear() | 84 | svc.Handlers.Validate.Clear() |
76 | svc.Handlers.Validate.PushBack(validateEndpointHandler) | 85 | svc.Handlers.Validate.PushBack(validateEndpointHandler) |
77 | 86 | ||
87 | // Disable the EC2 Metadata service if the environment variable is set. | ||
88 | // This shortcirctes the service's functionality to always fail to send | ||
89 | // requests. | ||
90 | if strings.ToLower(os.Getenv(disableServiceEnvVar)) == "true" { | ||
91 | svc.Handlers.Send.SwapNamed(request.NamedHandler{ | ||
92 | Name: corehandlers.SendHandler.Name, | ||
93 | Fn: func(r *request.Request) { | ||
94 | r.Error = awserr.New( | ||
95 | request.CanceledErrorCode, | ||
96 | "EC2 IMDS access disabled via "+disableServiceEnvVar+" env var", | ||
97 | nil) | ||
98 | }, | ||
99 | }) | ||
100 | } | ||
101 | |||
78 | // Add additional options to the service config | 102 | // Add additional options to the service config |
79 | for _, option := range opts { | 103 | for _, option := range opts { |
80 | option(svc.Client) | 104 | option(svc.Client) |