kafo 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kafo/configuration.rb +9 -1
- data/lib/kafo/kafo_configure.rb +2 -1
- data/lib/kafo/param.rb +28 -21
- data/lib/kafo/validator.rb +19 -10
- data/lib/kafo/version.rb +1 -1
- data/lib/kafo/wizard.rb +3 -0
- metadata +2 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 831fee1d8773e349d7967d6b8e2197cb017d30b0
         | 
| 4 | 
            +
              data.tar.gz: 46c3bc4a21f25b8d8f5f70c18d6d3730dd22f10d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e5aa20ffadf4cbf9f0942bab11aa7382611b07b3150de7887caa0a3d16f25aa86cdb5431c4598c63370c6788d6d0cb6ece3ed965fbc1d040a2872539b598629d
         | 
| 7 | 
            +
              data.tar.gz: cec32896880413196709850e0480b72f26c3807f07a7a1bea0794ddf590f3d617bb38de2c9757a961dcd5e64cc7d028058b48aa9d9a33a164733da36edeb3e64
         | 
    
        data/lib/kafo/configuration.rb
    CHANGED
    
    | @@ -229,8 +229,16 @@ module Kafo | |
| 229 229 | 
             
                  File.join(app[:log_dir], app[:log_name])
         | 
| 230 230 | 
             
                end
         | 
| 231 231 |  | 
| 232 | 
            +
                def log_files_pattern
         | 
| 233 | 
            +
                  log_file.sub(/(\.log)\Z/i) { |suffix| "{.[0-9]*,}#{suffix}" }
         | 
| 234 | 
            +
                end
         | 
| 235 | 
            +
             | 
| 236 | 
            +
                def log_files
         | 
| 237 | 
            +
                  Dir.glob(log_files_pattern)
         | 
| 238 | 
            +
                end
         | 
| 239 | 
            +
             | 
| 232 240 | 
             
                def log_exists?
         | 
| 233 | 
            -
                   | 
| 241 | 
            +
                  log_files.any? { |f| File.size(f) > 0 }
         | 
| 234 242 | 
             
                end
         | 
| 235 243 |  | 
| 236 244 | 
             
                def answers
         | 
    
        data/lib/kafo/kafo_configure.rb
    CHANGED
    
    | @@ -370,7 +370,8 @@ module Kafo | |
| 370 370 | 
             
                  logger.info 'Running validation checks'
         | 
| 371 371 | 
             
                  results = params.map do |param|
         | 
| 372 372 | 
             
                    result = param.valid?
         | 
| 373 | 
            -
                     | 
| 373 | 
            +
                    errors = param.validation_errors.join(', ')
         | 
| 374 | 
            +
                    progress_log(:error, "Parameter #{with_prefix(param)} invalid: #{errors}") if logging && !result
         | 
| 374 375 | 
             
                    result
         | 
| 375 376 | 
             
                  end
         | 
| 376 377 | 
             
                  results.all?
         | 
    
        data/lib/kafo/param.rb
    CHANGED
    
    | @@ -48,25 +48,23 @@ module Kafo | |
| 48 48 | 
             
                  if default == 'UNSET'
         | 
| 49 49 | 
             
                    self.default = nil
         | 
| 50 50 | 
             
                  else
         | 
| 51 | 
            -
                    if  | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                         | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
                         | 
| 65 | 
            -
             | 
| 66 | 
            -
                       | 
| 67 | 
            -
             | 
| 68 | 
            -
                      # or without using a params class), the existing default value from the manifest will
         | 
| 69 | 
            -
                      # be used. On calling #value, the default will be returned if no overriding value is set.
         | 
| 51 | 
            +
                    # if we don't have default value from dump (can happen for modules added from hooks,
         | 
| 52 | 
            +
                    # or without using a params class), the existing default value from the manifest will
         | 
| 53 | 
            +
                    # be used. On calling #value, the default will be returned if no overriding value is set.
         | 
| 54 | 
            +
                    value = defaults.has_key?(default) ? defaults[default] : default
         | 
| 55 | 
            +
                    case value
         | 
| 56 | 
            +
                      when :undef
         | 
| 57 | 
            +
                        # value can be set to :undef if value is not defined
         | 
| 58 | 
            +
                        # (e.g. puppetmaster = $::puppetmaster which is not defined yet)
         | 
| 59 | 
            +
                        self.default = nil
         | 
| 60 | 
            +
                      when :undefined
         | 
| 61 | 
            +
                        # in puppet 2.7 :undefined means that it's param which value is
         | 
