Sha256: adad04b436e58d27387da3ce1b98fabbdac46fff0b1055a92a6b5e85b39298c6

Contents?: true

Size: 1.09 KB

Versions: 27

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, to: :connection

    private

    attr_reader :url, :token
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
sdr-client-0.39.0 lib/sdr_client/connection.rb
sdr-client-0.38.0 lib/sdr_client/connection.rb
sdr-client-0.37.0 lib/sdr_client/connection.rb
sdr-client-0.36.0 lib/sdr_client/connection.rb
sdr-client-0.35.1 lib/sdr_client/connection.rb
sdr-client-0.35.0 lib/sdr_client/connection.rb
sdr-client-0.34.0 lib/sdr_client/connection.rb
sdr-client-0.33.0 lib/sdr_client/connection.rb
sdr-client-0.32.0 lib/sdr_client/connection.rb
sdr-client-0.31.0 lib/sdr_client/connection.rb
sdr-client-0.30.0 lib/sdr_client/connection.rb
sdr-client-0.29.0 lib/sdr_client/connection.rb
sdr-client-0.28.4 lib/sdr_client/connection.rb
sdr-client-0.28.3 lib/sdr_client/connection.rb
sdr-client-0.28.2 lib/sdr_client/connection.rb
sdr-client-0.28.1 lib/sdr_client/connection.rb
sdr-client-0.28.0 lib/sdr_client/connection.rb
sdr-client-0.27.0 lib/sdr_client/connection.rb
sdr-client-0.26.1 lib/sdr_client/connection.rb
sdr-client-0.26.0 lib/sdr_client/connection.rb