class Subiam::PasswordManager
Public Class Methods
new(output, options = {})
click to toggle source
# File lib/subiam/password_manager.rb, line 4 def initialize(output, options = {}) @output = output @options = options end
Public Instance Methods
identify(user, type)
click to toggle source
# File lib/subiam/password_manager.rb, line 9 def identify(user, type) password = mkpasswd puts_password(user, type, password) password end
puts_password(user, type, password)
click to toggle source
# File lib/subiam/password_manager.rb, line 15 def puts_password(user, type, password) log(:info, "User `#{user}` > `#{type}`: put password to `#{@output}`") open_output do |f| f.puts("#{user},#{type},#{password}") end end
Private Instance Methods
mkpasswd(len = 8)
click to toggle source
# File lib/subiam/password_manager.rb, line 25 def mkpasswd(len = 8) [*1..9, *'A'..'Z', *'a'..'z'].shuffle.slice(0, len).join end
open_output() { |$stdout| ... }
click to toggle source
# File lib/subiam/password_manager.rb, line 29 def open_output return if @options[:dry_run] if @output == '-' yield($stdout) $stdout.flush else open(@output, 'a') do |f| yield(f) end end end