Skip to content

Commit 1138d1c

Browse files
authored
feat: remove libexpat dependency (#1)
1 parent 50d9f08 commit 1138d1c

File tree

7 files changed

+46
-187
lines changed

7 files changed

+46
-187
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name: Test
22

3-
on: [push, pull_request]
4-
5-
env:
6-
LIBEXPAT_DOWNLOAD_URL: https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-2.5.0.tar.gz
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
78

89
jobs:
910

@@ -16,6 +17,8 @@ jobs:
1617
openresty_version:
1718
- 1.17.8.2
1819
- 1.19.9.1
20+
- 1.21.4.3
21+
- 1.25.3.2
1922

2023
runs-on: ubuntu-latest
2124
container:
@@ -30,18 +33,6 @@ jobs:
3033
apk add --no-cache curl perl bash wget git perl-dev libarchive-tools nodejs jq
3134
ln -s /usr/bin/bsdtar /usr/bin/tar
3235
33-
- name: Build libexpat
34-
if: matrix.openresty_version == '1.17.8.2'
35-
run: |
36-
mkdir -p /tmp/expat
37-
curl -Ls $LIBEXPAT_DOWNLOAD_URL | tar -xz --strip-components=1 -f - -C /tmp/expat
38-
cd /tmp/expat && ./configure && make && make install
39-
40-
- name: Install libexpat from package manager
41-
if: matrix.openresty_version == '1.19.9.1'
42-
run: |
43-
apk add --no-cache expat-dev
44-
4536
- name: Cache
4637
uses: actions/cache@v2
4738
with:

lua-resty-aws-dev-1.rockspec.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies = {
2727
"lua-resty-http >= 0.16",
2828
"lua-resty-luasocket ~> 1",
2929
"lua-resty-openssl >= 0.8.17",
30-
"luaexpat >= 1.5.1",
3130
}
3231

3332
build = {

spec/02-requests/02-build_request_spec.lua

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local cjson = require "cjson"
2-
local pl_stringx = require "pl.stringx"
32

43
describe("operations protocol", function()
54

@@ -37,10 +36,6 @@ describe("operations protocol", function()
3736
},
3837
input = {
3938
type = "structure",
40-
locationName = "mainXmlElement", -- only for rest-xml protocol
41-
xmlNamespace = { -- only for rest-xml protocol
42-
uri = "cool-name-space"
43-
},
4439
required = {
4540
"RoleArn",
4641
"RoleSessionName"
@@ -206,6 +201,7 @@ describe("operations protocol", function()
206201
local request = build_request(operation, config, params)
207202
assert.same({
208203
headers = {
204+
["Accept"] = 'application/json',
209205
["X-Sooper-Secret"] = "towel",
210206
["X-Amz-Target"] = "sts.AssumeRole",
211207
["Host"] = "sts.amazonaws.com",
@@ -239,6 +235,7 @@ describe("operations protocol", function()
239235

240236
assert.same({
241237
headers = {
238+
["Accept"] = 'application/json',
242239
["X-Sooper-Secret"] = "towel",
243240
["Content-Length"] = 172,
244241
["Content-Type"] = "application/x-amz-json-1.0",
@@ -279,6 +276,7 @@ describe("operations protocol", function()
279276

280277
assert.same({
281278
headers = {
279+
["Accept"] = 'application/json',
282280
["X-Sooper-Secret"] = "towel",
283281
["Content-Length"] = 172,
284282
["Content-Type"] = "application/x-amz-json-1.0",
@@ -314,6 +312,7 @@ describe("operations protocol", function()
314312

315313
assert.same({
316314
headers = {
315+
["Accept"] = 'application/json',
317316
["Content-Length"] = 4,
318317
["X-Amz-Target"] = "s3.PutObject",
319318
["Host"] = "s3.amazonaws.com",
@@ -328,85 +327,6 @@ describe("operations protocol", function()
328327
end)
329328

330329

331-
it("rest-xml: querystring, uri, header and body params", function()
332-
333-
config.protocol = "rest-xml"
334-
335-
local request = build_request(operation, config, params)
336-
if request and request.body then
337-
-- cannot reliably compare non-canonicalized json, so decode to Lua table
338-
local body_lines = pl_stringx.splitlines(request.body)
339-
for i, line in ipairs(body_lines) do
340-
body_lines[i] = pl_stringx.strip(line, ' ')
341-
end
342-
request.body = assert(require("pl.xml").parse(table.concat(body_lines, "")))
343-
local to_lua = function(t)
344-
-- convert LOM to comparable Lua table
345-
for i, v in ipairs(t) do
346-
if type(v) == "table" and v.tag then
347-
t[v.tag] = v
348-
v.tag = nil
349-
t[i] = nil
350-
if type(v.attr) == "table" and not next(v.attr) then
351-
-- delete empty attr table
352-
v.attr = nil
353-
end
354-
end
355-
end
356-
end
357-
to_lua(request.body)
358-
to_lua(request.body.someSubStructure)
359-
end
360-
361-
assert.same({
362-
headers = {
363-
["X-Sooper-Secret"] = "towel",
364-
["Content-Length"] = 456,
365-
["Content-Type"] = "application/xml",
366-
["X-Amz-Target"] = "sts.AssumeRole",
367-
["Host"] = "sts.amazonaws.com",
368-
},
369-
method = 'POST',
370-
path = '/hello%20world/42',
371-
host = 'sts.amazonaws.com',
372-
port = 443,
373-
body = {
374-
RoleArn = {
375-
[1] = 'hello' },
376-
RoleSessionName = {
377-
[1] = 'world' },
378-
BinaryData = {
379-
[1] = binary_data },
380-
attr = {
381-
[1] = 'xmlns',
382-
xmlns = 'cool-name-space' },
383-
someSubStructure = {
384-
hello = {
385-
[1] = 'the default hello thinghy' },
386-
world = {
387-
[1] = 'the default world thinghy' } },
388-
subList = {
389-
[1] = {
390-
[1] = '1',
391-
attr = {},
392-
tag = 'listELement' },
393-
[2] = {
394-
[1] = '2',
395-
attr = {},
396-
tag = 'listELement' },
397-
[3] = {
398-
[1] = '3',
399-
attr = {},
400-
tag = 'listELement' } },
401-
tag = 'mainXmlElement' },
402-
query = {
403-
UserId = "Arthur Dent",
404-
nice = '',
405-
}
406-
}, request)
407-
end)
408-
409-
410330
pending("ec2: querystring, uri, header and body params", function()
411331

412332
config.protocol = "ec2"

spec/02-requests/03-execute_spec.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe("request execution", function()
5151

5252
it("tls defaults to true", function ()
5353
local config = {
54-
region = "us-east-1"
54+
region = "us-east-1",
55+
protocol = "json",
5556
}
5657

5758
config.credentials = Credentials:new({
@@ -76,7 +77,8 @@ describe("request execution", function()
7677

7778
it("support configuring tls false", function ()
7879
local config = {
79-
region = "us-east-1"
80+
region = "us-east-1",
81+
protocol = "json",
8082
}
8183

8284
config.credentials = Credentials:new({
@@ -103,7 +105,8 @@ describe("request execution", function()
103105

104106
it("support configuring ssl verify false", function ()
105107
local config = {
106-
region = "us-east-1"
108+
region = "us-east-1",
109+
protocol = "json"
107110
}
108111

109112
config.credentials = Credentials:new({
@@ -129,7 +132,8 @@ describe("request execution", function()
129132

130133
it("support configure timeout", function ()
131134
local config = {
132-
region = "us-east-1"
135+
region = "us-east-1",
136+
protocol = "json",
133137
}
134138

135139
config.credentials = Credentials:new({
@@ -155,7 +159,8 @@ describe("request execution", function()
155159

156160
it("support configure keepalive idle timeout", function ()
157161
local config = {
158-
region = "us-east-1"
162+
region = "us-east-1",
163+
protocol = "json",
159164
}
160165

161166
config.credentials = Credentials:new({
@@ -181,7 +186,8 @@ describe("request execution", function()
181186

182187
it("support set proxy options", function ()
183188
local config = {
184-
region = "us-east-1"
189+
region = "us-east-1",
190+
protocol = "json",
185191
}
186192

187193
config.credentials = Credentials:new({
@@ -217,7 +223,8 @@ describe("request execution", function()
217223

218224
it("decoded json body should have array metatable", function ()
219225
local config = {
220-
region = "us-east-1"
226+
region = "us-east-1",
227+
protocol = "json",
221228
}
222229

223230
config.credentials = Credentials:new({

src/resty/aws/credentials/ChainableTemporaryCredentials.lua

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--- ChainableTemporaryCredentials class.
22
-- @classmod ChainableTemporaryCredentials
33

4-
local lom = require("lxp.lom")
4+
local cjson = require("cjson")
55

66

77
-- Create class
@@ -117,19 +117,17 @@ function ChainableTemporaryCredentials:refresh()
117117
return nil, "request for token returned invalid body: " .. err
118118
end
119119

120-
local resp_body_lom, err = lom.parse(response.body)
121-
if not resp_body_lom then
120+
local data, err = cjson.decode(response.body)
121+
if not data then
122122
return nil, "failed to parse response body: " .. err
123123
end
124-
125-
local cred_lom = lom.find_elem(lom.find_elem(resp_body_lom, "AssumeRoleResult"), "Credentials")
126-
127-
local AccessKeyId = lom.find_elem(cred_lom, "AccessKeyId")[1]
128-
local SecretAccessKey = lom.find_elem(cred_lom, "SecretAccessKey")[1]
129-
local SessionToken = lom.find_elem(cred_lom, "SessionToken")[1]
130-
local Expiration = lom.find_elem(cred_lom, "Expiration")[1]
131-
132-
self:set(AccessKeyId, SecretAccessKey, SessionToken, Expiration)
124+
local credentials = data.AssumeRoleResponse.AssumeRoleResult.Credentials
125+
self:set(
126+
credentials.AccessKeyId,
127+
credentials.SecretAccessKey,
128+
credentials.SessionToken,
129+
credentials.Expiration
130+
)
133131

134132
return true
135133
end

src/resty/aws/credentials/TokenFileWebIdentityCredentials.lua

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- @classmod TokenFileWebIdentityCredentials
33

44
local readfile = require("pl.utils").readfile
5-
local lom = require("lxp.lom")
5+
local cjson = require("cjson")
66

77
local aws_config = require("resty.aws.config")
88

@@ -79,19 +79,17 @@ function TokenFileWebIdentityCredentials:refresh()
7979
return nil, "request for token returned invalid body: " .. err
8080
end
8181

82-
local resp_body_lom, err = lom.parse(response.body)
83-
if not resp_body_lom then
82+
local data, err = cjson.decode(response.body)
83+
if not data then
8484
return nil, "failed to parse response body: " .. err
8585
end
86-
87-
local cred_lom = lom.find_elem(lom.find_elem(resp_body_lom, "AssumeRoleWithWebIdentityResult"), "Credentials")
88-
89-
local AccessKeyId = lom.find_elem(cred_lom, "AccessKeyId")[1]
90-
local SecretAccessKey = lom.find_elem(cred_lom, "SecretAccessKey")[1]
91-
local SessionToken = lom.find_elem(cred_lom, "SessionToken")[1]
92-
local Expiration = lom.find_elem(cred_lom, "Expiration")[1]
93-
94-
self:set(AccessKeyId, SecretAccessKey, SessionToken, Expiration)
86+
local credentials = data.AssumeRoleWithWebIdentityResponse.AssumeRoleWithWebIdentityResult.Credentials
87+
self:set(
88+
credentials.AccessKeyId,
89+
credentials.SecretAccessKey,
90+
credentials.SessionToken,
91+
credentials.Expiration
92+
)
9593

9694
return true
9795
end

0 commit comments

Comments
 (0)