Class: Certmeister::DynamoDB::Store
- Inherits:
-
Object
- Object
- Certmeister::DynamoDB::Store
- Includes:
- Enumerable
- Defined in:
- lib/certmeister/dynamodb/store.rb
Instance Method Summary collapse
- #each ⇒ Object
- #fetch(cn) ⇒ Object
- #health_check ⇒ Object
-
#initialize(table_name, options = {}, provision = {}) ⇒ Store
constructor
A new instance of Store.
- #remove(cn) ⇒ Object
- #store(cn, pem) ⇒ Object
Constructor Details
#initialize(table_name, options = {}, provision = {}) ⇒ Store
Returns a new instance of Store.
12 13 14 15 16 17 18 19 |
# File 'lib/certmeister/dynamodb/store.rb', line 12 def initialize(table_name, = {}, provision = {}) @table_name = table_name @db = Aws::DynamoDB::Client.new() if !provision.empty? do_provisioning(provision) end @healthy = true end |
Instance Method Details
#each ⇒ Object
36 37 38 39 40 |
# File 'lib/certmeister/dynamodb/store.rb', line 36 def each @db.scan(table_name: @table_name).items.each do |item| yield item["cn"], item["pem"] end end |
#fetch(cn) ⇒ Object
25 26 27 28 29 |
# File 'lib/certmeister/dynamodb/store.rb', line 25 def fetch(cn) if item = @db.get_item(table_name: @table_name, key: {cn: cn}).item item["pem"] end end |
#health_check ⇒ Object
42 43 44 |
# File 'lib/certmeister/dynamodb/store.rb', line 42 def health_check @healthy end |
#remove(cn) ⇒ Object
31 32 33 34 |
# File 'lib/certmeister/dynamodb/store.rb', line 31 def remove(cn) deleted = @db.delete_item(table_name: @table_name, key: {cn: cn}, return_values: "ALL_OLD").attributes !!deleted end |
#store(cn, pem) ⇒ Object
21 22 23 |
# File 'lib/certmeister/dynamodb/store.rb', line 21 def store(cn, pem) @db.put_item(table_name: @table_name, item: {cn: cn, pem: pem}) end |