Sha256: 2006995dcfba7ee130fd7ffad06c8208ac0f50f58241a72e4fec29f8e0a07e0d

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require 'faraday'

module CloudAlly
  # @private
  module Connection
    private

    def connection
      options = {
        :headers => {
          'Accept' => "application/#{format}; charset=utf-8",
          'User-Agent' => user_agent
        },
        :url => endpoint
      }.merge(connection_options)

      Faraday::Connection.new(options) do |connection|
        connection.use Faraday::Response::RaiseError
        connection.adapter Faraday.default_adapter

        connection.authorization :Bearer, access_token if access_token
        connection.headers['client-id'] = client_id
        connection.headers['client-secret'] = client_secret
        connection.response :json, :content_type => /\bjson$/
        connection.use Faraday::Request::UrlEncoded

        if logger
          connection.response :logger, logger, { headers: true, bodies: true } do |l|
            # filter json content
            l.filter(/(\"password\"\:\")(.+?)(\".*)/, '\1[REMOVED]\3')
            l.filter(/(\"accessToken\"\:\")(.+?)(\".*)/, '\1[REMOVED]\3')
            # filter header content
            l.filter(/(client-secret\:.)([^&]+)/, '\1[REMOVED]')
            l.filter(/(Authorization\:.)([^&]+)/, '\1[REMOVED]')
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloudally-0.1.1 lib/cloudally/connection.rb