wavefront-cli 4.3.0 → 4.3.1

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: 79bb78ee1f6515f3a168acdedfa89680be010f429a33520e23a6caae252fc42f
4
- data.tar.gz: 1e86e9eeb5ea1242443b0cf17eb1fea5c5f3a207c6895ab4102a1f705bf1a5a4
3
+ metadata.gz: 29567752b0846cf0bc23909151f65a0f023c02437203d97c0957f67c7802693f
4
+ data.tar.gz: be30496907d30aeb184d0d7cc3204452c79b219254caeb9c6a59785a240cca18
5
5
  SHA512:
6
- metadata.gz: 01a3a13dbca2192dfb50c375d833ec73115a6c76e31e5fbb0ee42cab3a3f95ea89264e35ebabcb2f34caee642e8e91b74c664d1669d546504cd30f16d364725c
7
- data.tar.gz: 1d076d96e1972ceb5d9de355ef1e88e6ea3e68961a911a5a2b691570a337fd8ac3d1cf7fe1d6b4b3c7bacf92ab8741becfb6cbfe4ccb223d363a037d5f219c28
6
+ metadata.gz: 1e1f43c9ad3a996c71b1c75478344b03d9c751fa0ba1db590f6d79f5ba32db18f7f25a52db23f48173418b69730cba46cc20dcde6a2cc843bec017b3be680a87
7
+ data.tar.gz: 928a9f2eb6523d26497ae6ac630f0bd070bd73ffea31876c7bee70bfe061216f08c8eb7d30c4d083c2adeaaf41b773a2a59249565ac230a17b56c05ffdcd727a
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.1 (2019-09-30)
4
+ * Bugfix `serviceaccount` command.
5
+
3
6
  ## 4.3.0 (2019-09-30)
4
7
  * Add `serviceaccount` command.
5
8
  * Add `user privileges` command.
data/README.md CHANGED
@@ -31,7 +31,7 @@ Usage:
31
31
 
32
32
  Commands:
33
33
  alert view and manage alerts
34
- apitoken view and manage API tokens
34
+ apitoken view and your own API tokens
35
35
  cloudintegration view and manage cloud integrations
36
36
  config create and manage local configuration
37
37
  dashboard view and manage dashboards
@@ -45,6 +45,7 @@ Commands:
45
45
  proxy view and manage proxies
46
46
  query run Wavefront queries
47
47
  savedsearch view and manage saved searches
48
+ serviceaccount view and manage service accounts
48
49
  settings view and manage system preferences
49
50
  source view and manage source tags and descriptions
50
51
  user view and manage Wavefront users
@@ -20,17 +20,17 @@ class WavefrontCommandServiceaccount < WavefrontCommandBase
20
20
  def _commands
21
21
  ["list #{CMN} [-l] [-O fields]",
22
22
  "describe #{CMN} <id>",
23
- "create #{CMN} [-I] [-d description] [-m permission...] [-g group...] " \
23
+ "create #{CMN} [-I] [-d description] [-p permission...] [-g group...] " \
24
24
  '[-k usertoken...] <id>',
25
25
  "activate #{CMN} <id>",
26
26
  "deactivate #{CMN} <id>",
27
27
  "dump #{CMN}",
28
28
  "groups #{CMN} <id>",
29
- "privileges #{CMN} <id>",
29
+ "permissions #{CMN} <id>",
30
30
  "join #{CMN} <id> <group>...",
31
31
  "leave #{CMN} <id> <group>...",
32
- "grant #{CMN} <privilege> to <id>",
33
- "revoke #{CMN} <privilege> from <id>",
32
+ "grant #{CMN} <permission> to <id>",
33
+ "revoke #{CMN} <permission> from <id>",
34
34
  "set #{CMN} <key=value> <id>",
35
35
  "import #{CMN} [-u] <file>",
36
36
  "apitoken list #{CMN} [-O fields] <id>",
@@ -50,7 +50,7 @@ class WavefrontCommandServiceaccount < WavefrontCommandBase
50
50
  "-u, --update update an existing #{thing}",
51
51
  "-I, --inactive create an inactive #{thing}",
52
52
  "-d, --desc=STRING description of #{thing}",
53
- "-m, --permission=STRING give #{thing} this permission",
53
+ "-p, --permission=STRING give #{thing} this permission",
54
54
  "-g, --group=STRING add #{thing} to this user group",
55
55
  '-N, --name=STRING name of token',
56
56
  '-k, --usertoken=STRING API token']
@@ -168,6 +168,8 @@ class WavefrontCliController
168
168
  abort "Cannot find user group '#{e.message}'."
