mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 07:33:05 +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
|
# Constructor
|
||||||
# @args: config_file -> the specify config file
|
# @args: config_file -> the specify config file
|
||||||
def initialize(config_file=nil)
|
def initialize(config_file=nil)
|
||||||
@error_msg = nil
|
|
||||||
@config_file = config_file
|
@config_file = config_file
|
||||||
|
|
||||||
if /darwin/ =~ RUBY_PLATFORM
|
if /darwin/ =~ RUBY_PLATFORM
|
||||||
|
@ -43,8 +42,7 @@ class Config
|
||||||
def setup(key, lang, wallet_dir)
|
def setup(key, lang, wallet_dir)
|
||||||
|
|
||||||
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
||||||
@error_msg = I18n.t('error.config.key_bad_format')
|
raise I18n.t('error.config.key_bad_format')
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if wallet_dir.empty?
|
if wallet_dir.empty?
|
||||||
|
@ -62,10 +60,8 @@ class Config
|
||||||
file << config.to_yaml
|
file << config.to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
|
raise "#{I18n.t('error.config.write')}\n#{e}"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup a new gpg key
|
# Setup a new gpg key
|
||||||
|
@ -76,11 +72,9 @@ class Config
|
||||||
# @rtrn: true if the GPG key is create, else false
|
# @rtrn: true if the GPG key is create, else false
|
||||||
def setup_gpg_key(password, name, length = 4096, expire = 0)
|
def setup_gpg_key(password, name, length = 4096, expire = 0)
|
||||||
if name.nil? or name.empty?
|
if name.nil? or name.empty?
|
||||||
@error_msg = "#{I18n.t('error.config.genkey_gpg.name')}"
|
raise "#{I18n.t('error.config.genkey_gpg.name')}"
|
||||||
return false
|
|
||||||
elsif password.nil? or password.empty?
|
elsif password.nil? or password.empty?
|
||||||
@error_msg = "#{I18n.t('error.config.genkey_gpg.password')}"
|
raise "#{I18n.t('error.config.genkey_gpg.password')}"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
param = ''
|
param = ''
|
||||||
|
@ -98,11 +92,8 @@ class Config
|
||||||
|
|
||||||
ctx = GPGME::Ctx.new
|
ctx = GPGME::Ctx.new
|
||||||
ctx.genkey(param, nil, nil)
|
ctx.genkey(param, nil, nil)
|
||||||
|
|
||||||
return true
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@error_msg = "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check the config file
|
# Check the config file
|
||||||
|
@ -114,15 +105,11 @@ class Config
|
||||||
@wallet_dir = config['config']['wallet_dir']
|
@wallet_dir = config['config']['wallet_dir']
|
||||||
|
|
||||||
if @key.empty? or @wallet_dir.empty?
|
if @key.empty? or @wallet_dir.empty?
|
||||||
@error_msg = I18n.t('error.config.check')
|
raise I18n.t('error.config.check')
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
I18n.locale = @lang.to_sym
|
I18n.locale = @lang.to_sym
|
||||||
|
|
||||||
return true
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@error_msg = "#{I18n.t('error.config.check')}\n#{e}"
|
raise "#{I18n.t('error.config.check')}\n#{e}"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if private key exist
|
# Check if private key exist
|
||||||
|
@ -148,11 +135,8 @@ class Config
|
||||||
File.open(@config_file, 'w') do |file|
|
File.open(@config_file, 'w') do |file|
|
||||||
file << config.to_yaml
|
file << config.to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
|
raise "#{I18n.t('error.config.write')}\n#{e}"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,18 +34,14 @@ class Cli
|
||||||
end
|
end
|
||||||
I18n.locale = language.to_sym
|
I18n.locale = language.to_sym
|
||||||
|
|
||||||
if @config.setup(key, lang, wallet_dir)
|
@config.setup(key, lang, wallet_dir)
|
||||||
puts "#{I18n.t('form.setup_config.valid')}".green
|
@config.checkconfig
|
||||||
else
|
|
||||||
puts "#{I18n.t('display.error')} #8: #{@config.error_msg}".red
|
|
||||||
exit 2
|
|
||||||
end
|
|
||||||
|
|
||||||
if not @config.checkconfig
|
puts "#{I18n.t('form.setup_config.valid')}".green
|
||||||
puts "#{I18n.t('display.error')} #9: #{@config.error_msg}".red
|
rescue Exception => e
|
||||||
|
puts "#{I18n.t('display.error')} #8: #{e}".red
|
||||||
exit 2
|
exit 2
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Setup a new GPG key
|
# Setup a new GPG key
|
||||||
def setup_gpg_key
|
def setup_gpg_key
|
||||||
|
@ -54,8 +50,7 @@ class Cli
|
||||||
ask = ask(I18n.t('form.setup_gpg_key.ask')).to_s
|
ask = ask(I18n.t('form.setup_gpg_key.ask')).to_s
|
||||||
|
|
||||||
if not ['Y', 'y', 'O', 'o'].include?(ask)
|
if not ['Y', 'y', 'O', 'o'].include?(ask)
|
||||||
puts I18n.t('form.setup_gpg_key.no_create')
|
raise I18n.t('form.setup_gpg_key.no_create')
|
||||||
exit 2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
name = ask(I18n.t('form.setup_gpg_key.name')).to_s
|
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}
|
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false}
|
||||||
|
|
||||||
if password != confirm
|
if password != confirm
|
||||||
puts I18n.t('form.setup_gpg_key.error_password')
|
raise I18n.t('form.setup_gpg_key.error_password')
|
||||||
exit 2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
length = ask(I18n.t('form.setup_gpg_key.length')).to_s
|
length = ask(I18n.t('form.setup_gpg_key.length')).to_s
|
||||||
|
@ -76,13 +70,13 @@ class Cli
|
||||||
|
|
||||||
puts I18n.t('form.setup_gpg_key.wait')
|
puts I18n.t('form.setup_gpg_key.wait')
|
||||||
|
|
||||||
if @config.setup_gpg_key(password, name, length, expire)
|
@config.setup_gpg_key(password, name, length, expire)
|
||||||
|
|
||||||
puts "#{I18n.t('form.setup_gpg_key.valid')}".green
|
puts "#{I18n.t('form.setup_gpg_key.valid')}".green
|
||||||
else
|
rescue Exception => e
|
||||||
puts "#{I18n.t('display.error')} #10: #{@config.error_msg}".red
|
puts "#{I18n.t('display.error')} #8: #{e}".red
|
||||||
exit 2
|
exit 2
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Setup wallet config for sync
|
# Setup wallet config for sync
|
||||||
def setup_wallet_config
|
def setup_wallet_config
|
||||||
|
|
Loading…
Reference in a new issue