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: letsencrypt_webfaction [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::ListField.new(:domains, 'Comma separated list of domains. The first one will be the common name.', [ArrayValidator.new]),
  Field::ListField.new(:public, 'Locations on the filesystem served by the desired sites (e.g. "~/webapps/myapp/public_html,~/webapps/myapp1/public_html")', [ArrayValidator.new]),
  Field.new(:output_dir, 'Location on the filesystem to which the certs will be saved.', [StringValidator.new]),
  Field.new(:letsencrypt_account_email, 'The email address associated with your account.', [StringValidator.new]),
  Field.new(:api_url, 'The URL to the Webfaction API.', [StringValidator.new]),
  Field.new(:username, 'The username for your Webfaction account.', [StringValidator.new]),
  Field.new(:password, 'The password for your Webfaction account.', [StringValidator.new]),
  Field.new(:servername, 'The server on which this application resides (e.g. Web123).', [StringValidator.new]),
  Field.new(:cert_name, 'The name of the certificate in the Webfaction UI.', [StringValidator.new]),
  Field::BooleanField.new(:quiet, 'Whether to display text on success.', []),
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ArgsParser

Returns a new instance of ArgsParser.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 47

def initialize(options)
  @options = options

  @errors = {}

  # Set defaults from default config file.
  file_path = File.join(File.dirname(__FILE__), '../../', DEFAULTS_PATH)
  load_config!(File.expand_path(file_path))

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

Instance Attribute Details

#email_configurationObject (readonly)

EMail config is special, as it only comes from the config file, due to complexity.



45
46
47
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 45

def email_configuration
  @email_configuration
end

Instance Method Details

#errorsObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 60

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)


73
74
75
# File 'lib/letsencrypt_webfaction/args_parser.rb', line 73

def valid?
  errors.empty?
end