Sha256: a516f22b93bce5b432a472ba46ddd98578f52abfb6fc25576d0bc95802144ab8
Contents?: true
Size: 1.57 KB
Versions: 6
Compression:
Stored size: 1.57 KB
Contents
require 'toml-rb' require 'socket' require 'letsencrypt_webfaction/options/certificate' module LetsencryptWebfaction class Options NON_BLANK_FIELDS = %i[username password letsencrypt_account_email endpoint api_url servername].freeze WEBFACTION_API_URL = 'https://api.webfaction.com/'.freeze def initialize(args) @config = args # Fetch options # Validate options end def self.from_toml(path) new TomlRB.parse(path.read) end def self.default_options_path Pathname.new(Dir.home).join('letsencrypt_webfaction.toml') end def self.default_config_path Pathname.new(Dir.home).join('.config', 'letsencrypt_webfaction') end def username @config['username'] end def password @config['password'] end def letsencrypt_account_email @config['letsencrypt_account_email'] end def endpoint @config['endpoint'] end def api_url @config['api_url'] || WEBFACTION_API_URL end def servername @config['servername'] || Socket.gethostname.split('.')[0].sub(/^./, &:upcase) end def certificates @_certs ||= @config['certificate'].map { |cert| Certificate.new(cert) } end def errors {}.tap do |e| 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 def valid? errors.none? end end end
Version data entries
6 entries across 6 versions & 1 rubygems