dogapi 1.20.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4468399eb2562412f21f437bac47ce6eee96d64
4
- data.tar.gz: 02b6507f392f7fdfa051104d466b0378841570fa
3
+ metadata.gz: ca850c71e9c22f3b3b5c8ddfa2eb6eda2174807e
4
+ data.tar.gz: 4a6dff6932e1a05e3acb6a4af3dacd0cc3a1cf51
5
5
  SHA512:
6
- metadata.gz: 249b343d68784129d73fadebe8622e73eb2401d5f62f294007cdd7152ae01d1e0461b4eaafc4263d005d71b65f4632abb7e9bd63cd00eec47a9fe06254264ad8
7
- data.tar.gz: 8170e19e1531983963a4ec44273838d30c8a31b249f192b3b4ba80cd1acd5d3e90caf038f23539c7718dbbcccf8a2ca6f95af084399405c74cdc4733ae5ea3af
6
+ metadata.gz: 5fe2e6a80a0a60cf838e235bf00e82675638783bd05cb63012d89d5cc5c6babf9873a012bd6bb075343073a3e35ef74af21d35e1244eb7f26c9cca401aec3ca7
7
+ data.tar.gz: 34df781325d7bbdd49454e6e7681a932c8282d9992a74ae65d5725f1429d3aa39c91ff99a9fa884c4d02b95184dff5805cb68d4bee4b8b2f2e35bac2c84c2e6d
@@ -1,6 +1,10 @@
1
1
  Changes
2
2
  =======
3
3
 
