Class: LetsencryptWebfaction::Options
- Inherits:
-
Object
- Object
- LetsencryptWebfaction::Options
- Defined in:
- lib/letsencrypt_webfaction/options.rb,
lib/letsencrypt_webfaction/options/certificate.rb
Defined Under Namespace
Classes: Certificate
Constant Summary collapse
- NON_BLANK_FIELDS =
%i[username password letsencrypt_account_email directory api_url servername].freeze
- WEBFACTION_API_URL =
'https://api.webfaction.com/'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #api_url ⇒ Object
- #certificates ⇒ Object
- #directory ⇒ Object
- #errors ⇒ Object
-
#initialize(args) ⇒ Options
constructor
A new instance of Options.
- #letsencrypt_account_email ⇒ Object
- #password ⇒ Object
- #servername ⇒ Object
- #username ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ Options
Returns a new instance of Options.
12 13 14 15 16 |
# File 'lib/letsencrypt_webfaction/options.rb', line 12 def initialize(args) @config = args # Fetch options # Validate options end |
Class Method Details
.default_config_path ⇒ Object
26 27 28 |
# File 'lib/letsencrypt_webfaction/options.rb', line 26 def self.default_config_path Pathname.new(Dir.home).join('.config', 'letsencrypt_webfaction') end |
.default_options_path ⇒ Object
22 23 24 |
# File 'lib/letsencrypt_webfaction/options.rb', line 22 def self. Pathname.new(Dir.home).join('letsencrypt_webfaction.toml') end |
.from_toml(path) ⇒ Object
18 19 20 |
# File 'lib/letsencrypt_webfaction/options.rb', line 18 def self.from_toml(path) new TomlRB.parse(path.read) end |
Instance Method Details
#api_url ⇒ Object
46 47 48 |
# File 'lib/letsencrypt_webfaction/options.rb', line 46 def api_url @config['api_url'] || WEBFACTION_API_URL end |
#certificates ⇒ Object
54 55 56 |
# File 'lib/letsencrypt_webfaction/options.rb', line 54 def certificates @_certs ||= @config['certificate'].map { |cert| Certificate.new(cert) } end |
#directory ⇒ Object
42 43 44 |
# File 'lib/letsencrypt_webfaction/options.rb', line 42 def directory @config['directory'] end |
#errors ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/letsencrypt_webfaction/options.rb', line 58 def errors {}.tap do |e| e[:endpoint] = 'needs to be updated to directory. See upgrade documentation.' if @config.key?('endpoint') NON_BLANK_FIELDS.each do |field| e[field] = "can't be blank" if public_send(field).nil? || public_send(field) == '' end cert_errors = certificates.map(&:errors).reject(&:empty?) e[:certificate] = cert_errors if cert_errors.any? end end |
#letsencrypt_account_email ⇒ Object
38 39 40 |
# File 'lib/letsencrypt_webfaction/options.rb', line 38 def letsencrypt_account_email @config['letsencrypt_account_email'] end |
#password ⇒ Object
34 35 36 |
# File 'lib/letsencrypt_webfaction/options.rb', line 34 def password @config['password'] end |
#servername ⇒ Object
50 51 52 |
# File 'lib/letsencrypt_webfaction/options.rb', line 50 def servername @config['servername'] || Socket.gethostname.split('.')[0].sub(/^./, &:upcase) end |
#username ⇒ Object
30 31 32 |
# File 'lib/letsencrypt_webfaction/options.rb', line 30 def username @config['username'] end |
#valid? ⇒ Boolean
69 70 71 |
# File 'lib/letsencrypt_webfaction/options.rb', line 69 def valid? errors.none? end |