Class: Wavefront::UserGroup

Inherits:
CoreApi
  • Object
show all
Includes:
Mixin::User
Defined in:
lib/wavefront-sdk/usergroup.rb

Overview

Manage and query Wavefront user groups

Instance Attribute Summary

Attributes inherited from CoreApi

#api, #creds, #logger, #opts

Instance Method Summary collapse

Methods included from Mixin::User

#validate_account_list, #validate_role_list, #validate_user_list, #validate_usergroup_list

Methods inherited from CoreApi

#api_base, #api_path, #hash_for_update, #initialize, #setup_api, #time_to_ms

Methods included from Mixins

#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?

Methods included from Validators

#uuid?, #wf_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredapplication_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_spansamplingpolicy_id?, #wf_string?, #wf_tag?, #wf_trace?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::CoreApi

Instance Method Details

#add_roles_to_group(id, role_list = []) ⇒ Wavefront::Response

POST /api/v2/usergroup/id/addRoles Add multiple roles to a specific user group

Parameters:

  • id (String)

    ID of the user group

  • role_list (Array[String]) (defaults to: [])

    list of roles to add

Returns:



118
119
120
121
122
# File 'lib/wavefront-sdk/usergroup.rb', line 118

def add_roles_to_group(id, role_list = [])
  wf_usergroup_id?(id)
  validate_role_list(role_list)
  api.post([id, 'addRoles'].uri_concat, role_list, 'application/json')
end

#add_users_to_group(id, user_list = []) ⇒ Wavefront::Response

POST /api/v2/usergroup/id/addUsers Add multiple users to a specific user group

Parameters:

  • id (String)

    ID of the user group

  • user_list (Array[String]) (defaults to: [])

    list of users to add

Returns:



91
92
93
94
95
# File 'lib/wavefront-sdk/usergroup.rb', line 91

def add_users_to_group(id, user_list = [])
  wf_usergroup_id?(id)
  validate_user_list(user_list)
  api.post([id, 'addUsers'].uri_concat, user_list, 'application/json')
end

#create(body) ⇒ Wavefront::Response

POST /api/v2/usergroup Create a specific user group

Parameters:

  • body (Hash)

    a hash of parameters describing the group. Please refer to the Wavefront Swagger docs for key:value information

Returns:

Raises:

  • (ArgumentError)


35
36
37
38
39
# File 'lib/wavefront-sdk/usergroup.rb', line 35

def create(body)
  raise ArgumentError unless body.is_a?(Hash)

  api.post('', body, 'application/json')
end

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/usergroup/id Delete a specific user group

Parameters:

  • id (String)

    ID of the user group

Returns:



47
48
49
50
# File 'lib/wavefront-sdk/usergroup.rb', line 47

def delete(id)
  wf_usergroup_id?(id)
  api.delete(id)
end

#describe(id) ⇒ Wavefront::Response

GET /api/v2/usergroup/id Get a specific user group

Parameters:

  • id (String)

    ID of the user group

Returns:



58
59
60
61
# File 'lib/wavefront-sdk/usergroup.rb', line 58

def describe(id)
  wf_usergroup_id?(id)
  api.get(id)
end

#list(offset = 0, limit = 100) ⇒ Wavefront::Response

GET /api/v2/usergroup Get all user groups for a customer

Parameters:

  • offset (Int) (defaults to: 0)

    usergroup at which the list begins

  • limit (Int) (defaults to: 100)

    the number of usergroups to return

Returns:



23
24
25
# File 'lib/wavefront-sdk/usergroup.rb', line 23

def list(offset = 0, limit = 100)
  api.get('', offset: offset, limit: limit)
end

#remove_roles_from_group(id, role_list = []) ⇒ Wavefront::Response

POST /api/v2/usergroup/id/removeRoles Remove multiple roles from a specific user group

Parameters:

  • id (String)

    ID of the user group

  • user_list (Array[String])

    list of roles to remove

Returns:



131
132
133
134
135
136
# File 'lib/wavefront-sdk/usergroup.rb', line 131

def remove_roles_from_group(id, role_list = [])
  wf_usergroup_id?(id)
  validate_role_list(role_list)
  api.post([id, 'removeRoles'].uri_concat, role_list,
           'application/json')
end

#remove_users_from_group(id, user_list = []) ⇒ Wavefront::Response

POST /api/v2/usergroup/id/removeUsers Remove multiple users from a specific user group

Parameters:

  • id (String)

    ID of the user group

  • user_list (Array[String]) (defaults to: [])

    list of users to remove

Returns:



104
105
106
107
108
109
# File 'lib/wavefront-sdk/usergroup.rb', line 104

def remove_users_from_group(id, user_list = [])
  wf_usergroup_id?(id)
  validate_user_list(user_list)
  api.post([id, 'removeUsers'].uri_concat, user_list,
           'application/json')
end

#update(id, body, modify = true) ⇒ Wavefront::Response

PUT /api/v2/usergroup/id Update a specific user group

Parameters:

  • id (String)

    a Wavefront usergroup ID

  • body (Hash)

    key-value hash of the parameters you wish to change

  • modify (true, false) (defaults to: true)

    if true, use #describe() to get a hash describing the existing object, and modify that with the new body. If false, pass the new body straight through.

Returns:

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
82
# File 'lib/wavefront-sdk/usergroup.rb', line 74

def update(id, body, modify = true)
  wf_usergroup_id?(id)
  raise ArgumentError unless body.is_a?(Hash)

  return api.put(id, body, 'application/json') unless modify

  api.put(id, hash_for_update(describe(id).response, body),
          'application/json')
end

#update_keysObject



13
14
15
# File 'lib/wavefront-sdk/usergroup.rb', line 13

def update_keys
  %i[id name]
end