Class: WavefrontCli::Dashboard
- Defined in:
- lib/wavefront-cli/dashboard.rb
Overview
CLI coverage for the v2 ‘dashboard’ 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
-
#acl_entities ⇒ Array
Based on command-line options, return an array describing the users or groups (entities) which will be granted or revoked a privilege.
- #do_acl_clear ⇒ Object
- #do_acl_grant ⇒ Object
- #do_acl_revoke ⇒ Object
- #do_acls ⇒ Object
-
#do_delete ⇒ Object
rubocop:disable Metrics/AbcSize.
- #do_describe ⇒ Object
- #do_fav ⇒ Object
- #do_favs ⇒ Object
-
#do_history ⇒ Object
rubocop:enable Metrics/AbcSize.
- #do_queries ⇒ Object
- #do_unfav ⇒ Object
-
#group_lists(acl_type, groups) ⇒ Object
Generate arrays ready for passing to the SDK acl methods.
- #list_filter(list) ⇒ Object
-
#user_lists(acl_type, users) ⇒ Array[Hash]
Make a list of users to be given to the SDK ACL methods.
Methods inherited from Base
#_sdk_class, #cannot_noop!, #check_status, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_import, #do_list, #do_search, #do_tag_add, #do_tag_clear, #do_tag_delete, #do_tag_set, #do_tags, #do_undelete, #do_update, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #import_to_create, #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, #validate_id, #validate_input, #validate_opts, #validate_tags, #validator_exception, #validator_method
Constructor Details
This class inherits a constructor from WavefrontCli::Base
Instance Method Details
#acl_entities ⇒ Array
Based on command-line options, return an array describing the users or groups (entities) which will be granted or revoked a privilege.
85 86 87 88 89 90 91 92 93 |
# File 'lib/wavefront-cli/dashboard.rb', line 85 def acl_entities acl_type = [:modify] ? :modify : :view if [:user] [:users, user_lists(acl_type, [:'<name>'])] else [:groups, group_lists(acl_type, [:'<name>'])] end end |
#do_acl_clear ⇒ Object
67 68 69 70 |
# File 'lib/wavefront-cli/dashboard.rb', line 67 def do_acl_clear wf.acl_set([:'<id>'], [], [id: everyone_id, name: 'Everyone']) do_acls end |
#do_acl_grant ⇒ Object
72 73 74 |
# File 'lib/wavefront-cli/dashboard.rb', line 72 def do_acl_grant acl_action(:grant_to) end |
#do_acl_revoke ⇒ Object
76 77 78 |
# File 'lib/wavefront-cli/dashboard.rb', line 76 def do_acl_revoke acl_action(:revoke_from) end |
#do_acls ⇒ Object
63 64 65 |
# File 'lib/wavefront-cli/dashboard.rb', line 63 def do_acls wf.acls([[:'<id>']]) end |
#do_delete ⇒ Object
rubocop:disable Metrics/AbcSize
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wavefront-cli/dashboard.rb', line 18 def do_delete cannot_noop! word = if wf.describe([:'<id>']).status.code == 200 'Soft' else 'Permanently' end puts "#{word} deleting dashboard '#{options[:'<id>']}'." wf.delete([:'<id>']) end |
#do_describe ⇒ Object
13 14 15 |
# File 'lib/wavefront-cli/dashboard.rb', line 13 def do_describe wf.describe([:'<id>'], [:version]) end |
#do_fav ⇒ Object
53 54 55 56 |
# File 'lib/wavefront-cli/dashboard.rb', line 53 def do_fav wf.favorite([:'<id>']) do_favs end |
#do_favs ⇒ Object
46 47 48 49 50 51 |
# File 'lib/wavefront-cli/dashboard.rb', line 46 def do_favs require 'wavefront-sdk/search' wfs = Wavefront::Search.new(mk_creds, mk_opts) query = conds_to_query(['favorite=true']) wfs.search(:dashboard, query, limit: :all, sort_field: :id) end |
#do_history ⇒ Object
rubocop:enable Metrics/AbcSize
32 33 34 |
# File 'lib/wavefront-cli/dashboard.rb', line 32 def do_history wf.history([:'<id>']) end |
#do_queries ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/wavefront-cli/dashboard.rb', line 36 def do_queries resp, data = one_or_all queries = data.each_with_object({}) do |d, a| a[d.id] = extract_values(d, 'query') end resp.tap { |r| r.response.items = queries } end |
#do_unfav ⇒ Object
58 59 60 61 |
# File 'lib/wavefront-cli/dashboard.rb', line 58 def do_unfav wf.unfavorite([:'<id>']) do_favs end |
#group_lists(acl_type, groups) ⇒ Object
Generate arrays ready for passing to the SDK acl methods
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/wavefront-cli/dashboard.rb', line 110 def group_lists(acl_type, groups) { view: [], modify: [] }.tap do |l| l[acl_type] = groups.each_with_object([]) do |g, a| name = group_name(g) if name.nil? puts "Cannot find group with id '#{g}'." next end a.<< ({ id: g, name: name }) end end end |
#list_filter(list) ⇒ Object
8 9 10 11 |
# File 'lib/wavefront-cli/dashboard.rb', line 8 def list_filter(list) return list unless [:nosystem] list.tap { |l| l.response.items.delete_if { |d| d[:systemOwned] } } end |
#user_lists(acl_type, users) ⇒ Array[Hash]
Make a list of users to be given to the SDK ACL methods. Users are defined as a Hash, with keys :id and :name.
101 102 103 104 105 |
# File 'lib/wavefront-cli/dashboard.rb', line 101 def user_lists(acl_type, users) { view: [], modify: [] }.tap do |l| l[acl_type] = users.map { |u| { id: u, name: u } } end end |