Skip to content

Commit

Permalink
agentless_mode_enabled and api_key settings
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 18, 2023
1 parent 003eb82 commit f741f3a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/datadog/ci/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ def self.add_settings!(base)
o.default false
end

option :agentless_mode_enabled do |o|
o.type :bool
o.env CI::Ext::Settings::ENV_AGENTLESS_MODE_ENABLED
o.default false
end

option :api_key do |o|
o.type :string, nilable: true
o.env CI::Ext::Settings::ENV_API_KEY
end

define_method(:instrument) do |integration_name, options = {}, &block|
return unless enabled

Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/ext/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Ext
# Defines constants for test tags
module Settings
ENV_MODE_ENABLED = "DD_TRACE_CI_ENABLED"
ENV_AGENTLESS_MODE_ENABLED = "DD_CIVISIBILITY_AGENTLESS_ENABLED"
ENV_API_KEY = "DD_API_KEY"
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/ext/settings.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Datadog
module Ext
module Settings
ENV_MODE_ENABLED: String
ENV_AGENTLESS_MODE_ENABLED: String
ENV_API_KEY: String
end
end
end
Expand Down
80 changes: 80 additions & 0 deletions spec/datadog/ci/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,86 @@ def patcher
end
end

describe "#agentless_mode_enabled" do
subject(:agentless_mode_enabled) { settings.ci.agentless_mode_enabled }

it { is_expected.to be false }

context "when #{Datadog::CI::Ext::Settings::ENV_AGENTLESS_MODE_ENABLED}" do
around do |example|
ClimateControl.modify(Datadog::CI::Ext::Settings::ENV_AGENTLESS_MODE_ENABLED => enable) do
example.run
end
end

context "is not defined" do
let(:enable) { nil }

it { is_expected.to be false }
end

context "is set to true" do
let(:enable) { "true" }

it { is_expected.to be true }
end

context "is set to false" do
let(:enable) { "false" }

it { is_expected.to be false }
end
end
end

describe "#agentless_mode_enabled=" do
it "updates the #enabled setting" do
expect { settings.ci.agentless_mode_enabled = true }
.to change { settings.ci.agentless_mode_enabled }
.from(false)
.to(true)
end
end

describe "#api_key" do
subject(:api_key) { settings.ci.api_key }

context "when #{Datadog::CI::Ext::Settings::ENV_API_KEY}" do
around do |example|
ClimateControl.modify(Datadog::CI::Ext::Settings::ENV_API_KEY => api_key) do
example.run
end
end

context "is not defined" do
let(:api_key) { nil }

it { is_expected.to be nil }
end

context "is set to dd_api_key" do
let(:api_key) { "dd_api_key" }

it { is_expected.to eq("dd_api_key") }
end
end
end

describe "#api_key=" do
around do |example|
ClimateControl.modify(Datadog::CI::Ext::Settings::ENV_API_KEY => nil) do
example.run
end
end

it "updates the #api_key setting" do
expect { settings.ci.api_key = "dd_api_key" }
.to change { settings.ci.api_key }
.from(nil)
.to("dd_api_key")
end
end

describe "#instrument" do
let(:integration_name) { :fake }

Expand Down

0 comments on commit f741f3a

Please sign in to comment.