Class: Certmeister::Pg::Store
- Inherits:
-
Object
- Object
- Certmeister::Pg::Store
- Defined in:
- lib/certmeister/pg/store.rb
Instance Method Summary collapse
- #fetch(cn) ⇒ Object
- #health_check ⇒ Object
-
#initialize(connection_string, options = {}) ⇒ Store
constructor
A new instance of Store.
- #remove(cn) ⇒ Object
- #store(cn, pem) ⇒ Object
Constructor Details
#initialize(connection_string, options = {}) ⇒ Store
Returns a new instance of Store.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/certmeister/pg/store.rb', line 10 def initialize(connection_string, = {}) @db = Sequel.connect(connection_string, ) @db.create_table? :certificates do primary_key :id String :cn, unique: true, null: false File :pem, null: false Time :created_at, null: false Time :updated_at, null: false end @certificates = @db[:certificates] @healthy = true end |
Instance Method Details
#fetch(cn) ⇒ Object
30 31 32 33 34 |
# File 'lib/certmeister/pg/store.rb', line 30 def fetch(cn) if cert = @certificates[cn: cn] cert[:pem] end end |
#health_check ⇒ Object
41 42 43 |
# File 'lib/certmeister/pg/store.rb', line 41 def health_check @healthy end |
#remove(cn) ⇒ Object
36 37 38 39 |
# File 'lib/certmeister/pg/store.rb', line 36 def remove(cn) num_removed = @certificates.where('cn = ?', cn).delete num_removed == 1 end |
#store(cn, pem) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/certmeister/pg/store.rb', line 23 def store(cn, pem) now = Time.now if 1 != @certificates.where('cn = ?', cn).update(pem: pem, updated_at: now) @certificates.insert(cn: cn, pem: pem, created_at: now, updated_at: now) end end |