Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .generator/src/generator/templates/api_client.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module {{ module_name }}
'User-Agent' => @user_agent
}
@default_headers['Accept-Encoding'] = 'gzip' if @config.compress
@default_headers['X-Datadog-Managed-By'] = 'iac' if @config.is_iac
end

def self.default
Expand Down
8 changes: 8 additions & 0 deletions .generator/src/generator/templates/configuration.j2
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ module {{ module_name }}
# Keep track of the unstable operations, and if they have been enabled
attr_accessor :unstable_operations

# Set this to true to mark requests as originating from infrastructure-as-code (IaC) tooling.
# When enabled, the `X-Datadog-Managed-By: iac` header is sent with every request.
# Default to false.
#
# @return [true, false]
attr_accessor :is_iac

### TLS/SSL setting
# Set this to false to skip verifying SSL certificate when calling API from https server.
# Default to true.
Expand Down Expand Up @@ -170,6 +177,7 @@ module {{ module_name }}
@cert_file = nil
@key_file = nil
@debugging = false
@is_iac = false
@inject_format = false
@force_ending_format = false
@compress = true
Expand Down
1 change: 1 addition & 0 deletions lib/datadog_api_client/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def initialize(config = Configuration.default)
'User-Agent' => @user_agent
}
@default_headers['Accept-Encoding'] = 'gzip' if @config.compress
@default_headers['X-Datadog-Managed-By'] = 'iac' if @config.is_iac
end

def self.default
Expand Down
8 changes: 8 additions & 0 deletions lib/datadog_api_client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Configuration
# Keep track of the unstable operations, and if they have been enabled
attr_accessor :unstable_operations

# Set this to true to mark requests as originating from infrastructure-as-code (IaC) tooling.
# When enabled, the `X-Datadog-Managed-By: iac` header is sent with every request.
# Default to false.
#
# @return [true, false]
attr_accessor :is_iac

### TLS/SSL setting
# Set this to false to skip verifying SSL certificate when calling API from https server.
# Default to true.
Expand Down Expand Up @@ -180,6 +187,7 @@ def initialize
@cert_file = nil
@key_file = nil
@debugging = false
@is_iac = false
@inject_format = false
@force_ending_format = false
@compress = true
Expand Down
17 changes: 17 additions & 0 deletions spec/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@
end
end

describe 'is_iac header in #build_request' do
let(:config) { DatadogAPIClient::Configuration.new }

it 'is not sent by default' do
api_client = DatadogAPIClient::APIClient.new(config)
request = api_client.build_request(Net::HTTP::Get, '/test')
expect(request.options[:headers]).not_to have_key('X-Datadog-Managed-By')
end

it 'is sent when is_iac is enabled on the configuration' do
config.is_iac = true
api_client = DatadogAPIClient::APIClient.new(config)
request = api_client.build_request(Net::HTTP::Get, '/test')
expect(request.options[:headers]['X-Datadog-Managed-By']).to eq('iac')
end
end

describe '#deserialize' do
it "handles Array<Integer>" do
api_client = DatadogAPIClient::APIClient.new
Expand Down
Loading