class MediTAF::Services::Clients::MauthAdapter

The specific resource adapter for MAuthClient. It depends on the following configurations

Public Class Methods

new() click to toggle source

verifies needed configuration items exist for mauth-client @raise [ResourceAdapterConfigurationMissing] lists the missing required configuration items

# File lib/MediTAF/services/clients/mauth_adapter.rb, line 20
def initialize
  errs = []
  errs << 'mauth configuration' unless mauth_config
  if errs.empty?
    errs << 'mauth_api_version' unless mauth_config[:mauth_api_version]
    errs << 'mauth_url' unless mauth_config[:mauth_baseurl]
    errs << 'app_uuid' unless mauth_config[:app_uuid]
    errs << 'key_file' unless mauth_config[:private_key_file]
    errs << 'authenticate_responses' if mauth_config[:authenticate_response].nil?
  end
  unless errs.empty?
    raise ResourceAdapterConfigurationMissing, 'Mauth Adapter Configurations: cannot find ' + errs.join(', ')
  end
end

Public Instance Methods

configure() click to toggle source

configure a new MAuth::Client based on configuration items @note configures MAuth::Client to return all response in JSON format

# File lib/MediTAF/services/clients/mauth_adapter.rb, line 37
def configure
  @mauth_client = ::MAuth::Client.new(mauth_config)

  @connection = Faraday.new do |builder|
    builder.use MAuth::Faraday::MAuthClientUserAgent, "MediTAF Mauth Client Adapter"
    builder.use MAuth::Faraday::RequestSigner, :mauth_client => @mauth_client
    builder.use MAuth::Faraday::ResponseAuthenticator, :mauth_client => @mauth_client if mauth_config[:authenticate_response]
    builder.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
    builder.use FaradayMiddleware::ParseXml, content_type: /\bxml$/
    builder.adapter Faraday.default_adapter
  end
end
load(args) click to toggle source

loads a new MauthClient object for request on base_url @param args [Hash] arguments @option args [String] :baseurl the base url of this resource @return [MediTAF::Services::Clients::MauthClient] @raise [ResourceAdapterLoadError] when instantiating a new MauthClient

# File lib/MediTAF/services/clients/mauth_adapter.rb, line 55
def load(args)
  raise MauthClientBaseURLMissing, "supply a base url" unless args.is_a?(Hash) && args.has_key?(:baseurl)
  MauthClient.new(@connection, args[:baseurl])
end

Private Instance Methods

mauth_config() click to toggle source
# File lib/MediTAF/services/clients/mauth_adapter.rb, line 62
def mauth_config
  raise ServiceConfigurationMissing, "services not found in configuration" unless  MediTAF::Utils::Configuration['services']
  raise ServiceConfigurationMissing, "euresource not found in configuration" unless  MediTAF::Utils::Configuration['services']['mauth']
  unless @mauth_config
    cfg =  MediTAF::Utils::Configuration['services']['mauth']
    @mauth_config = {}
    @mauth_config[:mauth_baseurl] = cfg['mauth_url']
    @mauth_config[:private_key_file] = cfg['key_file']
    @mauth_config[:app_uuid] = cfg['app_uuid']
    @mauth_config[:mauth_api_version] = cfg['mauth_api_version']
    @mauth_config[:authenticate_response] = cfg['authenticate_responses']
  end
  @mauth_config
rescue => e
  nil
end