Class: GitLab::SecretDetection::GRPC::Client

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize, SDLogger
Defined in:
lib/gitlab/secret_detection/grpc/client/grpc_client.rb

Constant Summary collapse

REQUEST_TIMEOUT_SECONDS =

Time to wait for the response from the service

10

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, included, normalize_key, #strong_memoize, #strong_memoize_with, #strong_memoize_with_expiration, #strong_memoized?

Constructor Details

#initialize(host, secure: false, compression: true) ⇒ Client

10 seconds



20
21
22
23
24
# File 'lib/gitlab/secret_detection/grpc/client/grpc_client.rb', line 20

def initialize(host, secure: false, compression: true)
  @host = host
  @secure = secure
  @compression = compression
end

Instance Method Details

#run_scan(request:, auth_token:, extra_headers: {}) ⇒ Object

Triggers Secret Detection service’s ‘/Scan` gRPC endpoint. To keep it consistent with SDS gem interface, this method transforms the gRPC response to GitLab::SecretDetection::Core::Response. Furthermore, any errors that are raised by the service will be translated to GitLab::SecretDetection::Core::Response type by assiging a appropriate status value to it.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/secret_detection/grpc/client/grpc_client.rb', line 30

def run_scan(request:, auth_token:, extra_headers: {})
  with_rescued_errors do
    grpc_response = stub.scan(
      request,
      metadata: (auth_token, extra_headers),
      deadline: request_deadline
    )

    convert_to_core_response(grpc_response)
  end
end

#run_scan_stream(requests:, auth_token:, extra_headers: {}) ⇒ Object

Triggers Secret Detection service’s ‘/ScanStream` gRPC endpoint.

To keep it consistent with SDS gem interface, this method transforms the gRPC response to GitLab::SecretDetection::Core::Response type. Furthermore, any errors that are raised by the service will be translated to GitLab::SecretDetection::Core::Response type by assiging a appropriate status value to it.

Note: If one of the stream requests result in an error, the stream will end immediately without processing the remaining requests.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gitlab/secret_detection/grpc/client/grpc_client.rb', line 50

def run_scan_stream(requests:, auth_token:, extra_headers: {})
  request_stream = GitLab::SecretDetection::GRPC::StreamRequestEnumerator.new(requests)
  results = []
  with_rescued_errors do
    stub.scan_stream(
      request_stream.each_item,
      metadata: (auth_token, extra_headers),
      deadline: request_deadline
    ).each do |grpc_response|
      response = convert_to_core_response(grpc_response)
      if block_given?
        yield response
      else
        results << response
      end
    end
    results
  end
end