Store token metadata in vmpooler__vm__ Redis hash

This commit is contained in:
Scott Schneider 2015-04-30 19:16:27 -07:00
parent c4ad99c493
commit 7bddfdef1b
2 changed files with 10 additions and 2 deletions

View file

@ -308,9 +308,16 @@ module Vmpooler
backend.hset('vmpooler__active__' + key, vm, Time.now) backend.hset('vmpooler__active__' + key, vm, Time.now)
backend.hset('vmpooler__vm__' + vm, 'checkout', Time.now) backend.hset('vmpooler__vm__' + vm, 'checkout', Time.now)
if Vmpooler::API.settings.config[:auth] and has_valid_token? and config['vm_lifetime_auth'].to_i > 0 if Vmpooler::API.settings.config[:auth] and has_valid_token?
backend.hset('vmpooler__vm__' + vm, 'token:token', request.env['HTTP_X_AUTH_TOKEN'])
backend.hset('vmpooler__vm__' + vm, 'token:user',
backend.hget('vmpooler__token__' + request.env['HTTP_X_AUTH_TOKEN'], 'user')
)
if config['vm_lifetime_auth'].to_i > 0
backend.hset('vmpooler__vm__' + vm, 'lifetime', config['vm_lifetime_auth'].to_i) backend.hset('vmpooler__vm__' + vm, 'lifetime', config['vm_lifetime_auth'].to_i)
end end
end
result[key] ||= {} result[key] ||= {}

View file

@ -177,6 +177,7 @@ describe Vmpooler::API::V1 do
app.settings.set :redis, redis app.settings.set :redis, redis
allow(redis).to receive(:exists).and_return '1' allow(redis).to receive(:exists).and_return '1'
allow(redis).to receive(:hget).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345', 'user').and_return 'jdoe'
allow(redis).to receive(:hset).and_return '1' allow(redis).to receive(:hset).and_return '1'
allow(redis).to receive(:sadd).and_return '1' allow(redis).to receive(:sadd).and_return '1'
allow(redis).to receive(:scard).and_return '5' allow(redis).to receive(:scard).and_return '5'