1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-21 10:20:05 +00:00

fix bug encrypt + export yaml

This commit is contained in:
nishiki 2015-01-29 21:48:56 +01:00
parent 16fd5d6c24
commit 7f7d8c862d
2 changed files with 30 additions and 25 deletions

View file

@ -32,6 +32,7 @@ module MPW
if File.exist?(@file_gpg) if File.exist?(@file_gpg)
crypto = GPGME::Crypto.new(armor: true) crypto = GPGME::Crypto.new(armor: true)
data_decrypt = crypto.decrypt(IO.read(@file_gpg), password: password).read.force_encoding('utf-8') data_decrypt = crypto.decrypt(IO.read(@file_gpg), password: password).read.force_encoding('utf-8')
if not data_decrypt.to_s.empty? if not data_decrypt.to_s.empty?
YAML.load(data_decrypt).each_value do |d| YAML.load(data_decrypt).each_value do |d|
@data.push(Item.new(id: d['id'], @data.push(Item.new(id: d['id'],
@ -64,18 +65,21 @@ module MPW
data_to_encrypt = {} data_to_encrypt = {}
@data.each do |item| @data.each do |item|
data_to_encrypt.merge!({'id' => item.id, next if item.empty?
'name' => item.name,
'group' => item.group, data_to_encrypt.merge!(item.id => {'id' => item.id,
'host' => item.host, 'name' => item.name,
'protocol' => item.protocol, 'group' => item.group,
'user' => item.user, 'host' => item.host,
'password' => item.password, 'protocol' => item.protocol,
'port' => item.port, 'user' => item.user,
'comment' => item.comment, 'password' => item.password,
'last_edit' => item.last_edit, 'port' => item.port,
'created' => item.created, 'comment' => item.comment,
}) 'last_edit' => item.last_edit,
'created' => item.created,
}
)
end end
recipients = [] recipients = []
@ -151,18 +155,19 @@ module MPW
when :yaml when :yaml
data = {} data = {}
@data.each do |item| @data.each do |item|
data.merge!({'id' => item.id, data.merge!(item.id => {'id' => item.id,
'name' => item.name, 'name' => item.name,
'group' => item.group, 'group' => item.group,
'host' => item.host, 'host' => item.host,
'protocol' => item.protocol, 'protocol' => item.protocol,
'user' => item.user, 'user' => item.user,
'password' => item.password, 'password' => item.password,
'port' => item.port, 'port' => item.port,
'comment' => item.comment, 'comment' => item.comment,
'last_edit' => item.last_edit, 'last_edit' => item.last_edit,
'created' => item.created, 'created' => item.created,
}) }
)
end end
File.open(file, 'w') {|f| f << data.to_yaml} File.open(file, 'w') {|f| f << data.to_yaml}

2
mpw
View file

@ -82,7 +82,7 @@ OptionParser.new do |opts|
opts.on('-e', '--export FILE', I18n.t('option.export')) do |file| opts.on('-e', '--export FILE', I18n.t('option.export')) do |file|
options[:export] = file options[:export] = file
options[:type] = :csv options[:type] = :yaml
end end
opts.on('-t', '--type TYPE', I18n.t('option.type')) do |type| opts.on('-t', '--type TYPE', I18n.t('option.type')) do |type|