wavefront-sdk 3.4.0 → 3.5.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: bf113855e97fd18cd468edb2eb47cc94ff7551ffdfd4eae01d151f3dd83f843d
4
- data.tar.gz: 2af7243524750797cb4da86732a0e39a0b7d050052a8b540ce732aa22a2ce516
3
+ metadata.gz: 4a1343ef6a630b783c158b7ff3373247ea541a22e1b3428a9bacc30c4bf6c4f0
4
+ data.tar.gz: bd9366f76e693b5ccafe6956ec841fde8816481bff27c24ce2f7167a150942d4
5
5
  SHA512:
6
- metadata.gz: 8690b71bfe78192af6360fcebea3c95e19901d4f8f673d8fb557533d91982c2f394b9f4462e3e2827eb2d7171e25b9a11885d080e44c85ea6aeb0d66dceb01ea
7
- data.tar.gz: 6ef9ab034e8f48df21a54aa122b1f6b6a3dbc03e716dcd91e4e1b752b918f71bb693912041aeadad0837692cb0fffd955d71e70ba9dca5f84390ce0c9e264ff2
6
+ metadata.gz: 4647a15bce3d481808699c017c21df2f08046e50a7931fc58b7b4c1249ad67315f779038aa619ec57f80ba714dff56d9cb46fed7c85feff70d1b66375e7aaea5
7
+ data.tar.gz: 8578a761628a6ce77a234d12ff59c084498bc2615448aaf905c8057f2230e2fd74df2638f4bbb7e9ebf6df74a963715f1c8bff2154e5894dff1fb51b67f8ff4c
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.5.0 (2019-09-30)
4
+ * Extend `apitoken` class to cover new service account paths.
5
+
3
6
  ## 3.4.0 (2019-09-28)
4
7
  * Add `serviceaccount` class.
5
8
  * Validator exceptions now return the value which failed validation.
@@ -4,7 +4,7 @@ require_relative 'core/api'
4
4
 
5
5
  module Wavefront
6
6
  #
7
- # View and manage API tokens
7
+ # View and manage API tokens for one's own user, and for service accounts.
8
8
  #
9
9
  class ApiToken < CoreApi
10
10
  # GET /api/v2/apitoken
@@ -47,5 +47,57 @@ module Wavefront
47
47
  wf_apitoken_id?(id)
48
48
  api.put(id, { tokenID: id, tokenName: name }, 'application/json')
49
49
  end
50
+
51
+ # GET /api/v2/apitoken/serviceaccount/{id}
52
+ # Get all api tokens for the given service account
53
+ #
54
+ # @param id [String] service account ID
55
+ # @return [Wavefront::Response]
56
+ #
57
+ def sa_list(id)
58
+ wf_serviceaccount_id?(id)
59
+ api.get(['serviceaccount', id].uri_concat)
60
+ end
61
+
62
+ # POST /api/v2/apitoken/serviceaccount/{id}
63
+ # Create a new api token for the service account
64
+ #
65
+ # @param id [String] service account ID
66
+ # @param name [String] optional name for token
67
+ # @return [Wavefront::Response]
68
+ #
69
+ def sa_create(id, name = nil)
70
+ wf_serviceaccount_id?(id)
71
+ body = {}.tap { |b| b[:tokenName] = name if name }
72
+ api.post(['serviceaccount', id].uri_concat, body, 'application/json')
73
+ end
74
+
75
+ # DELETE /api/v2/apitoken/serviceaccount/{id}/{token}
76
+ # Delete the specified api token of the given service account
77
+ #
78
+ # @param id [String] service account ID
79
+ # @param token_id [String] ID of the api token
80
+ # @return [Wavefront::Response]
81
+ #
82
+ def sa_delete(id, token_id)
83
+ wf_serviceaccount_id?(id)
84
+ wf_apitoken_id?(token_id)
85
+ api.delete(['serviceaccount', id, token_id].uri_concat)
86
+ end
87
+
88
+ # PUT /api/v2/apitoken/serviceaccount/{id}/{token}
89
+ # Update the name of the specified api token for the given service
90
+ # account
91
+ #
92
+ # @param id [String] service account ID
93
+ # @param token_id [String] ID of the api token
94
+ # @return [Wavefront::Response]
95
+ #
96
+ def sa_rename(id, token_id, name)
97
+ wf_serviceaccount_id?(id)
98
+ wf_apitoken_id?(token_id)
99
+ api.put(['serviceaccount', id, token_id].uri_concat,
100
+ { tokenID: token_id, tokenName: name }, 'application/json')
101
+ end
50
102
  end
51
103
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- WF_SDK_VERSION = '3.4.0'
5
+ WF_SDK_VERSION = '3.5.0'
6
6
  WF_SDK_LOCATION = Pathname.new(__dir__).parent.parent.parent
@@ -37,7 +37,7 @@ module Wavefront
37
37
  # GET /api/v2/account/serviceaccount/{id}
38
38
  # Retrieves a service account by identifier
39
39
  #
40
- # @param id [String, Integer] ID of the account
40
+ # @param id [String] ID of the account
41
41
  # @return [Wavefront::Response]
42
42
  #
43
43
  def describe(id)
