Sha256: 341d0005e8968f5e85a12ecaa1b993eb3607f03a89e663cafe38ea76cefce3fb

Contents?: true

Size: 765 Bytes

Versions: 26

Compression:

Stored size: 765 Bytes

Contents

class Miam::PasswordManager
  include Miam::Logger::Helper

  def initialize(output, options = {})
    @output = output
    @options = options
  end

  def identify(user, type)
    password = mkpasswd
    puts_password(user, type, password)
    password
  end

  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

  def mkpasswd(len = 8)
    [*1..9, *'A'..'Z', *'a'..'z'].shuffle.slice(0, len).join
  end

  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
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
miam-0.2.4.beta6 lib/miam/password_manager.rb
miam-0.2.4.beta5 lib/miam/password_manager.rb
miam-0.2.4.beta4 lib/miam/password_manager.rb
miam-0.2.4.beta3 lib/miam/password_manager.rb
miam-0.2.4.beta2 lib/miam/password_manager.rb
miam-0.2.4.beta lib/miam/password_manager.rb
miam-0.2.3 lib/miam/password_manager.rb
miam-0.2.3.beta3 lib/miam/password_manager.rb
miam-0.2.3.beta2 lib/miam/password_manager.rb
miam-0.2.3.beta lib/miam/password_manager.rb
miam-0.2.2 lib/miam/password_manager.rb
miam-0.2.2.beta4 lib/miam/password_manager.rb
miam-0.2.2.beta3 lib/miam/password_manager.rb
miam-0.2.2.beta2 lib/miam/password_manager.rb
miam-0.2.2.beta lib/miam/password_manager.rb
miam-0.2.1 lib/miam/password_manager.rb
miam-0.2.1.beta2 lib/miam/password_manager.rb
miam-0.2.1.beta lib/miam/password_manager.rb
miam-0.2.0 lib/miam/password_manager.rb
miam-0.2.0.beta3 lib/miam/password_manager.rb