Repository navigation
Expand file tree
/
Copy pathexec.lua
More file actions
56 lines (43 loc) · 1.39 KB
/
Copy pathexec.lua
File metadata and controls
56 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- functions
-- Read body being passed
-- Required for ngx.req.get_body_data()
-- ngx.req.read_body();
-- Parser for sending JSON back to the client
local cjson = require("cjson")
-- local body = ngx.req.get_body_data() ==
function os.capture(cmd, raw) -- this function cannot be local
local handle = assert(io.popen(cmd, 'r'))
local output = assert(handle:read('*a'))
handle:close()
if raw then
return output
end
output = string.gsub(
string.gsub(
string.gsub(output, '^%s+', ''),
'%s+$',
''
),
'[\n\r]+',
''
)
return output
end
local function run_command(cmd)
result = os.execute(cmd)
return result
end
local function run_command_output(cmd)
result = os.capture(cmd)
--result = str.replace(/\n/g, '');
return result
end
local accessKeyId = tostring(os.getenv('AWS_ACCESS_KEY_ID'))
local accessKeySecret = tostring(os.getenv('AWS_SECRET_ACCESS_KEY'))
--ngx.say('accessKeyId: '.. accessKeyId ..', accessKeySecret: '..accessKeySecret)
--aws s3 ls s3://bswtest --output json
ngx.print(cjson.encode(
{
s3objects=run_command_output('aws s3api list-objects --bucket bswtest --query "Contents[].{Key: Key, Size: Size}"'),
}
))