Module: Model::AcmeAccount

Extended by:
ActiveSupport::Concern
Included in:
Com::AcmeAccount
Defined in:
app/models/com/model/acme_account.rb

Instance Method Summary collapse

Instance Method Details

#accountObject



64
65
66
67
# File 'app/models/com/model/acme_account.rb', line 64

def 
  return @account if defined? @account
  @account = client.(contact: contact, terms_of_service_agreed: true)
end

#clientObject



46
47
48
49
50
51
52
53
54
# File 'app/models/com/model/acme_account.rb', line 46

def client
  return @client if defined? @client

  if self.kid
    @client = Acme::Client.new(private_key: private_key, directory: directory, kid: kid)
  else
    @client = Acme::Client.new(private_key: private_key, directory: directory)
  end
end

#contactObject



60
61
62
# File 'app/models/com/model/acme_account.rb', line 60

def contact
  "mailto:#{email}"
end

#directoryObject



56
57
58
# File 'app/models/com/model/acme_account.rb', line 56

def directory
  RailsCom.config.acme_url
end

#generate_accountObject



32
33
34
35
# File 'app/models/com/model/acme_account.rb', line 32

def 
  store_private_pem unless private_pem_blob
  self.update(kid: .kid)
end

#private_keyObject



23
24
25
26
27
28
29
30
# File 'app/models/com/model/acme_account.rb', line 23

def private_key
  return @private_key if defined? @private_key
  if private_pem_blob
    @private_key = OpenSSL::PKey::RSA.new(private_pem_blob.download)
  else
    @private_key = OpenSSL::PKey::RSA.new(4096)
  end
end

#store_private_pemObject



37
38
39
40
41
42
43
44
# File 'app/models/com/model/acme_account.rb', line 37

def store_private_pem
  Tempfile.open do |file|
    file.binmode
    file.write private_key.to_pem
    file.rewind
    self.private_pem.attach io: file, filename: "#{email}.pem"
  end
end