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/'.freeze

Class Method Summary collapse

Instance Method Summary collapse

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_pathObject



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_pathObject



22
23
24
# File 'lib/letsencrypt_webfaction/options.rb', line 22

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



46
47
48
# File 'lib/letsencrypt_webfaction/options.rb', line 46

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

#certificatesObject



54
55
56
# File 'lib/letsencrypt_webfaction/options.rb', line 54

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

#directoryObject



42
43
44
# File 'lib/letsencrypt_webfaction/options.rb', line 42

def directory
  @config['directory']
end

#errorsObject



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_emailObject



38
39
40
# File 'lib/letsencrypt_webfaction/options.rb', line 38

def 
  @config['letsencrypt_account_email']
end

#passwordObject



34
35
36
# File 'lib/letsencrypt_webfaction/options.rb', line 34

def password
  @config['password']
end

#servernameObject



50
51
52
# File 'lib/letsencrypt_webfaction/options.rb', line 50

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

#usernameObject



30
31
32
# File 'lib/letsencrypt_webfaction/options.rb', line 30

def username
  @config['username']
end

#valid?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/letsencrypt_webfaction/options.rb', line 69

def valid?
  errors.none?
end