Sha256: f9f5a0118b53274726631267bea77ae79ab9c01d5e9ce3f4949178fb6e173a20

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

module Brightbox
  module Config
    class ApiClient
      NON_BLANK_KEYS = %w[api_url client_id secret].freeze

      attr_accessor :selected_config, :client_name

      def initialize(incoming_config, client_name)
        @selected_config = incoming_config
        @client_name = client_name
      end

      def to_fog
        check_required_params
        {
          :provider => "Brightbox",
          :brightbox_api_url => selected_config["api_url"],
          :brightbox_auth_url => selected_config["auth_url"] || selected_config["api_url"],
          :brightbox_client_id => selected_config["client_id"],
          :brightbox_secret => selected_config["secret"],
          :persistent => persistent?
        }
      end

      def valid?
        NON_BLANK_KEYS.all? do |key|
          selected_config.key?(key) && !selected_config[key].to_s.empty?
        end
      end

      private

      def persistent?
        selected_config["persistent"] != "false"
      end

      def check_required_params
        return if valid?

        NON_BLANK_KEYS.each do |key|
          unless selected_config.key?(key) && !selected_config[key].to_s.empty?
            raise Brightbox::BBConfigError, "#{key} option missing from config in section #{client_name}"
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
brightbox-cli-4.8.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.7.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.6.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.5.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.5.0.rc1 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.4.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.3.2 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.3.1 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.3.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.2.1 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.2.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.1.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.0.0 lib/brightbox-cli/config/api_client.rb
brightbox-cli-4.0.0.rc2 lib/brightbox-cli/config/api_client.rb