Sha256: 4f9c6c0d468c3231ef4fa86eeb9de9e053de7b23e13dc6f6b62ce926f01942d9

Contents?: true

Size: 1.13 KB

Versions: 28

Compression:

Stored size: 1.13 KB

Contents

module Brightbox
  class ConnectionManager
    def initialize(connection_options)
      @connection_options = connection_options
      @connection = nil
    end

    def fetch_connection(account_flag = false)
      if account_flag
        connection_with_account
      else
        @connection ||= create_connection
      end
    end

    private

    def connection_with_account
      if @connection
        @connection.scoped_account = Brightbox.config.account
        @connection
      else
        selected_account = Brightbox.config.account
        @connection = create_connection(:brightbox_account => selected_account)
      end
    end

    def connection_options
      merged_options = @connection_options.dup
      if @connection && @connection.refresh_token
        merged_options.update(:brightbox_refresh_token => @connection.refresh_token)
      end

      if @connection && @connection.access_token
        merged_options.update(:brightbox_access_token => @connection.access_token)
      end
      merged_options
    end

    def create_connection(options = {})
      Fog::Compute.new(connection_options.merge(options))
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
brightbox-cli-3.3.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-3.2.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-3.1.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-3.0.1 lib/brightbox-cli/connection_manager.rb
brightbox-cli-3.0.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.12.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.11.2 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.11.1 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.11.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.10.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.9.3 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.9.2 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.9.1 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.9.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.8.2 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.8.1 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.8.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.7.1 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.7.0 lib/brightbox-cli/connection_manager.rb
brightbox-cli-2.6.0 lib/brightbox-cli/connection_manager.rb