Sha256: 775957a9d2998e0e6bdfaa9ab184bf8e77830ecab753e1cf75dccdcd759f7144

Contents?: true

Size: 733 Bytes

Versions: 7

Compression:

Stored size: 733 Bytes

Contents

require 'highline/import'

module HaveAPI::Fs::Auth
  class Token < Base
    register :token

    def self.use?(opts)
      opts[:token]
    end

    def setup
      @user = @opts[:user] || @cfg[:user]
      @passwd = @opts[:password] || @cfg[:password]
      @token = @opts[:token] || @cfg[:token]
    end

    def validate
      return if @token

      @user ||= ask('User name: ') { |q| q.default = nil }.to_s

      @passwd ||= ask('Password: ') do |q|
        q.default = nil
        q.echo = false
      end.to_s
    end

    def authenticate(client)
      if @token
        opts = {token: @token}

      else
        opts = {user: @user, password: @passwd}
      end

      client.authenticate(:token, opts)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
haveapi-fs-0.11.0 lib/haveapi/fs/auth/token.rb
haveapi-fs-0.10.0 lib/haveapi/fs/auth/token.rb
haveapi-fs-0.9.0 lib/haveapi/fs/auth/token.rb
haveapi-fs-0.8.0 lib/haveapi/fs/auth/token.rb
haveapi-fs-0.7.1 lib/haveapi/fs/auth/token.rb
haveapi-fs-0.7.0 lib/haveapi/fs/auth/token.rb
haveapi-fs-0.1.0 lib/haveapi/fs/auth/token.rb