class WavefrontCli::ServiceAccount
CLI coverage for the v2 'serviceaccount' API.
Attributes
wf_apitoken[R]
Public Instance Methods
do_activate()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 34 def do_activate wf.activate(options[:'<id>']) end
do_apitoken_create()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 82 def do_apitoken_create wf_apitoken.sa_create(options[:'<id>'], options[:name]) end
do_apitoken_delete()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 86 def do_apitoken_delete wf_apitoken.sa_delete(options[:'<id>'], options[:'<token_id>']) end
do_apitoken_list()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 78 def do_apitoken_list wf_apitoken.sa_list(options[:'<id>']) end
do_apitoken_rename()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 90 def do_apitoken_rename wf_apitoken.sa_rename(options[:'<id>'], options[:'<token_id>'], options[:'<name>']) end
do_create()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 29 def do_create wf_user_id?(options[:'<id>']) wf.create(user_body) end
do_deactivate()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 38 def do_deactivate wf.deactivate(options[:'<id>']) end
do_delete()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 50 def do_delete account_hook.delete_accounts(options[:'<account>']) end
do_describe()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 21 def do_describe wf.describe(options[:'<id>']) end
do_grant()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 62 def do_grant cannot_noop! wf_permission?(options[:'<permission>']) body = add_perm_to_list(current_state, options[:'<permission>']) wf.update(options[:'<id>'], body) end
do_join()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 42 def do_join cannot_noop! options[:'<group>'].each { |g| wf_usergroup_id?(g) } body = add_groups_to_list(current_state, options[:'<group>']) wf.update(options[:'<id>'], body) end
do_leave()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 54 def do_leave cannot_noop! options[:'<group>'].each { |g| wf_usergroup_id?(g) } body = remove_groups_from_list(current_state, options[:'<group>']) wf.update(options[:'<id>'], body) end
do_list()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 17 def do_list wf.list end
do_revoke()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 70 def do_revoke cannot_noop! wf_permission?(options[:'<permission>']) body = remove_perm_from_list(current_state, options[:'<permission>']) wf.update(options[:'<id>'], body) end
extra_validation()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 96 def extra_validation validate_groups validate_tokens validate_ingestion_policy end
post_initialize(_options)
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 13 def post_initialize(_options) @wf_apitoken = Wavefront::ApiToken.new(mk_creds, mk_opts) end
validator_exception()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 102 def validator_exception Wavefront::Exception::InvalidServiceAccountId end
Private Instance Methods
account_hook()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 200 def account_hook require 'wavefront-sdk/account' Wavefront::Account.new(mk_creds, mk_opts) end
active_account?()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 157 def active_account? !options[:inactive] end
add_groups_to_list(state, groups)
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 142 def add_groups_to_list(state, groups) { userGroups: (user_group_ids(state) + groups).uniq } end
add_perm_to_list(state, perm)
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 121 def add_perm_to_list(state, perm) if state[:groups].include?(perm) ok_exit(format("'%<account>s' already has the '%<perm>s' permission.", account: options[:'<id>'], perm: perm)) end { groups: state[:groups].push(perm), userGroups: user_group_ids(state) } end
current_state()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 108 def current_state resp = wf.describe(options[:'<id>']) return resp.response if resp.ok? if resp.status.code == 404 raise WavefrontCli::Exception::UserError, "Cannot find service account '#{options[:'<id>']}'" end raise resp.status.message end
descriptive_name()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 196 def descriptive_name 'service account' end
item_dump_call()
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/wavefront-cli/serviceaccount.rb, line 174 def item_dump_call wf.list.response end
remove_groups_from_list(state, groups)
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 146 def remove_groups_from_list(state, groups) { userGroups: (user_group_ids(state) - groups) } end
remove_perm_from_list(state, perm)
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 131 def remove_perm_from_list(state, perm) unless state[:groups].include?(perm) ok_exit(format("'%<account>s' does not have the '%<perm>s' permission.", account: options[:'<id>'], perm: perm)) end { groups: state[:groups].reject { |g| g == options[:'<permission>'] }, userGroups: user_group_ids(state) } end
user_body()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/wavefront-cli/serviceaccount.rb, line 162 def user_body { identifier: options[:'<id>'], active: active_account?, ingestionPolicyId: options[:policy], tokens: options[:usertoken], roles: options[:role], userGroups: options[:group] }.compact.tap do |b| b[:description] = options[:desc] if options[:desc] end end
user_group_ids(state)
click to toggle source
The API gives us an array of group objects, but expects back an array only of their IDs
# File lib/wavefront-cli/serviceaccount.rb, line 153 def user_group_ids(state) state[:userGroups].map { |g| g[:id] } end
validate_groups()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 178 def validate_groups options[:group].each { |g| wf_usergroup_id?(g) } end
validate_ingestion_policy()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 190 def validate_ingestion_policy return true unless options[:policy] wf_ingestionpolicy_id?(options[:policy]) end
validate_roles()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 182 def validate_roles options[:role].each { |r| wf_role_id?(r) } end
validate_tokens()
click to toggle source
# File lib/wavefront-cli/serviceaccount.rb, line 186 def validate_tokens options[:usertoken].each { |t| wf_apitoken_id?(t) } end