Skip to content

Instantly share code, notes, and snippets.

@dankozlowski
Last active December 12, 2019 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dankozlowski/29e35d81327dd175835a0d40272e4130 to your computer and use it in GitHub Desktop.
Save dankozlowski/29e35d81327dd175835a0d40272e4130 to your computer and use it in GitHub Desktop.
-- Script that writes secrets to k/v engine in Vault
-- Indicate number of secrets to write to secret/read-test path with "-- <N>"
local counter = 1
local threads = {}
function setup(thread)
thread:set("id", counter)
table.insert(threads, thread)
counter = counter + 1
end
function init(args)
requests = 0
writes = 0
responses = 0
body = ''
method = "POST"
path = "/v1/transit/encrypt/outreach_abitest"
local msg = "thread %d created"
if args[1] == nil then
num_secrets = 1000
else
num_secrets = tonumber(args[1])
end
print("Number of secrets is: " .. num_secrets)
print(msg:format(id))
end
function request()
-- First request is not actually invoked
-- So, don't process it in order to get secret-1 as first secret
if requests > 0 then
writes = writes + 1
-- path = "/v1/secret/read-test/outreach_secret-" .. writes
-- minimal secret giving thread id and # of write
body = '{"plaintext" : "1xxxxxxxxx2xxxxxxxxx3xxxxxxxxx4xxxxxxxxx5xxxxxxxxx6xxxxxxxxx7xxxxxxxxx8xxxxxxxxx9xxxxxxxxx0xxxxxxxxx"}'
-- print("Request body:")
-- print(body)
--print(request())
end
requests = requests + 1
return wrk.format(method, path, nil, body)
end
function response(status, headers, body)
responses = responses + 1
if responses == num_secrets then
-- os.exit()
-- print("Test complete, please CTRL-C to print results")
-- wrk.thread:stop()
end
end
function done(summary, latency, requests)
for index, thread in ipairs(threads) do
local id = thread:get("id")
local requests = thread:get("requests")
local writes = thread:get("writes")
local responses = thread:get("responses")
local msg = "thread %d made %d requests including %d writes and got %d responses"
print(msg:format(id, requests, writes, responses))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment