Skip to content

Commit

Permalink
agentless API accepts compressed response when calling Datadog API
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed May 2, 2024
1 parent c595521 commit df98b34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/datadog/ci/transport/api/agentless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ def citestcycle_request(path:, payload:, headers: {}, verb: "post")
def api_request(path:, payload:, headers: {}, verb: "post")
super

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

def citestcov_request(path:, payload:, headers: {}, verb: "post")
Expand All @@ -37,12 +44,13 @@ def citestcov_request(path:, payload:, headers: {}, verb: "post")

private

def perform_request(http_client, path:, payload:, headers:, verb:)
def perform_request(http_client, path:, payload:, headers:, verb:, accept_compressed_response: false)
http_client.request(
path: path,
payload: payload,
headers: headers_with_default(headers),
verb: verb
verb: verb,
accept_compressed_response: accept_compressed_response
)
end

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/transport/api/agentless.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Datadog

private

def perform_request: (Datadog::CI::Transport::HTTP client, path: String, payload: String, headers: Hash[String, String], verb: ::String) -> Datadog::CI::Transport::HTTP::ResponseDecorator
def perform_request: (Datadog::CI::Transport::HTTP client, path: String, payload: String, headers: Hash[String, String], verb: ::String, ?accept_compressed_response: bool) -> Datadog::CI::Transport::HTTP::ResponseDecorator

def build_http_client: (String url, compress: bool) -> Datadog::CI::Transport::HTTP

Expand Down
13 changes: 9 additions & 4 deletions spec/datadog/ci/transport/api/agentless_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
path: "path",
payload: "payload",
verb: "post",
headers: expected_headers
headers: expected_headers,
accept_compressed_response: false
)

subject.citestcycle_request(path: "path", payload: "payload")
Expand Down Expand Up @@ -120,7 +121,8 @@
path: "path",
payload: "payload",
verb: "post",
headers: expected_headers
headers: expected_headers,
accept_compressed_response: false
)

subject.citestcycle_request(path: "path", payload: "payload")
Expand All @@ -131,7 +133,8 @@
path: "path",
payload: "payload",
verb: "post",
headers: expected_headers.merge({"Content-Type" => "application/json"})
headers: expected_headers.merge({"Content-Type" => "application/json"}),
accept_compressed_response: false
)

subject.citestcycle_request(path: "path", payload: "payload", headers: {"Content-Type" => "application/json"})
Expand All @@ -154,7 +157,8 @@
headers: {
"DD-API-KEY" => "api_key",
"Content-Type" => "application/json"
}
},
accept_compressed_response: true
)

subject.api_request(path: "path", payload: "payload")
Expand Down Expand Up @@ -199,6 +203,7 @@
expect(args[:verb]).to eq("post")
expect(args[:headers]).to eq(expected_headers)
expect(args[:payload]).to eq(expected_payload)
expect(args[:accept_compressed_response]).to eq(false)
end
end
end
Expand Down

0 comments on commit df98b34

Please sign in to comment.