Module: Controls::Authentication

Included in:
Client
Defined in:
lib/controls/authentication.rb

Overview

A module that holds authentication methods for Client

Instance Method Summary collapse

Instance Method Details

#basic_authenticated?Boolean Also known as: authenticated?, user_authenticated?

Returns whether the user is authenticated using Basic Auth.

Returns:

  • (Boolean)

    whether the user is authenticated using Basic Auth



5
6
7
# File 'lib/controls/authentication.rb', line 5

def basic_authenticated?
  @username && @password
end

#login(username, password) ⇒ Object

Note:

this method should be updated if new methods for authentication become available.



16
17
18
# File 'lib/controls/authentication.rb', line 16

def (username, password)
  middleware.basic_auth(username, password)
end

#login_from_netrcBoolean

Whether the netrc file was successfully loaded, otherwise returns false and prints an error to STDERR

Returns:

  • (Boolean)

    whether the netrc file was successfully loaded, otherwise returns false and prints an error to STDERR



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/controls/authentication.rb', line 22

def 
  return false unless netrc?

  require 'netrc'
  host =  URI.parse(api_endpoint).host
  creds = Netrc.read(File.expand_path(netrc_file))[host]

  if creds
    self.username = creds.shift
    self.password = creds.shift

    middleware.basic_auth(username, password)
  else
    warn "No credentials found for '#{host}' in '#{netrc_file}'."

    false
  end
rescue LoadError
  warn 'You must install the netrc gem to login via netrc.',
       'Retry after running `gem install netrc`.'

  false
end