Class: Identikey::Base

Inherits:
Object
  • Object
show all
Extended by:
Savon::Model
Defined in:
lib/identikey/base.rb

Direct Known Subclasses

Administration, Authentication, Provisioning

Constant Summary collapse

DEFAULTS =
{
  endpoint: 'https://localhost:8888/',

  ssl_version: :TLSv1_2,
  ssl_verify_mode: :none,

  headers: default_user_agent_header,

  encoding: 'UTF-8',

  logger: Logger.new('log/identikey.log'),
  log_level: :debug,
  log: true,
  pretty_print_xml: true,

  filters: [
    'sessionID',
    'staticPassword',
    'identikey:CREDFLD_PASSWORD',
    'identikey:CREDFLD_STATIC_PASSWORD',
    'identikey:CREDFLD_SESSION_ID'
  ]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.client(options = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/identikey/base.rb', line 15

def self.client(options = nil)
  return super() unless options

  options = DEFAULTS.merge(options)
  options = process_identikey_filters(options)

  super options
end

.configure(&block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/identikey/base.rb', line 6

def self.configure(&block)
  self.client.globals.instance_eval(&block)

  # Work around a sillyness in Savon
  if client.globals[:wsdl] != client.wsdl.document
    client.wsdl.document = client.globals[:wsdl]
  end
end

.default_user_agent_headerObject



24
25
26
# File 'lib/identikey/base.rb', line 24

def self.default_user_agent_header
  {'User-Agent' => "ruby/identikey #{Identikey::VERSION}"}
end

.identikey_filter_proc_for(attribute) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/identikey/base.rb', line 60

def self.identikey_filter_proc_for(attribute)
  lambda do |document|
    document.xpath("//attributeID[text()='#{attribute}']/../value").each do |node|
      node.content = '***FILTERED***'
    end
  end
end

.process_identikey_filters(options) ⇒ Object

Loops over the filters option content and adds Identikey specific parameter filtering.

Due to faulty design in the Identikey SOAP endpoint, the parameter filters require context-dependant logic as all attributes are passed in ‘<attributeID>` elements, while all values are passed in `<value>` elements.

Identikey attributes to filter out are specified in the ‘filters` option with the `identikey:` prefix.

Example, filter out the ‘CREDFLD_PASSWORD` field from the logs (done by default):

configure do

filters [ 'identikey:CREDFLD_PASSWORD' ]

end



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/identikey/base.rb', line 46

def self.process_identikey_filters(options)
  filters = options[:filters] || []

  options[:filters] = filters.map do |filter|
    if filter.to_s =~ /^identikey:(.+)/
      filter = identikey_filter_proc_for($1)
    end

    filter
  end

  return options
end

Instance Method Details

#endpointObject



92
93
94
# File 'lib/identikey/base.rb', line 92

def endpoint
  self.class.client.globals[:endpoint]
end

#wsdlObject



96
97
98
# File 'lib/identikey/base.rb', line 96

def wsdl
  self.class.client.globals[:wsdl]
end