mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 05:47:53 +00:00
fix load config
This commit is contained in:
parent
e4c03619b3
commit
6d2a45217c
13 changed files with 34 additions and 26 deletions
|
@ -50,6 +50,7 @@ end.parse!
|
|||
config = MPW::Config.new(options[:config])
|
||||
cli = MPW::Cli.new(config, options[:sync])
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.add(options[:password])
|
||||
|
|
|
@ -65,6 +65,7 @@ config = MPW::Config.new(options[:config])
|
|||
cli = MPW::Cli.new(config, nil)
|
||||
|
||||
if not options[:init].nil?
|
||||
cli.load_config
|
||||
cli.get_wallet
|
||||
cli.setup(values)
|
||||
cli.setup_gpg_key(options[:init])
|
||||
|
|
|
@ -63,6 +63,7 @@ opts = { search: options[:pattern],
|
|||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.copy(options[:clipboard], opts)
|
||||
|
|
|
@ -58,6 +58,7 @@ opts = { search: options[:pattern],
|
|||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.delete(opts)
|
||||
|
|
|
@ -62,6 +62,7 @@ opts = { search: options[:pattern],
|
|||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.export(options[:file], opts)
|
||||
|
|
|
@ -54,6 +54,7 @@ opts = { search: options[:pattern],
|
|||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.import(options[:file])
|
||||
|
|
|
@ -58,6 +58,7 @@ opts = { search: options[:pattern],
|
|||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.list(opts)
|
||||
|
|
|
@ -58,6 +58,7 @@ opts = { search: options[:pattern],
|
|||
group: options[:group],
|
||||
}
|
||||
|
||||
cli.load_config
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
cli.update(opts)
|
||||
|
|
|
@ -75,6 +75,8 @@ end.parse!
|
|||
config = MPW::Config.new(options[:config])
|
||||
cli = MPW::Cli.new(config, options[:sync])
|
||||
|
||||
cli.load_config
|
||||
|
||||
if not options[:list].nil?
|
||||
cli.list_wallet
|
||||
else
|
||||
|
|
|
@ -3,7 +3,7 @@ en:
|
|||
error:
|
||||
config:
|
||||
write: "Can't write the config file!"
|
||||
check: "Checkconfig failed!"
|
||||
load: "Checkconfig failed!"
|
||||
key_bad_format: "The key string isn't in good format!"
|
||||
no_key_public: "You haven't the public key of %{key}!"
|
||||
genkey_gpg:
|
||||
|
|
|
@ -3,7 +3,7 @@ fr:
|
|||
error:
|
||||
config:
|
||||
write: "Impossible d'écrire le fichier de configuration!"
|
||||
check: "Le fichier de configuration est invalide!"
|
||||
load: "Le fichier de configuration est invalide!"
|
||||
key_bad_format: "La clé GPG est invalide!"
|
||||
no_key_public: "Vous ne possédez pas la clé publique de %{key}!"
|
||||
genkey_gpg:
|
||||
|
|
|
@ -40,8 +40,6 @@ class Cli
|
|||
# Change a parameter int the config after init
|
||||
# @args: options -> param to change
|
||||
def set_config(options)
|
||||
raise I18n.t('error.config.check') if not @config.is_valid?
|
||||
|
||||
gpg_key = options[:gpg_key] || @config.key
|
||||
lang = options[:lang] || @config.lang
|
||||
wallet_dir = options[:wallet_dir] || @config.wallet_dir
|
||||
|
@ -56,15 +54,13 @@ class Cli
|
|||
# Create a new config file
|
||||
# @args: options -> set param
|
||||
def setup(options)
|
||||
@config.is_valid?
|
||||
|
||||
lang = options[:lang] || Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
||||
|
||||
I18n.locale = lang.to_sym
|
||||
|
||||
@config.setup(options[:gpg_key], lang, options[:wallet_dir], options[:gpg_exe])
|
||||
|
||||
raise I18n.t('error.config.check') if not @config.is_valid?
|
||||
load_config
|
||||
|
||||
puts "#{I18n.t('form.setup_config.valid')}".green
|
||||
rescue Exception => e
|
||||
|
@ -116,6 +112,15 @@ class Cli
|
|||
exit 2
|
||||
end
|
||||
|
||||
# Load config
|
||||
def load_config
|
||||
@config.load_config
|
||||
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('display.error')} #10: #{e}".red
|
||||
exit 2
|
||||
end
|
||||
|
||||
# Request the GPG password and decrypt the file
|
||||
def decrypt
|
||||
if not defined?(@mpw)
|
||||
|
@ -305,8 +310,6 @@ class Cli
|
|||
|
||||
# List all wallets
|
||||
def list_wallet
|
||||
@config.is_valid?
|
||||
|
||||
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
|
||||
|
||||
wallets.each do |wallet|
|
||||
|
@ -317,8 +320,6 @@ class Cli
|
|||
# Display the wallet
|
||||
# @args: wallet -> the wallet name
|
||||
def get_wallet(wallet=nil)
|
||||
@config.is_valid?
|
||||
|
||||
if wallet.to_s.empty?
|
||||
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
|
||||
|
||||
|
|
|
@ -65,11 +65,10 @@ class Config
|
|||
wallet_dir = "#{@config_dir}/wallets"
|
||||
end
|
||||
|
||||
config = {'config' => {'key' => key,
|
||||
'lang' => lang,
|
||||
'wallet_dir' => wallet_dir,
|
||||
'gpg_exe' => gpg_exe,
|
||||
}
|
||||
config = { 'key' => key,
|
||||
'lang' => lang,
|
||||
'wallet_dir' => wallet_dir,
|
||||
'gpg_exe' => gpg_exe,
|
||||
}
|
||||
|
||||
FileUtils.mkdir_p(wallet_dir, mode: 0700)
|
||||
|
@ -113,22 +112,20 @@ class Config
|
|||
raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
||||
end
|
||||
|
||||
# Check the config file
|
||||
# @rtrn: true if the config file is correct
|
||||
def is_valid?
|
||||
# Load the config file
|
||||
def load_config
|
||||
config = YAML::load_file(@config_file)
|
||||
@key = config['config']['key']
|
||||
@lang = config['config']['lang']
|
||||
@wallet_dir = config['config']['wallet_dir']
|
||||
@gpg_exe = config['config']['gpg_exe']
|
||||
@key = config['key']
|
||||
@lang = config['lang']
|
||||
@wallet_dir = config['wallet_dir']
|
||||
@gpg_exe = config['gpg_exe']
|
||||
|
||||
raise if @key.empty? or @wallet_dir.empty?
|
||||
|
||||
I18n.locale = @lang.to_sym
|
||||
|
||||
return true
|
||||
rescue
|
||||
return false
|
||||
rescue Exception => e
|
||||
raise "#{I18n.t('error.config.load')}\n#{e}"
|
||||
end
|
||||
|
||||
# Check if private key exist
|
||||
|
|
Loading…
Reference in a new issue