Class: SoarSc::IdrClient

Inherits:
SoarIdm::IdmApi
  • Object
show all
Defined in:
lib/idr_client.rb

Overview

SOAR Idr Client Simplifies communication with Hetzner identity registries.

Examples:

Get roles

idr_client = SoarSc::IdrClient.new
idr_client.roles_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-roles')
subject_identifier = '[email protected]'
roles = idr_client.get_roles(subject_identifier)

Get all attributes

idr_client = SoarSc::IdrClient.new
idr_client.attributes_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-attributes')
subject_identifier = '[email protected]'
attributes = idr_client.get_attributes(subject_identifier)

Get attributes filtered by role

idr_client = SoarSc::IdrClient.new
idr_client.roles_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-roles')
idr_client.attributes_uri = SoarSc::Providers::ServiceRegistry::find_first_service_uri('idr-staff-get-attributes')
subject_identifier = '[email protected]'
role = 'technical'
attributes = idr_client.get_attributes(subject_identifier, role)

Defined Under Namespace

Classes: CommunicationError, MissingRequiredAttributeError, UnsupportedResponseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http = Net::HTTP) ⇒ Object

Creates an instance of IdrClient

Parameters:

  • http (defaults to: Net::HTTP)

    optional [Object]



44
45
46
# File 'lib/idr_client.rb', line 44

def initialize(http=Net::HTTP)
  @http = http
end

Instance Attribute Details

#attributes_uri=(attributes_uri) ⇒ Nil (writeonly)

Set remote uri used by get_attributes method

Parameters:

  • attributes_uri (String)

Returns:

  • (Nil)

Raises:

  • (URI::InvalidURIError)


38
39
40
# File 'lib/idr_client.rb', line 38

def attributes_uri=(value)
  @attributes_uri = value
end

#roles_uri=(roles_uri) ⇒ Nil (writeonly)

Set remote uri used by get_roles method

Parameters:

  • roles_uri (String)

Returns:

  • (Nil)

Raises:

  • (URI::InvalidURIError)


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

def roles_uri=(value)
  @roles_uri = value
end

Instance Method Details

#get_attributes(subject_identifier, role = nil) ⇒ Hash

Get attributes optionally filtered by role

Parameters:

  • subject_identifier (String)
  • role (defaults to: nil)

    optional [String]

Returns:

  • (Hash)

    dictionary of roles and attributes, optionally filtered by role

Raises:

  • MissingRequiredAttributeError

  • UnsupportedResponseError

  • CommunicationError



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/idr_client.rb', line 75

def get_attributes(subject_identifier, role = nil)
  begin
    super(subject_identifier, role)
  rescue MissingRequiredAttributeError => error
    raise error
  rescue JSON::ParserError => error
    raise UnsupportedResponseError, error.message
  rescue StandardError => error
    raise CommunicationError, error.message
  end
end

#get_roles(subject_identifier) ⇒ Array

Get roles

Parameters:

  • subject_identifier (String)

Returns:

  • (Array)

    list of roles

Raises:

  • MissingRequiredAttributeError when missing subject_identifier param

  • UnsupportedResponseError when remote response is not json

  • CommunicationError when network error



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/idr_client.rb', line 55

def get_roles(subject_identifier)
  begin
    super(subject_identifier)
  rescue MissingRequiredAttributeError => error
    raise error
  rescue JSON::ParserError => error
    raise UnsupportedResponseError, error.message
  rescue StandardError => error
    raise CommunicationError, error.message
  end
end