Skip to content

Instantly share code, notes, and snippets.

@kyleondata
Last active August 23, 2016 23:08
Show Gist options
  • Save kyleondata/4eec8cb8bb00fb481a8f33f9b74bd946 to your computer and use it in GitHub Desktop.
Save kyleondata/4eec8cb8bb00fb481a8f33f9b74bd946 to your computer and use it in GitHub Desktop.
local count = 0
core.register_service("auth", "http", function (applet)
count = count + 1
-- Get X-Auth-Token --
local token = applet.headers['x-auth-token'][0]
local cmd = 'curl -H "X-Auth-Token:'..token..'"'
cmd = cmd..' -sL -w "%{http_code}\\n"'
cmd = cmd..' "https://staging.identity-internal.api.rackspacecloud.com/v2.0/tokens/'..token..'"'
cmd = cmd..' -o /dev/null'
print(os.time())
local output = io.popen(cmd)
local result = output:read()
output:close()
print(os.time())
print('----')
print(count)
if (result == 200) then
applet:set_status(200)
else
applet:set_status(403)
end
local response = ""
applet:add_header("content-length", string.len(response))
applet:add_header("content-type", "text/plain")
applet:start_response()
applet:send(response)
end)
global
lua-load auth.lua
listen http_in
http-request use-service lua.auth
bind *:8080
mode http
timeout connect 5000
timeout client 50000
timeout server 50000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment