wavefront-cli 4.2.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.rubocop.yml +1 -14
  4. data/.travis.yml +4 -4
  5. data/Gemfile +2 -0
  6. data/HISTORY.md +82 -60
  7. data/Rakefile +2 -0
  8. data/bin/wf +1 -0
  9. data/lib/wavefront-cli/alert.rb +13 -5
  10. data/lib/wavefront-cli/apitoken.rb +2 -0
  11. data/lib/wavefront-cli/base.rb +95 -47
  12. data/lib/wavefront-cli/cloudintegration.rb +6 -0
  13. data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
  14. data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
  15. data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
  16. data/lib/wavefront-cli/commands/alert.rb +2 -1
  17. data/lib/wavefront-cli/commands/apitoken.rb +6 -0
  18. data/lib/wavefront-cli/commands/base.rb +30 -21
  19. data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
  20. data/lib/wavefront-cli/commands/config.rb +2 -0
  21. data/lib/wavefront-cli/commands/dashboard.rb +2 -0
  22. data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
  23. data/lib/wavefront-cli/commands/event.rb +3 -1
  24. data/lib/wavefront-cli/commands/integration.rb +2 -1
  25. data/lib/wavefront-cli/commands/link.rb +2 -0
  26. data/lib/wavefront-cli/commands/message.rb +2 -0
  27. data/lib/wavefront-cli/commands/metric.rb +2 -0
  28. data/lib/wavefront-cli/commands/notificant.rb +2 -0
  29. data/lib/wavefront-cli/commands/proxy.rb +2 -0
  30. data/lib/wavefront-cli/commands/query.rb +2 -0
  31. data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
  32. data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
  33. data/lib/wavefront-cli/commands/settings.rb +2 -0
  34. data/lib/wavefront-cli/commands/source.rb +3 -1
  35. data/lib/wavefront-cli/commands/user.rb +4 -1
  36. data/lib/wavefront-cli/commands/usergroup.rb +3 -0
  37. data/lib/wavefront-cli/commands/webhook.rb +2 -0
  38. data/lib/wavefront-cli/commands/window.rb +2 -0
  39. data/lib/wavefront-cli/commands/write.rb +2 -0
  40. data/lib/wavefront-cli/config.rb +23 -12
  41. data/lib/wavefront-cli/constants.rb +10 -4
  42. data/lib/wavefront-cli/controller.rb +53 -22
  43. data/lib/wavefront-cli/dashboard.rb +3 -0
  44. data/lib/wavefront-cli/derivedmetric.rb +12 -11
  45. data/lib/wavefront-cli/display/alert.rb +7 -4
  46. data/lib/wavefront-cli/display/apitoken.rb +2 -0
  47. data/lib/wavefront-cli/display/base.rb +34 -8
  48. data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
  49. data/lib/wavefront-cli/display/dashboard.rb +2 -0
  50. data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
  51. data/lib/wavefront-cli/display/distribution.rb +2 -0
  52. data/lib/wavefront-cli/display/event.rb +2 -0
  53. data/lib/wavefront-cli/display/externallink.rb +2 -0
  54. data/lib/wavefront-cli/display/integration.rb +2 -0
  55. data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
  56. data/lib/wavefront-cli/display/message.rb +7 -3
  57. data/lib/wavefront-cli/display/metric.rb +3 -1
  58. data/lib/wavefront-cli/display/notificant.rb +3 -1
  59. data/lib/wavefront-cli/display/printer/long.rb +36 -11
  60. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
  61. data/lib/wavefront-cli/display/printer/terse.rb +6 -1
  62. data/lib/wavefront-cli/display/proxy.rb +2 -0
  63. data/lib/wavefront-cli/display/query.rb +35 -24
  64. data/lib/wavefront-cli/display/savedsearch.rb +2 -0
  65. data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
  66. data/lib/wavefront-cli/display/settings.rb +2 -0
  67. data/lib/wavefront-cli/display/source.rb +18 -4
  68. data/lib/wavefront-cli/display/user.rb +56 -10
  69. data/lib/wavefront-cli/display/usergroup.rb +25 -19
  70. data/lib/wavefront-cli/display/webhook.rb +2 -0
  71. data/lib/wavefront-cli/display/write.rb +6 -2
  72. data/lib/wavefront-cli/event.rb +83 -62
  73. data/lib/wavefront-cli/exception.rb +3 -0
  74. data/lib/wavefront-cli/externallink.rb +6 -4
  75. data/lib/wavefront-cli/integration.rb +2 -0
  76. data/lib/wavefront-cli/maintenancewindow.rb +28 -17
  77. data/lib/wavefront-cli/message.rb +4 -0
  78. data/lib/wavefront-cli/metric.rb +4 -1
  79. data/lib/wavefront-cli/notificant.rb +2 -0
  80. data/lib/wavefront-cli/opt_handler.rb +2 -0
  81. data/lib/wavefront-cli/output/base.rb +8 -3
  82. data/lib/wavefront-cli/output/csv.rb +2 -0
  83. data/lib/wavefront-cli/output/csv/base.rb +2 -0
  84. data/lib/wavefront-cli/output/csv/query.rb +14 -7
  85. data/lib/wavefront-cli/output/hcl.rb +2 -0
  86. data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
  87. data/lib/wavefront-cli/output/hcl/base.rb +10 -4
  88. data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
  89. data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
  90. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
  91. data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
  92. data/lib/wavefront-cli/output/json.rb +2 -0
  93. data/lib/wavefront-cli/output/ruby.rb +2 -0
  94. data/lib/wavefront-cli/output/wavefront.rb +2 -0
  95. data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
  96. data/lib/wavefront-cli/output/yaml.rb +2 -0
  97. data/lib/wavefront-cli/proxy.rb +15 -3
  98. data/lib/wavefront-cli/query.rb +14 -12
  99. data/lib/wavefront-cli/savedsearch.rb +2 -0
  100. data/lib/wavefront-cli/serviceaccount.rb +179 -0
  101. data/lib/wavefront-cli/settings.rb +2 -0
  102. data/lib/wavefront-cli/source.rb +2 -0
  103. data/lib/wavefront-cli/stdlib/array.rb +3 -0
  104. data/lib/wavefront-cli/stdlib/string.rb +17 -11
  105. data/lib/wavefront-cli/user.rb +10 -4
  106. data/lib/wavefront-cli/usergroup.rb +4 -2
  107. data/lib/wavefront-cli/version.rb +3 -1
  108. data/lib/wavefront-cli/webhook.rb +2 -0
  109. data/lib/wavefront-cli/write.rb +80 -46
  110. data/spec/.rubocop.yml +3 -16
  111. data/spec/constants.rb +21 -0
  112. data/spec/spec_helper.rb +8 -422
  113. data/spec/support/command_base.rb +82 -0
  114. data/spec/support/minitest_assertions.rb +262 -0
  115. data/spec/support/output_tester.rb +32 -0
  116. data/spec/support/supported_commands.rb +19 -0
  117. data/spec/test_mixins/acl.rb +169 -0
  118. data/spec/test_mixins/delete.rb +25 -0
  119. data/spec/test_mixins/deleteundelete.rb +106 -0
  120. data/spec/test_mixins/describe.rb +24 -0
  121. data/spec/test_mixins/dump.rb +43 -0
  122. data/spec/test_mixins/general.rb +11 -0
  123. data/spec/test_mixins/history.rb +35 -0
  124. data/spec/test_mixins/import.rb +65 -0
  125. data/spec/test_mixins/list.rb +29 -0
  126. data/spec/test_mixins/search.rb +98 -0
  127. data/spec/test_mixins/set.rb +47 -0
  128. data/spec/test_mixins/tag.rb +99 -0
  129. data/spec/wavefront-cli/alert_spec.rb +288 -111
  130. data/spec/wavefront-cli/apitoken_spec.rb +53 -24
  131. data/spec/wavefront-cli/base_spec.rb +9 -27
  132. data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
  133. data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
  134. data/spec/wavefront-cli/commands/base_spec.rb +15 -13
  135. data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
  136. data/spec/wavefront-cli/commands/config_spec.rb +3 -0
  137. data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
  138. data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
  139. data/spec/wavefront-cli/commands/event_spec.rb +1 -0
  140. data/spec/wavefront-cli/commands/link_spec.rb +1 -0
  141. data/spec/wavefront-cli/commands/message_spec.rb +1 -0
  142. data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
  143. data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
  144. data/spec/wavefront-cli/commands/query_spec.rb +1 -0
  145. data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
  146. data/spec/wavefront-cli/commands/window_spec.rb +1 -0
  147. data/spec/wavefront-cli/commands/write_spec.rb +1 -0
  148. data/spec/wavefront-cli/config_spec.rb +25 -14
  149. data/spec/wavefront-cli/controller_spec.rb +13 -3
  150. data/spec/wavefront-cli/dashboard_spec.rb +125 -76
  151. data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
  152. data/spec/wavefront-cli/display/base_spec.rb +5 -7
  153. data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
  154. data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
  155. data/spec/wavefront-cli/event_spec.rb +360 -18
  156. data/spec/wavefront-cli/externallink_spec.rb +92 -58
  157. data/spec/wavefront-cli/integration_spec.rb +129 -31
  158. data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
  159. data/spec/wavefront-cli/message_spec.rb +73 -30
  160. data/spec/wavefront-cli/metric_spec.rb +60 -22
  161. data/spec/wavefront-cli/notificant_spec.rb +45 -32
  162. data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
  163. data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
  164. data/spec/wavefront-cli/output/csv_spec.rb +5 -2
  165. data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
  166. data/spec/wavefront-cli/output/helpers.rb +18 -0
  167. data/spec/wavefront-cli/output/json_spec.rb +3 -1
  168. data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
  169. data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
  170. data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
  171. data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
  172. data/spec/wavefront-cli/proxy_spec.rb +49 -27
  173. data/spec/wavefront-cli/query_spec.rb +174 -92
  174. data/spec/wavefront-cli/resources/responses/query.json +1 -0
  175. data/spec/wavefront-cli/resources/updates/alert.json +15 -0
  176. data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
  177. data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
  178. data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
  179. data/spec/wavefront-cli/settings_spec.rb +42 -11
  180. data/spec/wavefront-cli/source_spec.rb +120 -23
  181. data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
  182. data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
  183. data/spec/wavefront-cli/user_spec.rb +278 -108
  184. data/spec/wavefront-cli/usergroup_spec.rb +152 -102
  185. data/spec/wavefront-cli/webhook_spec.rb +30 -15
  186. data/spec/wavefront-cli/write_spec.rb +25 -1
  187. data/wavefront-cli.gemspec +5 -3
  188. metadata +65 -21
  189. data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
  190. data/spec/wavefront-cli/display/spec_helper.rb +0 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontOutput
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -14,16 +16,26 @@ module WavefrontCli
14
16
  wf.rename(options[:'<id>'], options[:'<name>'])
15
17
  end
16
18
 
19
+ def do_delete
20
+ smart_delete
21
+ end
22
+
17
23
  def do_versions
18
- raw = wf.list(0, :all).response.items.map do |i|
24
+ raw = wf.list(0, :all)
25
+ exit if options[:noop]
26
+
27
+ version_info(raw).sort_by { |p| Gem::Version.new(p[:version]) }.reverse
28
+ end
29
+
30
+ def version_info(raw)
31
+ raw.response.items.map do |i|
19
32
  { id: i.id, version: i.version, name: i.name }
20
33
  end
21
-
22
- raw.sort_by { |p| Gem::Version.new(p[:version]) }.reverse
23
34
  end
24
35
 
25
36
  def extra_validation
26
37
  return unless options[:'<name>']
38
+
27
39
  begin
28
40
  wf_string?(options[:'<name>'])
29
41
  rescue Wavefront::Exception::InvalidString
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'wavefront-sdk/support/mixins'
2
4
  require_relative 'base'
3
5
 
@@ -31,7 +33,7 @@ module WavefrontCli
31
33
  end
32
34
 
33
35
  def do_run
34
- alias_key = format('q_%s', options[:'<alias>']).to_sym
36
+ alias_key = format('q_%<alias>s', alias: options[:'<alias>']).to_sym
35
37
  query = all_aliases.fetch(alias_key, nil)
36
38
 
37
39
  unless query
@@ -51,17 +53,16 @@ module WavefrontCli
51
53
  #
52
54
  # rubocop:disable Metrics/AbcSize
53
55
  def q_opts
54
- ret = { autoEvents: options[:events],
55
- i: options[:inclusive],
56
- summarization: options[:summarize] || 'mean',
57
- listMode: true,
58
- strict: true,
59
- includeObsoleteMetrics: options[:obsolete],
60
- sorted: true }
61
-
62
- ret[:n] = options[:name] if options[:name]
63
- ret[:p] = options[:points] if options[:points]
64
- ret
56
+ { autoEvents: options[:events],
57
+ i: options[:inclusive],
58
+ summarization: options[:summarize] || 'mean',
59
+ listMode: true,
60
+ strict: true,
61
+ includeObsoleteMetrics: options[:obsolete],
62
+ sorted: true }.tap do |o|
63
+ o[:n] = options[:name] if options[:name]
64
+ o[:p] = options[:points] if options[:points]
65
+ end
65
66
  end
66
67
  # rubocop:enable Metrics/AbcSize
67
68
 
@@ -103,6 +104,7 @@ module WavefrontCli
103
104
 
104
105
  def extra_validation
105
106
  return unless options[:granularity]
107
+
106
108
  begin
