Module: Cts::Mpx::Registry

Defined in:
lib/cts/mpx/registry.rb

Overview

Set of procedural functions to interact with the Registry.

Class Method Summary collapse

Class Method Details

.domainsHash

Collection of domains stored in memory

Returns:

  • (Hash)

    key is an account_id, value is a hash of results



9
10
11
# File 'lib/cts/mpx/registry.rb', line 9

def domains
  @domains
end

.fetch_and_store_domain(user, account_id = 'urn:theplatform:auth:root') ⇒ Hash

Call fetch and store domain in sequence.

Parameters:

  • user (User)

    user to make calls with

  • account_id (String) (defaults to: 'urn:theplatform:auth:root')

    long form account id (ownerId)

Returns:

  • (Hash)

    hash of the newly fetched domain

Raises:

  • (ArgumentError)

    if the user is not a user object

  • (ArgumentError)

    if the account_id is not valid



18
19
20
21
22
23
# File 'lib/cts/mpx/registry.rb', line 18

def fetch_and_store_domain(user,  = 'urn:theplatform:auth:root')
   ||= 'urn:theplatform:auth:root'
  result = fetch_domain user, 
  store_domain result, 
  domains[]
end

.fetch_domain(user, account_id = 'urn:theplatform:auth:root') ⇒ Hash

Fetch a domain from the registry.

Parameters:

  • user (User)

    user to make calls with

  • account_id (String) (defaults to: 'urn:theplatform:auth:root')

    long form account id (ownerId)

Returns:

  • (Hash)

    hash of the newly fetched domain

Raises:

  • (ArgumentError)

    if the user is not a user object

  • (ArgumentError)

    if the account_id is not valid



31
32
33
34
35
36
37
38
39
40
# File 'lib/cts/mpx/registry.rb', line 31

def fetch_domain(user,  = 'urn:theplatform:auth:root')
  return domains['urn:theplatform:auth:root'] if  == 'urn:theplatform:auth:root'

  Driver::Exceptions.raise_unless_argument_error?(user, 'User') { !user.is_a? User }
  user.token!
  Driver::Exceptions.raise_unless_argument_error?(, 'account_id') { !Validators.  }

  response = Services::Web.post user: user, service: 'Access Data Service', endpoint: 'Registry', method: 'resolveDomain', arguments: { 'accountId' =>  }
  response.data['resolveDomainResponse']
end

.initializeObject

find and store the root registry from the US



57
58
59
60
61
# File 'lib/cts/mpx/registry.rb', line 57

def initialize
  @domains = {}
  content = File.read "#{Driver.config_dir}/root_registry_sea1.json"
  store_domain(Driver.parse_json(content)['resolveDomainResponse'], 'urn:theplatform:auth:root')
end

.store_domain(data, account_id = 'urn:theplatform:auth:root') ⇒ Void

Store the domain in memory

Parameters:

  • data (Hash)

    collection received from Registry

  • account_id (String) (defaults to: 'urn:theplatform:auth:root')

    long form account id (ownerId)

Returns:

  • (Void)

Raises:

  • (ArgumentError)

    if the data is not a valid hash

  • (ArgumentError)

    if the account_id is not valid



48
49
50
51
52
53
54
# File 'lib/cts/mpx/registry.rb', line 48

def store_domain(data,  = 'urn:theplatform:auth:root')
  raise ArgumentError, "#{} is not a valid account_id" unless Validators. 
  raise ArgumentError, "#{data} is not a valid Hash" unless data.is_a? Hash

  @domains.store , data
  nil
end