Registry of identities

Quickstart

Example data

identities = [{
    "uuid": "62936e70-1815-439b-bf89-8492855a7e6b",
    "email": "[email protected]",
}]

Directory

Create a directory provider

> require 'soar/registry/directory'
> directory_provider = Soar::Registry::Directory::Provider::Stub.new(
    table: "identities",
    index: ["uuid", "email"]
)

Create a directory

> directory = Soar::Registry::Directory.new(directory_provider)

Instantiation

Manual instantiation

Staff Email IDR

Search for identifiers by email address. Used by soar-authentication-identity to translate an authenticated identifier to an UUID.

require 'soar/registry/identity'
identity_provider = Soar::Registry::Identity::Provider::Staff::Email.new({
    directory: directory,
    fetch_index: 'uuid',
    search_index: 'email'
})
@email_idr = Soar::Registry::Identity.new(identity_provider)

Factory instantiation

Create a selector
> require 'object_selector'
> selector = ObjectSelector.new(
  ObjectSelector::Provider::RegexRuleList.new({
    rules: [
      {
        regex: /\A[\w+\-.][email protected]\z/i,
        object: Soar::Registry::Identity::Provider::Staff::Email.new({
          directory: Object.new,
          fetch_index: SecureRandom.hex,
          search_index: SecureRandom.hex
        })
      },
      {
        regex: /\A[\w+\-.]+@.+/i,
        object: Soar::Registry::Identity::Provider::Customer::Email.new({
          directory: Object.new,
          fetch_index: SecureRandom.hex,
          search_index: SecureRandom.hex
        })
      },
      {
        regex: /\A[CF]{0,1}\d+\z/,
        object: Soar::Registry::Identity::Provider::Customer::ClientNumber.new({
          directory: Object.new,
          fetch_index: SecureRandom.hex,
          search_index: SecureRandom.hex
        })
      }
    ]
  })
)
Get an IDR
> selector_value = 'your-string-here'
idr = Soar::Registry::Identity::Factory.create({
  value: selector_value,
  selector: selector
})

Use your IDR

Getting a list of identifiers
> identifiers = @email_idr.get_identifiers("[email protected]") 
> puts identifiers.inspect
["[email protected]", "identity-820d5660-2204-4f7d-8c04-746313439b81"]

Getting a list of roles

> roles = @uuid_idr.get_roles("identity-820d5660-2204-4f7d-8c04-746313439b81")
> # get_roles is not applicable to staff email idr
> puts roles.inspect
["staff", "configuration_publisher", "configuration_consumer"]

Getting a hash of attributes for a role

> role = 'staff'
> attributes = @uuid_idr.get_attributes("identity-820d5660-2204-4f7d-8c04-746313439b81", role)
> # get_attributes is not applicable to staff email idr
> puts attributes.inspect
{
    "staff": {
        "department": "technical"
    }
}

Getting a hash of all attributes

> attributes = @uuid_idr.get_attributes("identity-820d5660-2204-4f7d-8c04-746313439b81")
> # get_attributes is not applicate to staff email idr
> puts attributes.inspect
{
    "identity_id" => "identity-820d5660-2204-4f7d-8c04-746313439b81",
    "entity_id"=> "entity-bad85eb9-0713-4da7-8d36-07a8e4b00eab",
    "email"=> "[email protected]",
    "roles"=> {
        "staff"=> {},
        "configuration_publisher"=> {
            "configuration_identifiers"=> ["*"]
        },
        "configuration_consumer"=> {
            "configuration_identifiers"=> ["*"]
        }
    },
    "address"=> {
        "detail"=> "Belvedere Office Park, Unit F",
        "street"=> "Bella Rosa Street",
        "suburb"=> "Tygervalley",
        "city"=> "Durbanville",
        "postal"=> "7550"
    }
}

Tests

Local

$ bundle exec rspec 

CI

docker-compose --file docker-compose.ci.yml --project-name soar-registry-identity up --abort-on-container-exit --remove-orphans --build --force-recreate
EXIT_CODE=$(docker ps -a -f "name=soarregistryidentity_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
docker-compose --file docker-compose.ci.yml --project-name soar-registry-identity down --rmi local
exit $EXIT_CODE;

Resources

References