wavefront-cli 2.17.0 → 2.18.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: 409c2cb417bfe4b580a2d140a4088c030ddeaa676c7467372df205b3e9082ba5
4
- data.tar.gz: 74392fb743bfdd8673eeaecf46f2997be75fa4296d7ad4625e7014e312654f2b
3
+ metadata.gz: 4880abc13df515eb2e0446b72e0988c99d21cc8e28e7c1adfa532f063c58e1f3
4
+ data.tar.gz: fa812c04d90125e2a53161b13a52b0978e9e43bcdf949e8ab089f40152e261f9
5
5
  SHA512:
6
- metadata.gz: 555129158af2721bf4ebda76ebf3254e3aa1c1b6a2785c3a5e558a1a183bc36fa6591bd14447fa008d4f9a3b66e3ab5db9b6b0ad4388dd43a46c03a4bfb3ffc0
7
- data.tar.gz: 16df485a8d0706ec14bf2be94c94ab898e5c69bfa36ad950fefb6fac9134cfc6fe10343c15be1e88ac4431a52fd968c6a19d3ae71f3ee99585658d2359621595
6
+ metadata.gz: 92c1347338ecc3fa32995ada2d922fe40192730ffcc51eedb13f03f8efe87593c0f8e2bca3191575f2251033cc6792ff5218cd67c7af412288febb589e7f5509
7
+ data.tar.gz: c6500c4047b9b3565facc8a3bdbba78a536aefa0d66280dceb568712055ee5c3ecb18e1bcac7d7cd175a28b9241a8535dfe4bc196da98fa4a93b9a6d7245d405
data/HISTORY.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.18.0 (22/02/2019)
4
+ * Add `usergroup` command, and extend `user` command to cover new
5
+ RBAC features.
6
+ * Require 2.5.0 of [the SDK](https://github.com/snltd/wavefront-sdk).
7
+
3
8
  ## 2.17.0 (19/02/2019)
4
9
  * Add `-O field,field` to all `list` commands. This lets you select
5
10
  the fields displayed in the output.
@@ -27,7 +32,6 @@
27
32
  query outputs tried to process an empty data set.
28
33
 
29
34
  ## 2.15.1 (20/12/2018)
30
-
31
35
  * Fix bug where `alert snoozed` and `alert firing` did the same
32
36
  thing.
33
37
 
data/README.md CHANGED
@@ -32,6 +32,7 @@ Usage:
32
32
  Commands:
33
33
  alert view and manage alerts
34
34
  cloudintegration view and manage cloud integrations
35
+ config create and manage local configuration
35
36
  dashboard view and manage dashboards
36
37
  derivedmetric view and manage derived metrics
37
38
  event open, close, view, and manage events
@@ -39,16 +40,17 @@ Commands:
39
40
  link view and manage external links
40
41
  message read and mark user messages
41
42
  metric view metrics
42
- notificant view and manage Wavefront notification targets
43
+ notificant view and manage Wavefront alert targets
43
44
  proxy view and manage Wavefront proxies
44
45
  query query the Wavefront API
45
46
  report send data directly to Wavefront
46
47
  savedsearch view and manage saved searches
47
48
  source view and manage source tags and descriptions
48
49
  user view and manage Wavefront users
50
+ usergroup view and manage Wavefront user groups
49
51
  webhook view and manage webhooks
50
52
  window view and manage maintenance windows
51
- write send data to a Wavefront proxy
53
+ write send data to Wavefront
52
54
 
53
55
  Use 'wf <command> --help' for further information.
54
56
  ```
@@ -108,7 +108,11 @@ module WavefrontCli
108
108
  def validate_id
109
109
  send(validator_method, options[:'<id>'])
110
110
  rescue validator_exception
111
- abort "'#{options[:'<id>']}' is not a valid #{klass_word} ID."
111
+ abort failed_validation_message(options[:'<id>'])
112
+ end
113
+
114
+ def failed_validation_message(input)
115
+ format("'%s' is not a valid %s ID.", input, klass_word)
112
116
  end
113
117
 
114
118
  # Make a wavefront-sdk credentials object from standard
@@ -175,7 +179,7 @@ module WavefrontCli
175
179
  # matches. The order will ensure we match "do_delete_tags" before
176
180
  # we match "do_delete".
177
181
  #
178
- m_list.sort_by(&:length).reverse.each do |m|
182
+ m_list.sort_by(&:length).reverse_each do |m|
179
183
  if m.reject { |w| options[w.to_sym] }.empty?
180
184
  method = (%w[do] + m).join('_')
181
185
  return display(public_send(method), method)
@@ -229,7 +233,7 @@ module WavefrontCli
229
233
  #
230
234
  def display_api_error(status)
231
235
  msg = status.message || 'No further information'
232
- abort format('ERROR: API code %s: %s.', status.code, msg)
236
+ abort format('ERROR: API code %s: %s.', status.code, msg.chomp('.'))
233
237
  end
234
238
 
235
239
  def display_no_api_response(data, method)
@@ -38,8 +38,8 @@ class WavefrontCommandAlert < WavefrontCommandBase
38
38
  '-a, --all list all alerts',
39
39
  '-v, --version=INTEGER describe only this version of alert',
40
40
  '-o, --offset=n start from nth alert',
41
- '-O, --fields=F1,F2,... only show given fields',
42
41
  '-L, --limit=COUNT number of alerts to list',
42
+ '-O, --fields=F1,F2,... only show given fields',
43
43
  '-T, --time=SECONDS how long to snooze (default 3600)',
44
44
  '-b, --brief do not show alert names',
45
45
  '-f, --format=STRING output format']
@@ -7,19 +7,41 @@ class WavefrontCommandUser < WavefrontCommandBase
7
7
  'view and manage Wavefront users'
8
8
  end
9
9
 
10
+ # delete uses a different string because it accepts multiples.
11
+ # Adding ellipsis to <id> causes everything else to expect an
12
+ # array.
13
+ #
10
14
  def _commands
11
15
  ["list #{CMN} [-l] [-O fields]",
12
16
  "describe #{CMN} [-f format] <id>",
13
- "delete #{CMN} <id>",
17
+ "create #{CMN} [-e] [-m permission...] [-g group...] [-f format] <id>",
18
+ "invite #{CMN} [-m permission...] [-g group...] [-f format] <id>",
19
+ "update #{CMN} <key=value> <id>",
20
+ "delete #{CMN} <user>...",
14
21
  "import #{CMN} <file>",
22
+ "groups #{CMN} <id>",
23
+ "join #{CMN} <id> <group>...",
24
+ "leave #{CMN} <id> <group>...",
15
25
  "grant #{CMN} <privilege> to <id>",
16
- "revoke #{CMN} <privilege> from <id>"]
26
+ "revoke #{CMN} <privilege> from <id>",
27
+ "search #{CMN} [-al] [-f format] [-o offset] [-L limit] <condition>..."]
17
28
  end
18
29
 
19
30
  def _options
20
31
  [common_options,
21
32
  '-l, --long list users in detail',
33
+ '-o, --offset=n start from nth user',
34
+ '-L, --limit=COUNT number of users to list',
22
35
  '-O, --fields=F1,F2,... only show given fields',
36
+ '-e, --email send e-mail to user on account creation',
37
+ '-m, --permission=STRING give user this permission',
38
+ '-g, --group=STRING add user to this user group',
23
39
  '-f, --format=STRING output format']
24
40
  end
41
+
42
+ def postscript
43
+ 'If your account does not have RBAC enabled, you must grant user ' \
44
+ "permissions with '-m'. For a list of permissions, see " \
45
+ "'wf usergroup --help'.".fold(TW, 0)
46
+ end
25
47
  end
@@ -0,0 +1,52 @@
1
+ require_relative 'base'
2
+
3
+ # Define the usergroup command.
4
+ #
5
+ class WavefrontCommandUsergroup < WavefrontCommandBase
6
+ def description
7
+ 'view and manage Wavefront user groups'
8
+ end
9
+
10
+ def sdk_class
11
+ 'UserGroup'
12
+ end
13
+
14
+ def sdk_file
15
+ 'usergroup'
16
+ end
17
+
18
+ def _commands
19
+ ["list #{CMN} [-al] [-O fields] [-f format] [-o offset] [-L limit]",
20
+ "describe #{CMN} [-f format] <id>",
21
+ "create #{CMN} [-p permission...] <name>",
22
+ "delete #{CMN} <id>",
23
+ "import #{CMN} <file>",
24
+ "update #{CMN} <key=value> <id>",
25
+ "users #{CMN} <id>",
26
+ "permissions #{CMN} <id>",
27
+ "add user #{CMN} <id> <user>...",
28
+ "remove user #{CMN} <id> <user>...",
29
+ "grant #{CMN} <permission> to <id>",
30
+ "revoke #{CMN} <permission> from <id>",
31
+ "search #{CMN} [-al] [-f format] [-o offset] [-L limit] <condition>..."]
32
+ end
33
+
34
+ def _options
35
+ [common_options,
36
+ '-l, --long list users in detail',
37
+ '-o, --offset=n start from nth user group',
38
+ '-L, --limit=COUNT number of user group to list',
39
+ '-O, --fields=F1,F2,... only show given fields',
40
+ '-p, --permission=STRING Wavefront permission',
41
+ '-u, --user=STRING user name',
42
+ '-f, --format=STRING output format']
43
+ end
44
+
45
+ def postscript
46
+ 'Valid permissions at the time of writing are: agent_management, ' \
47
+ 'alerts_management, dashboard_management, embedded_charts, ' \
48
+ 'events_management, external_links_management, host_tag_management, ' \
49
+ 'metrics_management, and user_management. Check the API docs for ' \
50
+ 'an up-to-date list.'.fold(TW, 0)
51
+ end
52
+ end
@@ -4,7 +4,7 @@ require_relative 'base'
4
4
  #
5
5
  class WavefrontCommandWrite < WavefrontCommandBase
6
6
  def description
7
- 'send data to a Wavefront proxy'
7
+ 'send data to Wavefront'
8
8
  end
9
9
 
10
10
  def _commands
@@ -67,7 +67,7 @@ class WavefrontCliController
67
67
  rescue Docopt::Exit => e
68
68
  cmd = args.empty? ? nil : args.first.to_sym
69
69
 
70
- abort e.message unless usage.keys.include?(cmd)
70
+ abort e.message unless usage.key?(cmd)
71
71
 
72
72
  begin
73
73
  [cmd, sanitize_keys(Docopt.docopt(usage[cmd], argv: args))]
@@ -9,8 +9,34 @@ module WavefrontDisplay
9
9
  data.each { |user| puts user[:identifier] }
10
10
  end
11
11
 
12
+ def do_groups
13
+ if data.userGroups.empty?
14
+ puts 'User does not belong to any groups.'
15
+ else
16
+ data.userGroups.each { |u| puts format('%s (%s)', u[:id], u[:name]) }
17
+ end
18
+ end
19
+
20
+ def do_create
21
+ puts format("Created user '%s'.\nPermission groups\n%s\n" \
22
+ "User groups\n%s",
23
+ data.response[:identifier],
24
+ groups_as_string(data.response.groups),
25
+ user_groups_as_string(data.response.userGroups))
26
+ end
27
+
28
+ def groups_as_string(groups)
29
+ return ' <none>' if groups.empty?
30
+ data.response.groups.map { |g| format(' %s', g) }.join("\n ")
31
+ end
32
+
33
+ def user_groups_as_string(groups)
34
+ return ' <none>' if groups.empty?
35
+ groups.map { |g| format(' %s (%s)', g[:name], g[:id]) }.join("\n")
36
+ end
37
+
12
38
  def do_delete
13
- puts "Deleted user '#{options[:'<id>']}."
39
+ puts format('Deleted %s', options[:'<user>'].join(', '))
14
40
  end
15
41
  end
16
42
  end
@@ -0,0 +1,52 @@
1
+ require_relative 'base'
2
+
3
+ module WavefrontDisplay
4
+ #
5
+ # Format human-readable output for user management.
6
+ #
7
+ class UserGroup < Base
8
+ def do_list_brief
9
+ multicolumn(:id, :name, :userCount)
10
+ end
11
+
12
+ def do_delete
13
+ puts "Deleted user group '#{options[:'<id>']}."
14
+ end
15
+
16
+ def do_add_user
17
+ puts format('Added %s to %s.', options[:'<user>'].join(', '),
18
+ options[:'<id>']).fold(TW, 0)
19
+ end
20
+
21
+ def do_remove_user
22
+ puts format("Removed '%s' from %s.", options[:'<user>'].join(', '),
23
+ options[:'<id>']).fold(TW, 0)
24
+ end
25
+
26
+ def do_grant
27
+ puts format("Granted '%s' permission to %s.",
28
+ options[:'<permission>'], options[:'<id>'])
29
+ end
30
+
31
+ def do_revoke
32
+ puts format("Revoked '%s' permission from %s.",
33
+ options[:'<permission>'], options[:'<id>'])
34
+ end
35
+
36
+ def do_users
37
+ if data.users.empty?
38
+ puts 'No users in group.'
39
+ else
40
+ data.users.each { |u| puts u }
41
+ end
42
+ end
43
+
44
+ def do_permissions
45
+ if data.permissions.empty?
46
+ puts 'Group has no permissions.'
47
+ else
48
+ data.permissions.each { |u| puts u }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -79,7 +79,7 @@ module WavefrontCli
79
79
  if events.size.zero?
80
80
  puts 'No open events.'
81
81
  else
82
- events.sort.reverse.each { |e| puts e.basename }
82
+ events.sort.reverse_each { |e| puts e.basename }
83
83
  end
84
84
 
85
85
  exit
@@ -208,7 +208,7 @@ module WavefrontCli
208
208
  list = local_events_with_name(name)
209
209
  return false if list.empty?
210
210
 
211
- ev_file = list.sort.last
211
+ ev_file = list.max
212
212
  File.unlink(ev_file)
213
213
  ev_file.basename.to_s
214
214
  end
@@ -9,6 +9,25 @@ module WavefrontCli
9
9
  wf.list
10
10
  end
11
11
 
12
+ def do_delete
13
+ wf.delete_users(options[:'<user>'])
14
+ end
15
+
16
+ def do_create
17
+ wf_user_id?(options[:'<id>'])
18
+ wf.create(user_body, options[:email])
19
+ end
20
+
21
+ alias do_groups do_describe
22
+
23
+ def do_join
24
+ wf.add_groups_to_user(options[:'<id>'], options[:'<group>'])
25
+ end
26
+
27
+ def do_leave
28
+ wf.remove_groups_from_user(options[:'<id>'], options[:'<group>'])
29
+ end
30
+
12
31
  def do_grant
13
32
  wf.grant(options[:'<id>'], options[:'<privilege>'])
14
33
  end
@@ -17,9 +36,42 @@ module WavefrontCli
17
36
  wf.revoke(options[:'<id>'], options[:'<privilege>'])
18
37
  end
19
38
 
39
+ def do_invite
40
+ wf_user_id?(options[:'<id>'])
41
+ wf.invite([user_body])
42
+ end
43
+
20
44
  def import_to_create(raw)
21
- raw['emailAddress'] = raw['identifier']
22
- raw.delete_if { |k, _v| k == 'customer' || k == 'identifier' }
45
+ { emailAddress: raw['items']['identifier'],
46
+ groups: raw['items']['groups'] }.tap do |r|
47
+
48
+ if raw['items'].key?('userGroups')
49
+ r['userGroups'] = raw['items']['userGroups'].map { |g| g['id'] }
50
+ end
51
+ end
52
+ end
53
+
54
+ # Object used to create and invite users.
55
+ #
56
+ def user_body
57
+ { emailAddress: options[:'<id>'],
58
+ groups: options[:permission],
59
+ userGroups: options[:group] }
60
+ end
61
+
62
+ # Because of the way docopt works, we have to call the user ID
63
+ # parameter something else on the delete command. This means the
64
+ # automatic validtion doesn't work, and we have to do it
65
+ # ourselves.
66
+ #
67
+ def extra_validation
68
+ options[:'<user>'].each { |u| validate_user(u) }
69
+ end
70
+
71
+ def validate_user(user)
72
+ wf_user_id?(user)
73
+ rescue Wavefront::Exception::InvalidUserId
74
+ abort failed_validation_message(user)
23
75
  end
24
76
  end
25
77
  end
@@ -0,0 +1,41 @@
1
+ require_relative 'base'
2
+
3
+ module WavefrontCli
4
+ #
5
+ # CLI coverage for the v2 'usergroup' API.
6
+ #
7
+ class UserGroup < WavefrontCli::Base
8
+ def validator_exception
9
+ Wavefront::Exception::InvalidUserGroupId
10
+ end
11
+
12
+ alias do_users do_describe
13
+ alias do_permissions do_describe
14
+
15
+ def do_create
16
+ wf.create(name: options[:'<name>'],
17
+ permissions: options[:permission])
18
+ end
19
+
20
+ def do_add_user
21
+ wf.add_users_to_group(options[:'<id>'], options[:'<user>'])
22
+ end
23
+
24
+ def do_remove_user
25
+ wf.remove_users_from_group(options[:'<id>'], options[:'<user>'])
26
+ end
27
+
28
+ def do_grant
29
+ wf.grant(options[:'<permission>'], Array(options[:'<id>']))
30
+ end
31
+
32
+ def do_revoke
33
+ wf.revoke(options[:'<permission>'], Array(options[:'<id>']))
34
+ end
35
+
36
+ def import_to_create(raw)
37
+ raw['emailAddress'] = raw['identifier']
38
+ raw.delete_if { |k, _v| k == 'customer' || k == 'identifier' }
39
+ end
40
+ end
41
+ end
@@ -1 +1 @@
1
- WF_CLI_VERSION = '2.17.0'.freeze
1
+ WF_CLI_VERSION = '2.18.0'.freeze
@@ -10,9 +10,20 @@ include Wavefront::Mixins
10
10
  # rubocop:enable Style/MixinUsage
11
11
 
12
12
  q = 'ts("dev.cli.test")'
13
- t1 = parse_time('12:00', true)
14
- t2 = parse_time('12:10', true)
15
- o = '-g m -s 12:00'
13
+ #
14
+ # The SDK has got smarter about calculating granularity options, so
15
+ # we can't use any kind of absolute time any more. We round time
16
+ # down to the nearest minute, because that's how users will most
17
+ # likely specify it.
18
+ #
19
+ t1_t = Time.now - (30 * 60)
20
+ t1_t = Time.at(t1_t.to_i - t1_t.sec)
21
+ t2_t = Time.at(t1_t + (10 * 60))
22
+
23
+ t1 = parse_time(t1_t, true)
24
+ t2 = parse_time(t2_t, true)
25
+ o = "-g m -s #{t1_t.strftime('%H:%M')}"
26
+ s_and_e_opts = "-s #{t1_t.strftime('%H:%M')} -e #{t2_t.strftime('%H:%M')}"
16
27
 
17
28
  describe "#{word} command" do
18
29
  cmd_to_call(word, "-s -2h #{q}",
@@ -21,12 +32,12 @@ describe "#{word} command" do
21
32
  '&s=[0-9]{13}&sorted=true&strict=true&summarization=mean',
22
33
  regex: true)
23
34
 
24
- missing_creds(word, ["-g m -s 12:00 '#{q}'", "raw #{q}"])
35
+ missing_creds(word, ["#{o} '#{q}'", "raw #{q}"])
25
36
 
26
37
  cmd_noop(word, "-s #{t1} #{q}",
27
38
  ['GET https://metrics.wavefront.com/api/v2/chart/api',
28
39
  i: false, summarization: 'mean', listMode: true, strict: true,
29
- sorted: true, q: q, g: :h, s: t1])
40
+ sorted: true, q: q, g: :m, s: t1])
30
41
 
31
42
  cmd_noop(word, 'raw dev.cli.test',
32
43
  ['GET https://metrics.wavefront.com/api/v2/chart/raw',
@@ -36,29 +47,30 @@ describe "#{word} command" do
36
47
  path: '/api/v2/chart/api?g=m&i=false&listMode=true' \
37
48
  "&q=ts(%22dev.cli.test%22)&s=#{t1}&sorted=true" \
38
49
  '&strict=true&summarization=mean')
39
- cmd_to_call(word, "#{o} -e 12:10 #{q}",
50
+
51
+ cmd_to_call(word, "#{s_and_e_opts} #{q}",
40
52
  path: "/api/v2/chart/api?e=#{t2}&g=m&i=false" \
41
53
  '&listMode=true&q=ts(%22dev.cli.test%22)' \
42
54
  "&s=#{t1}&sorted=true&strict=true&summarization=mean")
43
55
 
44
- cmd_to_call(word, "-g s -s 12:00 -e 12:10 -S max #{q}",
56
+ cmd_to_call(word, "-g s #{s_and_e_opts} -S max #{q}",
45
57
  path: "/api/v2/chart/api?e=#{t2}&g=s&i=false" \
46
58
  '&listMode=true&q=ts(%22dev.cli.test%22)' \
47
59
  "&s=#{t1}&sorted=true&strict=true&summarization=max")
48
60
 
49
- cmd_to_call(word, "-g s -s 12:00 -e 12:10 -p 100 #{q}",
61
+ cmd_to_call(word, "-g s #{s_and_e_opts} -p 100 #{q}",
50
62
  path: "/api/v2/chart/api?e=#{t2}&g=s&i=false" \
51
63
  '&listMode=true&q=ts(%22dev.cli.test%22)' \
52
64
  "&s=#{t1}&sorted=true&summarization=mean&strict=true" \
53
65
  '&p=100')
54
66
 
55
- cmd_to_call(word, "-iO -g h -s 12:00 -e 12:10 -p 100 #{q}",
67
+ cmd_to_call(word, "-iO -g h #{s_and_e_opts} -p 100 #{q}",
56
68
  path: "/api/v2/chart/api?e=#{t2}&g=h&i=true" \
57
69
  '&listMode=true&q=ts(%22dev.cli.test%22)' \
58
70
  "&s=#{t1}&sorted=true&summarization=mean" \
59
71
  '&strict=true&p=100&includeObsoleteMetrics=true')
60
72
 
61
- cmd_to_call(word, "-N query -g h -s 12:00 -e 12:10 -p 100 #{q}",
73
+ cmd_to_call(word, "-N query -g h #{s_and_e_opts} -p 100 #{q}",
62
74
  path: "/api/v2/chart/api?e=#{t2}&g=h&i=false" \
63
75
  '&listMode=true&q=ts(%22dev.cli.test%22)' \
64
76
  "&s=#{t1}&sorted=true&summarization=mean" \
@@ -70,11 +82,11 @@ describe "#{word} command" do
70
82
  cmd_to_call(word, 'raw -H h1 dev.cli.test',
71
83
  path: '/api/v2/chart/raw?metric=dev.cli.test&source=h1')
72
84
 
73
- cmd_to_call(word, 'raw -s 12:00 -H h1 dev.cli.test',
85
+ cmd_to_call(word, "raw -s #{t1_t.strftime('%H:%M')} -H h1 dev.cli.test",
74
86
  path: '/api/v2/chart/raw?metric=dev.cli.test&source=h1' \
75
87
  "&startTime=#{t1}")
76
88
 
77
- cmd_to_call(word, 'raw -s 12:00 -e 12:10 -H h1 dev.cli.test',
89
+ cmd_to_call(word, "raw #{s_and_e_opts} -H h1 dev.cli.test",
78
90
  path: '/api/v2/chart/raw?metric=dev.cli.test&source=h1' \
79
91
  "&startTime=#{t1}&endTime=#{t2}")
80
92
  end
@@ -3,6 +3,9 @@
3
3
  id = 'someone@somewhere.com'
4
4
  bad_id = '__BAD__'
5
5
  word = 'user'
6
+ gid1 = '2659191e-aad4-4302-a94e-9667e1517127'
7
+ gid2 = 'abcdef12-1234-abcd-1234-abcdef012345'
8
+ priv = 'alerts_management'
6
9
 
7
10
  require_relative '../spec_helper'
8
11
  require_relative "../../lib/wavefront-cli/#{word}"
@@ -12,22 +15,102 @@ describe "#{word} command" do
12
15
  'Content-Type': 'application/x-www-form-urlencoded'
13
16
  )
14
17
 
15
- missing_creds(word, ['list', "describe #{id}", "delete #{id}"])
18
+ missing_creds(word, ['list',
19
+ "describe #{id}",
20
+ "delete #{id}",
21
+ "create #{id}",
22
+ "invite #{id}",
23
+ "update key=val #{id}",
24
+ 'import file',
25
+ "groups #{id}",
26
+ "join #{id} #{gid1}",
27
+ "leave #{id} #{gid1}",
28
+ "grant #{priv} to #{id}",
29
+ "revoke #{priv} from #{id}"])
30
+
16
31
  cmd_to_call(word, 'list', path: "/api/v2/#{word}")
32
+
17
33
  cmd_to_call(word, "describe #{id}", path: "/api/v2/#{word}/#{id}")
18
- cmd_to_call(word, "delete #{id}", method: :delete,
19
- path: "/api/v2/#{word}/#{id}")
34
+
35
+ cmd_to_call(word, "create #{id}",
36
+ method: :post,
37
+ path: "/api/v2/#{word}?sendEmail=false",
38
+ body: { emailAddress: id,
39
+ groups: [],
40
+ userGroups: [] }.to_json)
41
+
42
+ cmd_to_call(word, "create -e #{id} -m #{priv}",
43
+ method: :post,
44
+ path: "/api/v2/#{word}?sendEmail=true",
45
+ body: { emailAddress: id,
46
+ groups: [priv],
47
+ userGroups: [] }.to_json)
48
+
49
+ cmd_to_call(word, "create #{id} -g #{gid1} -g #{gid2}",
50
+ method: :post,
51
+ path: "/api/v2/#{word}?sendEmail=false",
52
+ body: { emailAddress: id,
53
+ groups: [],
54
+ userGroups: [gid1, gid2] }.to_json)
55
+
56
+ cmd_to_call(word, "invite -m #{priv} -g #{gid2} #{id}",
57
+ method: :post,
58
+ path: "/api/v2/#{word}/invite",
59
+ body: [{ emailAddress: id,
60
+ groups: [priv],
61
+ userGroups: [gid2] }].to_json)
62
+
63
+ cmd_to_call(word, "delete #{id}",
64
+ method: :post,
65
+ path: "/api/v2/#{word}/deleteUsers",
66
+ body: [id].to_json)
67
+
68
+ cmd_to_call(word, "groups #{id}", path: "/api/v2/#{word}/#{id}")
69
+
70
+ cmd_to_call(word, "join #{id} #{gid1}",
71
+ method: :post,
72
+ path: "/api/v2/#{word}/#{id}/addUserGroups",
73
+ body: [gid1].to_json)
74
+
75
+ cmd_to_call(word, "leave #{id} #{gid2} #{gid1}",
76
+ method: :post,
77
+ path: "/api/v2/#{word}/#{id}/removeUserGroups",
78
+ body: [gid2, gid1].to_json)
79
+
20
80
  cmd_to_call(word, "grant agent_management to #{id}",
21
- method: :post, path: "/api/v2/#{word}/#{id}/grant",
81
+ method: :post,
82
+ path: "/api/v2/#{word}/#{id}/grant",
22
83
  body: 'group=agent_management',
23
84
  headers: hdrs)
24
85
 
25
86
  cmd_to_call(word, "revoke agent_management from #{id}",
26
- method: :post, path: "/api/v2/#{word}/#{id}/revoke",
87
+ method: :post,
88
+ path: "/api/v2/#{word}/#{id}/revoke",
27
89
  body: 'group=agent_management',
28
90
  headers: hdrs)
29
91
 
30
- invalid_ids(word, ["describe #{bad_id}", "delete #{bad_id}"])
92
+ cmd_to_call(word, "search -L 40 id=#{id}",
93
+ { method: :post, path: "/api/v2/search/#{word}",
94
+ body: { limit: '40',
95
+ offset: 0,
96
+ query: [{ key: 'id',
97
+ value: id,
98
+ matchingMethod: 'EXACT' }],
99
+ sort: { field: 'id', ascending: true } },
100
+ headers: JSON_POST_HEADERS }, WavefrontCli::User)
101
+
102
+ invalid_ids(word, ["describe #{bad_id}",
103
+ "delete #{bad_id}",
104
+ "delete #{id} #{bad_id}",
105
+ "delete #{bad_id}",
106
+ "invite #{bad_id}",
107
+ "create -e #{bad_id}",
108
+ "groups #{bad_id}",
109
+ "join #{bad_id} #{gid1}",
110
+ "leave #{bad_id} #{gid1}",
111
+ "grant #{priv} to #{bad_id}",
112
+ "revoke #{priv} from #{bad_id}"])
113
+
31
114
  cmd_noop(word, 'list',
32
115
  ["GET https://metrics.wavefront.com/api/v2/#{word}"])
33
116
  cmd_noop(word, 'describe rob@a.com',
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ uid1 = 'someone@somewhere.com'
4
+ uid2 = 'other@elsewhere.com'
5
+ name = 'testgroup'
6
+ bad_id = '__BAD__'
7
+ word = 'usergroup'
8
+ gid1 = '2659191e-aad4-4302-a94e-9667e1517127'
9
+ priv1 = 'alerts_management'
10
+ priv2 = 'events_management'
11
+
12
+ require_relative '../spec_helper'
13
+ require_relative "../../lib/wavefront-cli/#{word}"
14
+
15
+ k = WavefrontCli::UserGroup
16
+
17
+ describe "#{word} command" do
18
+ missing_creds(word, ['list',
19
+ "describe #{gid1}",
20
+ "create #{name}",
21
+ "delete #{gid1}",
22
+ 'import file',
23
+ "update key=val #{gid1}",
24
+ "users #{gid1}",
25
+ "permissions #{gid1}",
26
+ "add user #{gid1} #{uid1} #{uid2}",
27
+ "remove user #{gid1} #{uid1} #{uid2}",
28
+ "grant #{priv1} to #{gid1}",
29
+ "revoke #{priv2} from #{gid1}",
30
+ 'search key=value'])
31
+
32
+ list_tests(word, 'usergroup', k)
33
+
34
+ cmd_to_call(word, "describe #{gid1}",
35
+ { path: "/api/v2/#{word}/#{gid1}" }, k)
36
+
37
+ cmd_to_call(word, "create #{name}",
38
+ { method: :post,
39
+ path: "/api/v2/#{word}",
40
+ body: { name: name, permissions: [] }.to_json }, k)
41
+
42
+ cmd_to_call(word, "create -p #{priv1} -p #{priv2} #{name}",
43
+ { method: :post,
44
+ path: "/api/v2/#{word}",
45
+ body: { name: name,
46
+ permissions: [priv1, priv2] }.to_json }, k)
47
+
48
+ cmd_to_call(word, "delete #{gid1}",
49
+ { method: :delete, path: "/api/v2/#{word}/#{gid1}" }, k)
50
+
51
+ cmd_to_call(word, "users #{gid1}",
52
+ { path: "/api/v2/#{word}/#{gid1}" }, k)
53
+
54
+ cmd_to_call(word, "permissions #{gid1}",
55
+ { path: "/api/v2/#{word}/#{gid1}" }, k)
56
+
57
+ cmd_to_call(word, "add user #{gid1} #{uid1}",
58
+ { method: :post,
59
+ path: "/api/v2/#{word}/#{gid1}/addUsers",
60
+ body: [uid1].to_json }, k)
61
+
62
+ cmd_to_call(word, "add user #{gid1} #{uid1} #{uid2}",
63
+ { method: :post,
64
+ path: "/api/v2/#{word}/#{gid1}/addUsers",
65
+ body: [uid1, uid2].to_json }, k)
66
+
67
+ cmd_to_call(word, "remove user #{gid1} #{uid1}",
68
+ { method: :post,
69
+ path: "/api/v2/#{word}/#{gid1}/removeUsers",
70
+ body: [uid1].to_json }, k)
71
+
72
+ cmd_to_call(word, "remove user #{gid1} #{uid1} #{uid2}",
73
+ { method: :post,
74
+ path: "/api/v2/#{word}/#{gid1}/removeUsers",
75
+ body: [uid1, uid2].to_json }, k)
76
+
77
+ cmd_to_call(word, "grant #{priv1} to #{gid1}",
78
+ { method: :post,
79
+ path: "/api/v2/#{word}/grant/#{priv1}",
80
+ body: [gid1].to_json }, k)
81
+
82
+ cmd_to_call(word, "revoke #{priv1} from #{gid1}",
83
+ { method: :post,
84
+ path: "/api/v2/#{word}/revoke/#{priv1}",
85
+ body: [gid1].to_json }, k)
86
+
87
+ cmd_to_call(word, 'search -L 40 id=string',
88
+ { method: :post, path: "/api/v2/search/#{word}",
89
+ body: { limit: '40',
90
+ offset: 0,
91
+ query: [{ key: 'id',
92
+ value: 'string',
93
+ matchingMethod: 'EXACT' }],
94
+ sort: { field: 'id', ascending: true } } }, k)
95
+
96
+ invalid_ids(word, ["describe #{bad_id}",
97
+ "delete #{bad_id}",
98
+ "update key=val #{bad_id}",
99
+ "users #{bad_id}",
100
+ "permissions #{bad_id}",
101
+ "add user #{bad_id} #{uid1} #{uid2}",
102
+ "remove user #{bad_id} #{uid1} #{uid2}",
103
+ "grant #{priv1} to #{bad_id}",
104
+ "revoke #{priv2} from #{bad_id}"])
105
+
106
+ cmd_noop(word, 'list',
107
+ ["GET https://metrics.wavefront.com/api/v2/#{word}"], k)
108
+ cmd_noop(word, "describe #{gid1}",
109
+ ["GET https://metrics.wavefront.com/api/v2/#{word}/#{gid1}"], k)
110
+ end
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
24
24
 
25
25
  gem.add_runtime_dependency 'docopt', '~> 0.6.0'
26
26
  gem.add_runtime_dependency 'inifile', '~> 3.0'
27
- gem.add_runtime_dependency 'wavefront-sdk', '~> 2.2', '>= 2.2.1'
27
+ gem.add_runtime_dependency 'wavefront-sdk', '~> 2.5', '>= 2.5.0'
28
28
 
29
29
  gem.add_development_dependency 'bundler', '~> 1.3'
30
30
  gem.add_development_dependency 'minitest', '~> 5.11', '>= 5.11.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.0
4
+ version: 2.18.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-02-19 00:00:00.000000000 Z
11
+ date: 2019-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -42,22 +42,22 @@ dependencies:
42
42
  name: wavefront-sdk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2.2'
48
45
  - - ">="
49
46
  - !ruby/object:Gem::Version
50
- version: 2.2.1
47
+ version: 2.5.0
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '2.5'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '2.2'
58
55
  - - ">="
59
56
  - !ruby/object:Gem::Version
60
- version: 2.2.1
57
+ version: 2.5.0
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.5'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +203,7 @@ files:
203
203
  - lib/wavefront-cli/commands/savedsearch.rb
204
204
  - lib/wavefront-cli/commands/source.rb
205
205
  - lib/wavefront-cli/commands/user.rb
206
+ - lib/wavefront-cli/commands/usergroup.rb
206
207
  - lib/wavefront-cli/commands/webhook.rb
207
208
  - lib/wavefront-cli/commands/window.rb
208
209
  - lib/wavefront-cli/commands/write.rb
@@ -234,6 +235,7 @@ files:
234
235
  - lib/wavefront-cli/display/savedsearch.rb
235
236
  - lib/wavefront-cli/display/source.rb
236
237
  - lib/wavefront-cli/display/user.rb
238
+ - lib/wavefront-cli/display/usergroup.rb
237
239
  - lib/wavefront-cli/display/webhook.rb
238
240
  - lib/wavefront-cli/display/write.rb
239
241
  - lib/wavefront-cli/event.rb
@@ -268,6 +270,7 @@ files:
268
270
  - lib/wavefront-cli/source.rb
269
271
  - lib/wavefront-cli/stdlib/string.rb
270
272
  - lib/wavefront-cli/user.rb
273
+ - lib/wavefront-cli/usergroup.rb
271
274
  - lib/wavefront-cli/version.rb
272
275
  - lib/wavefront-cli/webhook.rb
273
276
  - lib/wavefront-cli/write.rb
@@ -325,6 +328,7 @@ files:
325
328
  - spec/wavefront-cli/source_spec.rb
326
329
  - spec/wavefront-cli/stdlib/string_spec.rb
327
330
  - spec/wavefront-cli/user_spec.rb
331
+ - spec/wavefront-cli/usergroup_spec.rb
328
332
  - spec/wavefront-cli/webhook_spec.rb
329
333
  - spec/wavefront-cli/write_spec.rb
330
334
  - wavefront-cli.gemspec
@@ -406,5 +410,6 @@ test_files:
406
410
  - spec/wavefront-cli/source_spec.rb
407
411
  - spec/wavefront-cli/stdlib/string_spec.rb
408
412
  - spec/wavefront-cli/user_spec.rb
413
+ - spec/wavefront-cli/usergroup_spec.rb
409
414
  - spec/wavefront-cli/webhook_spec.rb
410
415
  - spec/wavefront-cli/write_spec.rb