Class: Sailpoint::Config

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

Overview

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hostString

Used to fetch the host for the API request

Returns:

  • (String)
    • If a valid host was specified, it will returned a trimmed string with trailing whitespaces and slashes removed



41
42
43
44
45
# File 'lib/sailpoint/config.rb', line 41

def host
  return '' if @host.blank?

  trimmed_host
end

.interfaceString

Used for setting if the interface type is Rest || SCIM

Returns:

  • (String)
    • Returns either the specified interface (Default: rest)



29
30
31
# File 'lib/sailpoint/config.rb', line 29

def interface
  (@interface ||= 'rest')
end

.passwordString

Used for fetching the requesting users credentials password (if it has been set)

Returns:

  • (String)
    • The password for the API credentials



68
69
70
# File 'lib/sailpoint/config.rb', line 68

def password
  @password || ''
end

.url(interface = '') ⇒ String

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

Parameters:

  • interface (String) (defaults to: '')
    • used for when the user is specicically calling an API such as Unmh::Sailpoint::Scim.get_user('brhicks')

Returns:

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



50
51
52
53
54
# File 'lib/sailpoint/config.rb', line 50

def url(interface = '')
  return '' if @host.blank? || @interface.blank?

  full_host(interface)
end

.usernameString

Used for fetching credentails username (if it has been set)

Returns:

  • (String)
    • The credentails username



62
63
64
# File 'lib/sailpoint/config.rb', line 62

def username
  @username || ''
end

Instance Attribute Details

#interfaceObject

Returns the value of attribute interface.



9
10
11
# File 'lib/sailpoint/config.rb', line 9

def interface
  @interface
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/sailpoint/config.rb', line 9

def password
  @password
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/sailpoint/config.rb', line 9

def url
  @url
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/sailpoint/config.rb', line 9

def username
  @username
end

Class 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



98
99
100
101
102
# File 'lib/sailpoint/config.rb', line 98

def auth_header
  return '' if @username.blank? && @password.blank?

  { 'Authorization' => "Basic #{Sailpoint::Config.hashed_credentials}" }
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)



74
75
76
# File 'lib/sailpoint/config.rb', line 74

def credentials
  { username: @username, password: @password }
end

.full_host(interface = '') ⇒ Object



56
57
58
# File 'lib/sailpoint/config.rb', line 56

def full_host(interface = '')
  interface.blank? ? [trimmed_host, 'identityiq', interface_path].join('/') : [trimmed_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)



90
91
92
93
94
# File 'lib/sailpoint/config.rb', line 90

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

  Base64.encode64("#{@username}:#{@password}").strip
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



35
36
37
# File 'lib/sailpoint/config.rb', line 35

def interface_path
  (@interface == 'scim' ? 'scim' : 'rest')
end

.set_credentials(username, password) ⇒ Object

Used to set the API requests BasicAuth credentails

Parameters:

  • username (String)
    • Username for the API request

  • password (String)
    • Password for the API request



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

def set_credentials(username, password)
  @username = username unless username.nil?
  @password = password unless password.nil?
end

.trimmed_hostString

Remove trailing forward slashes from the end of the Host, that way hosts and interfaces can be properly joined

> I also did this because you’d get the same results if something supplied http://example.com or https://example.com/

Returns:

  • (String)
    • Returns a cleaned up and trimmed host with trailing slashs removed



81
82
83
84
85
# File 'lib/sailpoint/config.rb', line 81

def trimmed_host
  return '' if @host.blank?

  @host.strip.gsub!(%r{\/?++$}, '')
end