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