Class: Soar::Registry::Staff::Directory::DynamoDb::Base
- Inherits:
-
SoarIdm::DirectoryProvider
- Object
- SoarIdm::DirectoryProvider
- Soar::Registry::Staff::Directory::DynamoDb::Base
- Defined in:
- lib/soar/registry/staff/directory/dynamo_db/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
Instance Method Summary collapse
- #authenticate(credentials) ⇒ Object
- #bootstrap(configuration) ⇒ Nil
-
#bootstrapped? ⇒ Bool
Whether directory provider received minimum required configuration.
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #put_identity(entity) ⇒ Object
- #ready? ⇒ Boolean
- #uri ⇒ Object
Instance Attribute Details
#client ⇒ Object (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 |
#configuration ⇒ Object (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 |
#credentials ⇒ Object (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
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.
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 |
#connect ⇒ Object
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 = @configuration.dup ['credentials'] = Aws::Credentials.new(@credentials['access_key_id'], @credentials['secret_access_key']) @client = Aws::DynamoDB::Client.new(Hashie.symbolize_keys()) @client rescue ArgumentError => e raise Soar::Registry::Staff::Directory::Error::ConnectionError, e. rescue raise Soar::Registry::Staff::Directory::Error::ConnectionError, 'error creating client' end end |
#connected? ⇒ 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
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 |
#uri ⇒ Object
35 36 37 |
# File 'lib/soar/registry/staff/directory/dynamo_db/base.rb', line 35 def uri @configuration['endpoint'] end |