107
109
  wf_granularity?(options[:granularity])
108
110
  rescue Wavefront::Exception::InvalidGranularity
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+ require 'wavefront-sdk/apitoken'
5
+
6
+ module WavefrontCli
7
+ #
8
+ # CLI coverage for the v2 'serviceaccount' API.
9
+ #
10
+ class ServiceAccount < WavefrontCli::Base
11
+ attr_reader :wf_apitoken
12
+
13
+ def post_initialize(_options)
14
+ @wf_apitoken = Wavefront::ApiToken.new(mk_creds, mk_opts)
15
+ end
16
+
17
+ def do_list
18
+ wf.list
19
+ end
20
+
21
+ def do_describe
22
+ wf.describe(options[:'<id>'])
23
+ end
24
+
25
+ alias do_groups do_describe
26
+ alias do_privileges do_describe
27
+
28
+ def do_create
29
+ wf_user_id?(options[:'<id>'])
30
+ wf.create(user_body)
31
+ end
32
+
33
+ def do_activate
34
+ wf.activate(options[:'<id>'])
35
+ end
36
+
37
+ def do_deactivate
38
+ wf.deactivate(options[:'<id>'])
39
+ end
40
+
41
+ def do_join
42
+ cannot_noop!
43
+ options[:'<group>'].each { |g| wf_usergroup_id?(g) }
44
+
45
+ body = add_groups_to_list(current_state, options[:'<group>'])
46
+ wf.update(options[:'<id>'], body)
47
+ end
48
+
49
+ def do_leave
50
+ cannot_noop!
51
+ options[:'<group>'].each { |g| wf_usergroup_id?(g) }
52
+
53
+ body = remove_groups_from_list(current_state, options[:'<group>'])
54
+ wf.update(options[:'<id>'], body)
55
+ end
56
+
57
+ def do_grant
58
+ cannot_noop!
59
+ wf_permission?(options[:'<privilege>'])
60
+
61
+ body = add_priv_to_list(current_state, options[:'<privilege>'])
62
+ wf.update(options[:'<id>'], body)
63
+ end
64
+
65
+ def do_revoke
66
+ cannot_noop!
67
+ wf_permission?(options[:'<privilege>'])
68
+
69
+ body = remove_priv_from_list(current_state, options[:'<privilege>'])
70
+ wf.update(options[:'<id>'], body)
71
+ end
72
+
73
+ def do_apitoken_list
74
+ wf_apitoken.list(options[:'<id>'])
75
+ end
76
+
77
+ def do_apitoken_create
78
+ wf_apitoken.create(options[:'<id>'], options[:name])
79
+ end
80
+
81
+ def do_apitoken_delete
82
+ wf_apitoken.delete(options[:'<id>'], options[:'<token_id>'])
83
+ end
84
+
85
+ def do_apitoken_rename
86
+ wf_apitoken.rename(options[:'<id>'],
87
+ options[:'<token_id>'],
88
+ options[:'<name>'])
89
+ end
90
+
91
+ def extra_validation
92
+ validate_groups
93
+ validate_tokens
94
+ validate_perms
95
+ end
96
+
97
+ def validator_exception
98
+ Wavefront::Exception::InvalidServiceAccountId
99
+ end
100
+
101
+ private
102
+
103
+ def current_state
104
+ wf.describe(options[:'<id>']).response
105
+ end
106
+
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.",
110
+ account: options[:'<id>'],
111
+ priv: priv))
112
+ end
113
+
114
+ { groups: state[:groups].push(priv), userGroups: user_group_ids(state) }
115
+ end
116
+
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.",
120
+ account: options[:'<id>'],
121
+ priv: priv))
122
+ end
123
+
124
+ { groups: state[:groups].reject { |g| g == options[:'<privilege>'] },
125
+ userGroups: user_group_ids(state) }
126
+ end
127
+
128
+ def add_groups_to_list(state, groups)
129
+ { userGroups: (user_group_ids(state) + groups).uniq }
130
+ end
131
+
132
+ def remove_groups_from_list(state, groups)
133
+ { userGroups: (user_group_ids(state) - groups) }
134
+ end
135
+
136
+ # The API gives us an array of group objects, but expects back an array
137
+ # only of their IDs
138
+ #
139
+ def user_group_ids(state)
140
+ state[:userGroups].map { |g| g[:id] }
141
+ end
142
+
143
+ def active_account?
144
+ !options[:inactive]
145
+ end
146
+
147
+ def user_body
148
+ { identifier: options[:'<id>'],
149
+ active: active_account?,
150
+ groups: options[:permission],
151
+ tokens: options[:usertoken],
152
+ userGroups: options[:group] }.tap do |b|
153
+ b[:description] = options[:desc] if options[:desc]
154
+ end
155
+ end
156
+
157
+ def item_dump_call
158
+ wf.list.response
159
+ end
160
+
161
+ def validate_groups
162
+ options[:group].each { |g| wf_usergroup_id?(g) }
163
+ rescue Wavefront::Exception::InvalidUserGroupId => e
164
+ raise e, 'Invalid usergroup ID'
165
+ end
166
+
167
+ def validate_tokens
168
+ options[:usertoken].each { |t| wf_apitoken_id?(t) }
169
+ rescue Wavefront::Exception::InvalidApiTokenId => e
170
+ raise e, 'Invalid API token'
171
+ end
172
+
173
+ def validate_perms
174
+ options[:permission].each { |p| wf_permission?(p) }
175
+ rescue Wavefront::Exception::InvalidPermission => e
176
+ raise e, 'Invalid permission'
177
+ end
178
+ end
179
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
  require_relative 'command_mixins/tag'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Extensions to stdlib's Array
