Sha256: bfae103fd01148a70e397fc8c1af32e87cf1cf1639f27aac2fe884f7945d563e

Contents?: true

Size: 1.09 KB

Versions: 25

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module SdrClient
  # The connection to the server
  class Connection
    include Dry::Monads[:result]

    def initialize(url:, token: Credentials.read)
      @url = url
      @token = token
    end

    def connection
      @connection ||= Faraday.new(url: url) do |conn|
        conn.authorization :Bearer, token
        conn.adapter :net_http
      end
    end

    # This is only available to certain blessed accounts (argo) as it gives the
    # token that allows you to act as any other user. Thus the caller must authenticate
    # the user (e.g. using Shibboleth) before calling this method with their email address.
    # @param [String] the email address of the person to proxy to.
    # @return [Result] the token for the account
    def proxy(to)
      response = connection.post("/v1/auth/proxy?to=#{to}")
      case response.status
      when 200
        Success(response.body)
      else
        Failure("Status: #{response.status}\n#{response.body}")
      end
    end

    delegate :put, :post, :get, to: :connection

    private

    attr_reader :url, :token
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sdr-client-0.60.0 lib/sdr_client/connection.rb
sdr-client-0.59.0 lib/sdr_client/connection.rb
sdr-client-0.58.0 lib/sdr_client/connection.rb
sdr-client-0.57.0 lib/sdr_client/connection.rb
sdr-client-0.56.0 lib/sdr_client/connection.rb
sdr-client-0.55.1 lib/sdr_client/connection.rb
sdr-client-0.55.0 lib/sdr_client/connection.rb
sdr-client-0.54.0 lib/sdr_client/connection.rb
sdr-client-0.53.0 lib/sdr_client/connection.rb
sdr-client-0.52.0 lib/sdr_client/connection.rb
sdr-client-0.51.0 lib/sdr_client/connection.rb
sdr-client-0.51.0.beta.1 lib/sdr_client/connection.rb
sdr-client-0.50.0 lib/sdr_client/connection.rb
sdr-client-0.49.0 lib/sdr_client/connection.rb
sdr-client-0.48.0 lib/sdr_client/connection.rb
sdr-client-0.47.0 lib/sdr_client/connection.rb
sdr-client-0.46.0 lib/sdr_client/connection.rb
sdr-client-0.45.0 lib/sdr_client/connection.rb
sdr-client-0.44.0 lib/sdr_client/connection.rb
sdr-client-0.43.1 lib/sdr_client/connection.rb