Class: LetsencryptWebfaction::Options

Inherits:
Object
  • Object
show all
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

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_pathObject



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_pathObject



24
25
26
# File 'lib/letsencrypt_webfaction/options.rb', line 24

def self.default_options_path
  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_urlObject



48
49
50
# File 'lib/letsencrypt_webfaction/options.rb', line 48

def api_url
  @config['api_url'] || WEBFACTION_API_URL
end

#certificatesObject



56
57
58
# File 'lib/letsencrypt_webfaction/options.rb', line 56

def certificates
  @_certs ||= @config['certificate'].map { |cert| Certificate.new(cert) }
end

#directoryObject



44
45
46
# File 'lib/letsencrypt_webfaction/options.rb', line 44

def directory
  @config['directory']
end

#errorsObject



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_emailObject



40
41
42
# File 'lib/letsencrypt_webfaction/options.rb', line 40

def 
  @config['letsencrypt_account_email']
end

#passwordObject



36
37
38
# File 'lib/letsencrypt_webfaction/options.rb', line 36

def password
  @config['password']
end

#servernameObject



52
53
54
# File 'lib/letsencrypt_webfaction/options.rb', line 52

def servername
  @config['servername'] || Socket.gethostname.split('.')[0].sub(/^./, &:upcase)
end

#usernameObject



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