Sha256: 08df2af0a49df792ad09352676cd2c4b6eb0a8cc2e065d29cf794ec21d4a5fba

Contents?: true

Size: 1.6 KB

Versions: 34

Compression:

Stored size: 1.6 KB

Contents

module TreasureData
module Command

  def password_change(op)
    op.cmd_parse

    old_password = nil
    password = nil

    begin
      system "stty -echo"  # TODO termios
      $stdout.print "Old password (typing will be hidden): "
      old_password = STDIN.gets || ""
      old_password = old_password[0..-2]  # strip \n
    rescue Interrupt
      $stderr.print "\ncanceled."
      exit 1
    ensure
      system "stty echo"   # TODO termios
      $stdout.print "\n"
    end

    if old_password.empty?
      $stderr.puts "canceled."
      exit 0
    end

    3.times do
      begin
        system "stty -echo"  # TODO termios
        $stdout.print "New password (typing will be hidden): "
        password = STDIN.gets || ""
        password = password[0..-2]  # strip \n
      rescue Interrupt
        $stderr.print "\ncanceled."
        exit 1
      ensure
        system "stty echo"   # TODO termios
        $stdout.print "\n"
      end

      if password.empty?
        $stderr.puts "canceled."
        exit 0
      end

      begin
        system "stty -echo"  # TODO termios
        $stdout.print "Retype new password: "
        password2 = STDIN.gets || ""
        password2 = password2[0..-2]  # strip \n
      rescue Interrupt
        $stderr.print "\ncanceled."
        exit 1
      ensure
        system "stty echo"   # TODO termios
        $stdout.print "\n"
      end

      if password == password2
        break
      end

      $stdout.puts "Doesn't match."
    end

    client = get_client(:ssl => true)

    client.change_my_password(old_password, password)

    $stderr.puts "Password changed."
  end

end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
td-0.17.1 lib/td/command/password.rb
td-0.17.0 lib/td/command/password.rb
td-0.16.10 lib/td/command/password.rb
td-0.16.9 lib/td/command/password.rb
td-0.16.8 lib/td/command/password.rb
td-0.16.7 lib/td/command/password.rb
td-0.16.6 lib/td/command/password.rb
td-0.16.5 lib/td/command/password.rb
td-0.16.4 lib/td/command/password.rb
td-0.16.3 lib/td/command/password.rb
td-0.16.1 lib/td/command/password.rb
td-0.16.0 lib/td/command/password.rb
td-0.15.9 lib/td/command/password.rb
td-0.15.8 lib/td/command/password.rb
td-0.15.7 lib/td/command/password.rb
td-0.15.6 lib/td/command/password.rb
td-0.15.5 lib/td/command/password.rb
td-0.15.4 lib/td/command/password.rb
td-0.15.3 lib/td/command/password.rb
td-0.15.2 lib/td/command/password.rb