class Tipi::ACME::SQLiteCertificateStore

Attributes

db[R]

Public Class Methods

new(path) click to toggle source
# File lib/tipi/acme.rb, line 257
def initialize(path)
  require 'extralite'

  @db = Extralite::Database.new(path)
  @db.query("
    create table if not exists certificates (
      name primary key not null,
      private_key not null,
      certificate not null,
      expired_stamp not null
    );"
  )
end

Public Instance Methods

get(name) click to toggle source
# File lib/tipi/acme.rb, line 280
def get(name)
  remove_expired_certificates

  entry = @db.query_single_row("
    select name, private_key, certificate, expired_stamp
      from certificates
     where name = ?
  ", name)
  return nil unless entry
  entry[:expired_stamp] = Time.at(entry[:expired_stamp])
  entry[:private_key] = OpenSSL::PKey::RSA.new(entry[:private_key])
  entry
rescue Extralite::Error => e
  p error_in_get: e
  raise e
end
remove_expired_certificates() click to toggle source
# File lib/tipi/acme.rb, line 297
def remove_expired_certificates
  @db.query("
    delete from certificates
    where expired_stamp < ?
  ", Time.now.to_i)
rescue Extralite::Error => e
  p error_in_remove_expired_certificates: e
  raise e
end
set(name, private_key:, certificate:, expired_stamp:) click to toggle source
# File lib/tipi/acme.rb, line 271
def set(name, private_key:, certificate:, expired_stamp:)
  @db.query("
    insert into certificates values (?, ?, ?, ?)
  ", name, private_key.to_s, certificate, expired_stamp.to_i)
rescue Extralite::Error => e
  p error_in_set: e
  raise e
end