Sha256: 9f05d436ecd0f69651e286f7ead7cbfc45dc9d9b822dfc531429e05c36c4cb65

Contents?: true

Size: 776 Bytes

Versions: 18

Compression:

Stored size: 776 Bytes

Contents

class Gratan::Identifier::Auto
  def initialize(output, options = {})
    @output = output
    @options = options
    @cache = {}
  end

  def identify(user, host)
    if @cache[user]
      password = @cache[user]
    else
      password = mkpasswd
      @cache[user] = password
    end

    puts_password(user, host, password)
    password
  end

  private

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

  def puts_password(user, host, password)
    open_output do |f|
      f.puts("#{user}@#{host},#{password}")
    end
  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

18 entries across 18 versions & 1 rubygems

Version Path
gratan-0.3.2 lib/gratan/identifier/auto.rb
gratan-0.3.1 lib/gratan/identifier/auto.rb
gratan-0.3.1.beta4 lib/gratan/identifier/auto.rb
gratan-0.3.1.beta3 lib/gratan/identifier/auto.rb
gratan-0.3.1.beta2 lib/gratan/identifier/auto.rb
gratan-0.3.1.beta lib/gratan/identifier/auto.rb
gratan-0.3.0 lib/gratan/identifier/auto.rb
gratan-0.3.0.beta lib/gratan/identifier/auto.rb
gratan-0.2.9 lib/gratan/identifier/auto.rb
gratan-0.2.9.beta3 lib/gratan/identifier/auto.rb
gratan-0.2.9.beta2 lib/gratan/identifier/auto.rb
gratan-0.2.9.beta lib/gratan/identifier/auto.rb
gratan-0.2.8 lib/gratan/identifier/auto.rb
gratan-0.2.8.beta3 lib/gratan/identifier/auto.rb
gratan-0.2.8.beta2 lib/gratan/identifier/auto.rb
gratan-0.2.8.beta lib/gratan/identifier/auto.rb
gratan-0.2.7 lib/gratan/identifier/auto.rb
gratan-0.2.6 lib/gratan/identifier/auto.rb