Class: NewRelic::Security::Agent::Control::GRPCContext

Inherits:
Object
  • Object
show all
Defined in:
lib/newrelic_security/agent/control/grpc_context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grpc_request) ⇒ GRPCContext

Returns a new instance of GRPCContext.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 13

def initialize(grpc_request)
  @time_stamp = current_time_millis
  @method = grpc_request[:method]
  @route = "/#{@method}"
  @headers = grpc_request[:headers]
  @body =  grpc_request[:body]
  if defined?(::GRPC::RpcServer)
    ObjectSpace.each_object(::GRPC::RpcServer) do |z|
      grpc_host = z.instance_variable_get(:@host_nr)
      grpc_port = z.instance_variable_get(:@port_nr)
      @server_name = "#{grpc_host}:#{grpc_port}"
      @server_port = grpc_port
      @client_ip = grpc_request[:peer].rpartition(COLON)[0] if grpc_request[:peer]
      @client_port = grpc_request[:peer].rpartition(COLON)[-1] if grpc_request[:peer]
      @url = "/#{@method}"
    end
  end
  @is_grpc = true
  @metadata = { :reflectedMetaData => { :isGrpcClientStream => grpc_request[:is_grpc_client_stream], :isGrpcServerStream => grpc_request[:is_grpc_server_stream] } }
  @cache = {}
  @fuzz_files = ::Set.new
  @event_counter = 0
  @mutex = Mutex.new
  NewRelic::Security::Agent.agent.http_request_count.increment
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def body
  @body
end

#cacheObject

Returns the value of attribute cache.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def cache
  @cache
end

#client_ipObject

Returns the value of attribute client_ip.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def client_ip
  @client_ip
end

#client_portObject

Returns the value of attribute client_port.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def client_port
  @client_port
end

#event_counterObject

Returns the value of attribute event_counter.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def event_counter
  @event_counter
end

#fuzz_filesObject

Returns the value of attribute fuzz_files.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def fuzz_files
  @fuzz_files
end

#headersObject

Returns the value of attribute headers.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def headers
  @headers
end

#is_grpcObject

Returns the value of attribute is_grpc.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def is_grpc
  @is_grpc
end

#metadataObject

Returns the value of attribute metadata.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def 
  @metadata
end

#methodObject

Returns the value of attribute method.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def method
  @method
end

#mutexObject

Returns the value of attribute mutex.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def mutex
  @mutex
end

#routeObject

Returns the value of attribute route.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def route
  @route
end

#server_nameObject

Returns the value of attribute server_name.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def server_name
  @server_name
end

#server_portObject

Returns the value of attribute server_port.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def server_port
  @server_port
end

#time_stampObject

Returns the value of attribute time_stamp.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def time_stamp
  @time_stamp
end

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 11

def url
  @url
end

Class Method Details

.get_contextObject



43
44
45
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 43

def self.get_context
  Thread.current[:security_context_data]
end

.reset_contextObject



51
52
53
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 51

def self.reset_context
  Thread.current[:security_context_data] = nil if Thread.current[:security_context_data]
end

.set_context(grpc_request) ⇒ Object



47
48
49
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 47

def self.set_context(grpc_request)
  Thread.current[:security_context_data] = GRPCContext.new(grpc_request)
end

Instance Method Details

#current_time_millisObject



39
40
41
# File 'lib/newrelic_security/agent/control/grpc_context.rb', line 39

def current_time_millis
  (Time.now.to_f * 1000).to_i
end