Class: MingleEvents::MingleBasicAuthAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/mingle_events/mingle_basic_auth_access.rb

Overview

Supports fetching of Mingle resources using HTTP basic auth. Please only use this class to access resources over HTTPS so as not to send credentials over plain-text connections.

Constant Summary collapse

BASIC_AUTH_HTTP_WARNING =
%{
WARNING!!!
It looks like you are using basic authentication over a plain-text HTTP connection.
We HIGHLY recommend AGAINST this practice. You should only use basic authentication over
a secure HTTPS connection. Instructions for enabling HTTPS/SSL in Mingle can be found at
<http://www.thoughtworks-studios.com/mingle/3.3/help/advanced_mingle_configuration.html>
WARNING!!
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, username, password, http = Http) ⇒ MingleBasicAuthAccess

Returns a new instance of MingleBasicAuthAccess.



17
18
19
20
21
22
# File 'lib/mingle_events/mingle_basic_auth_access.rb', line 17

def initialize(base_url, username, password, http=Http)
  @base_url = base_url
  @username = username
  @password = password
  @http = http
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



15
16
17
# File 'lib/mingle_events/mingle_basic_auth_access.rb', line 15

def base_url
  @base_url
end

Instance Method Details

#fetch_page(location) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/mingle_events/mingle_basic_auth_access.rb', line 24

def fetch_page(location)
  location = @base_url + location if location[0..0] == '/'
  @http.get(location) do |req|
    MingleEvents.log.warn(BASIC_AUTH_HTTP_WARNING) if URI.parse(location).scheme == 'http'
    req['authorization'] = basic_encode(@username, @password)
  end
end