Class: Datadog::CI::Transport::Api::Agentless

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/ci/transport/api/agentless.rb

Constant Summary collapse

AUTHENTICATION_ERROR_CODES =

HTTP status codes returned by the Datadog backend when a request is rejected for authentication/authorization reasons (typically because of a missing or invalid DD_API_KEY).

[401, 403].freeze
API_KEY_ERROR_PAYLOAD_MARKER =

Substring we look for in the response payload to confirm the rejection is API-key related rather than some other permission issue. Examples of payloads we want to match:

{"errors":[{"status":"403","title":"Forbidden","detail":"API key is missing"}]}
{"errors":[{"status":"403","title":"Forbidden","detail":"API key is invalid"}]}
"API key"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#headers_with_default

Constructor Details

#initialize(api_key:, citestcycle_url:, api_url:, citestcov_url:, logs_intake_url:, cicovreprt_url:) ⇒ Agentless

Returns a new instance of Agentless.



25
26
27
28
29
30
31
32
33
# File 'lib/datadog/ci/transport/api/agentless.rb', line 25

def initialize(api_key:, citestcycle_url:, api_url:, citestcov_url:, logs_intake_url:, cicovreprt_url:)
  @api_key = api_key
  @citestcycle_http = build_http_client(citestcycle_url, compress: true)
  @api_http = build_http_client(api_url, compress: false)
  @citestcov_http = build_http_client(citestcov_url, compress: true)
  @logs_intake_http = build_http_client(logs_intake_url, compress: true)
  @cicovreprt_http = build_http_client(cicovreprt_url, compress: false)
  @api_key_error_logged = false
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/datadog/ci/transport/api/agentless.rb', line 11

def api_key
  @api_key
end

Instance Method Details

#api_request(path:, payload:, headers: {}, verb: "post") ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/datadog/ci/transport/api/agentless.rb', line 41

def api_request(path:, payload:, headers: {}, verb: "post")
  super

  perform_request(
    @api_http,
    path: path,
    payload: payload,
    headers: headers,
    verb: verb,
    accept_compressed_response: true
  )
end

#cicovreprt_request(path:, event_payload:, compressed_coverage_report:, headers: {}, verb: "post") ⇒ Object



66
67
68
69
70
# File 'lib/datadog/ci/transport/api/agentless.rb', line 66

def cicovreprt_request(path:, event_payload:, compressed_coverage_report:, headers: {}, verb: "post")
  super

  perform_request(@cicovreprt_http, path: path, payload: @cicovreprt_payload, headers: headers, verb: verb)
end

#citestcov_request(path:, payload:, headers: {}, verb: "post") ⇒ Object



54
55
56
57
58
# File 'lib/datadog/ci/transport/api/agentless.rb', line 54

def citestcov_request(path:, payload:, headers: {}, verb: "post")
  super

  perform_request(@citestcov_http, path: path, payload: @citestcov_payload, headers: headers, verb: verb)
end

#citestcycle_request(path:, payload:, headers: {}, verb: "post") ⇒ Object



35
36
37
38
39
# File 'lib/datadog/ci/transport/api/agentless.rb', line 35

def citestcycle_request(path:, payload:, headers: {}, verb: "post")
  super

  perform_request(@citestcycle_http, path: path, payload: payload, headers: headers, verb: verb)
end

#logs_intake_request(path:, payload:, headers: {}, verb: "post") ⇒ Object



60
61
62
63
64
# File 'lib/datadog/ci/transport/api/agentless.rb', line 60

def logs_intake_request(path:, payload:, headers: {}, verb: "post")
  super

  perform_request(@logs_intake_http, path: path, payload: payload, headers: headers, verb: verb)
end