169
169
  rescue Wavefront::Exception::UnsupportedWriter => e
170
170
  abort "Unsupported writer '#{e.message}'."
171
+ rescue WavefrontCli::Exception::UserError => e
172
+ abort "User error: #{e.message}."
171
173
  rescue WavefrontCli::Exception::ImpossibleSearch
172
174
  abort 'Search on non-existent key. Please use a top-level field.'
173
175
  rescue StandardError => e
@@ -12,7 +12,11 @@ module WavefrontDisplay
12
12
  end
13
13
 
14
14
  def do_list_brief
15
- multicolumn(:identifier, :description)
15
+ if data.empty?
16
+ puts 'You have no service accounts.'
17
+ else
18
+ multicolumn(:identifier, :description)
19
+ end
16
20
  end
17
21
 
18
22
  def do_activate
@@ -34,27 +38,42 @@ module WavefrontDisplay
34
38
  alias do_join do_groups
35
39
  alias do_leave do_groups
36
40
 
37
- def do_privileges
41
+ def do_permissions
38
42
  if data[:groups].empty?
39
- puts 'Account does not have any Wavefront privileges.'
43
+ puts 'Account does not have any Wavefront permissions.'
40
44
  else
41
45
  puts data[:groups]
42
46
  end
43
47
  end
44
48
 
45
- alias do_grant do_privileges
46
- alias do_revoke do_privileges
49
+ def do_grant
50
+ puts format("Granted '%<perm>s' to '%<account>s'.",
51
+ perm: options[:'<permission>'], account: options[:'<id>'])
52
+ end
53
+
54
+ def do_revoke
55
+ puts format("Revoked '%<perm>s' from '%<account>s'.",
56
+ perm: options[:'<permission>'], account: options[:'<id>'])
57
+ end
47
58
 
48
59
  def do_apitoken_list
49
60
  if data.empty?
50
- puts 'Account does not have any tokens.'
61
+ puts 'Account does not have any API tokens.'
51
62
  else
52
63
  multicolumn(:tokenID, :tokenName)
53
64
  end
54
65
  end
55
66
 
67
+ def do_apitoken_delete
68
+ puts format("Deleted API token '#{options[:'<token_id>']}'.")
69
+ end
70
+
56
71
  def search_identifier_key
57
72
  :identifier
58
73
  end
74
+
75
+ def priority_keys
76
+ %i[identifier]
77
+ end
59
78
  end
60
79
  end
@@ -27,5 +27,6 @@ module WavefrontCli
27
27
  class UnsupportedOperation < RuntimeError; end
28
28
  class UnsupportedOutput < RuntimeError; end
29
29
  class UserGroupNotFound < RuntimeError; end
30
+ class UserError < RuntimeError; end
30
31
  end
31
32
  end
@@ -23,7 +23,7 @@ module WavefrontCli
23
23
  end
24
24
 
25
25
  alias do_groups do_describe
26
- alias do_privileges do_describe
26
+ alias do_permissions do_describe
27
27
 
28
28
  def do_create
29
29
  wf_user_id?(options[:'<id>'])
@@ -56,36 +56,36 @@ module WavefrontCli
56
56
 
57
57
  def do_grant
58
58
  cannot_noop!
59
- wf_permission?(options[:'<privilege>'])
59
+ wf_permission?(options[:'<permission>'])
60
60
 
61
- body = add_priv_to_list(current_state, options[:'<privilege>'])
61
+ body = add_perm_to_list(current_state, options[:'<permission>'])
62
62
  wf.update(options[:'<id>'], body)
63
63
  end
64
64
 
65
65
  def do_revoke
66
66
  cannot_noop!
67
- wf_permission?(options[:'<privilege>'])
67
+ wf_permission?(options[:'<permission>'])
68
68
 
69
- body = remove_priv_from_list(current_state, options[:'<privilege>'])
69
+ body = remove_perm_from_list(current_state, options[:'<permission>'])
70
70
  wf.update(options[:'<id>'], body)
71
71
  end
72
72
 
73
73
  def do_apitoken_list
74
- wf_apitoken.list(options[:'<id>'])
74
+ wf_apitoken.sa_list(options[:'<id>'])
75
75
  end
76
76
 
77
77
  def do_apitoken_create
78
- wf_apitoken.create(options[:'<id>'], options[:name])
78
+ wf_apitoken.sa_create(options[:'<id>'], options[:name])
79
79
  end
80
80
 
81
81
  def do_apitoken_delete
82
- wf_apitoken.delete(options[:'<id>'], options[:'<token_id>'])
82
+ wf_apitoken.sa_delete(options[:'<id>'], options[:'<token_id>'])
83
83
  end