@@ -69,7 +69,7 @@ module Wavefront
69
69
  # POST /api/v2/account/serviceaccount/{id}/activate
70
70
  # Activates the given service account
71
71
  #
72
- # @param id [String, Integer] ID of the account
72
+ # @param id [String] ID of the account
73
73
  # @return [Wavefront::Response]
74
74
  #
75
75
  def activate(id)
@@ -80,7 +80,7 @@ module Wavefront
80
80
  # POST /api/v2/account/serviceaccount/{id}/deactivate
81
81
  # Deactivates the given service account
82
82
  #
83
- # @param id [String, Integer] ID of the account
83
+ # @param id [String] ID of the account
84
84
  # @return [Wavefront::Response]
85
85
  #
86
86
  def deactivate(id)
@@ -14,11 +14,15 @@ class WavefrontTestBase < MiniTest::Test
14
14
  attr_reader :wf, :wf_noop, :headers, :invalid_id, :valid_id
15
15
 
16
16
  def initialize(args)
17
- require_relative "../lib/wavefront-sdk/#{class_basename.downcase}"
17
+ require_relative libfile_to_test
18
18
  setup_fixtures if respond_to?(:setup_fixtures)
19
19
  super(args)
20
20
  end
21
21
 
22
+ def libfile_to_test
23
+ "../lib/wavefront-sdk/#{class_basename.downcase}"
24
+ end
25
+
22
26
  private
23
27
 
24
28
  def setup
@@ -2,13 +2,10 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative '../spec_helper'
5
- require_relative '../test_mixins/general'
6
5
 
7
6
  # Unit tests for API token class
8
7
  #
9
8
  class WavefrontApiTokenTest < WavefrontTestBase
10
- include WavefrontTest::Delete
11
-
12
9
  def test_list
13
10
  assert_gets('/api/v2/apitoken') { wf.list }
14
11
  end
@@ -19,22 +16,79 @@ class WavefrontApiTokenTest < WavefrontTestBase
19
16
  end
20
17
 
21
18
  def test_rename
22
- assert_puts("/api/v2/apitoken/#{id}",
23
- tokenID: id, tokenName: 'token name') do
24
- wf.rename(id, 'token name')
19
+ assert_puts("/api/v2/apitoken/#{token_id}",
20
+ tokenID: token_id, tokenName: 'token name') do
21
+ wf.rename(token_id, 'token name')
25
22
  end
26
23
 
27
24
  assert_invalid_id { wf.rename(invalid_id, 'token name') }
28
25
  assert_raises(ArgumentError) { wf.rename }
26
+ assert_raises(ArgumentError) { wf.rename(token_id) }
27
+ end
28
+
29
+ def test_sa_list
30
+ assert_gets("/api/v2/apitoken/serviceaccount/#{id}") { wf.sa_list(id) }
31
+
32
+ assert_raises(Wavefront::Exception::InvalidServiceAccountId) do
33
+ wf.sa_list(invalid_id)
34
+ end
35
+ end
36
+
37
+ def test_sa_create
38
+ assert_posts("/api/v2/apitoken/serviceaccount/#{id}",
39
+ tokenName: 'token name') do
40
+ wf.sa_create(id, 'token name')
41
+ end
42
+
43
+ assert_raises(Wavefront::Exception::InvalidServiceAccountId) do
44
+ wf.sa_create(invalid_id, 'token name')
45
+ end
46
+ end
47
+
48
+ def test_sa_rename
49
+ assert_puts("/api/v2/apitoken/serviceaccount/#{id}/#{token_id}",
50
+ tokenID: token_id, tokenName: 'new token name') do
51
+ wf.sa_rename(id, token_id, 'new token name')
52
+ end
53
+
54
+ assert_invalid_id { wf.sa_rename(id, invalid_token_id, 'token name') }
55
+ assert_raises(ArgumentError) { wf.sa_rename }
29
56
  assert_raises(ArgumentError) { wf.rename(id) }
57
+
58
+ assert_raises(Wavefront::Exception::InvalidServiceAccountId) do
59
+ wf.sa_rename(invalid_id, token_id, 'token name')
60
+ end
61
+ end
62
+
63
+ def test_delete
64
+ assert_deletes("/api/v2/apitoken/serviceaccount/#{id}/#{token_id}") do
65
+ wf.sa_delete(id, token_id)
66
+ end
67
+
68
+ assert_invalid_id { wf.sa_delete(id, invalid_token_id) }
69
+
70
+ assert_raises(Wavefront::Exception::InvalidServiceAccountId) do
71
+ wf.sa_delete(invalid_id, token_id)
72
+ end
73
+
74
+ assert_raises(ArgumentError) { wf.sa_delete(id) }
75
+ assert_raises(ArgumentError) { wf.sa_delete }
30
76
  end
31
77
 
32
78
  private
33
79
 
34
80
  def id
81
+ 'sa::tester'
82
+ end
83
+
84
+ def token_id
35
85
  '17db4cc1-65f6-40a8-a1fa-6fcae460c4bd'
36
86
  end
37
87
 
88
+ def invalid_token_id
89
+ '__bad__'
90
+ end
91
+
38
92
  def invalid_id
39
93
  '__rubbish__'
40
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-28 00:00:00.000000000 Z
11
+ date: 2019-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable