mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +00:00
remove error_msg in config class
This commit is contained in:
parent
68a0fddde8
commit
a4fe063703
2 changed files with 23 additions and 45 deletions
|
@ -19,7 +19,6 @@ class Config
|
|||
# Constructor
|
||||
# @args: config_file -> the specify config file
|
||||
def initialize(config_file=nil)
|
||||
@error_msg = nil
|
||||
@config_file = config_file
|
||||
|
||||
if /darwin/ =~ RUBY_PLATFORM
|
||||
|
@ -43,8 +42,7 @@ class Config
|
|||
def setup(key, lang, wallet_dir)
|
||||
|
||||
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
||||
@error_msg = I18n.t('error.config.key_bad_format')
|
||||
return false
|
||||
raise I18n.t('error.config.key_bad_format')
|
||||
end
|
||||
|
||||
if wallet_dir.empty?
|
||||
|
@ -62,10 +60,8 @@ class Config
|
|||
file << config.to_yaml
|
||||
end
|
||||
|
||||
return true
|
||||
rescue Exception => e
|
||||
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
|
||||
return false
|
||||
raise "#{I18n.t('error.config.write')}\n#{e}"
|
||||
end
|
||||
|
||||
# Setup a new gpg key
|
||||
|
@ -76,11 +72,9 @@ class Config
|
|||
# @rtrn: true if the GPG key is create, else false
|
||||
def setup_gpg_key(password, name, length = 4096, expire = 0)
|
||||
if name.nil? or name.empty?
|
||||
@error_msg = "#{I18n.t('error.config.genkey_gpg.name')}"
|
||||
return false
|
||||
raise "#{I18n.t('error.config.genkey_gpg.name')}"
|
||||
elsif password.nil? or password.empty?
|
||||
@error_msg = "#{I18n.t('error.config.genkey_gpg.password')}"
|
||||
return false
|
||||
raise "#{I18n.t('error.config.genkey_gpg.password')}"
|
||||
end
|
||||
|
||||
param = ''
|
||||
|
@ -98,31 +92,24 @@ class Config
|
|||
|
||||
ctx = GPGME::Ctx.new
|
||||
ctx.genkey(param, nil, nil)
|
||||
|
||||
return true
|
||||
rescue Exception => e
|
||||
@error_msg = "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
||||
return false
|
||||
raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
||||
end
|
||||
|
||||
# Check the config file
|
||||
# @rtrn: true if the config file is correct
|
||||
def checkconfig
|
||||
config = YAML::load_file(@config_file)
|
||||
config = YAML::load_file(@config_file)
|
||||
@key = config['config']['key']
|
||||
@lang = config['config']['lang']
|
||||
@wallet_dir = config['config']['wallet_dir']
|
||||
|
||||
if @key.empty? or @wallet_dir.empty?
|
||||
@error_msg = I18n.t('error.config.check')
|
||||
return false
|
||||
raise I18n.t('error.config.check')
|
||||
end
|
||||
I18n.locale = @lang.to_sym
|
||||
|
||||
return true
|
||||
rescue Exception => e
|
||||
@error_msg = "#{I18n.t('error.config.check')}\n#{e}"
|
||||
return false
|
||||
raise "#{I18n.t('error.config.check')}\n#{e}"
|
||||
end
|
||||
|
||||
# Check if private key exist
|
||||
|
@ -148,11 +135,8 @@ class Config
|
|||
File.open(@config_file, 'w') do |file|
|
||||
file << config.to_yaml
|
||||
end
|
||||
|
||||
return true
|
||||
rescue Exception => e
|
||||
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
|
||||
return false
|
||||
raise "#{I18n.t('error.config.write')}\n#{e}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -34,17 +34,13 @@ class Cli
|
|||
end
|
||||
I18n.locale = language.to_sym
|
||||
|
||||
if @config.setup(key, lang, wallet_dir)
|
||||
puts "#{I18n.t('form.setup_config.valid')}".green
|
||||
else
|
||||
puts "#{I18n.t('display.error')} #8: #{@config.error_msg}".red
|
||||
exit 2
|
||||
end
|
||||
@config.setup(key, lang, wallet_dir)
|
||||
@config.checkconfig
|
||||
|
||||
if not @config.checkconfig
|
||||
puts "#{I18n.t('display.error')} #9: #{@config.error_msg}".red
|
||||
exit 2
|
||||
end
|
||||
puts "#{I18n.t('form.setup_config.valid')}".green
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('display.error')} #8: #{e}".red
|
||||
exit 2
|
||||
end
|
||||
|
||||
# Setup a new GPG key
|
||||
|
@ -54,8 +50,7 @@ class Cli
|
|||
ask = ask(I18n.t('form.setup_gpg_key.ask')).to_s
|
||||
|
||||
if not ['Y', 'y', 'O', 'o'].include?(ask)
|
||||
puts I18n.t('form.setup_gpg_key.no_create')
|
||||
exit 2
|
||||
raise I18n.t('form.setup_gpg_key.no_create')
|
||||
end
|
||||
|
||||
name = ask(I18n.t('form.setup_gpg_key.name')).to_s
|
||||
|
@ -63,8 +58,7 @@ class Cli
|
|||
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false}
|
||||
|
||||
if password != confirm
|
||||
puts I18n.t('form.setup_gpg_key.error_password')
|
||||
exit 2
|
||||
raise I18n.t('form.setup_gpg_key.error_password')
|
||||
end
|
||||
|
||||
length = ask(I18n.t('form.setup_gpg_key.length')).to_s
|
||||
|
@ -76,12 +70,12 @@ class Cli
|
|||
|
||||
puts I18n.t('form.setup_gpg_key.wait')
|
||||
|
||||
if @config.setup_gpg_key(password, name, length, expire)
|
||||
puts "#{I18n.t('form.setup_gpg_key.valid')}".green
|
||||
else
|
||||
puts "#{I18n.t('display.error')} #10: #{@config.error_msg}".red
|
||||
exit 2
|
||||
end
|
||||
@config.setup_gpg_key(password, name, length, expire)
|
||||
|
||||
puts "#{I18n.t('form.setup_gpg_key.valid')}".green
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('display.error')} #8: #{e}".red
|
||||
exit 2
|
||||
end
|
||||
|
||||
# Setup wallet config for sync
|
||||
|
|
Loading…
Reference in a new issue