mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
B #5236: Make oneuser token-create work with the tests again
This commit is contained in:
parent
e22fd82f0b
commit
c060ef97b8
@ -27,11 +27,14 @@ class TokenAuth
|
||||
end
|
||||
|
||||
class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
if ENV['HOME']
|
||||
ONE_AUTH = ENV['HOME']+'/.one/one_auth'
|
||||
if ENV['ONE_AUTH']
|
||||
ONE_AUTH = ENV['ONE_AUTH']
|
||||
else
|
||||
ONE_AUTH = "/var/lib/one/.one/one_auth"
|
||||
if ENV['HOME']
|
||||
ONE_AUTH = ENV['HOME']+'/.one/one_auth'
|
||||
else
|
||||
ONE_AUTH = "/var/lib/one/.one/one_auth"
|
||||
end
|
||||
end
|
||||
|
||||
def self.rname
|
||||
@ -206,12 +209,14 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
return -1, token_oned.message if OpenNebula.is_error?(token_oned)
|
||||
|
||||
token_info = "Authentication Token is:\n#{username}:#{token_oned}"
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Check that ONE_AUTH target can be written
|
||||
#-----------------------------------------------------------------------
|
||||
if File.file?(ONE_AUTH) && !options[:force]
|
||||
return 0, "File #{ONE_AUTH} exists, use --force to overwrite."\
|
||||
"\nAuthentication Token is:\n#{username}:#{token_oned}"
|
||||
"\n#{token_info}"
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
@ -228,7 +233,7 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
File.chmod(0600, ONE_AUTH)
|
||||
|
||||
return 0, ''
|
||||
return 0, token_info
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
@ -459,6 +464,10 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
|
||||
username = args[0]
|
||||
use_client = false
|
||||
else
|
||||
if !defined?(@@client)
|
||||
return -1, "No username in the argument or valid ONE_AUTH found."
|
||||
end
|
||||
|
||||
user = self.get_client_user
|
||||
username = user['NAME']
|
||||
use_client = true
|
||||
|
@ -33,8 +33,6 @@ require 'one_helper/onequota_helper'
|
||||
|
||||
require 'uri'
|
||||
|
||||
NO_CLIENT_CMDS = [ :key, :"token-create", :login ]
|
||||
|
||||
cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`oneuser` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
@ -42,13 +40,13 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
helper = OneUserHelper.new
|
||||
|
||||
before_proc do
|
||||
if !NO_CLIENT_CMDS.include?(@comm_name)
|
||||
if ![:key].include?(@comm_name)
|
||||
begin
|
||||
helper.set_client(options)
|
||||
rescue Exception => e
|
||||
STDERR.puts e.message
|
||||
|
||||
if e.message != "ONE_AUTH file not present"
|
||||
if e.message != OpenNebula::Client::NO_ONE_AUTH_ERROR
|
||||
STDERR.puts e.backtrace
|
||||
end
|
||||
|
||||
|
@ -85,6 +85,8 @@ module OpenNebula
|
||||
# The client class, represents the connection with the core and handles the
|
||||
# xml-rpc calls.
|
||||
class Client
|
||||
NO_ONE_AUTH_ERROR = "ONE_AUTH file not present"
|
||||
|
||||
attr_accessor :one_auth
|
||||
attr_reader :one_endpoint
|
||||
|
||||
@ -129,7 +131,7 @@ module OpenNebula
|
||||
elsif File.file?("/var/lib/one/.one/one_auth")
|
||||
@one_auth = File.read("/var/lib/one/.one/one_auth")
|
||||
else
|
||||
raise "ONE_AUTH file not present"
|
||||
raise NO_ONE_AUTH_ERROR
|
||||
end
|
||||
|
||||
@one_auth = @one_auth.rstrip
|
||||
|
Loading…
Reference in New Issue
Block a user