Class: WavefrontCli::User

Inherits:
Base
  • Object
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::EVENT_STATE_DIR, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS, Constants::SEARCH_SPLIT

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_response_blocks, #check_status, #cli_output_class, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_describe, #do_dump, #do_import, #do_search, #do_set, #do_undelete, #dump_json, #dump_yaml, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #import_message, #import_object, #import_update, #initialize, #load_display_class, #load_file, #load_from_stdin, #load_json, #load_yaml, #matching_method, #method_word_list, #mk_creds, #mk_opts, #name_of_do_method, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #run, #search_key, #smart_delete, #smart_delete_message, #status_error_handler, #unsupported_format_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method, #warning_message

Constructor Details

This class inherits a constructor from WavefrontCli::Base

Instance Method Details

#do_business_functionsObject



47
48
49
50
# File 'lib/wavefront-cli/user.rb', line 47

def do_business_functions
  wf_user_id?(options[:'<id>'])
  wf.business_functions(options[:'<id>'])
end

#do_createObject



18
19
20
21
# File 'lib/wavefront-cli/user.rb', line 18

def do_create
  wf_user_id?(options[:'<id>'])
  wf.create(user_body, options[:email])
end

#do_deleteObject



14
15
16
# File 'lib/wavefront-cli/user.rb', line 14

def do_delete
  wf.delete_users(options[:'<user>'])
end

#do_grantObject



34
35
36
# File 'lib/wavefront-cli/user.rb', line 34

def do_grant
  wf.grant(options[:'<id>'], options[:'<privilege>'])
end

#do_inviteObject



42
43
44
45
# File 'lib/wavefront-cli/user.rb', line 42

def do_invite
  wf_user_id?(options[:'<id>'])
  wf.invite([user_body])
end

#do_joinObject



26
27
28
# File 'lib/wavefront-cli/user.rb', line 26

def do_join
  wf.add_groups_to_user(options[:'<id>'], options[:'<group>'])
end

#do_leaveObject



30
31
32
# File 'lib/wavefront-cli/user.rb', line 30

def do_leave
  wf.remove_groups_from_user(options[:'<id>'], options[:'<group>'])
end

#do_listObject



10
11
12
# File 'lib/wavefront-cli/user.rb', line 10

def do_list
  wf.list
end

#do_revokeObject



38
39
40
# File 'lib/wavefront-cli/user.rb', line 38

def do_revoke
  wf.revoke(options[:'<id>'], options[:'<privilege>'])
end

#extra_validationObject

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.



74
75
76
# File 'lib/wavefront-cli/user.rb', line 74

def extra_validation
  options[:'<user>']&.each { |u| validate_user(u) }
end

#import_to_create(raw) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/wavefront-cli/user.rb', line 52

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

#item_dump_callObject



84
85
86
# File 'lib/wavefront-cli/user.rb', line 84

def item_dump_call
  wf.list.response.items
end

#user_bodyObject

Object used to create and invite users.



63
64
65
66
67
# File 'lib/wavefront-cli/user.rb', line 63

def user_body
  { emailAddress: options[:'<id>'],
    groups: options[:permission],
    userGroups: options[:group] }
end

#validate_user(user) ⇒ Object



78
79
80
81
82
# File 'lib/wavefront-cli/user.rb', line 78

def validate_user(user)
  wf_user_id?(user)
rescue Wavefront::Exception::InvalidUserId
  abort failed_validation_message(user)
end