Sha256: a8963650f0bb3b935428c7a606a257fcd5dd2f9a2aa041b050124bd50a84b60d

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

require_relative "base"
require_relative "../../ext/transport"

module Datadog
  module CI
    module Transport
      module Api
        class Agentless < Base
          attr_reader :api_key

          def initialize(api_key:, citestcycle_url:, api_url:)
            @api_key = api_key
            @citestcycle_http = build_http_client(citestcycle_url, compress: true)
            @api_http = build_http_client(api_url, compress: false)
          end

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

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

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

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

          private

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

          def build_http_client(url, compress:)
            uri = URI.parse(url)
            raise "Invalid agentless mode URL: #{url}" if uri.host.nil?

            Datadog::CI::Transport::HTTP.new(
              host: uri.host,
              port: uri.port,
              ssl: uri.scheme == "https" || uri.port == 443,
              compress: compress
            )
          end

          def default_headers
            headers = super
            headers[Ext::Transport::HEADER_DD_API_KEY] = api_key
            headers
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
datadog-ci-0.8.3 lib/datadog/ci/transport/api/agentless.rb
datadog-ci-0.8.2 lib/datadog/ci/transport/api/agentless.rb
datadog-ci-0.8.1 lib/datadog/ci/transport/api/agentless.rb
datadog-ci-0.8.0 lib/datadog/ci/transport/api/agentless.rb