Class: StatelyDB::Common::Auth::Interceptor

Inherits:
GRPC::ClientInterceptor
  • Object
show all
Defined in:
lib/common/auth/interceptor.rb

Overview

GRPC interceptor to authenticate against Stately and append bearer tokens to outgoing requests

Instance Method Summary collapse

Constructor Details

#initialize(token_provider:) ⇒ Interceptor

This must have been started already.

Parameters:



14
15
16
17
18
19
# File 'lib/common/auth/interceptor.rb', line 14

def initialize(
  token_provider:
)
  super()
  @token_provider = token_provider
end

Instance Method Details

#add_jwt_to_grpc_request(metadata:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Adds a JWT to the metadata hash

Parameters:

  • metadata (Hash)

    The metadata hash



77
78
79
# File 'lib/common/auth/interceptor.rb', line 77

def add_jwt_to_grpc_request(metadata:)
  ["authorization"] = "Bearer #{@token_provider.get_token}"
end

#bidi_streamer(requests:, call:, method:, metadata:) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC bidirectional streaming interceptor

Parameters:

  • requests (Enumerable)

    The list of requests

  • call (::GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Enumerator)

    The response enumerator



68
69
70
71
# File 'lib/common/auth/interceptor.rb', line 68

def bidi_streamer(requests:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end

#client_streamer(requests:, call:, method:, metadata:) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC client streaming interceptor

Parameters:

  • requests (Enumerable)

    The list of requests

  • call (::GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Enumerator)

    The response enumerator



42
43
44
45
# File 'lib/common/auth/interceptor.rb', line 42

def client_streamer(requests:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end

#request_response(request:, call:, method:, metadata:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC client unary interceptor

Parameters:

  • request (Object)

    The request object

  • call (::GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Object)

    The response object



29
30
31
32
# File 'lib/common/auth/interceptor.rb', line 29

def request_response(request:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end

#server_streamer(request:, call:, method:, metadata:) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

gRPC server streaming interceptor

Parameters:

  • request (Object)

    The request object

  • call (::GRPC::ActiveCall)

    The active call object

  • method (Symbol)

    The method being called

  • metadata (Hash)

    The metadata hash

Returns:

  • (Enumerator)

    The response enumerator



55
56
57
58
# File 'lib/common/auth/interceptor.rb', line 55

def server_streamer(request:, call:, method:, metadata:) # rubocop:disable Lint/UnusedMethodArgument
  add_jwt_to_grpc_request(metadata:)
  yield
end