]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/aws/aws-sdk-go/aws/session/env_config.go
Transfer of provider code
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / aws / aws-sdk-go / aws / session / env_config.go
1 package session
2
3 import (
4 "os"
5 "strconv"
6
7 "github.com/aws/aws-sdk-go/aws/credentials"
8 )
9
10 // envConfig is a collection of environment values the SDK will read
11 // setup config from. All environment values are optional. But some values
12 // such as credentials require multiple values to be complete or the values
13 // will be ignored.
14 type envConfig struct {
15 // Environment configuration values. If set both Access Key ID and Secret Access
16 // Key must be provided. Session Token and optionally also be provided, but is
17 // not required.
18 //
19 // # Access Key ID
20 // AWS_ACCESS_KEY_ID=AKID
21 // AWS_ACCESS_KEY=AKID # only read if AWS_ACCESS_KEY_ID is not set.
22 //
23 // # Secret Access Key
24 // AWS_SECRET_ACCESS_KEY=SECRET
25 // AWS_SECRET_KEY=SECRET=SECRET # only read if AWS_SECRET_ACCESS_KEY is not set.
26 //
27 // # Session Token
28 // AWS_SESSION_TOKEN=TOKEN
29 Creds credentials.Value
30
31 // Region value will instruct the SDK where to make service API requests to. If is
32 // not provided in the environment the region must be provided before a service
33 // client request is made.
34 //
35 // AWS_REGION=us-east-1
36 //
37 // # AWS_DEFAULT_REGION is only read if AWS_SDK_LOAD_CONFIG is also set,
38 // # and AWS_REGION is not also set.
39 // AWS_DEFAULT_REGION=us-east-1
40 Region string
41
42 // Profile name the SDK should load use when loading shared configuration from the
43 // shared configuration files. If not provided "default" will be used as the
44 // profile name.
45 //
46 // AWS_PROFILE=my_profile
47 //
48 // # AWS_DEFAULT_PROFILE is only read if AWS_SDK_LOAD_CONFIG is also set,
49 // # and AWS_PROFILE is not also set.
50 // AWS_DEFAULT_PROFILE=my_profile
51 Profile string
52
53 // SDK load config instructs the SDK to load the shared config in addition to
54 // shared credentials. This also expands the configuration loaded from the shared
55 // credentials to have parity with the shared config file. This also enables
56 // Region and Profile support for the AWS_DEFAULT_REGION and AWS_DEFAULT_PROFILE
57 // env values as well.
58 //
59 // AWS_SDK_LOAD_CONFIG=1
60 EnableSharedConfig bool
61
62 // Shared credentials file path can be set to instruct the SDK to use an alternate
63 // file for the shared credentials. If not set the file will be loaded from
64 // $HOME/.aws/credentials on Linux/Unix based systems, and
65 // %USERPROFILE%\.aws\credentials on Windows.
66 //
67 // AWS_SHARED_CREDENTIALS_FILE=$HOME/my_shared_credentials
68 SharedCredentialsFile string
69
70 // Shared config file path can be set to instruct the SDK to use an alternate
71 // file for the shared config. If not set the file will be loaded from
72 // $HOME/.aws/config on Linux/Unix based systems, and
73 // %USERPROFILE%\.aws\config on Windows.
74 //
75 // AWS_CONFIG_FILE=$HOME/my_shared_config
76 SharedConfigFile string
77
78 // Sets the path to a custom Credentials Authroity (CA) Bundle PEM file
79 // that the SDK will use instead of the the system's root CA bundle.
80 // Only use this if you want to configure the SDK to use a custom set
81 // of CAs.
82 //
83 // Enabling this option will attempt to merge the Transport
84 // into the SDK's HTTP client. If the client's Transport is
85 // not a http.Transport an error will be returned. If the
86 // Transport's TLS config is set this option will cause the
87 // SDK to overwrite the Transport's TLS config's RootCAs value.
88 //
89 // Setting a custom HTTPClient in the aws.Config options will override this setting.
90 // To use this option and custom HTTP client, the HTTP client needs to be provided
91 // when creating the session. Not the service client.
92 //
93 // AWS_CA_BUNDLE=$HOME/my_custom_ca_bundle
94 CustomCABundle string
95 }
96
97 var (
98 credAccessEnvKey = []string{
99 "AWS_ACCESS_KEY_ID",
100 "AWS_ACCESS_KEY",
101 }
102 credSecretEnvKey = []string{
103 "AWS_SECRET_ACCESS_KEY",
104 "AWS_SECRET_KEY",
105 }
106 credSessionEnvKey = []string{
107 "AWS_SESSION_TOKEN",
108 }
109
110 regionEnvKeys = []string{
111 "AWS_REGION",
112 "AWS_DEFAULT_REGION", // Only read if AWS_SDK_LOAD_CONFIG is also set
113 }
114 profileEnvKeys = []string{
115 "AWS_PROFILE",
116 "AWS_DEFAULT_PROFILE", // Only read if AWS_SDK_LOAD_CONFIG is also set
117 }
118 sharedCredsFileEnvKey = []string{
119 "AWS_SHARED_CREDENTIALS_FILE",
120 }
121 sharedConfigFileEnvKey = []string{
122 "AWS_CONFIG_FILE",
123 }
124 )
125
126 // loadEnvConfig retrieves the SDK's environment configuration.
127 // See `envConfig` for the values that will be retrieved.
128 //
129 // If the environment variable `AWS_SDK_LOAD_CONFIG` is set to a truthy value
130 // the shared SDK config will be loaded in addition to the SDK's specific
131 // configuration values.
132 func loadEnvConfig() envConfig {
133 enableSharedConfig, _ := strconv.ParseBool(os.Getenv("AWS_SDK_LOAD_CONFIG"))
134 return envConfigLoad(enableSharedConfig)
135 }
136
137 // loadEnvSharedConfig retrieves the SDK's environment configuration, and the
138 // SDK shared config. See `envConfig` for the values that will be retrieved.
139 //
140 // Loads the shared configuration in addition to the SDK's specific configuration.
141 // This will load the same values as `loadEnvConfig` if the `AWS_SDK_LOAD_CONFIG`
142 // environment variable is set.
143 func loadSharedEnvConfig() envConfig {
144 return envConfigLoad(true)
145 }
146
147 func envConfigLoad(enableSharedConfig bool) envConfig {
148 cfg := envConfig{}
149
150 cfg.EnableSharedConfig = enableSharedConfig
151
152 setFromEnvVal(&cfg.Creds.AccessKeyID, credAccessEnvKey)
153 setFromEnvVal(&cfg.Creds.SecretAccessKey, credSecretEnvKey)
154 setFromEnvVal(&cfg.Creds.SessionToken, credSessionEnvKey)
155
156 // Require logical grouping of credentials
157 if len(cfg.Creds.AccessKeyID) == 0 || len(cfg.Creds.SecretAccessKey) == 0 {
158 cfg.Creds = credentials.Value{}
159 } else {
160 cfg.Creds.ProviderName = "EnvConfigCredentials"
161 }
162
163 regionKeys := regionEnvKeys
164 profileKeys := profileEnvKeys
165 if !cfg.EnableSharedConfig {
166 regionKeys = regionKeys[:1]
167 profileKeys = profileKeys[:1]
168 }
169
170 setFromEnvVal(&cfg.Region, regionKeys)
171 setFromEnvVal(&cfg.Profile, profileKeys)
172
173 setFromEnvVal(&cfg.SharedCredentialsFile, sharedCredsFileEnvKey)
174 setFromEnvVal(&cfg.SharedConfigFile, sharedConfigFileEnvKey)
175
176 cfg.CustomCABundle = os.Getenv("AWS_CA_BUNDLE")
177
178 return cfg
179 }
180
181 func setFromEnvVal(dst *string, keys []string) {
182 for _, k := range keys {
183 if v := os.Getenv(k); len(v) > 0 {
184 *dst = v
185 break
186 }
187 }
188 }