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 +4 -4
- data/HISTORY.md +3 -0
- data/README.md +2 -1
- data/lib/wavefront-cli/commands/serviceaccount.rb +5 -5
- data/lib/wavefront-cli/controller.rb +2 -0
- data/lib/wavefront-cli/display/serviceaccount.rb +25 -6
- data/lib/wavefront-cli/exception.rb +1 -0
- data/lib/wavefront-cli/serviceaccount.rb +31 -22
- data/lib/wavefront-cli/version.rb +1 -1
- data/spec/wavefront-cli/serviceaccount_spec.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29567752b0846cf0bc23909151f65a0f023c02437203d97c0957f67c7802693f
|
4
|
+
data.tar.gz: be30496907d30aeb184d0d7cc3204452c79b219254caeb9c6a59785a240cca18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e1f43c9ad3a996c71b1c75478344b03d9c751fa0ba1db590f6d79f5ba32db18f7f25a52db23f48173418b69730cba46cc20dcde6a2cc843bec017b3be680a87
|
7
|
+
data.tar.gz: 928a9f2eb6523d26497ae6ac630f0bd070bd73ffea31876c7bee70bfe061216f08c8eb7d30c4d083c2adeaaf41b773a2a59249565ac230a17b56c05ffdcd727a
|
data/HISTORY.md
CHANGED
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
|
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] [-
|
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
|
-
"
|
29
|
+
"permissions #{CMN} <id>",
|
30
30
|
"join #{CMN} <id> <group>...",
|
31
31
|
"leave #{CMN} <id> <group>...",
|
32
|
-
"grant #{CMN} <
|
33
|
-
"revoke #{CMN} <
|
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
|
-
"-
|
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
|
-
|
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
|
41
|
+
def do_permissions
|
38
42
|
if data[:groups].empty?
|
39
|
-
puts 'Account does not have any Wavefront
|
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
|
-
|
46
|
-
|
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
|
@@ -23,7 +23,7 @@ module WavefrontCli
|
|
23
23
|
end
|
24
24
|
|
25
25
|
alias do_groups do_describe
|
26
|
-
alias
|
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[:'<
|
59
|
+
wf_permission?(options[:'<permission>'])
|
60
60
|
|
61
|
-
body =
|
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[:'<
|
67
|
+
wf_permission?(options[:'<permission>'])
|
68
68
|
|
69
|
-
body =
|
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.
|
74
|
+
wf_apitoken.sa_list(options[:'<id>'])
|
75
75
|
end
|
76
76
|
|
77
77
|
def do_apitoken_create
|
78
|
-
wf_apitoken.
|
78
|
+
wf_apitoken.sa_create(options[:'<id>'], options[:name])
|
79
79
|
end
|
80
80
|
|
81
81
|
def do_apitoken_delete
|
82
|
-
wf_apitoken.
|
82
|
+
wf_apitoken.sa_delete(options[:'<id>'], options[:'<token_id>'])
|
83
83
|
end
|
84
84
|
|
85
85
|
def do_apitoken_rename
|
86
|
-
wf_apitoken.
|
87
|
-
|
88
|
-
|
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>'])
|
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
|
108
|
-
if state[:groups].include?(
|
109
|
-
ok_exit(format("'%<account>s' already has the '%<
|
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
|
-
|
120
|
+
perm: perm))
|
112
121
|
end
|
113
122
|
|
114
|
-
{ groups: state[:groups].push(
|
123
|
+
{ groups: state[:groups].push(perm), userGroups: user_group_ids(state) }
|
115
124
|
end
|
116
125
|
|
117
|
-
def
|
118
|
-
unless state[:groups].include?(
|
119
|
-
ok_exit(format("'%<account>s' does not have the '%<
|
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
|
-
|
130
|
+
perm: perm))
|
122
131
|
end
|
123
132
|
|
124
|
-
{ groups: state[:groups].reject { |g| g == options[:'<
|
133
|
+
{ groups: state[:groups].reject { |g| g == options[:'<permission>'] },
|
125
134
|
userGroups: user_group_ids(state) }
|
126
135
|
end
|
127
136
|
|
@@ -41,20 +41,20 @@ class ServiceAccountEndToEndTest < EndToEndTest
|
|
41
41
|
assert_abort_on_missing_creds("groups #{id}")
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def test_permissions
|
45
45
|
quietly do
|
46
|
-
assert_cmd_gets("
|
46
|
+
assert_cmd_gets("permissions #{id}", "/api/v2/#{api_path}/#{id}")
|
47
47
|
end
|
48
48
|
|
49
|
-
assert_invalid_id("
|
50
|
-
assert_usage('
|
49
|
+
assert_invalid_id("permissions #{invalid_id}")
|
50
|
+
assert_usage('permissions')
|
51
51
|
|
52
52
|
assert_noop(
|
53
|
-
"
|
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("
|
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 -
|
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 -
|
163
|
+
"create -p 123456 #{id}")
|
164
164
|
end
|
165
165
|
|
166
166
|
def test_create_invalid_token
|