Module: PDC::Request::TokenFetcher

Extended by:
Configuration
Defined in:
lib/pdc/http/request/token_fetcher.rb

Defined Under Namespace

Modules: Configuration

Constant Summary

Constants included from Configuration

Configuration::VALID_KEYS

Class Method Summary collapse

Methods included from Configuration

configure, options

Class Method Details

.curl_easyObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pdc/http/request/token_fetcher.rb', line 37

def self.curl_easy
  Curl::Easy.new(url.to_s) do |request|
    request.ssl_verify_peer    = ssl_verify_mode != OpenSSL::SSL::VERIFY_NONE
    request.headers['Accept']  = 'application/json'
    request.http_auth_types    = :gssnegotiate

    # The curl man page (http://curl.haxx.se/docs/manpage.html)
    # specifes setting a fake username when using Negotiate auth,
    # and use ':' in their example.
    request.username = ':'
  end
end

.fetchObject

uses kerberos token to obtain token from pdc



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pdc/http/request/token_fetcher.rb', line 22

def self.fetch
  PDC.logger.debug "Fetch token from: #{url}"

  curl = curl_easy
  curl.perform
  if curl.response_code != 200
    PDC.logger.info "Obtain token from #{url} failed: #{curl.body_str}"
    error = { url: url, body: curl.body, code: curl.response_code }
    raise PDC::TokenFetchFailed, error
  end
  result = JSON.parse(curl.body_str)
  curl.close
  result['token']
end