|  | @@ -32,6 +32,8 @@ require 'grpc/version'
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # GRPC contains the General RPC module.
 | 
	
		
			
				|  |  |  module GRPC
 | 
	
		
			
				|  |  | +  # rubocop:disable Metrics/ParameterLists
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    # ClientStub represents an endpoint used to send requests to GRPC servers.
 | 
	
		
			
				|  |  |    class ClientStub
 | 
	
		
			
				|  |  |      include Core::StatusCodes
 | 
	
	
		
			
				|  | @@ -68,6 +70,12 @@ module GRPC
 | 
	
		
			
				|  |  |        update_metadata
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    # Allows users of the stub to modify the propagate mask.
 | 
	
		
			
				|  |  | +    #
 | 
	
		
			
				|  |  | +    # This is an advanced feature for use when making calls to another gRPC
 | 
	
		
			
				|  |  | +    # server whilst running in the handler of an existing one.
 | 
	
		
			
				|  |  | +    attr_writer :propagate_mask
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      # Creates a new ClientStub.
 | 
	
		
			
				|  |  |      #
 | 
	
		
			
				|  |  |      # Minimally, a stub is created with the just the host of the gRPC service
 | 
	
	
		
			
				|  | @@ -91,8 +99,8 @@ module GRPC
 | 
	
		
			
				|  |  |      #
 | 
	
		
			
				|  |  |      # - :update_metadata
 | 
	
		
			
				|  |  |      # when present, this a func that takes a hash and returns a hash
 | 
	
		
			
				|  |  | -    # it can be used to update metadata, i.e, remove, change or update
 | 
	
		
			
				|  |  | -    # amend metadata values.
 | 
	
		
			
				|  |  | +    # it can be used to update metadata, i.e, remove, or amend
 | 
	
		
			
				|  |  | +    # metadata values.
 | 
	
		
			
				|  |  |      #
 | 
	
		
			
				|  |  |      # @param host [String] the host the stub connects to
 | 
	
		
			
				|  |  |      # @param q [Core::CompletionQueue] used to wait for events
 | 
	
	
		
			
				|  | @@ -105,6 +113,7 @@ module GRPC
 | 
	
		
			
				|  |  |                     channel_override: nil,
 | 
	
		
			
				|  |  |                     timeout: nil,
 | 
	
		
			
				|  |  |                     creds: nil,
 | 
	
		
			
				|  |  | +                   propagate_mask: nil,
 | 
	
		
			
				|  |  |                     update_metadata: nil,
 | 
	
		
			
				|  |  |                     **kw)
 | 
	
		
			
				|  |  |        fail(TypeError, '!CompletionQueue') unless q.is_a?(Core::CompletionQueue)
 | 
	
	
		
			
				|  | @@ -113,6 +122,7 @@ module GRPC
 | 
	
		
			
				|  |  |        @update_metadata = ClientStub.check_update_metadata(update_metadata)
 | 
	
		
			
				|  |  |        alt_host = kw[Core::Channel::SSL_TARGET]
 | 
	
		
			
				|  |  |        @host = alt_host.nil? ? host : alt_host
 | 
	
		
			
				|  |  | +      @propagate_mask = propagate_mask
 | 
	
		
			
				|  |  |        @timeout = timeout.nil? ? DEFAULT_TIMEOUT : timeout
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -151,11 +161,15 @@ module GRPC
 | 
	
		
			
				|  |  |      # @param marshal [Function] f(obj)->string that marshals requests
 | 
	
		
			
				|  |  |      # @param unmarshal [Function] f(string)->obj that unmarshals responses
 | 
	
		
			
				|  |  |      # @param timeout [Numeric] (optional) the max completion time in seconds
 | 
	
		
			
				|  |  | +    # @param parent [Core::Call] a prior call whose reserved metadata
 | 
	
		
			
				|  |  | +    #   will be propagated by this one.
 | 
	
		
			
				|  |  |      # @param return_op [true|false] return an Operation if true
 | 
	
		
			
				|  |  |      # @return [Object] the response received from the server
 | 
	
		
			
				|  |  |      def request_response(method, req, marshal, unmarshal, timeout = nil,
 | 
	
		
			
				|  |  | -                         return_op: false, **kw)
 | 
	
		
			
				|  |  | -      c = new_active_call(method, marshal, unmarshal, timeout)
 | 
	
		
			
				|  |  | +                         return_op: false,
 | 
	
		
			
				|  |  | +                         parent: parent,
 | 
	
		
			
				|  |  | +                         **kw)
 | 
	
		
			
				|  |  | +      c = new_active_call(method, marshal, unmarshal, timeout, parent: parent)
 | 
	
		
			
				|  |  |        kw_with_jwt_uri = self.class.update_with_jwt_aud_uri(kw, @host, method)
 | 
	
		
			
				|  |  |        md = @update_metadata.nil? ? kw : @update_metadata.call(kw_with_jwt_uri)
 | 
	
		
			
				|  |  |        return c.request_response(req, **md) unless return_op
 | 
	
	
		
			
				|  | @@ -210,10 +224,14 @@ module GRPC
 | 
	
		
			
				|  |  |      # @param unmarshal [Function] f(string)->obj that unmarshals responses
 | 
	
		
			
				|  |  |      # @param timeout [Numeric] the max completion time in seconds
 | 
	
		
			
				|  |  |      # @param return_op [true|false] return an Operation if true
 | 
	
		
			
				|  |  | +    # @param parent [Core::Call] a prior call whose reserved metadata
 | 
	
		
			
				|  |  | +    #   will be propagated by this one.
 | 
	
		
			
				|  |  |      # @return [Object|Operation] the response received from the server
 | 
	
		
			
				|  |  |      def client_streamer(method, requests, marshal, unmarshal, timeout = nil,
 | 
	
		
			
				|  |  | -                        return_op: false, **kw)
 | 
	
		
			
				|  |  | -      c = new_active_call(method, marshal, unmarshal, timeout)
 | 
	
		
			
				|  |  | +                        return_op: false,
 | 
	
		
			
				|  |  | +                        parent: nil,
 | 
	
		
			
				|  |  | +                        **kw)
 | 
	
		
			
				|  |  | +      c = new_active_call(method, marshal, unmarshal, timeout, parent: parent)
 | 
	
		
			
				|  |  |        kw_with_jwt_uri = self.class.update_with_jwt_aud_uri(kw, @host, method)
 | 
	
		
			
				|  |  |        md = @update_metadata.nil? ? kw : @update_metadata.call(kw_with_jwt_uri)
 | 
	
		
			
				|  |  |        return c.client_streamer(requests, **md) unless return_op
 | 
	
	
		
			
				|  | @@ -276,11 +294,16 @@ module GRPC
 | 
	
		
			
				|  |  |      # @param unmarshal [Function] f(string)->obj that unmarshals responses
 | 
	
		
			
				|  |  |      # @param timeout [Numeric] the max completion time in seconds
 | 
	
		
			
				|  |  |      # @param return_op [true|false]return an Operation if true
 | 
	
		
			
				|  |  | +    # @param parent [Core::Call] a prior call whose reserved metadata
 | 
	
		
			
				|  |  | +    #   will be propagated by this one.
 | 
	
		
			
				|  |  |      # @param blk [Block] when provided, is executed for each response
 | 
	
		
			
				|  |  |      # @return [Enumerator|Operation|nil] as discussed above
 | 
	
		
			
				|  |  |      def server_streamer(method, req, marshal, unmarshal, timeout = nil,
 | 
	
		
			
				|  |  | -                        return_op: false, **kw, &blk)
 | 
	
		
			
				|  |  | -      c = new_active_call(method, marshal, unmarshal, timeout)
 | 
	
		
			
				|  |  | +                        return_op: false,
 | 
	
		
			
				|  |  | +                        parent: nil,
 | 
	
		
			
				|  |  | +                        **kw,
 | 
	
		
			
				|  |  | +                        &blk)
 | 
	
		
			
				|  |  | +      c = new_active_call(method, marshal, unmarshal, timeout, parent: parent)
 | 
	
		
			
				|  |  |        kw_with_jwt_uri = self.class.update_with_jwt_aud_uri(kw, @host, method)
 | 
	
		
			
				|  |  |        md = @update_metadata.nil? ? kw : @update_metadata.call(kw_with_jwt_uri)
 | 
	
		
			
				|  |  |        return c.server_streamer(req, **md, &blk) unless return_op
 | 
	
	
		
			
				|  | @@ -381,12 +404,17 @@ module GRPC
 | 
	
		
			
				|  |  |      # @param marshal [Function] f(obj)->string that marshals requests
 | 
	
		
			
				|  |  |      # @param unmarshal [Function] f(string)->obj that unmarshals responses
 | 
	
		
			
				|  |  |      # @param timeout [Numeric] (optional) the max completion time in seconds
 | 
	
		
			
				|  |  | -    # @param blk [Block] when provided, is executed for each response
 | 
	
		
			
				|  |  | +    # @param parent [Core::Call] a prior call whose reserved metadata
 | 
	
		
			
				|  |  | +    #   will be propagated by this one.
 | 
	
		
			
				|  |  |      # @param return_op [true|false] return an Operation if true
 | 
	
		
			
				|  |  | +    # @param blk [Block] when provided, is executed for each response
 | 
	
		
			
				|  |  |      # @return [Enumerator|nil|Operation] as discussed above
 | 
	
		
			
				|  |  |      def bidi_streamer(method, requests, marshal, unmarshal, timeout = nil,
 | 
	
		
			
				|  |  | -                      return_op: false, **kw, &blk)
 | 
	
		
			
				|  |  | -      c = new_active_call(method, marshal, unmarshal, timeout)
 | 
	
		
			
				|  |  | +                      return_op: false,
 | 
	
		
			
				|  |  | +                      parent: nil,
 | 
	
		
			
				|  |  | +                      **kw,
 | 
	
		
			
				|  |  | +                      &blk)
 | 
	
		
			
				|  |  | +      c = new_active_call(method, marshal, unmarshal, timeout, parent: parent)
 | 
	
		
			
				|  |  |        kw_with_jwt_uri = self.class.update_with_jwt_aud_uri(kw, @host, method)
 | 
	
		
			
				|  |  |        md = @update_metadata.nil? ? kw : @update_metadata.call(kw_with_jwt_uri)
 | 
	
		
			
				|  |  |        return c.bidi_streamer(requests, **md, &blk) unless return_op
 | 
	
	
		
			
				|  | @@ -407,10 +435,17 @@ module GRPC
 | 
	
		
			
				|  |  |      # @param method [string] the method being called.
 | 
	
		
			
				|  |  |      # @param marshal [Function] f(obj)->string that marshals requests
 | 
	
		
			
				|  |  |      # @param unmarshal [Function] f(string)->obj that unmarshals responses
 | 
	
		
			
				|  |  | +    # @param parent [Grpc::Call] a parent call, available when calls are
 | 
	
		
			
				|  |  | +    #   made from server
 | 
	
		
			
				|  |  |      # @param timeout [TimeConst]
 | 
	
		
			
				|  |  | -    def new_active_call(method, marshal, unmarshal, timeout = nil)
 | 
	
		
			
				|  |  | +    def new_active_call(method, marshal, unmarshal, timeout = nil, parent: nil)
 | 
	
		
			
				|  |  |        deadline = from_relative_time(timeout.nil? ? @timeout : timeout)
 | 
	
		
			
				|  |  | -      call = @ch.create_call(@queue, method, nil, deadline)
 | 
	
		
			
				|  |  | +      call = @ch.create_call(@queue,
 | 
	
		
			
				|  |  | +                             parent, # parent call
 | 
	
		
			
				|  |  | +                             @propagate_mask, # propagation options
 | 
	
		
			
				|  |  | +                             method,
 | 
	
		
			
				|  |  | +                             nil, # host use nil,
 | 
	
		
			
				|  |  | +                             deadline)
 | 
	
		
			
				|  |  |        ActiveCall.new(call, @queue, marshal, unmarshal, deadline, started: false)
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |    end
 |