From f741f3a97e49b04c5e7fe9677b5c49acee6d9b8d Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Mon, 18 Sep 2023 16:24:51 +0200 Subject: [PATCH] agentless_mode_enabled and api_key settings --- lib/datadog/ci/configuration/settings.rb | 11 +++ lib/datadog/ci/ext/settings.rb | 2 + sig/datadog/ci/ext/settings.rbs | 2 + .../datadog/ci/configuration/settings_spec.rb | 80 +++++++++++++++++++ 4 files changed, 95 insertions(+) diff --git a/lib/datadog/ci/configuration/settings.rb b/lib/datadog/ci/configuration/settings.rb index 85500ce7..11f01c04 100644 --- a/lib/datadog/ci/configuration/settings.rb +++ b/lib/datadog/ci/configuration/settings.rb @@ -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 diff --git a/lib/datadog/ci/ext/settings.rb b/lib/datadog/ci/ext/settings.rb index d74dbbd6..8907b6b6 100644 --- a/lib/datadog/ci/ext/settings.rb +++ b/lib/datadog/ci/ext/settings.rb @@ -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 diff --git a/sig/datadog/ci/ext/settings.rbs b/sig/datadog/ci/ext/settings.rbs index b133c8d0..afa71d4c 100644 --- a/sig/datadog/ci/ext/settings.rbs +++ b/sig/datadog/ci/ext/settings.rbs @@ -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 diff --git a/spec/datadog/ci/configuration/settings_spec.rb b/spec/datadog/ci/configuration/settings_spec.rb index 5b86ed8c..3b50516a 100644 --- a/spec/datadog/ci/configuration/settings_spec.rb +++ b/spec/datadog/ci/configuration/settings_spec.rb @@ -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 }