forked from futurice/terraform-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
google_cloud/openresty-beyondcorp/files/swiss/secretmanager.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local _M = { | ||
_VERSION = '0.01', | ||
} | ||
local cjson = require "cjson" | ||
local http = require "resty.http" | ||
local b64 = require("ngx.base64") | ||
|
||
function _M.fetch(location, access_token) | ||
local httpc = http.new() | ||
local secretlocation = location | ||
ngx.log(ngx.WARN, "fetching secret from: " .. secretlocation) | ||
local res, err = httpc:request_uri( | ||
secretlocation, | ||
{ | ||
headers = { | ||
["Content-Type"] = "application/json", | ||
["Authorization"] = "Bearer " .. access_token | ||
}, | ||
ssl_verify = false | ||
} | ||
) | ||
if err ~= nil then | ||
return nil, err | ||
elseif res.status == 200 then | ||
local content = cjson.decode(res.body) | ||
return b64.decode_base64url(content.payload.data), nil | ||
else | ||
return nil, res.body | ||
end | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local hmac = require "resty.hmac" | ||
local hmacs = {} | ||
local version = "v0" | ||
local err | ||
|
||
local _M = { | ||
_VERSION = '0.01', | ||
} | ||
|
||
function _M.isAuthentic(request, signingsecret) | ||
if hmacs[signingsecret] == nil then | ||
hmacs[signingsecret] = hmac:new(signingsecret, hmac.ALGOS.SHA256) | ||
end | ||
|
||
local hmac_sha256 = hmacs[signingsecret] | ||
local timestamp = request.get_headers()["X-Slack-Request-Timestamp"] | ||
local signature = request.get_headers()["X-Slack-Signature"] | ||
local body = request.get_body_data() | ||
if body == nil or timestamp == nil or signature == nil then | ||
return false | ||
end | ||
|
||
local basestring = version .. ":" .. timestamp .. ":" .. body | ||
local mac = version .. "=" .. hmac_sha256:final(basestring, true) | ||
hmac_sha256:reset() | ||
return mac == signature | ||
end | ||
|
||
return _M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters