dogapi 1.40.0 → 1.41.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03dcbb8f50795fb901c13effb712107ac78beb545d55bebccb9f2cfc83c92908
4
- data.tar.gz: d6cbb3c3dd0807d8d684879fa3efb44e8a54acd7c07298261ebc11b5b9a099e4
3
+ metadata.gz: bedd02d8446f4dfce31b9a2b375da5376860490ea6122e3829db203c51f2120b
4
+ data.tar.gz: 8378113bb0b466b3cf6b9e05622c1386691492e474d8c64f5fe8c742b60b32ba
5
5
  SHA512:
6
- metadata.gz: 4b969abe11bd88812b9eb70066fb1d1fb2ff5df49a5a95de7c92893357dde80af0e5636500b1a7ed9703ce525a96d10662ff4900d09fd2676db263be17dfcaaf
7
- data.tar.gz: 3b63c822096ba541151e837c16d47c0aa298baff22257be5b098e13041bba0dd00bba328d479240d17b2c58c9a1c9cacfdbf33a9416752b5a61a4dd65a999457
6
+ metadata.gz: 84dd004b3f9cc6e55f4523339690ee1e8688e45d53febeb10d472cbf510b5a42caf9caeb0a9f0e86721887aba0fa48adc694a7b67aa21da4984d3752001a1d81
7
+ data.tar.gz: eb764eb19d7b150798e758487bf1457fc7d245cbbc9315d99b7616ea3eddf4d79d061e30cf423924aa6930cae9be98eb7ff88339ee11a3cb959f9c78f8dd6eec
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 1.41.0 / 2020-07-27
4
+
5
+ * [Added] Improve user-agent header to include telemetry information. See [#235](https://github.com/DataDog/dogapi-rb/pull/235).
6
+ * [Added] Move setting hostname to end of method body in order to actually return it. See [#233](https://github.com/DataDog/dogapi-rb/pull/233).
7
+
3
8
  ## 1.40.0 / 2020-04-06
4
9
 
5
10
  * [Added] Re-add service level objectives support. See [#224](https://github.com/DataDog/dogapi-rb/pull/224).
@@ -4,6 +4,7 @@
4
4
 
5
5
  require 'cgi'
6
6
  require 'net/https'
7
+ require 'rbconfig'
7
8
  require 'socket'
8
9
  require 'uri'
9
10
  require 'English'
@@ -13,7 +14,16 @@ require 'multi_json'
13
14
  require 'set'
14
15
  require 'open3'
15
16
 
17
+ require 'dogapi/version'
18
+
16
19
  module Dogapi
20
+ USER_AGENT = format(
21
+ 'dogapi-rb/%<version>s (ruby %<ruver>s; os %<os>s; arch %<arch>s)',
22
+ version: VERSION,
23
+ ruver: RUBY_VERSION,
24
+ os: RbConfig::CONFIG['host_os'].downcase,
25
+ arch: RbConfig::CONFIG['host_cpu']
26
+ )
17
27
 
18
28
  # Metadata class to hold the scope of an API call
19
29
  class Scope
@@ -138,11 +148,11 @@ module Dogapi
138
148
  def prepare_request(method, url, params, body, send_json, with_app_key)
139
149
  url_with_params = url + params
140
150
  req = method.new(url_with_params)
151
+ req['User-Agent'] = USER_AGENT
141
152
  unless should_set_api_and_app_keys_in_params?(url)
142
153
  req['DD-API-KEY'] = @api_key
143
154
  req['DD-APPLICATION-KEY'] = @application_key if with_app_key
144
155
  end
145
-
146
156
  if send_json
147
157
  req.content_type = 'application/json'
148
158
  req.body = MultiJson.dump(body)
@@ -202,9 +212,9 @@ module Dogapi
202
212
  def Dogapi.find_localhost
203
213
  unless @@hostname
204
214
  out, status = Open3.capture2('hostname', '-f', err: File::NULL)
205
- @@hostname = out.strip
206
215
  # Get status to check if the call was successful
207
216
  raise SystemCallError, 'Could not get hostname with `hostname -f`' unless status.exitstatus.zero?
217
+ @@hostname = out.strip
208
218
  end
209
219
  rescue SystemCallError
210
220
  @@hostname = Addrinfo.getaddrinfo(Socket.gethostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first.canonname
@@ -3,5 +3,5 @@
3
3
  # Copyright 2011-Present Datadog, Inc.
4
4
 
5
5
  module Dogapi
6
- VERSION = '1.40.0'
6
+ VERSION = '1.41.0'
7
7
  end
@@ -134,6 +134,15 @@ describe 'Common' do
134
134
  expect(req['DD-APPLICATION-KEY']).to eq service.application_key
135
135
  end
136
136
  end
137
+
138
+ it 'properly sets User-Agent header' do
139
+ service = Dogapi::APIService.new('api_key', 'app_key', true, nil, 'https://app.example.com')
140
+ params = service.prepare_params(nil, '/api/v1/validate', true)
141
+ req = service.prepare_request(Net::HTTP::Get, '/api/v1/validate', params, nil, false, true)
142
+
143
+ expect(req.key?('User-Agent')).to be true
144
+ expect(req['User-Agent']).to match(%r{dogapi-rb\/[^\s]+ \(ruby [^\s]+; os [^\s]+; arch [^\s]+\)})
145
+ end
137
146
  end
138
147
  end
139
148
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dogapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.40.0
4
+ version: 1.41.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -198,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  - !ruby/object:Gem::Version
199
199
  version: '0'
200
200
  requirements: []
201
- rubygems_version: 3.0.6
201
+ rubygems_version: 3.0.3
202
202
  signing_key:
203
203
  specification_version: 4
204
204
  summary: Ruby bindings for Datadog's API