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/'
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
14 15 16 17 18 |
# File 'lib/letsencrypt_webfaction/options.rb', line 14 def initialize(args) @config = args # Fetch options # Validate options end |
Class Method Details
.default_config_path ⇒ Object
28 29 30 |
# File 'lib/letsencrypt_webfaction/options.rb', line 28 def self.default_config_path Pathname.new(Dir.home).join('.config', 'letsencrypt_webfaction') end |
.default_options_path ⇒ Object
24 25 26 |
# File 'lib/letsencrypt_webfaction/options.rb', line 24 def self. Pathname.new(Dir.home).join('letsencrypt_webfaction.toml') end |
.from_toml(path) ⇒ Object
20 21 22 |
# File 'lib/letsencrypt_webfaction/options.rb', line 20 def self.from_toml(path) new TomlRB.parse(path.read) end |
Instance Method Details
#api_url ⇒ Object
48 49 50 |
# File 'lib/letsencrypt_webfaction/options.rb', line 48 def api_url @config['api_url'] || WEBFACTION_API_URL end |
#certificates ⇒ Object
56 57 58 |
# File 'lib/letsencrypt_webfaction/options.rb', line 56 def certificates @_certs ||= @config['certificate'].map { |cert| Certificate.new(cert) } end |
#directory ⇒ Object
44 45 46 |
# File 'lib/letsencrypt_webfaction/options.rb', line 44 def directory @config['directory'] end |
#errors ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/letsencrypt_webfaction/options.rb', line 60 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
40 41 42 |
# File 'lib/letsencrypt_webfaction/options.rb', line 40 def letsencrypt_account_email @config['letsencrypt_account_email'] end |
#password ⇒ Object
36 37 38 |
# File 'lib/letsencrypt_webfaction/options.rb', line 36 def password @config['password'] end |
#servername ⇒ Object
52 53 54 |
# File 'lib/letsencrypt_webfaction/options.rb', line 52 def servername @config['servername'] || Socket.gethostname.split('.')[0].sub(/^./, &:upcase) end |
#username ⇒ Object
32 33 34 |
# File 'lib/letsencrypt_webfaction/options.rb', line 32 def username @config['username'] end |
#valid? ⇒ Boolean
71 72 73 |
# File 'lib/letsencrypt_webfaction/options.rb', line 71 def valid? errors.none? end |