Skip to content

Commit 4901eda

Browse files
committed
fix: remove more module-level uses of config.global
1 parent 078bc30 commit 4901eda

5 files changed

+21
-19
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ Release process:
171171

172172
### 1.3.3 (13-Sep-2023)
173173

174+
- fix: remove more module-level uses of config.global
175+
[83](https://github.com/Kong/lua-resty-aws/pull/83)
176+
177+
### 1.3.3 (13-Sep-2023)
178+
174179
- fix: don't invoke region detection code on the module toplevel and advise against trying to.
175180
[81](https://github.com/Kong/lua-resty-aws/pull/81)
176181

src/resty/aws/credentials/CredentialProviderChain.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local CredentialProviderChain = setmetatable({}, Super)
88
CredentialProviderChain.__index = CredentialProviderChain
99

1010

11-
local AWS_EC2_METADATA_DISABLED = require("resty.aws.config").global.AWS_EC2_METADATA_DISABLED
11+
local aws_config = require("resty.aws.config")
1212

1313

1414
CredentialProviderChain.defaultProviders = {} do
@@ -36,7 +36,7 @@ CredentialProviderChain.defaultProviders = {} do
3636
add_if_exists("RemoteCredentials") -- since "ECSCredentials" doesn't exist? and for ECS RemoteCredentials is used???
3737
add_if_exists("ProcessCredentials")
3838
add_if_exists("TokenFileWebIdentityCredentials")
39-
if AWS_EC2_METADATA_DISABLED then
39+
if aws_config.global.AWS_EC2_METADATA_DISABLED then
4040
ngx.log(ngx.DEBUG, "AWS_EC2_METADATA_DISABLED is set, skipping EC2MetadataCredentials provider")
4141
else
4242
add_if_exists("EC2MetadataCredentials")

src/resty/aws/credentials/EnvironmentCredentials.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
-- @classmod EnvironmentCredentials
33

44

5+
local aws_config = require("resty.aws.config")
6+
7+
58
-- Create class
69
local Super = require "resty.aws.credentials.Credentials"
710
local EnvironmentCredentials = setmetatable({}, Super)
@@ -33,7 +36,7 @@ end
3336
-- updates credentials.
3437
-- @return success, or nil+err
3538
function EnvironmentCredentials:refresh()
36-
local global_config = require("resty.aws.config").global
39+
local global_config = aws_config.global
3740

3841
local access = os.getenv(self.envPrefix .. "_ACCESS_KEY_ID") or global_config[self.envPrefix .. "_ACCESS_KEY_ID"]
3942
if not access then

src/resty/aws/credentials/RemoteCredentials.lua

+6-8
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,19 @@ local FullUri do
2525
return t
2626
end
2727

28-
local global_config = require("resty.aws.config").global
28+
local aws_config = require("resty.aws.config")
2929

30-
local ENV_RELATIVE_URI = global_config.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
31-
local ENV_FULL_URI = global_config.AWS_CONTAINER_CREDENTIALS_FULL_URI
3230
local FULL_URI_UNRESTRICTED_PROTOCOLS = makeset { "https" }
3331
local FULL_URI_ALLOWED_PROTOCOLS = makeset { "http", "https" }
3432
local FULL_URI_ALLOWED_HOSTNAMES = makeset { "localhost", "127.0.0.1" }
3533
local RELATIVE_URI_HOST = '169.254.170.2'
3634

3735
local function getFullUri()
38-
if ENV_RELATIVE_URI then
39-
return 'http://' .. RELATIVE_URI_HOST .. ENV_RELATIVE_URI
36+
if aws_config.global.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI then
37+
return 'http://' .. RELATIVE_URI_HOST .. aws_config.global.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
4038

41-
elseif ENV_FULL_URI then
42-
local parsed_url = url.parse(ENV_FULL_URI)
39+
elseif aws_config.global.AWS_CONTAINER_CREDENTIALS_FULL_URI then
40+
local parsed_url = url.parse(aws_config.global.AWS_CONTAINER_CREDENTIALS_FULL_URI)
4341

4442
if not FULL_URI_ALLOWED_PROTOCOLS[parsed_url.scheme] then
4543
return nil, 'Unsupported protocol, must be one of '
@@ -55,7 +53,7 @@ local FullUri do
5553
.. parsed_url.host .. ' requested.'
5654
end
5755

58-
return ENV_FULL_URI
56+
return aws_config.global.AWS_CONTAINER_CREDENTIALS_FULL_URI
5957

6058
else
6159
return nil, 'Environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI or '

src/resty/aws/credentials/TokenFileWebIdentityCredentials.lua

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
local readfile = require("pl.utils").readfile
55
local lom = require("lxp.lom")
66

7-
8-
local global_config = require("resty.aws.config").global
9-
local AWS_ROLE_ARN = global_config.role_arn
10-
local AWS_WEB_IDENTITY_TOKEN_FILE = global_config.web_identity_token_file
11-
local AWS_ROLE_SESSION_NAME = global_config.role_session_name or "session@lua-resty-aws"
7+
local aws_config = require("resty.aws.config")
128

139

1410
-- Create class
@@ -29,14 +25,14 @@ function TokenFileWebIdentityCredentials:new(opts)
2925

3026
opts = opts or {}
3127
self.token_file = assert(
32-
opts.token_file or AWS_WEB_IDENTITY_TOKEN_FILE,
28+
opts.token_file or aws_config.global.AWS_WEB_IDENTITY_TOKEN_FILE,
3329
"either 'opts.token_file' or environment variable 'AWS_WEB_IDENTITY_TOKEN_FILE' must be set"
3430
)
3531
self.role_arn = assert(
36-
opts.role_arn or AWS_ROLE_ARN,
32+
opts.role_arn or aws_config.global.AWS_ROLE_ARN,
3733
"either 'opts.role_arn' or environment variable 'AWS_ROLE_ARN' must be set"
3834
)
39-
self.session_name = opts.session_name or AWS_ROLE_SESSION_NAME
35+
self.session_name = opts.session_name or aws_config.global.AWS_ROLE_SESSION_NAME
4036

4137
return self
4238
end

0 commit comments

Comments
 (0)