4
+ # 1.21.0 / Unreleased
5
+ * [FEATURE] User CRUD API. See [#82][]
6
+ * [IMPROVEMENT] Support capistrano SimpleTextFormatter (thanks [@rmoriz][] [#81][])
7
+
4
8
  # 1.20.0 / 2015-07-29
5
9
  * [FEATURE] Embeddable graphs API. See [#73][]
6
10
 
@@ -134,6 +138,9 @@ Changes
134
138
  [#64]: https://github.com/DataDog/dogapi-rb/issues/64
135
139
  [#69]: https://github.com/DataDog/dogapi-rb/issues/69
136
140
  [#73]: https://github.com/DataDog/dogapi-rb/issues/73
141
+ [#81]: https://github.com/DataDog/dogapi-rb/issues/81
142
+ [#82]: https://github.com/DataDog/dogapi-rb/issues/82
143
+
137
144
  [@ArjenSchwarz]: https://github.com/ArjenSchwarz
138
145
  [@Kaixiang]: https://github.com/Kaixiang
139
146
  [@ansel1]: https://github.com/ansel1
@@ -142,3 +149,4 @@ Changes
142
149
  [@treeder]: https://github.com/treeder
143
150
  [@winebarrel]: https://github.com/winebarrel
144
151
  [@yyuu]: https://github.com/yyuu
152
+ [@rmoriz]: https://github.com/rmoriz
@@ -1,5 +1,6 @@
1
1
  require "benchmark"
2
2
  require "sshkit/formatters/pretty"
3
+ require "sshkit/formatters/simple_text"
3
4
 
4
5
  # Capistrano v3 uses Rake's DSL instead of its own
5
6
 
@@ -48,6 +49,12 @@ module SSHKit
48
49
  super(Capistrano::Datadog::CaptureIO.new(oio))
49
50
  end
50
51
  end
52
+
53
+ class SimpleText
54
+ def initialize(oio)
55
+ super(Capistrano::Datadog::CaptureIO.new(oio))
56
+ end
57
+ end
51
58
  end
52
59
  end
53
60
 
@@ -291,6 +291,26 @@ module Dogapi
291
291
  @user_svc.invite(emails, options)
292
292
  end
293
293
 
294
+ def create_user(description = {})
295
+ @user_svc.create_user(description)
296
+ end
297
+
298
+ def get_all_users()
299
+ @user_svc.get_all_users()
300
+ end
301
+
302
+ def get_user(handle)
303
+ @user_svc.get_user(handle)
304
+ end
305
+
306
+ def update_user(handle, description = {})
307
+ @user_svc.update_user(handle, description)
308
+ end
309
+
310
+ def disable_user(handle)
311
+ @user_svc.disable_user(handle)
312
+ end
313
+
294
314
  # Graph snapshot
295
315
  def graph_snapshot(metric_query, start_ts, end_ts, event_query = nil)
296
316
  @snapshot_svc.snapshot(metric_query, start_ts, end_ts, event_query)
@@ -7,7 +7,10 @@ module Dogapi
7
7
 
8
8
  API_VERSION = "v1"
9
9
 
10
+ # <b>DEPRECATED:</b> Going forward, we're using a new and more restful API,
11
+ # the new methods are get_user, create_user, update_user, disable_user
10
12
  def invite(emails, options = {})
13
+ warn "[DEPRECATION] Dogapi::V1::UserService::invite has been deprecated in favor of Dogapi::V1::UserService::create_user"
11
14
  begin
12
15
  params = {
13
16
  :api_key => @api_key,
@@ -23,6 +26,87 @@ module Dogapi
23
26
  suppress_error_if_silent e
24
27
  end
25
28
  end
29
+
30
+ # Create a user
31
+ #
32
+ # :description => Hash: user description containing 'handle' and 'name' properties
33
+ def create_user(description = {})
34
+ begin
35
+ params = {
36
+ :api_key => @api_key,
37
+ :application_key => @application_key
38
+ }
39
+
40
+ request(Net::HTTP::Post, "/api/#{API_VERSION}/user", params, description, true)
41
+ rescue Exception => e
42
+ suppress_error_if_silent e
43
+ end
44
+ end
45
+
46
+ # Retrieve user information
47
+ #
48
+ # :handle => String: user handle
49
+ def get_user(handle)
50
+ begin
51
+ params = {
52
+ :api_key => @api_key,
53
+ :application_key => @application_key
54
+ }
55
+
56
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/user/#{handle}", params, nil, false)
57
+ rescue Exception => e
58
+ suppress_error_if_silent e
59
+ end
60
+ end
61
+
62
+ # Retrieve all users
63
+ def get_all_users()
64
+ begin
65
+ params = {
66
+ :api_key => @api_key,
67
+ :application_key => @application_key
68
+ }
69
+
70
+ request(Net::HTTP::Get, "/api/#{API_VERSION}/user", params, nil, false)
71
+ rescue Exception => e
72
+ suppress_error_if_silent e
73
+ end
74
+ end
75
+
76
+ # Update a user
77
+ #
78
+ # :handle => String: user handle
79
+ # :description => Hash: user description optionally containing 'name', 'email',
80
+ # 'is_admin', 'disabled' properties
81
+ def update_user(handle, description = {})
82
+ begin
83
+ params = {
84
+ :api_key => @api_key,
85
+ :application_key => @application_key
86
+ }
87
+
88
+ request(Net::HTTP::Put, "/api/#{API_VERSION}/user/#{handle}", params, description, true)
89
+ rescue Exception => e
90
+ suppress_error_if_silent e
91
+ end
92
+ end
93
+
94
+ # Disable a user
95
+ #
96
+ # :handle => String: user handle
97
+ def disable_user(handle)
98
+ begin
99
+ params = {
100
+ :api_key => @api_key,
101
+ :application_key => @application_key
102
+ }
103
+
104
+ request(Net::HTTP::Delete, "/api/#{API_VERSION}/user/#{handle}", params, nil, false)
105
+ rescue Exception => e
106
+ suppress_error_if_silent e
107
+ end
108
+ end
109
+
26
110
  end
27
111
 
28
112
  end
@@ -1,3 +1,3 @@
1
1
  module Dogapi
2
- VERSION = "1.20.0"
2
+ VERSION = "1.21.0"
3
3
  end
@@ -107,7 +107,7 @@ class TestAlerts < Test::Unit::TestCase
107
107
 
108
108
  # We shouldn't be able to mute a simple alert on a scope.
109
109
  status, _ = dog.mute_monitor(monitor_id, :scope => 'env:staging')
110
- assert_equal status.to_i, 403, status.to_i
110
+ assert_equal status.to_i, 400, status.to_i
111
111
 
112
112
  query2 = 'avg(last_1h):sum:system.net.bytes_rcvd{*} by {host} > 100'
113
113
  monitor_id = dog.monitor('metric alert', query2)[1]['id']
@@ -8,9 +8,58 @@ class TestUsers < Test::Unit::TestCase
8
8
  def test_users
9
9
  dog = Dogapi::Client.new(@api_key, @app_key)
10
10
 
11
+ # user invite (deprecated)
11
12
  emails = ["notarealperson@datadoghq.com", "alsoreallyfake@datadoghq.com"]
12
13
 
13
14
  invited = dog.invite(emails)
14
15
  assert_equal emails, invited[1]["emails"], invited
16
+
17
+ # user CRUD
18
+ handle = 'user@test.com'
19
+ name = 'Test User'
20
+ alternate_name = 'Test User Alt'
21
+ alternate_email = 'user+1@test.com'
22
+
23
+ # test create user
24
+ # the user might already exist
25
+ dog.create_user({
26
+ 'handle' => handle,
27
+ 'name' => name,
28
+ })
29
+
30
+ # reset user to original status
31
+ status, res = dog.update_user(handle, {
32
+ 'name' => name,
33
+ 'email' => handle,
34
+ 'disabled' => false,
35
+ })
36
+ assert_equal handle, res['user']['handle']
37
+ assert_equal name, res['user']['name']
38
+ assert_equal handle, res['user']['email']
39
+
40
+ # test get
41
+ status, res = dog.get_user(handle)
42
+ assert_equal handle, res['user']['handle']
43
+
44
+ # test update user
45
+ status, res = dog.update_user(handle, {
46
+ 'name' => alternate_name,
47
+ 'email' => alternate_email,
48
+ })
49
+ assert_equal handle, res['user']['handle']
50
+ assert_equal alternate_name, res['user']['name']
51
+ assert_equal alternate_email, res['user']['email']
52
+
53
+ # test disable user
54
+ status, res = dog.disable_user(handle)
55
+ assert_equal '200', status
56
+
57
+ # test get all users
58
+ status, res = dog.get_all_users()
59
+ assert_equal true, res['users'].length >= 1
60
+
15
61
  end
62
+
63
+
64
+
16
65
  end
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.20.0
4
+ version: 1.21.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: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json