Skip to content

Commit

Permalink
EVPProxy initializer accepts parameters derived from AgentSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Oct 17, 2023
1 parent 96a7a56 commit c4322bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
10 changes: 10 additions & 0 deletions lib/datadog/ci/transport/api/builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative "ci_intake"
require_relative "evp_proxy"

module Datadog
module CI
Expand All @@ -14,6 +15,15 @@ def self.build_ci_test_cycle_api(settings)

CIIntake.new(api_key: settings.api_key, url: url)
end

def self.build_evp_proxy_api(agent_settings)
EVPProxy.new(
host: agent_settings.hostname,
port: agent_settings.port,
ssl: agent_settings.ssl,
timeout: agent_settings.timeout_seconds
)
end
end
end
end
Expand Down
12 changes: 5 additions & 7 deletions lib/datadog/ci/transport/api/evp_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ 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?

def initialize(host:, port:, ssl:, timeout:)
@http = Datadog::CI::Transport::HTTP.new(
host: uri.host,
port: uri.port,
ssl: uri.scheme == "https" || uri.port == 443,
host: host,
port: port,
ssl: ssl,
timeout: timeout,
compress: false
)
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/transport/api/evp_proxy.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Datadog

attr_reader http: Datadog::CI::Transport::HTTP

def initialize: (url: String) -> void
def initialize: (host: String, port: Integer, ssl: bool, timeout: Integer) -> void

def request: (path: String, payload: String, ?verb: ::String) -> Datadog::CI::Transport::HTTP::ResponseDecorator

Expand Down
44 changes: 17 additions & 27 deletions spec/datadog/ci/transport/api/evp_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,31 @@
RSpec.describe Datadog::CI::Transport::Api::EVPProxy do
subject do
described_class.new(
url: url
host: host,
port: port,
ssl: ssl,
timeout: timeout
)
end

let(:url) { "http://localhost:5555" }
let(:host) { "localhost" }
let(:port) { 5555 }
let(:ssl) { false }
let(:timeout) { 42 }

let(:http) { double(:http) }

describe "#initialize" do
context "with https URL" do
let(:url) { "https://citestcycle-intake.datad0ghq.com:443" }
it "creates HTTP transport" do
expect(Datadog::CI::Transport::HTTP).to receive(:new).with(
host: host,
port: port,
ssl: ssl,
timeout: timeout,
compress: false
).and_return(http)

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
subject
end
end

Expand Down

0 comments on commit c4322bc

Please sign in to comment.