Class: Sailpoint::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sailpoint/configuration.rb

Overview

Used for setting API configuration before creating API Requests Configuration can include: username, password, interface, host, url

Constant Summary collapse

ALLOWED_INTERFACES =
%w[rest scim].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



18
19
20
# File 'lib/sailpoint/configuration.rb', line 18

def initialize
  reload_config
end

Instance Attribute Details

#host_valObject

Variables used for storing values for host= and interface=



16
17
18
# File 'lib/sailpoint/configuration.rb', line 16

def host_val
  @host_val
end

#interface_valObject

Variables used for storing values for host= and interface=



16
17
18
# File 'lib/sailpoint/configuration.rb', line 16

def interface_val
  @interface_val
end

#passwordObject

Returns the value of attribute password.



13
14
15
# File 'lib/sailpoint/configuration.rb', line 13

def password
  @password
end

#usernameObject

Returns the value of attribute username.



13
14
15
# File 'lib/sailpoint/configuration.rb', line 13

def username
  @username
end

Instance Method Details

#auth_headerString

Used for generating the API BasicAuth Header when creating an API request

Returns:

  • (String)
    • Return the API Authorization header for the making API requests



82
83
84
85
86
# File 'lib/sailpoint/configuration.rb', line 82

def auth_header
  return {}.freeze if username.blank? && password.blank?

  { 'Authorization' => "Basic #{hashed_credentials}" }.freeze
end

#credentialsString

Used for fetching the API credentials when setting API requests headers

Returns:

  • (String)
    • Return a hash of the current API credentils (for validation purposes)



76
77
78
# File 'lib/sailpoint/configuration.rb', line 76

def credentials
  { username: username, password: password }.freeze
end

#full_host(interface = '') ⇒ Object



70
71
72
# File 'lib/sailpoint/configuration.rb', line 70

def full_host(interface = '')
  (interface.blank? ? [host, 'identityiq', interface_path].join('/') : [host, 'identityiq', interface].join('/'))
end

#hashed_credentialsString

SailPoints auth requires a Base64 string of (username:password) This is how most BasicAuth authentication methods work

Returns:

  • (String)
    • It will either return an empty string or a Base64.encoded hash for the the API credentials (BasicAuth requires Base64)



48
49
50
51
52
# File 'lib/sailpoint/configuration.rb', line 48

def hashed_credentials
  return '' if username.blank? && password.blank?

  Base64.encode64("#{username}:#{password}").strip
end

#hostObject



26
27
28
# File 'lib/sailpoint/configuration.rb', line 26

def host
  host_val
end

#host=(val = nil) ⇒ Object



22
23
24
# File 'lib/sailpoint/configuration.rb', line 22

def host=(val = nil)
  self.host_val = trim_host(val)
end

#interfaceObject



41
42
43
# File 'lib/sailpoint/configuration.rb', line 41

def interface
  interface_val
end

#interface=(val = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/sailpoint/configuration.rb', line 30

def interface=(val = nil)
  val = val&.to_s&.strip unless val.blank?
  self.interface_val = begin
    if val.blank? || !ALLOWED_INTERFACES.include?(val)
      'scim'
    else
      val
    end
  end
end

#interface_pathString

Used for fetching the API interface_path based on the API interface specification

Returns:

  • (String)
    • Returns the API’s interface path, based on interface type



56
57
58
59
60
# File 'lib/sailpoint/configuration.rb', line 56

def interface_path
  return 'scim' if interface.blank? || !ALLOWED_INTERFACES.include?(interface)

  interface
end

#urlString

Used for fetching the requesting users entire URL (Host+Interface)

Returns:

  • (String)
    • Returns the entire requesting URL (based on host and interface type)



64
65
66
67
68
# File 'lib/sailpoint/configuration.rb', line 64

def url
  return '' if host.blank? || interface.blank?

  full_host(interface)
end