Class: WavefrontDisplay::User

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-cli/display/user.rb

Overview

Format human-readable output for user management.

Constant Summary

Constants included from WavefrontCli::Constants

WavefrontCli::Constants::ALL_PAGE_SIZE, WavefrontCli::Constants::DEFAULT_CONFIG, WavefrontCli::Constants::DEFAULT_OPTS, WavefrontCli::Constants::EVENT_STATE_DIR, WavefrontCli::Constants::HUMAN_TIME_FORMAT, WavefrontCli::Constants::HUMAN_TIME_FORMAT_MS, WavefrontCli::Constants::SEARCH_SPLIT

Instance Attribute Summary

Attributes inherited from Base

#data, #options, #raw

Instance Method Summary collapse

Methods inherited from Base

#_prioritize_keys, #display_brief_freetext_results, #do_import, #do_list, #do_list_fields, #do_queries, #do_search, #do_search_brief, #do_search_fields, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_pathsearch, #do_tag_set, #do_tags, #do_undelete, #drop_fields, #filter_data, #filter_fields_as_arr, #freetext_keys, #friendly_name, #human_time, #index_of_final_item, #initialize, #key_width, #long_output, #multicolumn, #pagination_line, #prioritize_keys, #priority_keys, #quoted, #readable_time, #readable_time_arr, #run, #run_error, #run_list, #run_search, #search_display_keys, #search_identifier_key, #time_formats

Constructor Details

This class inherits a constructor from WavefrontDisplay::Base

Instance Method Details

#do_business_functionsObject



88
89
90
# File 'lib/wavefront-cli/display/user.rb', line 88

def do_business_functions
  puts data.sort
end

#do_createObject



32
33
34
35
36
37
38
39
# File 'lib/wavefront-cli/display/user.rb', line 32

def do_create
  info = data[0]
  puts format("Created user '%<user>s'.\nPermission groups\n" \
              "%<perm_groups>s\nUser groups\n%<user_groups>s",
              user: info[:identifier],
              perm_groups: groups_as_string(info[:groups]),
              user_groups: user_groups_as_string(info[:userGroups]))
end

#do_deleteObject



55
56
57
58
# File 'lib/wavefront-cli/display/user.rb', line 55

def do_delete
  puts format('Deleted %<quoted_user>s.',
              quoted_user: quoted(options[:'<user>']))
end

#do_grantObject



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

def do_grant
  puts format("Granted '%<priv>s' to '%<id>s'.",
              priv: options[:'<privilege>'],
              id: options[:'<id>'])
end

#do_groupsObject



14
15
16
17
18
19
20
21
22
# File 'lib/wavefront-cli/display/user.rb', line 14

def do_groups
  groups = data.first.userGroups

  if groups.empty?
    puts 'User does not belong to any groups.'
  else
    groups.each { |u| puts format('%<id>s (%<name>s)', u) }
  end
end

#do_inviteObject



60
61
62
# File 'lib/wavefront-cli/display/user.rb', line 60

def do_invite
  puts format("Sent invitation to '%<id>s'.", id: options[:'<id>'])
end

#do_joinObject



76
77
78
79
80
# File 'lib/wavefront-cli/display/user.rb', line 76

def do_join
  puts format("Added '%<id>s' to %<quoted_group>s.",
              id: options[:'<id>'],
              quoted_group: quoted(options[:'<group>']))
end

#do_leaveObject



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

def do_leave
  puts format("Removed '%<id>s' from %<quoted_group>s.",
              id: options[:'<id>'],
              quoted_group: quoted(options[:'<group>']))
end

#do_list_briefObject



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

def do_list_brief
  data.each { |user| puts user[:identifier] }
end

#do_privilegesObject



24
25
26
27
28
29
30
# File 'lib/wavefront-cli/display/user.rb', line 24

def do_privileges
  puts(if data.first[:groups].empty?
         'User does not have any Wavefront privileges.'
       else
         data.first[:groups]
       end)
end

#do_revokeObject



70
71
72
73
74
# File 'lib/wavefront-cli/display/user.rb', line 70

def do_revoke
  puts format("Revoked '%<priv>s' from '%<id>s'.",
              priv: options[:'<privilege>'],
              id: options[:'<id>'])
end

#do_validate_briefObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/wavefront-cli/display/user.rb', line 92

def do_validate_brief
  valid = data[0][:validUsers]
  invalid = data[0][:invalidIdentifiers]

  puts 'valid ',
       valid.empty? ? '  <none>' : valid.map { |u| "  #{u[:identifier]}" }

  puts 'invalid',
       invalid.empty? ? '  <none>' : invalid.map { |u| "  #{u}" }
end

#groups_as_string(groups) ⇒ Object



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

def groups_as_string(groups)
  return '  <none>' if groups.empty?

  data.response.groups.map do |g|
    format('  %<group>s', group: g)
  end.join("\n  ")
end

#user_groups_as_string(groups) ⇒ Object



49
50
51
52
53
# File 'lib/wavefront-cli/display/user.rb', line 49

def user_groups_as_string(groups)
  return '  <none>' if groups.empty?

  groups.map { |g| format('  %<name>s (%<id>s)', g) }.join("\n")
end