Module: WavefrontCli::Mixin::Acl

Included in:
Alert, Dashboard
Defined in:
lib/wavefront-cli/command_mixins/acl.rb

Overview

Standard ACL commands. Mix this module in to get ACL support.

Instance Method Summary collapse

Instance Method Details

#_acl_action(action) ⇒ Wavefront::Response

Parameters:

  • action (Symbol)

    :grant_to or :revoke_from

Returns:

  • (Wavefront::Response)


66
67
68
69
70
71
72
73
74
75
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 66

def _acl_action(action)
  entity_type, entities = acl_entities

  resp = send(format('%s_%s', action, entity_type),
              options[:'<id>'],
              entities)

  print_status(resp.status)
  do_acls
end

#do_acl_clearObject



11
12
13
14
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 11

def do_acl_clear
  wf.acl_set(options[:'<id>'], [], [everyone_id])
  do_acls
end

#do_acl_grantObject



16
17
18
19
20
21
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 16

def do_acl_grant
  return grant_view if options[:view]
  return grant_modify if options[:modify]

  raise WavefrontCli::Exception::InsufficientData
end

#do_acl_revokeObject



23
24
25
26
27
28
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 23

def do_acl_revoke
  return revoke_view if options[:view]
  return revoke_modify if options[:modify]

  raise WavefrontCli::Exception::InsufficientData
end

#do_aclsObject



7
8
9
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 7

def do_acls
  wf.acls([options[:'<id>']])
end

#everyone_idString

Returns UUID of ‘Everyone’ group.

Returns:

  • (String)

    UUID of ‘Everyone’ group

Raises:

  • WavefrontCli::Exception::UserGroupNotFound if group does not exist. This is caught in the controller.



34
35
36
37
38
39
40
41
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 34

def everyone_id
  require 'wavefront-sdk/search'
  wfs = Wavefront::Search.new(mk_creds, mk_opts)
  query = conds_to_query(['name=Everyone'])
  wfs.search(:usergroup, query).response.items.first.id
rescue RuntimeError
  raise WavefrontCli::Exception::UserGroupNotFound, 'Everyone'
end

#grant_modifyObject



43
44
45
46
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 43

def grant_modify
  wf.acl_add(options[:'<id>'], [], options[:'<name>'])
  do_acls
end

#grant_viewObject



48
49
50
51
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 48

def grant_view
  wf.acl_add(options[:'<id>'], options[:'<name>'], [])
  do_acls
end


77
78
79
80
81
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 77

def print_status(status)
  puts status.message unless status.message.empty?
rescue NoMethodError
  nil
end

#revoke_modifyObject



58
59
60
61
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 58

def revoke_modify
  wf.acl_delete(options[:'<id>'], [], options[:'<name>'])
  do_acls
end

#revoke_viewObject



53
54
55
56
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 53

def revoke_view
  wf.acl_delete(options[:'<id>'], options[:'<name>'], [])
  do_acls
end