Sha256: f845bb2ca17f47073e665711224091b3d609b12d889b3bd9e98f3332086d2874

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Toolshed
  class Password
    attr_accessor :password, :sudo_password

    def initialize(options={})
      self.password = options[:password] ||= ''
      self.sudo_password = options[:sudo_password] ||= ''
    end

    def read_user_input_password(type, prompt_message='Password:')
      value = self.send(type)
      unless value.nil? || value.empty?
        read_password_from_configuration(type)
      else
        prompt_user_to_input_password(prompt_message)
      end
    end

    protected

      def prompt_user_to_input_password(message)
        system "stty -echo"
        puts message
        value = get_password_input
        system "stty echo"

        value
      end

      def get_password_input
        $stdin.gets.chomp.strip
      end

      def read_password_from_configuration(type)
        begin
          credentials = Toolshed::Client.read_credenials
          if credentials[self.send(type)]
            credentials[self.send(type)]
          else
            self.send(type)
          end
        rescue => e
          puts e.inspect
        end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toolshed-1.0.3 lib/toolshed/password.rb