| 62 | 
            +
                        # not set by another parameter (e.g. foreman_group = 'something')
         | 
| 63 | 
            +
                        # which means, default is sensible unlike dumped default
         | 
| 64 | 
            +
                        # newer puppet has default dump in format 'value' => 'value' so
         | 
| 65 | 
            +
                        # it's handled correctly by else branch
         | 
| 66 | 
            +
                      else
         | 
| 67 | 
            +
                        self.default = value
         | 
| 70 68 | 
             
                    end
         | 
| 71 69 | 
             
                  end
         | 
| 72 70 | 
             
                end
         | 
| @@ -89,8 +87,17 @@ module Kafo | |
| 89 87 | 
             
                    {:name => v.name, :arguments => interpret_validation_args(args)}
         | 
| 90 88 | 
             
                  end
         | 
| 91 89 |  | 
| 92 | 
            -
                  validator = Validator.new
         | 
| 93 | 
            -
                  validations. | 
| 90 | 
            +
                  @validator = Validator.new
         | 
| 91 | 
            +
                  validations.each { |v| @validator.send(v[:name], v[:arguments]) }
         | 
| 92 | 
            +
                  @validator.errors.empty?
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                def validation_errors
         | 
| 96 | 
            +
                  if @validator
         | 
| 97 | 
            +
                    @validator.errors
         | 
| 98 | 
            +
                  else
         | 
| 99 | 
            +
                    []
         | 
| 100 | 
            +
                  end
         | 
| 94 101 | 
             
                end
         | 
| 95 102 |  | 
| 96 103 | 
             
                # To be overwritten in children
         | 
    
        data/lib/kafo/validator.rb
    CHANGED
    
    | @@ -1,15 +1,17 @@ | |
| 1 1 | 
             
            # encoding: UTF-8
         | 
| 2 2 | 
             
            module Kafo
         | 
| 3 3 | 
             
              class Validator
         | 
| 4 | 
            +
                attr_reader :errors
         | 
| 4 5 |  | 
| 5 6 | 
             
                def initialize
         | 
| 7 | 
            +
                  @errors = []
         | 
| 6 8 | 
             
                  @logger = KafoConfigure.logger
         | 
| 7 9 | 
             
                end
         | 
| 8 10 |  | 
| 9 11 | 
             
                def validate_absolute_path(args)
         | 
| 10 12 | 
             
                  args.each do |arg|
         | 
| 11 13 | 
             
                    unless arg.to_s.start_with?('/')
         | 
| 12 | 
            -
                       | 
| 14 | 
            +
                      error "#{arg.inspect} is not an absolute path"
         | 
| 13 15 | 
             
                      return false
         | 
| 14 16 | 
             
                    end
         | 
| 15 17 | 
             
                  end
         | 
| @@ -19,7 +21,7 @@ module Kafo | |
| 19 21 | 
             
                def validate_array(args)
         | 
| 20 22 | 
             
                  args.each do |arg|
         | 
| 21 23 | 
             
                    unless arg.is_a?(Array)
         | 
| 22 | 
            -
                       | 
| 24 | 
            +
                      error "#{arg.inspect} is not a valid array"
         | 
| 23 25 | 
             
                      return false
         | 
| 24 26 | 
             
                    end
         | 
| 25 27 | 
             
                  end
         | 
| @@ -29,7 +31,7 @@ module Kafo | |
| 29 31 | 
             
                def validate_bool(args)
         | 
| 30 32 | 
             
                  args.each do |arg|
         | 
| 31 33 | 
             
                    unless arg.is_a?(TrueClass) || arg.is_a?(FalseClass)
         | 
| 32 | 
            -
                       | 
| 34 | 
            +
                      error "#{arg.inspect} is not a valid boolean"
         | 
| 33 35 | 
             
                      return false
         | 
| 34 36 | 
             
                    end
         | 
| 35 37 | 
             
                  end
         | 
| @@ -39,7 +41,7 @@ module Kafo | |
| 39 41 | 
             
                def validate_hash(args)
         | 
| 40 42 | 
             
                  args.each do |arg|
         | 
| 41 43 | 
             
                    unless arg.is_a?(Hash)
         | 
| 42 | 
            -
                       | 
| 44 | 
            +
                      error "#{arg.inspect} is not a valid hash"
         | 
| 43 45 | 
             
                      return false
         | 
| 44 46 | 
             
                    end
         | 
| 45 47 | 
             
                  end
         | 
| @@ -52,16 +54,16 @@ module Kafo | |
| 52 54 | 
             
                  min = args[2]
         | 
