Commit b6c537b3 authored by Roque's avatar Roque

bug fix: credentials were requested more than one time

parent c31993df
......@@ -132,35 +132,41 @@ class DatasetUtils
end
def getCredentials(tool_dir)
credential_path = appendSlashTo(tool_dir) + CREDENTIALS_FILE
if File.exist?(credential_path)
credentials = File.open(credential_path).read.chomp.split(RECORD_SEPARATOR)
user = credentials[0]
password = credentials[1]
@logger.info("Using stored credentials for user '#{user}'", print=TRUE)
else
puts
puts "Please, enter your ebulk user and password:"
puts
puts "** If you don't have a user, please feel free to register in the web site **"
puts
@logger.info("Remember that you can store your credentials for automatic authentication by running 'ebulk store-credentials'", print=TRUE)
puts
print "User:"
user = gets.chomp
if not /^[A-Za-z][-A-Za-z0-9_]*$/.match(user)
puts
@logger.error("Invalid user name. Did enter an invalid character?", print=TRUE)
@logger.info("Please enter a valid user name.", print=TRUE)
@logger.abortExecution(error=FALSE)
# using logger because it's a singleton
# TODO: refactor datase_utils to be a singleton and keep credentials in it
user, password = @logger.getCredentials()
if user.nil?
credential_path = appendSlashTo(tool_dir) + CREDENTIALS_FILE
if File.exist?(credential_path)
credentials = File.open(credential_path).read.chomp.split(RECORD_SEPARATOR)
user = credentials[0]
password = credentials[1]
@logger.info("Using stored credentials for user '#{user}'", print=TRUE)
else
puts
puts "Please, enter your ebulk user and password:"
puts
puts "** If you don't have a user, please feel free to register in the web site **"
puts
@logger.info("Remember that you can store your credentials for automatic authentication by running 'ebulk store-credentials'", print=TRUE)
puts
print "User:"
user = gets.chomp
if not /^[A-Za-z][-A-Za-z0-9_]*$/.match(user)
puts
@logger.error("Invalid user name. Did enter an invalid character?", print=TRUE)
@logger.info("Please enter a valid user name.", print=TRUE)
@logger.abortExecution(error=FALSE)
end
print "Password:"
password = STDIN.noecho(&:gets).chomp
puts
puts
@logger.info("Remember that you can store your credentials for automatic authentication by running 'ebulk store-credentials'", print=TRUE)
puts
sleep 1
end
print "Password:"
password = STDIN.noecho(&:gets).chomp
puts
puts
@logger.info("Remember that you can store your credentials for automatic authentication by running 'ebulk store-credentials'", print=TRUE)
puts
sleep 1
@logger.setCredentials(user, password)
end
return user, password
end
......@@ -814,7 +820,7 @@ class DatasetUtils
renamed_dict = isRenamed(file_path, new_changed_files, file_dict)
if renamed_dict
changed_data_stream = {"reference" => reference, "id" => new_changed_files[renamed_dict["key"]]["id"],
"new_reference" => new_changed_files[renamed_dict["key"]]["reference"], "status" => STATUS_RENAMED,
"new_reference" => new_changed_files[renamed_dict["key"]]["reference"], "status" => STATUS_RENAMED,
"size" => renamed_dict["size"], "hash" => renamed_dict["hash"] }
new_changed_files.delete(renamed_dict["key"])
end
......
......@@ -11,6 +11,8 @@ class LogManager
def initialize()
now = Time.now.strftime("%d-%m-%Y")
@filename = "#{now.to_s}.log"
@user
@password
end
def setFilename(tool_dir, prefix)
......@@ -22,6 +24,15 @@ class LogManager
File.open(@path, 'a') { |file| file.puts "------------------------------------------------" + "\r\n" }
end
def setCredentials(user, password)
@user = user
@password = password
end
def getCredentials()
return @user, @password
end
def getLogPath()
return @path
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment