Sha256: e08009248436649a67b8828cda15e903c54fcceb7eb3b551e7fcfa5ea799dcf4

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Aserto
  module Directory
    module Interceptors
      class Headers < GRPC::ClientInterceptor
        def initialize(api_key, tenant_id)
          @api_key = api_key
          @tenant_id = tenant_id
          super()
        end

        def request_response(request: nil, call: nil, method: nil, metadata: nil)
          update_metadata(metadata)
          yield(request, call, method, metadata)
        end

        def bidi_streamer(requests: nil, call: nil, method: nil, metadata: nil)
          update_metadata(metadata)
          yield(requests, call, method, metadata)
        end

        def client_streamer(requests: nil, call: nil, method: nil, metadata: nil)
          update_metadata(metadata)
          yield(requests, call, method, metadata)
        end

        def server_streamer(request: nil, call: nil, method: nil, metadata: nil)
          update_metadata(metadata)
          yield(request, call, method, metadata)
        end

        private

        def update_metadata(metadata)
          metadata["aserto-tenant-id"] = @tenant_id
          metadata["authorization"] = @api_key
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
aserto-0.31.3 lib/aserto/directory/interceptors/headers.rb
aserto-0.31.2 lib/aserto/directory/interceptors/headers.rb
aserto-0.31.1 lib/aserto/directory/interceptors/headers.rb
aserto-0.31.0 lib/aserto/directory/interceptors/headers.rb
aserto-0.30.6 lib/aserto/directory/interceptors/headers.rb
aserto-0.30.5 lib/aserto/directory/interceptors/headers.rb
aserto-0.30.4 lib/aserto/directory/interceptors/headers.rb
aserto-0.30.1 lib/aserto/directory/interceptors/headers.rb
aserto-0.30.0 lib/aserto/directory/interceptors/headers.rb