Sha256: 0597f9c947bc886a4c0cb9fe965356c5e33c083def734d085a06d66668451835

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

require 'yaml'

module Vcloud
  module Tools
    module Tester
      class UserParameters
        attr_reader :user_params

        def initialize(config_file, expected_params)
          @config_file = config_file
          @expected_params = expected_params || []

          parse_config
        end

        private

        def parse_config
          unless File.exist?(@config_file)
            raise ArgumentError.new("Missing required file: #{@config_file}")
          end

          organization = ENV.fetch('FOG_CREDENTIAL') do
            raise "Must set FOG_CREDENTIAL environment variable"
          end

          all_config = YAML::load_file(@config_file)

          @user_params = all_config.fetch(organization) do
            raise "No matching organisation was found in #{@config_file} for FOG_CREDENTIAL value '#{organization}'"
          end

          defined_keys = @user_params.keys
          missing_params = @expected_params - defined_keys
          if missing_params.any?
            raise "Required parameters not defined in #{@config_file}: " + missing_params.join(", ")
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vcloud-tools-tester-2.2.0 lib/vcloud/tools/tester/user_parameters.rb
vcloud-tools-tester-2.1.0 lib/vcloud/tools/tester/user_parameters.rb
vcloud-tools-tester-2.0.0 lib/vcloud/tools/tester/user_parameters.rb
vcloud-tools-tester-1.0.0 lib/vcloud/tools/tester/user_parameters.rb
vcloud-tools-tester-0.3.1 lib/vcloud/tools/tester/user_parameters.rb
vcloud-tools-tester-0.3.0 lib/vcloud/tools/tester/user_parameters.rb