1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

feature #967: Fix method scope

This commit is contained in:
Ruben S. Montero 2012-03-24 00:47:36 +01:00
parent 0931fdaa25
commit f433e6f0ae
2 changed files with 40 additions and 33 deletions

View File

@ -46,10 +46,10 @@ class CloudAuth
# conf a hash with the configuration attributes as symbols
def initialize(conf, logger=nil)
@conf = conf
@conf = conf
@logger = logger
@lock = Mutex.new
@lock = Mutex.new
@token_expiration_time = Time.now.to_i + EXPIRE_DELTA
@ -63,7 +63,7 @@ class CloudAuth
if AUTH_CORE_MODULES.include?(@conf[:core_auth])
core_auth = AUTH_CORE_MODULES[@conf[:core_auth]]
else
core_auth =AUTH_CORE_MODULES["cipher"]
core_auth = AUTH_CORE_MODULES["cipher"]
end
begin
@ -84,22 +84,24 @@ class CloudAuth
# ussername:: _String_ Name of the User
# [return] _Client_
def client(username=nil)
expiration_time = @lock.synchronize {
time_now = Time.now.to_i
if time_now > @token_expiration_time - EXPIRE_MARGIN
@token_expiration_time = time_now + EXPIRE_DELTA
end
@token_expiration_time
}
token = @server_auth.login_token(expiration_time,username)
Client.new(token,@conf[:one_xmlrpc])
end
def update_userpool_cache
oneadmin_client = client
@lock.synchronize {
@user_pool = OpenNebula::UserPool.new(oneadmin_client)
rc = @user_pool.info
raise rc.message if OpenNebula.is_error?(rc)
}
end
#
#
#
def auth(env, params={})
username = do_auth(env, params)
@ -113,24 +115,10 @@ class CloudAuth
protected
def expiration_time
@lock.synchronize {
time_now = Time.now.to_i
if time_now > @token_expiration_time - EXPIRE_MARGIN
@token_expiration_time = time_now + EXPIRE_DELTA
end
@token_expiration_time
}
end
def retrieve_from_userpool(xpath)
@lock.synchronize {
@user_pool[xpath]
}
end
# Gets the password associated with a username
# username:: _String_ the username
# driver:: _String_ list of valid drivers for the user, | separated
# [return] _Hash_ with the username
def get_password(username, driver=nil)
xpath = "USER[NAME=\"#{username}\""
if driver
@ -150,4 +138,24 @@ class CloudAuth
retrieve_from_userpool(xpath)
end
private
def retrieve_from_userpool(xpath)
@lock.synchronize {
@user_pool[xpath]
}
end
def update_userpool_cache
oneadmin_client = client
@lock.synchronize {
@user_pool = OpenNebula::UserPool.new(oneadmin_client)
rc = @user_pool.info
raise rc.message if OpenNebula.is_error?(rc)
}
end
end

View File

@ -107,7 +107,6 @@ helpers do
def build_session
begin
settings.cloud_auth.update_userpool_cache
result = settings.cloud_auth.auth(request.env, params)
rescue Exception => e
error 500, ""