Class: LetsencryptWebfaction::ArgsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/letsencrypt_webfaction/args_parser.rb,
lib/letsencrypt_webfaction/args_parser/field.rb,
lib/letsencrypt_webfaction/args_parser/array_validator.rb,
lib/letsencrypt_webfaction/args_parser/string_validator.rb,
lib/letsencrypt_webfaction/args_parser/defined_values_validator.rb

Defined Under Namespace

Classes: ArrayValidator, DefinedValuesValidator, Field, StringValidator

Constant Summary collapse

'Usage: get_cert [options]'.freeze
DEFAULTS_PATH =
'config.defaults.yml'.freeze
VALID_KEY_SIZES =
[2048, 4096].freeze
FIELDS =
[
  Field::IntegerField.new(:key_size, 'Size of private key (e.g. 4096)', [DefinedValuesValidator.new(VALID_KEY_SIZES)]),
  Field.new(:endpoint, 'ACME endpoint (e.g. https://acme-v01.api.letsencrypt.org/)', [StringValidator.new]),
  Field.new(:contact, 'Email address to notify on renewal', [StringValidator.new]),
  Field::ListField.new(:domains, 'Comma separated list of domains. The first one will be the common name.', [ArrayValidator.new]),
  Field.new(:public, 'Location on the filesystem served by the desired site (e.g. ~/webapps/myapp/public_html)', [StringValidator.new]),
  Field.new(:output_dir, 'Location on the filesystem to which the certs will be saved.', [StringValidator.new])
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ArgsParser

Returns a new instance of ArgsParser.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 29

def initialize(options)
  @options = options

  @errors = {}

  # Set defaults from default config file.
  load_config!(DEFAULTS_PATH)

  # TODO: Rework this to not exit on instantiation due to help text.
  parse!
end

Instance Method Details

#errorsObject



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

def errors
  errors = {}

  FIELDS.each do |field|
    val = instance_variable_get("@#{field.identifier}")
    next if field.valid? val
    errors[field.identifier] ||= []
    errors[field.identifier] << "Invalid #{field.identifier} '#{val}'"
  end

  errors
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  errors.empty?
end