wavefront-cli 4.2.1 → 4.3.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 +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +1 -14
- data/.travis.yml +4 -4
- data/Gemfile +2 -0
- data/HISTORY.md +82 -60
- data/Rakefile +2 -0
- data/bin/wf +1 -0
- data/lib/wavefront-cli/alert.rb +13 -5
- data/lib/wavefront-cli/apitoken.rb +2 -0
- data/lib/wavefront-cli/base.rb +95 -47
- data/lib/wavefront-cli/cloudintegration.rb +6 -0
- data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
- data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
- data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
- data/lib/wavefront-cli/commands/alert.rb +2 -1
- data/lib/wavefront-cli/commands/apitoken.rb +6 -0
- data/lib/wavefront-cli/commands/base.rb +30 -21
- data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
- data/lib/wavefront-cli/commands/config.rb +2 -0
- data/lib/wavefront-cli/commands/dashboard.rb +2 -0
- data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/commands/event.rb +3 -1
- data/lib/wavefront-cli/commands/integration.rb +2 -1
- data/lib/wavefront-cli/commands/link.rb +2 -0
- data/lib/wavefront-cli/commands/message.rb +2 -0
- data/lib/wavefront-cli/commands/metric.rb +2 -0
- data/lib/wavefront-cli/commands/notificant.rb +2 -0
- data/lib/wavefront-cli/commands/proxy.rb +2 -0
- data/lib/wavefront-cli/commands/query.rb +2 -0
- data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
- data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
- data/lib/wavefront-cli/commands/settings.rb +2 -0
- data/lib/wavefront-cli/commands/source.rb +3 -1
- data/lib/wavefront-cli/commands/user.rb +4 -1
- data/lib/wavefront-cli/commands/usergroup.rb +3 -0
- data/lib/wavefront-cli/commands/webhook.rb +2 -0
- data/lib/wavefront-cli/commands/window.rb +2 -0
- data/lib/wavefront-cli/commands/write.rb +2 -0
- data/lib/wavefront-cli/config.rb +23 -12
- data/lib/wavefront-cli/constants.rb +10 -4
- data/lib/wavefront-cli/controller.rb +53 -22
- data/lib/wavefront-cli/dashboard.rb +3 -0
- data/lib/wavefront-cli/derivedmetric.rb +12 -11
- data/lib/wavefront-cli/display/alert.rb +7 -4
- data/lib/wavefront-cli/display/apitoken.rb +2 -0
- data/lib/wavefront-cli/display/base.rb +34 -8
- data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
- data/lib/wavefront-cli/display/dashboard.rb +2 -0
- data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/display/distribution.rb +2 -0
- data/lib/wavefront-cli/display/event.rb +2 -0
- data/lib/wavefront-cli/display/externallink.rb +2 -0
- data/lib/wavefront-cli/display/integration.rb +2 -0
- data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
- data/lib/wavefront-cli/display/message.rb +7 -3
- data/lib/wavefront-cli/display/metric.rb +3 -1
- data/lib/wavefront-cli/display/notificant.rb +3 -1
- data/lib/wavefront-cli/display/printer/long.rb +36 -11
- data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
- data/lib/wavefront-cli/display/printer/terse.rb +6 -1
- data/lib/wavefront-cli/display/proxy.rb +2 -0
- data/lib/wavefront-cli/display/query.rb +35 -24
- data/lib/wavefront-cli/display/savedsearch.rb +2 -0
- data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
- data/lib/wavefront-cli/display/settings.rb +2 -0
- data/lib/wavefront-cli/display/source.rb +18 -4
- data/lib/wavefront-cli/display/user.rb +56 -10
- data/lib/wavefront-cli/display/usergroup.rb +25 -19
- data/lib/wavefront-cli/display/webhook.rb +2 -0
- data/lib/wavefront-cli/display/write.rb +6 -2
- data/lib/wavefront-cli/event.rb +83 -62
- data/lib/wavefront-cli/exception.rb +3 -0
- data/lib/wavefront-cli/externallink.rb +6 -4
- data/lib/wavefront-cli/integration.rb +2 -0
- data/lib/wavefront-cli/maintenancewindow.rb +28 -17
- data/lib/wavefront-cli/message.rb +4 -0
- data/lib/wavefront-cli/metric.rb +4 -1
- data/lib/wavefront-cli/notificant.rb +2 -0
- data/lib/wavefront-cli/opt_handler.rb +2 -0
- data/lib/wavefront-cli/output/base.rb +8 -3
- data/lib/wavefront-cli/output/csv.rb +2 -0
- data/lib/wavefront-cli/output/csv/base.rb +2 -0
- data/lib/wavefront-cli/output/csv/query.rb +14 -7
- data/lib/wavefront-cli/output/hcl.rb +2 -0
- data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
- data/lib/wavefront-cli/output/hcl/base.rb +10 -4
- data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
- data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
- data/lib/wavefront-cli/output/json.rb +2 -0
- data/lib/wavefront-cli/output/ruby.rb +2 -0
- data/lib/wavefront-cli/output/wavefront.rb +2 -0
- data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
- data/lib/wavefront-cli/output/yaml.rb +2 -0
- data/lib/wavefront-cli/proxy.rb +15 -3
- data/lib/wavefront-cli/query.rb +14 -12
- data/lib/wavefront-cli/savedsearch.rb +2 -0
- data/lib/wavefront-cli/serviceaccount.rb +179 -0
- data/lib/wavefront-cli/settings.rb +2 -0
- data/lib/wavefront-cli/source.rb +2 -0
- data/lib/wavefront-cli/stdlib/array.rb +3 -0
- data/lib/wavefront-cli/stdlib/string.rb +17 -11
- data/lib/wavefront-cli/user.rb +10 -4
- data/lib/wavefront-cli/usergroup.rb +4 -2
- data/lib/wavefront-cli/version.rb +3 -1
- data/lib/wavefront-cli/webhook.rb +2 -0
- data/lib/wavefront-cli/write.rb +80 -46
- data/spec/.rubocop.yml +3 -16
- data/spec/constants.rb +21 -0
- data/spec/spec_helper.rb +8 -422
- data/spec/support/command_base.rb +82 -0
- data/spec/support/minitest_assertions.rb +262 -0
- data/spec/support/output_tester.rb +32 -0
- data/spec/support/supported_commands.rb +19 -0
- data/spec/test_mixins/acl.rb +169 -0
- data/spec/test_mixins/delete.rb +25 -0
- data/spec/test_mixins/deleteundelete.rb +106 -0
- data/spec/test_mixins/describe.rb +24 -0
- data/spec/test_mixins/dump.rb +43 -0
- data/spec/test_mixins/general.rb +11 -0
- data/spec/test_mixins/history.rb +35 -0
- data/spec/test_mixins/import.rb +65 -0
- data/spec/test_mixins/list.rb +29 -0
- data/spec/test_mixins/search.rb +98 -0
- data/spec/test_mixins/set.rb +47 -0
- data/spec/test_mixins/tag.rb +99 -0
- data/spec/wavefront-cli/alert_spec.rb +288 -111
- data/spec/wavefront-cli/apitoken_spec.rb +53 -24
- data/spec/wavefront-cli/base_spec.rb +9 -27
- data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
- data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
- data/spec/wavefront-cli/commands/base_spec.rb +15 -13
- data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
- data/spec/wavefront-cli/commands/config_spec.rb +3 -0
- data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
- data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/event_spec.rb +1 -0
- data/spec/wavefront-cli/commands/link_spec.rb +1 -0
- data/spec/wavefront-cli/commands/message_spec.rb +1 -0
- data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
- data/spec/wavefront-cli/commands/query_spec.rb +1 -0
- data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
- data/spec/wavefront-cli/commands/window_spec.rb +1 -0
- data/spec/wavefront-cli/commands/write_spec.rb +1 -0
- data/spec/wavefront-cli/config_spec.rb +25 -14
- data/spec/wavefront-cli/controller_spec.rb +13 -3
- data/spec/wavefront-cli/dashboard_spec.rb +125 -76
- data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
- data/spec/wavefront-cli/display/base_spec.rb +5 -7
- data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
- data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
- data/spec/wavefront-cli/event_spec.rb +360 -18
- data/spec/wavefront-cli/externallink_spec.rb +92 -58
- data/spec/wavefront-cli/integration_spec.rb +129 -31
- data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
- data/spec/wavefront-cli/message_spec.rb +73 -30
- data/spec/wavefront-cli/metric_spec.rb +60 -22
- data/spec/wavefront-cli/notificant_spec.rb +45 -32
- data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
- data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
- data/spec/wavefront-cli/output/csv_spec.rb +5 -2
- data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
- data/spec/wavefront-cli/output/helpers.rb +18 -0
- data/spec/wavefront-cli/output/json_spec.rb +3 -1
- data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
- data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
- data/spec/wavefront-cli/proxy_spec.rb +49 -27
- data/spec/wavefront-cli/query_spec.rb +174 -92
- data/spec/wavefront-cli/resources/responses/query.json +1 -0
- data/spec/wavefront-cli/resources/updates/alert.json +15 -0
- data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
- data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
- data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
- data/spec/wavefront-cli/settings_spec.rb +42 -11
- data/spec/wavefront-cli/source_spec.rb +120 -23
- data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
- data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
- data/spec/wavefront-cli/user_spec.rb +278 -108
- data/spec/wavefront-cli/usergroup_spec.rb +152 -102
- data/spec/wavefront-cli/webhook_spec.rb +30 -15
- data/spec/wavefront-cli/write_spec.rb +25 -1
- data/wavefront-cli.gemspec +5 -3
- metadata +65 -21
- data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
- data/spec/wavefront-cli/display/spec_helper.rb +0 -3
data/lib/wavefront-cli/proxy.rb
CHANGED
|
@@ -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)
|
|
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
|
data/lib/wavefront-cli/query.rb
CHANGED
|
@@ -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_
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
@@ -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
|
data/lib/wavefront-cli/source.rb
CHANGED
|
@@ -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("
|
|
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
|
|
43
|
-
|
|
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
|
-
|
|
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
|
data/lib/wavefront-cli/user.rb
CHANGED
|
@@ -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:
|
|
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:
|
|
59
|
-
userGroups:
|
|
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:
|
|
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|
|
|
40
|
+
raw.delete_if { |k, _v| %w[customer identifier].include?(k) }
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
end
|