Class: Soar::Registry::Staff::Directory::DynamoDb::Base

Inherits:
SoarIdm::DirectoryProvider
  • Object
show all
Defined in:
lib/soar/registry/staff/directory/dynamo_db/base.rb

Direct Known Subclasses

Identity

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 13

def client
  @client
end

#configurationObject (readonly)

Returns the value of attribute configuration.



13
14
15
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 13

def configuration
  @configuration
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



13
14
15
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 13

def credentials
  @credentials
end

Instance Method Details

#authenticate(credentials) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 39

def authenticate(credentials)
  raise Soar::Registry::Staff::Directory::Error::AuthenticationError, 'missing username' if not credentials.key?('username')
  raise Soar::Registry::Staff::Directory::Error::AuthenticationError, 'missing password' if not credentials.key?('password')
  @credentials = {
    "access_key_id" => credentials['username'],
    "secret_access_key" => credentials['password']
  }
end

#bootstrap(configuration) ⇒ Nil

Parameters:

  • configuration (Hash)

    for the directory provider

Returns:

  • (Nil)

Raises:



20
21
22
23
24
25
26
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 20

def bootstrap(configuration)
  @configuration = Hashie.stringify_keys(configuration)
  raise Soar::Registry::Staff::Directory::Error::BootstrapError, 'Missing region' if not @configuration.has_key?('region')
  raise Soar::Registry::Staff::Directory::Error::BootstrapError, 'Missing endpoint' if not @configuration.has_key?('endpoint')
  @table_name = @configuration.delete('table')
  raise Soar::Registry::Staff::Directory::Error::BootstrapError, 'Missing table name' if not @table_name
end

#bootstrapped?Bool

Returns whether directory provider received minimum required configuration.

Returns:

  • (Bool)

    whether directory provider received minimum required configuration



31
32
33
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 31

def bootstrapped?
  @configuration.has_key?('region') and @configuration.has_key?('endpoint') 
end

#connectObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 48

def connect
  begin
    options = @configuration.dup
    options['credentials'] = Aws::Credentials.new(@credentials['access_key_id'], @credentials['secret_access_key'])
    @client = Aws::DynamoDB::Client.new(Hashie.symbolize_keys(options))
    @client
  rescue ArgumentError => e
    raise Soar::Registry::Staff::Directory::Error::ConnectionError, e.message 
  rescue 
    raise Soar::Registry::Staff::Directory::Error::ConnectionError, 'error creating client'
  end

end

#connected?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 62

def connected?
  return @client.class.name == 'Aws::DynamoDB::Client'
end

#put_identity(entity) ⇒ Object



74
75
76
77
78
79
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 74

def put_identity(entity)
  @client.put_item({
    table_name: @table_name,
    item: Hashie.symbolize_keys(entity)
  })
end

#ready?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 66

def ready?
  begin
    return @client.list_tables.table_names.class.name == 'Array'
  rescue Seahorse::Client::NetworkingError
    return false
  end
end

#uriObject



35
36
37
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 35

def uri
  @configuration['endpoint']
end