Class: WavefrontCli::User
- Inherits:
-
Base
- Object
- Base
- WavefrontCli::User
show all
- Defined in:
- lib/wavefront-cli/user.rb
Overview
CLI coverage for the v2 ‘user’ API.
Constant Summary
Constants included
from Constants
Constants::ALL_PAGE_SIZE, Constants::DEFAULT_CONFIG, Constants::DEFAULT_OPTS, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS
Instance Attribute Summary
Attributes inherited from Base
#klass, #klass_word, #options, #wf
Instance Method Summary
collapse
Methods inherited from Base
#_sdk_class, #cannot_noop!, #check_status, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_describe, #do_import, #do_search, #do_undelete, #do_update, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #initialize, #load_display_class, #load_file, #load_from_stdin, #mk_creds, #mk_opts, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #run, #search_key, #smart_delete, #smart_delete_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method
Instance Method Details
#do_create ⇒ Object
16
17
18
19
|
# File 'lib/wavefront-cli/user.rb', line 16
def do_create
wf_user_id?(options[:'<id>'])
wf.create(user_body, options[:email])
end
|
#do_delete ⇒ Object
12
13
14
|
# File 'lib/wavefront-cli/user.rb', line 12
def do_delete
wf.delete_users(options[:'<user>'])
end
|
#do_grant ⇒ Object
31
32
33
|
# File 'lib/wavefront-cli/user.rb', line 31
def do_grant
wf.grant(options[:'<id>'], options[:'<privilege>'])
end
|
#do_invite ⇒ Object
39
40
41
42
|
# File 'lib/wavefront-cli/user.rb', line 39
def do_invite
wf_user_id?(options[:'<id>'])
wf.invite([user_body])
end
|
#do_join ⇒ Object
23
24
25
|
# File 'lib/wavefront-cli/user.rb', line 23
def do_join
wf.add_groups_to_user(options[:'<id>'], options[:'<group>'])
end
|
#do_leave ⇒ Object
27
28
29
|
# File 'lib/wavefront-cli/user.rb', line 27
def do_leave
wf.remove_groups_from_user(options[:'<id>'], options[:'<group>'])
end
|
#do_list ⇒ Object
8
9
10
|
# File 'lib/wavefront-cli/user.rb', line 8
def do_list
wf.list
end
|
#do_revoke ⇒ Object
35
36
37
|
# File 'lib/wavefront-cli/user.rb', line 35
def do_revoke
wf.revoke(options[:'<id>'], options[:'<privilege>'])
end
|
Because of the way docopt works, we have to call the user ID parameter something else on the delete command. This means the automatic validtion doesn’t work, and we have to do it ourselves.
67
68
69
|
# File 'lib/wavefront-cli/user.rb', line 67
def
options[:'<user>']&.each { |u| validate_user(u) }
end
|
#import_to_create(raw) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/wavefront-cli/user.rb', line 44
def import_to_create(raw)
{ emailAddress: raw['items']['identifier'],
groups: raw['items']['groups'] }.tap do |r|
if raw['items'].key?('userGroups')
r['userGroups'] = raw['items']['userGroups'].map { |g| g['id'] }
end
end
end
|
#user_body ⇒ Object
Object used to create and invite users.
56
57
58
59
60
|
# File 'lib/wavefront-cli/user.rb', line 56
def user_body
{ emailAddress: options[:'<id>'],
groups: options[:permission],
userGroups: options[:group] }
end
|
#validate_user(user) ⇒ Object
71
72
73
74
75
|
# File 'lib/wavefront-cli/user.rb', line 71
def validate_user(user)
wf_user_id?(user)
rescue Wavefront::Exception::InvalidUserId
abort failed_validation_message(user)
end
|