Skip to content
This repository was archived by the owner on Nov 10, 2018. It is now read-only.

Commit 3acd360

Browse files
committed
Merge branch 'release/v1.1.2'
change hmac
2 parents cf38d17 + c8a95f6 commit 3acd360

File tree

4 files changed

+80
-12
lines changed

4 files changed

+80
-12
lines changed
File renamed without changes.

ngx-lua-images/lua/app.lua

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
local _M = {}
2+
3+
function _M.s3run()
4+
5+
-- Hashing functions
6+
local access_key = 'HXKJ2FLL7BAWENBMP0HF'
7+
local secret_key = 'DEeFyCPlBKK2vS7DPJDeeozNiF5WAjL7pVMNpDlO'
8+
local encode_base64 = ngx.encode_base64
9+
local hmac_sha1 = ngx.hmac_sha1
10+
local md5 = ngx.md5
11+
12+
local method = 'POST'
13+
local destination = '/'
14+
local content_type = ''
15+
local timestamp = os.date("!%a, %d %b %Y %H:%M:%S +0000")
16+
17+
local StringToSign = method..string.char(10)..string.char(10)..content_type..string.char(10)..timestamp..string.char(10)..destination
18+
19+
local signature = encode_base64(hmac_sha1(secret_key, StringToSign))
20+
signature = 'AWS' .. ' ' .. access_key .. ':' .. signature
21+
-- ngx.say(signature)
22+
local hmac = require "resty.hmac"
23+
local hm, err = hmac:new(secret_key)
24+
headerstr, err = hm:generate_headers("AWS", access_key, "sha1", StringToSign)
25+
signed = headerstr["auth"]
26+
-- ngx.say(signed)
27+
28+
bucket = ngx.var.arg_b
29+
file = ngx.var.arg_f
30+
content = ngx.var.arg_c
31+
del = ngx.var.arg_d
32+
create = ngx.var.arg_cr
33+
34+
local cephs3 = require("cephs3")
35+
local app = cephs3:new(config.access_key, config.secret_key)
36+
37+
if (bucket and create ) then
38+
local data = app:create_bucket(bucket)
39+
ngx.say(data)
40+
elseif ((not file) and (not del) and bucket) then
41+
app:get_all_objs(bucket)
42+
43+
elseif (file and bucket and content) then
44+
local url = app:create_obj(bucket, file, content)
45+
ngx.say(url)
46+
elseif (bucket and file and del) then
47+
local data = app:del_obj(bucket, file)
48+
ngx.say(data)
49+
elseif ((not file) and bucket and del) then
50+
local data = app:del_bucket(bucket)
51+
ngx.say(data)
52+
elseif (not del and bucket and file) then
53+
-- local exsite = app:check_for_existance(bucket, file)
54+
-- ngx.say(exsite)
55+
local data = app:get_obj(bucket, file)
56+
ngx.say(data)
57+
else
58+
app:get_all_buckets()
59+
end
60+
61+
62+
end
63+
64+
return _M

ngx-lua-images/lua/main.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ function _M.run()
175175
ngx.log(ngx.INFO, "cut_name: ", key)
176176
local data = cache.get_img(key)
177177
if data then
178-
ngx.status = 304
178+
-- ngx.status = 304
179179
ngx.header["Content-Type"] = "image/jpeg"
180180
ngx.print(data)
181-
ngx.exit(304)
181+
-- ngx.exit(304)
182182
else
183183
response_from_ceph(bucket, file, cut_name, w, h, g, x, y, r, p, q, f)
184184
end

ngx-lua-images/vendor/cephs3.lua

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
-- local http = require"resty.http"
55
local cjson = require "cjson"
6-
local hmac = require "resty.hmac"
6+
-- local hmac = require "resty.hmac"
77
local os = require "os"
88

9+
910
config = {
1011
host = 'http://192.168.2.99',
1112
access_key = 'HXKJ2FLL7BAWENBMP0HF',
@@ -60,19 +61,22 @@ function _M.generate_auth_headers(self, method, destination, content_type)
6061

6162
local timestamp = os.date("!%a, %d %b %Y %H:%M:%S +0000")
6263

63-
local hm, err = hmac:new(self.key)
6464
local StringToSign = method..string.char(10)..string.char(10)..content_type..string.char(10)..timestamp..string.char(10)..destination
65+
local signed = ngx.encode_base64(ngx.hmac_sha1(self.key, StringToSign))
66+
signed = 'AWS' .. ' ' .. self.id .. ':' .. signed
67+
68+
-- local hm, err = hmac:new(self.key)
69+
-- headerstr, err = hm:generate_headers("AWS", self.id, "sha1", StringToSign)
70+
-- signed = headerstr["auth"]
6571

66-
headerstr, err = hm:generate_headers("AWS", self.id, "sha1", StringToSign)
67-
signed = headerstr["auth"]
72+
headers = {}
73+
headers['auth'] = signed
74+
headers['Content-Type'] = content_type
75+
headers['date'] = timestamp
6876

69-
-- headers = {}
70-
-- headers['Authorization'] = signed
71-
-- headers['Content-Type'] = content_type
72-
-- headers['Date'] = timestamp
77+
-- ngx.say(cjson.encode(headers))
7378

74-
-- ngx.say(timestamp, cjson.encode(headers))
75-
return headerstr
79+
return headers
7680
end
7781

7882
function _M.get_all_buckets(self)

0 commit comments

Comments
 (0)