84
84
 
85
85
  def do_apitoken_rename
86
- wf_apitoken.rename(options[:'<id>'],
87
- options[:'<token_id>'],
88
- options[:'<name>'])
86
+ wf_apitoken.sa_rename(options[:'<id>'],
87
+ options[:'<token_id>'],
88
+ options[:'<name>'])
89
89
  end
90
90
 
91
91
  def extra_validation
@@ -101,27 +101,36 @@ module WavefrontCli
101
101
  private
102
102
 
103
103
  def current_state
104
- wf.describe(options[:'<id>']).response
104
+ resp = wf.describe(options[:'<id>'])
105
+
106
+ return resp.response if resp.ok?
107
+
108
+ if resp.status.code == 404
109
+ raise WavefrontCli::Exception::UserError,
110
+ "Cannot find service account '#{options[:'<id>']}'"
111
+ end
112
+
113
+ raise resp.status.message
105
114
  end
106
115
 
107
- def add_priv_to_list(state, priv)
108
- if state[:groups].include?(priv)
109
- ok_exit(format("'%<account>s' already has the '%<priv>s' privilege.",
116
+ def add_perm_to_list(state, perm)
117
+ if state[:groups].include?(perm)
118
+ ok_exit(format("'%<account>s' already has the '%<perm>s' permission.",
110
119
  account: options[:'<id>'],
111
- priv: priv))
120
+ perm: perm))
112
121
  end
113
122
 
114
- { groups: state[:groups].push(priv), userGroups: user_group_ids(state) }
123
+ { groups: state[:groups].push(perm), userGroups: user_group_ids(state) }
115
124
  end
116
125
 
117
- def remove_priv_from_list(state, priv)
118
- unless state[:groups].include?(priv)
119
- ok_exit(format("'%<account>s' does not have the '%<priv>s' privilege.",
126
+ def remove_perm_from_list(state, perm)
127
+ unless state[:groups].include?(perm)
128
+ ok_exit(format("'%<account>s' does not have the '%<perm>s' permission.",
120
129
  account: options[:'<id>'],
121
- priv: priv))
130
+ perm: perm))
122
131
  end
123
132
 
124
- { groups: state[:groups].reject { |g| g == options[:'<privilege>'] },
133
+ { groups: state[:groups].reject { |g| g == options[:'<permission>'] },
125
134
  userGroups: user_group_ids(state) }
126
135
  end
127
136
 
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- WF_CLI_VERSION = '4.3.0'
3
+ WF_CLI_VERSION = '4.3.1'
@@ -41,20 +41,20 @@ class ServiceAccountEndToEndTest < EndToEndTest
41
41
  assert_abort_on_missing_creds("groups #{id}")
42
42
  end
43
43
 
44
- def test_privileges
44
+ def test_permissions
45
45
  quietly do
46
- assert_cmd_gets("privileges #{id}", "/api/v2/#{api_path}/#{id}")
46
+ assert_cmd_gets("permissions #{id}", "/api/v2/#{api_path}/#{id}")
47
47
  end
48
48
 
49
- assert_invalid_id("privileges #{invalid_id}")
50
- assert_usage('privileges')
49
+ assert_invalid_id("permissions #{invalid_id}")
50
+ assert_usage('permissions')
51
51
 
52
52
  assert_noop(
53
- "privileges #{id}",
53
+ "permissions #{id}",
54
54
  "uri: GET https://default.wavefront.com/api/v2/#{api_path}/#{id}"
55
55
  )
56
56
 
57
- assert_abort_on_missing_creds("privileges #{id}")
57
+ assert_abort_on_missing_creds("permissions #{id}")
58
58
  end
59
59
 
60
60
  def test_activate
@@ -143,7 +143,7 @@ class ServiceAccountEndToEndTest < EndToEndTest
143
143
 
144
144
  def test_create_account_with_permissions
145
145
  quietly do
146
- assert_cmd_posts("create -m #{permissions[0]} -m #{permissions[1]} #{id}",
146
+ assert_cmd_posts("create -p #{permissions[0]} -p #{permissions[1]} #{id}",
147
147
  '/api/v2/account/serviceaccount',
148
148
  identifier: id,
149
149
  active: true,
@@ -160,7 +160,7 @@ class ServiceAccountEndToEndTest < EndToEndTest
160
160
 
161
161
  def test_create_invalid_permission
162
162
  assert_exits_with('Unable to run command. Invalid permission.',
163
- "create -m 123456 #{id}")
163
+ "create -p 123456 #{id}")
164
164
  end
165
165
 
166
166
  def test_create_invalid_token
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher