Class: Sailpoint::Rest
- Inherits:
-
Object
- Object
- Sailpoint::Rest
- Defined in:
- lib/sailpoint/rest.rb
Overview
Used for created REST API calls to the organizations IdentityIQ source
Class Method Summary collapse
-
.authenticate ⇒ Hash
Used to verify if the supplied credentials are valid.
-
.check_roles(identity, roles) ⇒ Hash
Verify if the user has any policies set within the specified roles.
-
.get_identity(identity) ⇒ Hash
Used to fetch the specified user identiy from the REST API interface.
-
.get_user(identity) ⇒ Hash
Used to fetch the specified users associated data.
-
.permitted_roles(identity) ⇒ Hash
Get a users roles within the Organization.
-
.ping ⇒ Hash
Used to verify your credentials are valid and IdentityIQ reource is properly responding.
Class Method Details
.authenticate ⇒ Hash
Used to verify if the supplied credentials are valid
10 11 12 13 14 15 |
# File 'lib/sailpoint/rest.rb', line 10 def self.authenticate response = HTTParty.get([Sailpoint::Config.url('rest'), 'authentication'].join('/'), headers: Sailpoint::Config.auth_header, output: 'json') JSON.parse(response) end |
.check_roles(identity, roles) ⇒ Hash
Verify if the user has any policies set within the specified roles
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sailpoint/rest.rb', line 21 def self.check_roles(identity, roles) # Values for both attributes are required in order to create the request # And verify the user exists before attempting to create the request (this prevents IdentityIQ from making a long last query looking for a non-existant user) return {} if identity.blank? || roles.blank? || get_user(identity).empty? # the roles attribute should either be 'Contractor,Assistant' or ['Contractor', 'Assistant'] roles = roles.join(',') if roles.is_a?(Array) response = HTTParty.get([Sailpoint::Config.url('rest'), "policies/checkRolePolicies?identity=#{identity.escape_str}&roles=#{roles}"].join('/'), headers: Sailpoint::Config.auth_header, output: 'json') JSON.parse(response&.body || '{}') end |
.get_identity(identity) ⇒ Hash
Used to fetch the specified user identiy from the REST API interface
37 38 39 40 41 42 43 44 |
# File 'lib/sailpoint/rest.rb', line 37 def self.get_identity(identity) response = HTTParty.get([Sailpoint::Config.url('rest'), 'identities', identity.escape_str, 'managedIdentities'].join('/'), headers: Sailpoint::Config.auth_header, output: 'json') return [] if response.code == '500' JSON.parse(response&.body || '{}').first end |
.get_user(identity) ⇒ Hash
Used to fetch the specified users associated data
49 50 51 52 53 54 55 56 |
# File 'lib/sailpoint/rest.rb', line 49 def self.get_user(identity) response = HTTParty.get([Sailpoint::Config.url('rest'), 'identities', identity.escape_str].join('/'), headers: Sailpoint::Config.auth_header, output: 'json') raise AuthenticationException, 'Invalid credentials, please try again.' if response.code == 401 JSON.parse(response&.body || '{}') end |
.permitted_roles(identity) ⇒ Hash
Get a users roles within the Organization
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sailpoint/rest.rb', line 60 def self.permitted_roles(identity) # Before requesting a users roles we need to verify if the identiy matches a valid user first return {} if identity.blank? || get_user(identity).empty? response = HTTParty.get([Sailpoint::Config.url('rest'), "roles/assignablePermits/?roleMode=assignable&identity=#{identity.escape_str}"].join('/'), headers: Sailpoint::Config.auth_header, output: 'json') response_body = JSON.parse(response&.body || '{}') return response_body['objects'].map { |role| role['name'] } if response['status'].present? && response['status'] == 'success' response_body end |
.ping ⇒ Hash
Used to verify your credentials are valid and IdentityIQ reource is properly responding
75 76 77 78 79 |
# File 'lib/sailpoint/rest.rb', line 75 def self.ping HTTParty.get([Sailpoint::Config.url('rest'), 'ping'].join('/'), headers: Sailpoint::Config.auth_header, output: 'json') end |