Class: Gitlab::SecretDetection::GRPC::Client
- Inherits:
-
Object
- Object
- Gitlab::SecretDetection::GRPC::Client
- 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
-
#initialize(host, secure: false, compression: true, logger: nil) ⇒ Client
constructor
10 seconds.
-
#run_scan(request:, auth_token:, extra_headers: {}) ⇒ Object
Triggers Secret Detection service’s ‘/Scan` gRPC endpoint.
-
#run_scan_stream(requests:, auth_token:, extra_headers: {}) ⇒ Object
Triggers Secret Detection service’s ‘/ScanStream` gRPC endpoint.
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, logger: nil) ⇒ Client
10 seconds
20 21 22 23 24 25 |
# File 'lib/gitlab/secret_detection/grpc/client/grpc_client.rb', line 20 def initialize(host, secure: false, compression: true, logger: nil) @host = host @secure = secure @compression = compression @logger = logger.nil? ? LOGGER : logger 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.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab/secret_detection/grpc/client/grpc_client.rb', line 31 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gitlab/secret_detection/grpc/client/grpc_client.rb', line 51 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 |