2
4
  #
3
5
  class Array
@@ -6,6 +8,7 @@ class Array
6
8
  #
7
9
  def max_length
8
10
  return 0 if empty?
11
+
9
12
  map(&:to_s).map(&:length).max
10
13
  end
11
14
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Extensions to the String class to help with formatting.
2
4
  #
3
5
  class String
@@ -32,26 +34,23 @@ class String
32
34
  # @param prefix [String] prepended to every line
33
35
  # @return [String] the folded line
34
36
  #
35
- # rubocop:disable Metrics/AbcSize
36
37
  def fold(twidth = TW, indent = 10, prefix = '')
37
38
  chunks = gsub(/default: /, 'default:^').scan_line(twidth - 8)
38
- first_line = format("%s%s\n", prefix, chunks.shift)
39
+ first_line = format("%<padding>s%<text>s\n",
40
+ padding: prefix,
41
+ text: chunks.shift)
39
42
 
40
43
  return first_line.restored if chunks.empty?
41
44
 
42
- rest = chunks.join(' ').scan_line(twidth - indent - 5).map do |l|
43
- prefix + ' ' * indent + l
44
- end
45
-
46
- (first_line + rest.join("\n") + "\n").restored
45
+ rest = indent_folded_lines(chunks, twidth, indent, prefix)
46
+ (first_line + rest.join("\n")).restored
47
47
  end
