Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): auto detection and default to tls #42

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ Release process:
1. upload using: `VERSION=x.y.z APIKEY=abc... make upload`
1. test installing the rock from LuaRocks

### 1.1.2 (5-Dec-2022)

- fix: auto detection scheme and default to tls [#42](https://github.com/Kong/lua-resty-aws/pull/42)

### 1.1.1 (21-Nov-2022)

- fix: port is repeated when port is not standard [#39](https://github.com/Kong/lua-resty-aws/pull/39)
Expand Down
8 changes: 4 additions & 4 deletions spec/02-requests/02-build_request_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe("operations protocol", function()
method = 'POST',
path = '/hello%20world/42',
host = 'sts.amazonaws.com',
port = 80,
port = 443,
query = {
RoleArn = 'hello',
RoleSessionName = 'world',
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("operations protocol", function()
method = 'POST',
path = '/hello%20world/42',
host = 'sts.amazonaws.com',
port = 80,
port = 443,
body = {
subStructure = {
hello = "the default hello thinghy",
Expand Down Expand Up @@ -228,7 +228,7 @@ describe("operations protocol", function()
method = 'POST',
path = '/hello%20world/42',
host = 'sts.amazonaws.com',
port = 80,
port = 443,
body = {
subStructure = {
hello = "the default hello thinghy",
Expand Down Expand Up @@ -283,7 +283,7 @@ describe("operations protocol", function()
method = 'POST',
path = '/hello%20world/42',
host = 'sts.amazonaws.com',
port = 80,
port = 443,
body = {
RoleArn = {
[1] = 'hello' },
Expand Down
8 changes: 4 additions & 4 deletions spec/04-services/02-s3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("S3 service", function()
s3_3rd = assert(aws:S3 {
scheme = "http",
endpoint = "testendpoint.com",
port = 80,
port = 443,
tls = false,
})
end)
Expand Down Expand Up @@ -83,7 +83,7 @@ describe("S3 service", function()
host = 'testbucket.testendpoint.com',
method = 'PUT',
path = '/testkey',
port = 80,
port = 443,
query = {},
tls = false,
},
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("S3 service", function()
['host'] = 'testbucket.testendpoint.com',
['method'] = 'GET',
['path'] = '/testkey',
['port'] = 80,
['port'] = 443,
['query'] = {},
['tls'] = false,
}
Expand Down Expand Up @@ -152,7 +152,7 @@ describe("S3 service", function()
['host'] = 'testbucket.testendpoint.com',
['method'] = 'GET',
['path'] = '',
['port'] = 80,
['port'] = 443,
['query'] = {
['acl'] = ''
},
Expand Down
8 changes: 4 additions & 4 deletions spec/04-services/03-s3_compat_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("S3 service", function()
s3_3rd = assert(aws:S3 {
scheme = "http",
endpoint = "testendpoint.com",
port = 80,
port = 443,
tls = false,
})
end)
Expand Down Expand Up @@ -85,7 +85,7 @@ describe("S3 service", function()
host = 'testendpoint.com',
method = 'PUT',
path = '/testbucket/testkey',
port = 80,
port = 443,
query = {},
tls = false,
},
Expand Down Expand Up @@ -119,7 +119,7 @@ describe("S3 service", function()
['host'] = 'testendpoint.com',
['method'] = 'GET',
['path'] = '/testbucket/testkey',
['port'] = 80,
['port'] = 443,
['query'] = {},
['tls'] = false,
}
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("S3 service", function()
['host'] = 'testendpoint.com',
['method'] = 'GET',
['path'] = '/testbucket',
['port'] = 80,
['port'] = 443,
['query'] = {
['acl'] = ''
},
Expand Down
25 changes: 15 additions & 10 deletions src/resty/aws/request/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ local function parse_query(q)
end

local function get_host_port(config)
local host = config.endpoint or config.globalEndpoint
local endpoint = config.endpoint or config.globalEndpoint
do
local s, e = host:find("://")
local s, e = endpoint:find("://")
local scheme = config.scheme
if s then
scheme = scheme or endpoint:sub(1, s-1):lower()
-- the "globalSSL" one from the region_config_data file
local scheme = host:sub(1, s-1):lower()
host = host:sub(e+1, -1)
if config.tls == nil then
config.tls = scheme == "https"
end
endpoint = endpoint:sub(e+1, -1)
end

scheme = scheme or "https"
config.scheme = scheme

if config.tls == nil then
config.tls = scheme == "https"
end
end

Expand All @@ -97,13 +102,13 @@ local function get_host_port(config)
with_port = port ~= 80
end
if with_port then
host_header = string.format("%s:%d", host, port)
host_header = string.format("%s:%d", endpoint, port)
else
host_header = host
host_header = endpoint
end
end

return host, port, host_header
return endpoint, port, host_header
end

-- implement AWS api protocols.
Expand Down