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)


69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 69

def _acl_action(action)
  entity_type, entities = acl_entities

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

  print_status(resp.status)
  do_acls
end

#do_acl_clearObject



13
14
15
16
17
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 13

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

#do_acl_grantObject



19
20
21
22
23
24
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 19

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

  raise WavefrontCli::Exception::InsufficientData
end

#do_acl_revokeObject



26
27
28
29
30
31
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 26

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

  raise WavefrontCli::Exception::InsufficientData
end

#do_aclsObject



9
10
11
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 9

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.



37
38
39
40
41
42
43
44
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 37

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



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

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

#grant_viewObject



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

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


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

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

#revoke_modifyObject



61
62
63
64
# File 'lib/wavefront-cli/command_mixins/acl.rb', line 61

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

#revoke_viewObject



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

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