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.



8
9
10
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 8

def initialize(args)
  @args = args
end

Instance Method Details

#cert_nameObject



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

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

#domainsObject



12
13
14
15
16
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 12

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

  Array(@args['domains'])
end

#errorsObject

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



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

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 cert_name =~ VALID_CERT_NAME
    e[:key_size] = "must be one of #{VALID_KEY_SIZES.join(', ')}" unless VALID_KEY_SIZES.include?(key_size)
  end
end

#key_sizeObject



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

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

#public_dirsObject



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

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

  Array(@args['public'])
end

#validation_methodObject



18
19
20
# File 'lib/letsencrypt_webfaction/options/certificate.rb', line 18

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