Class: LetsencryptWebfaction::Options::Certificate

Inherits:
Object
  • Object
show all
Defined in:
lib/letsencrypt_webfaction/options/certificate.rb

Constant Summary collapse

SUPPORTED_VALIDATION_METHODS =
['http01'].freeze
VALID_CERT_NAME =
/[^a-zA-Z\d_]/.freeze
VALID_KEY_SIZES =
[2048, 4096].freeze

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Certificate

Returns a new instance of Certificate.



10
11
12
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 10

def initialize(args)
  @args = args
end

Instance Method Details

#cert_nameObject



30
31
32
33
34
35
36
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 30

def cert_name
  if @args['name'].nil? && domains.any?
    domains[0].gsub(VALID_CERT_NAME, '_')
  else
    @args['name']
  end
end

#domainsObject



14
15
16
17
18
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 14

def domains
  return [] if @args['domains'].nil? || @args['domains'] == ''

  Array(@args['domains'])
end

#errorsObject

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



42
43
44
45
46
47
48
49
50
51
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 42

def errors # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  {}.tap do |e|
    e[:domains] = "can't be empty" if domains.none?
    e[:method] = 'must be "http01"' unless SUPPORTED_VALIDATION_METHODS.include?(validation_method)
    e[:public] = "can't be empty" if public_dirs.none?
    e[:name] = "can't be blank" if cert_name.nil? || cert_name == ''
    e[:name] = 'can only include letters, numbers, and underscores' if VALID_CERT_NAME.match?(cert_name)
    e[:key_size] = "must be one of #{VALID_KEY_SIZES.join(', ')}" unless VALID_KEY_SIZES.include?(key_size)
  end
end

#key_sizeObject



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

def key_size
  @args['key_size'] || 4096
end

#public_dirsObject



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

def public_dirs
  return [] if @args['public'].nil? || @args['public'] == ''

  Array(@args['public'])
end

#validation_methodObject



20
21
22
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 20

def validation_method
  @args['method'] || 'http01'
end