mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
List tokens via GET /token
This commit is contained in:
parent
4e7dc236b9
commit
492cfb06a3
2 changed files with 38 additions and 0 deletions
|
|
@ -15,6 +15,10 @@ module Vmpooler
|
|||
call env.merge("PATH_INFO" => "/api/v#{api_version}/summary/#{params[:route]}/#{params[:key]}")
|
||||
end
|
||||
|
||||
get '/token/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token")
|
||||
end
|
||||
|
||||
post '/token/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -162,6 +162,40 @@ module Vmpooler
|
|||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get "#{api_prefix}/token/?" do
|
||||
content_type :json
|
||||
|
||||
status 404
|
||||
result = { 'ok' => false }
|
||||
|
||||
if Vmpooler::API.settings.config[:auth]
|
||||
status 401
|
||||
|
||||
need_auth!
|
||||
|
||||
backend.keys('vmpooler__token__*').each do |key|
|
||||
data = backend.hgetall(key)
|
||||
|
||||
if data['user'] == Rack::Auth::Basic::Request.new(request.env).username
|
||||
token = key.split('__').last
|
||||
|
||||
result[token] ||= {}
|
||||
result[token]['created'] = data['timestamp']
|
||||
|
||||
result['ok'] = true
|
||||
end
|
||||
end
|
||||
|
||||
if result['ok']
|
||||
status 200
|
||||
else
|
||||
status 404
|
||||
end
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get "#{api_prefix}/token/:token/?" do
|
||||
content_type :json
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue