Class: LECLI::CertificateBuilder
- Inherits:
-
Object
- Object
- LECLI::CertificateBuilder
- Defined in:
- lib/lecli/certificate_builder.rb
Overview
Helper class to generate certs and access the default options
Constant Summary collapse
- YAML_FILENAME =
'lecli.yml'.freeze
Instance Attribute Summary collapse
-
#production ⇒ Object
Returns the value of attribute production.
Class Method Summary collapse
- .load_options(config_file:) ⇒ Object
- .persist_defaults_file(override:) ⇒ Object
- .required_options ⇒ Object
- .runtime_defaults ⇒ Object
- .sample_options ⇒ Object
Instance Method Summary collapse
- #generate_certs(options) ⇒ Object
-
#initialize {|_self| ... } ⇒ CertificateBuilder
constructor
A new instance of CertificateBuilder.
Constructor Details
#initialize {|_self| ... } ⇒ CertificateBuilder
Returns a new instance of CertificateBuilder.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lecli/certificate_builder.rb', line 13 def initialize @challenges = [] @production = false # Pass a block to edit the new object for prod/staging or other options yield self if block_given? prod_url = 'https://acme-v02.api.letsencrypt.org/directory' staging_url = 'https://acme-staging-v02.api.letsencrypt.org/directory' @endpoint = @production ? prod_url : staging_url end |
Instance Attribute Details
#production ⇒ Object
Returns the value of attribute production.
9 10 11 |
# File 'lib/lecli/certificate_builder.rb', line 9 def production @production end |
Class Method Details
.load_options(config_file:) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/lecli/certificate_builder.rb', line 49 def self.(config_file:) opts = LECLI::CertificateBuilder.runtime_defaults opts.merge!(YAML.load_file(config_file)) if File.file?(config_file) = LECLI::CertificateBuilder. # Should return nil if all required options are not present opts if (opts.keys & ).count == .count end |
.persist_defaults_file(override:) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/lecli/certificate_builder.rb', line 58 def self.persist_defaults_file(override:) opts = LECLI::CertificateBuilder. if !File.file?(YAML_FILENAME) || override File.write(YAML_FILENAME, opts.to_yaml) puts YAML_FILENAME else puts "#{YAML_FILENAME} already exists. Try `lecli help yaml`" end end |
.required_options ⇒ Object
25 26 27 |
# File 'lib/lecli/certificate_builder.rb', line 25 def self. ['domains', 'common_name', 'account_email'] end |
.runtime_defaults ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/lecli/certificate_builder.rb', line 41 def self.runtime_defaults { 'request_key' => 'request.pem', 'certificate_key' => 'certificate.pem', 'challenges_relative_path' => 'challenges' } end |
.sample_options ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lecli/certificate_builder.rb', line 29 def self. { 'domains' => ['example.com', 'test.net'], 'common_name' => 'example.com', 'account_email' => '[email protected]', 'request_key' => 'request.pem', 'certificate_key' => 'certificate.pem', 'challenges_relative_path' => 'challenges', 'success_callback_script' => 'deploy.sh' } end |
Instance Method Details
#generate_certs(options) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/lecli/certificate_builder.rb', line 68 def generate_certs() success = true begin request_challenges(options: ) sleep(3) # We are unaware of challenge hosting, better give extra time request_challenge_validation request_key = finalize_order( domains: ['domains'], title: ['common_name'] ) write_certificate( cert: @order.certificate, relative_path: ['certificate_key'] ) write_certificate( cert: request_key, relative_path: ['request_key'] ) rescue Acme::Client::Error::RateLimited => e puts e. success = false end success end |