| 53 55 | 
             
                  int = Integer(value.to_s)
         | 
| 54 56 | 
             
                  if min && int < min.to_i
         | 
| 55 | 
            -
                     | 
| 57 | 
            +
                    error "#{value} must be at least #{min}"
         | 
| 56 58 | 
             
                    return false
         | 
| 57 59 | 
             
                  end
         | 
| 58 60 | 
             
                  if max && int > max.to_i
         | 
| 59 | 
            -
                     | 
| 61 | 
            +
                    error "#{value} must be less than #{max}"
         | 
| 60 62 | 
             
                    return false
         | 
| 61 63 | 
             
                  end
         | 
| 62 64 | 
             
                  return true
         | 
| 63 65 | 
             
                rescue TypeError, ArgumentError
         | 
| 64 | 
            -
                   | 
| 66 | 
            +
                  error "#{value.inspect} is not a valid integer"
         | 
| 65 67 | 
             
                  return false
         | 
| 66 68 | 
             
                end
         | 
| 67 69 |  | 
| @@ -70,7 +72,7 @@ module Kafo | |
| 70 72 | 
             
                  valid_values = ['http', 'https', 'both']
         | 
| 71 73 | 
             
                  args.each do |arg|
         | 
| 72 74 | 
             
                    unless valid_values.include?(arg)
         | 
| 73 | 
            -
                       | 
| 75 | 
            +
                      error "#{arg.inspect} is not a valid value.  Valid values are: #{valid_values.join(", ")}"
         | 
| 74 76 | 
             
                      return false
         | 
| 75 77 | 
             
                    end
         | 
| 76 78 | 
             
                  end
         | 
| @@ -86,7 +88,7 @@ module Kafo | |
| 86 88 | 
             
                  if regexes.any? { |rx| value =~ Regexp.compile(rx) }
         | 
| 87 89 | 
             
                    return true
         | 
| 88 90 | 
             
                  else
         | 
| 89 | 
            -
                     | 
| 91 | 
            +
                    error message
         | 
| 90 92 | 
             
                    return false
         | 
| 91 93 | 
             
                  end
         | 
| 92 94 | 
             
                end
         | 
| @@ -94,7 +96,7 @@ module Kafo | |
| 94 96 | 
             
                def validate_string(args)
         | 
| 95 97 | 
             
                  args.each do |arg|
         | 
| 96 98 | 
             
                    unless arg.is_a?(String)
         | 
| 97 | 
            -
                       | 
| 99 | 
            +
                      error "#{arg.inspect} is not a valid string"
         | 
| 98 100 | 
             
                      return false
         | 
| 99 101 | 
             
                    end
         | 
| 100 102 | 
             
                  end
         | 
| @@ -109,5 +111,12 @@ module Kafo | |
| 109 111 | 
             
                    super
         | 
| 110 112 | 
             
                  end
         | 
| 111 113 | 
             
                end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                private
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                def error(message)
         | 
| 118 | 
            +
                  @errors << message
         | 
| 119 | 
            +
                  @logger.error "Validation error: #{message}"
         | 
| 120 | 
            +
                end
         | 
| 112 121 | 
             
              end
         | 
| 113 122 | 
             
            end
         | 
    
        data/lib/kafo/version.rb
    CHANGED
    
    
    
        data/lib/kafo/wizard.rb
    CHANGED
    
    | @@ -131,6 +131,9 @@ END | |
| 131 131 | 
             
                  until param.valid?
         | 
| 132 132 | 
             
                    param.value = value_was
         | 
| 133 133 | 
             
                    say "\n" + HighLine.color("Invalid value for #{param.name}", :important)
         | 
| 134 | 
            +
                    param.validation_errors.each do |error|
         | 
| 135 | 
            +
                      say "  " + HighLine.color(error, :important)
         | 
| 136 | 
            +
                    end
         | 
| 134 137 | 
             
                    value       = param.multivalued? ? configure_multi(param) : configure_single(param)
         | 
| 135 138 | 
             
                    param.value = value unless value.empty?
         | 
| 136 139 | 
             
                  end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kafo
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.9. | 
| 4 | 
            +
              version: 0.9.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marek Hulan
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-07-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -288,4 +288,3 @@ specification_version: 4 | |
| 288 288 | 
             
            summary: If you write puppet modules for installing your software, you can use kafo
         | 
| 289 289 | 
             
              to create powerful installer
         | 
| 290 290 | 
             
            test_files: []
         | 
| 291 | 
            -
            has_rdoc: 
         |