-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
382552f
commit 96a7a56
Showing
8 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "base" | ||
require_relative "../http" | ||
|
||
module Datadog | ||
module CI | ||
module Transport | ||
module Api | ||
class EVPProxy < Base | ||
attr_reader :http | ||
|
||
def initialize(url:) | ||
uri = URI.parse(url) | ||
raise "Invalid evp proxy mode URL: #{url}" if uri.host.nil? | ||
|
||
@http = Datadog::CI::Transport::HTTP.new( | ||
host: uri.host, | ||
port: uri.port, | ||
ssl: uri.scheme == "https" || uri.port == 443, | ||
compress: false | ||
) | ||
end | ||
|
||
def request(path:, payload:, verb: "post") | ||
path = "#{Ext::Transport::EVP_PROXY_PATH_PREFIX}#{path}" | ||
|
||
http.request( | ||
path: path, | ||
payload: payload, | ||
verb: verb, | ||
headers: headers | ||
) | ||
end | ||
|
||
private | ||
|
||
def container_id | ||
return @container_id if defined?(@container_id) | ||
|
||
@container_id = Datadog::Core::Environment::Container.container_id | ||
end | ||
|
||
def headers | ||
headers = super | ||
headers[Ext::Transport::HEADER_EVP_SUBDOMAIN] = Ext::Transport::TEST_VISIBILITY_INTAKE_HOST_PREFIX | ||
|
||
c_id = container_id | ||
headers[Ext::Transport::HEADER_CONTAINER_ID] = c_id unless c_id.nil? | ||
|
||
headers | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Datadog | ||
module CI | ||
module Transport | ||
module Api | ||
class EVPProxy < Base | ||
@http: Datadog::CI::Transport::HTTP | ||
|
||
@container_id: String? | ||
|
||
attr_reader http: Datadog::CI::Transport::HTTP | ||
|
||
def initialize: (url: String) -> void | ||
|
||
def request: (path: String, payload: String, ?verb: ::String) -> Datadog::CI::Transport::HTTP::ResponseDecorator | ||
|
||
private | ||
|
||
def container_id: () -> String? | ||
|
||
def headers: () -> Hash[String, String] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require_relative "../../../../../lib/datadog/ci/transport/api/evp_proxy" | ||
|
||
RSpec.describe Datadog::CI::Transport::Api::EVPProxy do | ||
subject do | ||
described_class.new( | ||
url: url | ||
) | ||
end | ||
|
||
let(:url) { "http://localhost:5555" } | ||
|
||
let(:http) { double(:http) } | ||
|
||
describe "#initialize" do | ||
context "with https URL" do | ||
let(:url) { "https://citestcycle-intake.datad0ghq.com:443" } | ||
|
||
it "creates SSL transport" do | ||
expect(Datadog::CI::Transport::HTTP).to receive(:new).with( | ||
host: "citestcycle-intake.datad0ghq.com", | ||
port: 443, | ||
ssl: true, | ||
compress: false | ||
).and_return(http) | ||
|
||
subject | ||
end | ||
end | ||
|
||
context "with http URL" do | ||
it "creates http transport without SSL" do | ||
expect(Datadog::CI::Transport::HTTP).to receive(:new).with( | ||
host: "localhost", | ||
port: 5555, | ||
ssl: false, | ||
compress: false | ||
).and_return(http) | ||
|
||
subject | ||
end | ||
end | ||
end | ||
|
||
describe "#request" do | ||
before do | ||
allow(Datadog::CI::Transport::HTTP).to receive(:new).and_return(http) | ||
expect(Datadog::Core::Environment::Container).to receive(:container_id).and_return(container_id) | ||
end | ||
|
||
context "without container id" do | ||
let(:container_id) { nil } | ||
|
||
it "produces correct headers and forwards request to HTTP layer" do | ||
expect(http).to receive(:request).with( | ||
path: "/evp_proxy/v2/path", | ||
payload: "payload", | ||
verb: "post", | ||
headers: { | ||
"Content-Type" => "application/msgpack", | ||
"X-Datadog-EVP-Subdomain" => "citestcycle-intake" | ||
} | ||
) | ||
|
||
subject.request(path: "/path", payload: "payload") | ||
end | ||
end | ||
|
||
context "with container id" do | ||
let(:container_id) { "container-id" } | ||
|
||
it "produces correct headers and forwards request to HTTP layer" do | ||
expect(http).to receive(:request).with( | ||
path: "/evp_proxy/v2/path", | ||
payload: "payload", | ||
verb: "post", | ||
headers: { | ||
"Content-Type" => "application/msgpack", | ||
"X-Datadog-EVP-Subdomain" => "citestcycle-intake", | ||
"Datadog-Container-ID" => "container-id" | ||
} | ||
) | ||
|
||
subject.request(path: "/path", payload: "payload") | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
vendor/rbs/ddtrace/0/datadog/core/environment/container.rbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Datadog | ||
module Core | ||
module Environment | ||
module Container | ||
UUID_PATTERN: untyped | ||
|
||
CONTAINER_PATTERN: untyped | ||
|
||
PLATFORM_REGEX: untyped | ||
|
||
POD_REGEX: untyped | ||
|
||
CONTAINER_REGEX: untyped | ||
|
||
FARGATE_14_CONTAINER_REGEX: untyped | ||
|
||
Descriptor: untyped | ||
|
||
def self?.platform: () -> untyped | ||
|
||
def self?.container_id: () -> untyped | ||
|
||
def self?.task_uid: () -> untyped | ||
|
||
def self?.descriptor: () -> untyped | ||
end | ||
end | ||
end | ||
end |