48
- # rubocop:enable Metrics/AbcSize
49
48
 
50
49
  # We use a carat as a temporary whitespace character to avoid
51
50
  # undesirable line breaking. This puts it back
52
51
  #
53
52
  def restored
54
- tr('^', ' ')
53
+ tr('^', ' ').chomp("\n")
55
54
  end
56
55
 
57
56
  # Fold long value lines in two-column output. The returned string
@@ -95,8 +94,15 @@ class String
95
94
  #
96
95
  def to_snake
97
96
  gsub(/(.)([A-Z])/) do
98
- Regexp.last_match[1] + '_' +
99
- Regexp.last_match[2].downcase
97
+ Regexp.last_match[1] + '_' + Regexp.last_match[2].downcase
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ def indent_folded_lines(chunks, twidth, indent, prefix)
104
+ chunks.join(' ').scan_line(twidth - indent - 5).map do |line|
105
+ prefix + ' ' * indent + line
100
106
  end
101
107
  end
102
108
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -19,6 +21,7 @@ module WavefrontCli
19
21
  end
20
22
 
21
23
  alias do_groups do_describe
24
+ alias do_privileges do_describe
22
25
 
23
26
  def do_join
24
27
  wf.add_groups_to_user(options[:'<id>'], options[:'<group>'])
@@ -43,8 +46,7 @@ module WavefrontCli
43
46
 
44
47
  def import_to_create(raw)
45
48
  { emailAddress: raw['items']['identifier'],
46
- groups: raw['items']['groups'] }.tap do |r|
47
-
49
+ groups: raw['items']['groups'] }.tap do |r|
48
50
  if raw['items'].key?('userGroups')
49
51
  r['userGroups'] = raw['items']['userGroups'].map { |g| g['id'] }
50
52
  end
@@ -55,8 +57,8 @@ module WavefrontCli
55
57
  #
56
58
  def user_body
57
59
  { emailAddress: options[:'<id>'],
58
- groups: options[:permission],
59
- userGroups: options[:group] }
60
+ groups: options[:permission],
61
+ userGroups: options[:group] }
60
62
  end
61
63
 
62
64
  # Because of the way docopt works, we have to call the user ID
@@ -73,5 +75,9 @@ module WavefrontCli
73
75
  rescue Wavefront::Exception::InvalidUserId
74
76
  abort failed_validation_message(user)
75
77
  end
78
+
79
+ def item_dump_call
80
+ wf.list.response.items
81
+ end
76
82
  end
77
83
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli
@@ -13,7 +15,7 @@ module WavefrontCli
13
15
  alias do_permissions do_describe
14
16
 
15
17
  def do_create
16
- wf.create(name: options[:'<name>'],
18
+ wf.create(name: options[:'<name>'],
17
19
  permissions: options[:permission])
18
20
  end
19
21
 
@@ -35,7 +37,7 @@ module WavefrontCli
35
37
 
36
38
  def import_to_create(raw)
37
39
  raw['emailAddress'] = raw['identifier']
38
- raw.delete_if { |k, _v| k == 'customer' || k == 'identifier' }
40
+ raw.delete_if { |k, _v| %w[customer identifier].include?(k) }
39
41
  end
40
42
  end
41
43
  end
@@ -1 +1,3 @@
1
- WF_CLI_VERSION = '4.2.1'.freeze
1
+ # frozen_string_literal: true
2
+
3
+ WF_CLI_VERSION = '4.3.0'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module WavefrontCli