mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
fix spacing
This commit is contained in:
parent
6a6120ca14
commit
7a831555f4
4 changed files with 47 additions and 47 deletions
|
@ -68,8 +68,8 @@ class Cli
|
|||
def setup_gpg_key(gpg_key)
|
||||
return if @config.check_gpg_key?
|
||||
|
||||
password = ask(I18n.t('form.setup_gpg_key.password')) {|q| q.echo = false}
|
||||
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) {|q| q.echo = false}
|
||||
password = ask(I18n.t('form.setup_gpg_key.password')) { |q| q.echo = false }
|
||||
confirm = ask(I18n.t('form.setup_gpg_key.confirm_password')) { |q| q.echo = false }
|
||||
|
||||
if password != confirm
|
||||
raise I18n.t('form.setup_gpg_key.error_password')
|
||||
|
@ -104,7 +104,7 @@ class Cli
|
|||
# Request the GPG password and decrypt the file
|
||||
def decrypt
|
||||
unless defined?(@mpw)
|
||||
@password = ask(I18n.t('display.gpg_password')) {|q| q.echo = false}
|
||||
@password = ask(I18n.t('display.gpg_password')) { |q| q.echo = false }
|
||||
@mpw = MPW.new(@config.gpg_key, @wallet_file, @password, @config.gpg_exe)
|
||||
end
|
||||
|
||||
|
@ -140,7 +140,7 @@ class Cli
|
|||
end
|
||||
|
||||
# Format items on a table
|
||||
def table_items(items=[])
|
||||
def table_items(items = [])
|
||||
group = '.'
|
||||
i = 1
|
||||
length_total = 10
|
||||
|
@ -160,7 +160,7 @@ class Cli
|
|||
v[:length] = item.send(k.to_s).to_s.length + 3 if item.send(k.to_s).to_s.length >= v[:length]
|
||||
end
|
||||
end
|
||||
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
|
||||
data[:id][:length] = items.length.to_s.length + 2 if items.length.to_s.length > data[:id][:length]
|
||||
|
||||
data.each_value { |v| length_total += v[:length] }
|
||||
items.sort! { |a, b| a.group.to_s.downcase <=> b.group.to_s.downcase }
|
||||
|
@ -221,7 +221,7 @@ class Cli
|
|||
|
||||
# Display the query's result
|
||||
# @args: options -> the option to search
|
||||
def list(options={})
|
||||
def list(options = {})
|
||||
result = @mpw.list(options)
|
||||
|
||||
if result.empty?
|
||||
|
@ -237,16 +237,16 @@ class Cli
|
|||
def get_item(items)
|
||||
return items[0] if items.length == 1
|
||||
|
||||
items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase }
|
||||
items.sort! { |a, b| a.group.to_s.downcase <=> b.group.to_s.downcase }
|
||||
choice = ask(I18n.t('form.select')).to_i
|
||||
|
||||
choice >= 1 && choice <= items.length ? items[choice-1] : nil
|
||||
choice >= 1 && choice <= items.length ? items[choice - 1] : nil
|
||||
end
|
||||
|
||||
# Copy in clipboard the login and password
|
||||
# @args: item -> the item
|
||||
# clipboard -> enable clipboard
|
||||
def clipboard(item, clipboard=true)
|
||||
def clipboard(item, clipboard = true)
|
||||
pid = nil
|
||||
|
||||
# Security: force quit after 90s
|
||||
|
@ -321,7 +321,7 @@ class Cli
|
|||
|
||||
# Display the wallet
|
||||
# @args: wallet -> the wallet name
|
||||
def get_wallet(wallet=nil)
|
||||
def get_wallet(wallet = nil)
|
||||
if wallet.to_s.empty?
|
||||
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
|
||||
|
||||
|
@ -363,7 +363,7 @@ class Cli
|
|||
# @args: template -> template name
|
||||
# item -> the item to edit
|
||||
# password -> disable field password
|
||||
def text_editor(template_name, item=nil, password=false)
|
||||
def text_editor(template_name, item = nil, password = false)
|
||||
editor = ENV['EDITOR'] || 'nano'
|
||||
options = {}
|
||||
opts = {}
|
||||
|
@ -382,9 +382,9 @@ class Cli
|
|||
opts = YAML.load_file(tmp_file)
|
||||
end
|
||||
|
||||
opts.delete_if { |k,v| v.to_s.empty? }
|
||||
opts.delete_if { |k, v| v.to_s.empty? }
|
||||
|
||||
opts.each do |k,v|
|
||||
opts.each do |k, v|
|
||||
options[k.to_sym] = v
|
||||
end
|
||||
|
||||
|
@ -393,7 +393,7 @@ class Cli
|
|||
|
||||
# Form to add a new item
|
||||
# @args: password -> generate a random password
|
||||
def add(password=false)
|
||||
def add(password = false)
|
||||
options = text_editor('add_form', nil, password)
|
||||
item = Item.new(options)
|
||||
options[:password] = MPW.password(@config.password) if password
|
||||
|
@ -411,7 +411,7 @@ class Cli
|
|||
# Update an item
|
||||
# @args: password -> generate a random password
|
||||
# options -> the option to search
|
||||
def update(password=false, options={})
|
||||
def update(password = false, options = {})
|
||||
items = @mpw.list(options)
|
||||
|
||||
if items.empty?
|
||||
|
@ -421,7 +421,7 @@ class Cli
|
|||
|
||||
item = get_item(items)
|
||||
options = text_editor('update_form', item, password)
|
||||
options[:password] = MPW.password(@config.password) if password
|
||||
options[:password] = MPW.password(@config.password) if password
|
||||
|
||||
item.update(options)
|
||||
@mpw.set_password(item.id, options[:password]) if options.key?(:password)
|
||||
|
@ -436,7 +436,7 @@ class Cli
|
|||
|
||||
# Remove an item
|
||||
# @args: options -> the option to search
|
||||
def delete(options={})
|
||||
def delete(options = {})
|
||||
items = @mpw.list(options)
|
||||
|
||||
if items.empty?
|
||||
|
@ -461,7 +461,7 @@ class Cli
|
|||
# Copy a password, otp, login
|
||||
# @args: clipboard -> enable clipboard
|
||||
# options -> the option to search
|
||||
def copy(clipboard=true, options={})
|
||||
def copy(clipboard = true, options = {})
|
||||
items = @mpw.list(options)
|
||||
|
||||
if items.empty?
|
||||
|
@ -499,7 +499,7 @@ class Cli
|
|||
)
|
||||
end
|
||||
|
||||
File.open(file, 'w') {|f| f << data.to_yaml}
|
||||
File.open(file, 'w') { |f| f << data.to_yaml }
|
||||
|
||||
puts I18n.t('form.export.valid', file: file).to_s.green
|
||||
rescue Exception => e
|
||||
|
|
|
@ -36,7 +36,7 @@ class Config
|
|||
|
||||
# Constructor
|
||||
# @args: config_file -> the specify config file
|
||||
def initialize(config_file=nil)
|
||||
def initialize(config_file = nil)
|
||||
@config_file = config_file
|
||||
|
||||
if /darwin/ =~ RUBY_PLATFORM
|
||||
|
|
|
@ -36,7 +36,7 @@ class Item
|
|||
# Create a new item
|
||||
# @args: options -> a hash of parameter
|
||||
# raise an error if the hash hasn't the key name
|
||||
def initialize(options={})
|
||||
def initialize(options = {})
|
||||
if !options.key?(:host) || options[:host].to_s.empty?
|
||||
raise I18n.t('error.update.host_empty')
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ class Item
|
|||
|
||||
# Update the item
|
||||
# @args: options -> a hash of parameter
|
||||
def update(options={})
|
||||
def update(options = {})
|
||||
if options.key?(:host) && options[:host].to_s.empty?
|
||||
raise I18n.t('error.update.host_empty')
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ class Item
|
|||
# Generate an random id
|
||||
private
|
||||
def generate_id
|
||||
([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
|
||||
([*('A'..'Z'), *('a'..'z'), *('0'..'9')]).sample(16).join
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ module MPW
|
|||
class MPW
|
||||
|
||||
# Constructor
|
||||
def initialize(key, wallet_file, gpg_pass=nil, gpg_exe=nil)
|
||||
def initialize(key, wallet_file, gpg_pass = nil, gpg_exe = nil)
|
||||
@key = key
|
||||
@gpg_pass = gpg_pass
|
||||
@gpg_exe = gpg_exe
|
||||
|
@ -53,29 +53,29 @@ class MPW
|
|||
Gem::Package::TarReader.new(File.open(@wallet_file)) do |tar|
|
||||
tar.each do |f|
|
||||
case f.full_name
|
||||
when 'wallet/config.gpg'
|
||||
@config = YAML.safe_load(decrypt(f.read))
|
||||
when 'wallet/config.gpg'
|
||||
@config = YAML.safe_load(decrypt(f.read))
|
||||
|
||||
when 'wallet/meta.gpg'
|
||||
data = decrypt(f.read)
|
||||
when 'wallet/meta.gpg'
|
||||
data = decrypt(f.read)
|
||||
|
||||
when /^wallet\/keys\/(?<key>.+)\.pub$/
|
||||
key = Regexp.last_match('key')
|
||||
when /^wallet\/keys\/(?<key>.+)\.pub$/
|
||||
key = Regexp.last_match('key')
|
||||
|
||||
if GPGME::Key.find(:public, key).empty?
|
||||
GPGME::Key.import(f.read, armor: true)
|
||||
end
|
||||
if GPGME::Key.find(:public, key).empty?
|
||||
GPGME::Key.import(f.read, armor: true)
|
||||
end
|
||||
|
||||
@keys[key] = f.read
|
||||
@keys[key] = f.read
|
||||
|
||||
when /^wallet\/passwords\/(?<id>[a-zA-Z0-9]+)\.gpg$/
|
||||
@passwords[Regexp.last_match('id')] = f.read
|
||||
when /^wallet\/passwords\/(?<id>[a-zA-Z0-9]+)\.gpg$/
|
||||
@passwords[Regexp.last_match('id')] = f.read
|
||||
|
||||
when /^wallet\/otp_keys\/(?<id>[a-zA-Z0-9]+)\.gpg$/
|
||||
@otp_keys[Regexp.last_match('id')] = f.read
|
||||
when /^wallet\/otp_keys\/(?<id>[a-zA-Z0-9]+)\.gpg$/
|
||||
@otp_keys[Regexp.last_match('id')] = f.read
|
||||
|
||||
else
|
||||
next
|
||||
else
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -220,7 +220,7 @@ class MPW
|
|||
|
||||
# Set config
|
||||
# args: config -> a hash with config options
|
||||
def set_config(options={})
|
||||
def set_config(options = {})
|
||||
@config = {} if @config.nil?
|
||||
|
||||
@config['protocol'] = options[:protocol] if options.key?(:protocol)
|
||||
|
@ -243,7 +243,7 @@ class MPW
|
|||
# Search in some csv data
|
||||
# @args: options -> a hash with paramaters
|
||||
# @rtrn: a list with the resultat of the search
|
||||
def list(options={})
|
||||
def list(options = {})
|
||||
result = []
|
||||
|
||||
search = options[:pattern].to_s.downcase
|
||||
|
@ -305,7 +305,7 @@ class MPW
|
|||
# Generate a random password
|
||||
# @args: options -> :length, :special, :alpha, :numeric
|
||||
# @rtrn: a random string
|
||||
def self.password(options={})
|
||||
def self.password(options = {})
|
||||
if !options.include?(:length) || options[:length].to_i <= 0
|
||||
length = 8
|
||||
elsif options[:length].to_i >= 32768
|
||||
|
@ -315,10 +315,10 @@ class MPW
|
|||
end
|
||||
|
||||
chars = []
|
||||
chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]
|
||||
chars += [*('A'..'Z'),*('a'..'z')] if options[:alpha]
|
||||
chars += [*('0'..'9')] if options[:numeric]
|
||||
chars = [*('A'..'Z'),*('a'..'z'),*('0'..'9')] if chars.empty?
|
||||
chars += [*('!'..'?')] - [*('0'..'9')] if options[:special]
|
||||
chars += [*('A'..'Z'), *('a'..'z')] if options[:alpha]
|
||||
chars += [*('0'..'9')] if options[:numeric]
|
||||
chars = [*('A'..'Z'), *('a'..'z'), *('0'..'9')] if chars.empty?
|
||||
|
||||
result = ''
|
||||
while length > 62 do
|
||||
|
|
Loading…
Add table
Reference in a new issue