Class: Acmesmith::Storages::Filesystem
- Defined in:
- lib/acmesmith/storages/filesystem.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #get_account_key ⇒ Object
- #get_certificate(common_name, version: 'current') ⇒ Object
- #get_current_certificate_version(common_name) ⇒ Object
-
#initialize(path:) ⇒ Filesystem
constructor
A new instance of Filesystem.
- #list_certificate_versions(common_name) ⇒ Object
- #list_certificates ⇒ Object
- #put_account_key(key, passphrase = nil) ⇒ Object
- #put_certificate(cert, passphrase = nil, update_current: true) ⇒ Object
Constructor Details
#initialize(path:) ⇒ Filesystem
Returns a new instance of Filesystem.
10 11 12 |
# File 'lib/acmesmith/storages/filesystem.rb', line 10 def initialize(path:) @path = Pathname(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/acmesmith/storages/filesystem.rb', line 14 def path @path end |
Instance Method Details
#get_account_key ⇒ Object
16 17 18 19 |
# File 'lib/acmesmith/storages/filesystem.rb', line 16 def get_account_key raise NotExist.new("Account key doesn't exist") unless account_key_path.exist? AccountKey.new account_key_path.read end |
#get_certificate(common_name, version: 'current') ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/acmesmith/storages/filesystem.rb', line 39 def get_certificate(common_name, version: 'current') raise NotExist.new("Certificate for #{common_name.inspect} of #{version} version doesn't exist") unless certificate_base_path(common_name, version).exist? certificate = certificate_path(common_name, version).read chain = chain_path(common_name, version).read private_key = private_key_path(common_name, version).read Certificate.new(certificate, chain, private_key) end |
#get_current_certificate_version(common_name) ⇒ Object
55 56 57 |
# File 'lib/acmesmith/storages/filesystem.rb', line 55 def get_current_certificate_version(common_name) path.join('certs', common_name, 'current').readlink end |
#list_certificate_versions(common_name) ⇒ Object
51 52 53 |
# File 'lib/acmesmith/storages/filesystem.rb', line 51 def list_certificate_versions(common_name) Dir[path.join('certs', common_name, '*').to_s].map { |_| File.basename(_) }.reject { |_| _ == 'current' } end |
#list_certificates ⇒ Object
47 48 49 |
# File 'lib/acmesmith/storages/filesystem.rb', line 47 def list_certificates Dir[path.join('certs', '*').to_s].map { |_| File.basename(_) } end |
#put_account_key(key, passphrase = nil) ⇒ Object
21 22 23 24 |
# File 'lib/acmesmith/storages/filesystem.rb', line 21 def put_account_key(key, passphrase = nil) raise AlreadyExist if account_key_path.exist? File.write account_key_path.to_s, key.export(passphrase), 0, perm: 0600 end |
#put_certificate(cert, passphrase = nil, update_current: true) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acmesmith/storages/filesystem.rb', line 26 def put_certificate(cert, passphrase = nil, update_current: true) h = cert.export(passphrase) certificate_base_path(cert.common_name, cert.version).mkpath File.write certificate_path(cert.common_name, cert.version), "#{h[:certificate].rstrip}\n" File.write chain_path(cert.common_name, cert.version), "#{h[:chain].rstrip}\n" File.write fullchain_path(cert.common_name, cert.version), "#{h[:fullchain].rstrip}\n" File.write private_key_path(cert.common_name, cert.version), "#{h[:private_key].rstrip}\n", 0, perm: 0600 if update_current File.symlink(cert.version, certificate_base_path(cert.common_name, 'current.new')) File.rename(certificate_base_path(cert.common_name, 'current.new'), certificate_base_path(cert.common_name, 'current')) end end |