1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

bug #847: Add timestamp generation to Cloud Servers

This commit is contained in:
Daniel Molina 2011-10-25 11:53:09 +02:00
parent 2650f81e50
commit 5ff614d58d

View File

@ -23,11 +23,21 @@ class CloudAuth
"x509" => 'X509CloudAuth'
}
# Default interval for timestamps. Tokens will be generated using the same
# timestamp for this interval of time.
EXPIRE_DELTA = 36000
# Tokens will be generated if time > EXPIRE_TIME - EXPIRE_MARGIN
EXPIRE_MARGIN = 300
attr_reader :client, :token
def initialize(conf)
@conf = conf
@token_expiration_delta = @conf[:token_expiration_delta] || EXPIRE_DELTA
@token_expiration_time = Time.now.to_i + @token_expiration_delta
if AUTH_MODULES.include?(@conf[:auth])
require 'CloudAuth/' + AUTH_MODULES[@conf[:auth]]
extend Kernel.const_get(AUTH_MODULES[@conf[:auth]])
@ -40,8 +50,19 @@ class CloudAuth
protected
def expiration_time
time_now = Time.now.to_i
expire = time_now - @token_expiration_time
if expire < EXPIRE_MARGIN
@token_expiration_time = time_now + @token_expiration_delta
end
@token_expiration_time
end
def get_password(username)
token = @server_auth.login_token
token = @server_auth.login_token(nil, expiration_time)
@oneadmin_client ||= OpenNebula::Client.new(token, @conf[:one_xmlrpc])
if @user_pool.nil?