Class: Wavefront::User

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

Overview

Manage and query Wavefront users

Instance Attribute Summary

Attributes inherited from CoreApi

#api, #creds, #logger, #opts, #update_keys

Instance Method Summary collapse

Methods included from Mixin::User

#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_alert_id?, #wf_alert_severity?, #wf_apitoken_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_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_source_id?, #wf_string?, #wf_tag?, #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_groups_to_user(id, group_list = []) ⇒ Wavefront::Response

POST /api/v2/user/id/addUserGroups Adds specific user groups to the user



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

def add_groups_to_user(id, group_list = [])
  wf_user_id?(id)
  validate_usergroup_list(group_list)
  api.post([id, 'addUserGroups'].uri_concat, group_list,
           'application/json')
end

#create(body, send_email = false) ⇒ Wavefront::Response

POST /api/v2/user Creates or updates a user

Raises:

  • (ArgumentError)


26
27
28
29
# File 'lib/wavefront-sdk/user.rb', line 26

def create(body, send_email = false)
  raise ArgumentError unless body.is_a?(Hash)
  api.post("?sendEmail=#{send_email}", body, 'application/json')
end

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/user/id Delete a specific user. See also #delete_users.



37
38
39
40
# File 'lib/wavefront-sdk/user.rb', line 37

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

#delete_users(user_list) ⇒ Wavefront::Response

POST /api/v2/user/deleteUsers Deletes multiple users

Yep, a POST that DELETEs. Not to be confused with DELETE. I don’t make the API, I just cover it.

Raises:

  • (ArgumentError)


146
147
148
149
150
# File 'lib/wavefront-sdk/user.rb', line 146

def delete_users(user_list)
  raise ArgumentError unless user_list.is_a?(Array)
  validate_user_list(user_list)
  api.post('deleteUsers', user_list, 'application/json')
end

#describe(id) ⇒ Wavefront::Response

GET /api/v2/user/id Retrieves a user by identifier (email addr).



48
49
50
51
# File 'lib/wavefront-sdk/user.rb', line 48

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

#everythingObject

the user API class does not support pagination. Be up-front about that.

Raises:

  • (NoMethodError)


216
217
218
# File 'lib/wavefront-sdk/user.rb', line 216

def everything
  raise NoMethodError
end

#grant(id, pgroup) ⇒ Wavefront::Response

PUT /api/v2/user/id/grant Grants a specific user permission.

Raises:

  • (ArgumentError)


115
116
117
118
119
120
# File 'lib/wavefront-sdk/user.rb', line 115

def grant(id, pgroup)
  wf_user_id?(id)
  raise ArgumentError unless pgroup.is_a?(String)
  api.post([id, 'grant'].uri_concat, "group=#{pgroup}",
           'application/x-www-form-urlencoded')
end

#grant_permission(permission, user_list) ⇒ Wavefront::Response

POST /api/v2/user/grant/permission Grants a specific user permission to multiple users See #grant for possible permissions. This method operates on multiple users.

Raises:

  • (ArgumentError)


161
162
163
164
165
166
# File 'lib/wavefront-sdk/user.rb', line 161

def grant_permission(permission, user_list)
  raise ArgumentError unless user_list.is_a?(Array)
  validate_user_list(user_list)
  api.post(['grant', permission].uri_concat, user_list,
           'application/json')
end

#invite(body) ⇒ Wavefront::Response

POST /api/v2/user/invite Invite users with given user groups and permissions.

Raises:

  • (ArgumentError)


190
191
192
193
194
# File 'lib/wavefront-sdk/user.rb', line 190

def invite(body)
  raise ArgumentError unless body.is_a?(Array)
  raise ArgumentError unless body.first.is_a?(Hash)
  api.post('invite', body, 'application/json')
end

#listObject

GET /api/v2/user Get all users.



14
15
16
# File 'lib/wavefront-sdk/user.rb', line 14

def list
  api.get('')
end

#remove_groups_from_user(id, group_list = []) ⇒ Wavefront::Response

POST /api/v2/user/id/removeUserGroups Removes specific user groups from the user



94
95
96
97
98
99
# File 'lib/wavefront-sdk/user.rb', line 94

def remove_groups_from_user(id, group_list = [])
  wf_user_id?(id)
  validate_usergroup_list(group_list)
  api.post([id, 'removeUserGroups'].uri_concat, group_list,
           'application/json')
end

#response_shim(body, status) ⇒ Object

Fake a response which looks like we get from all the other paths. I’m expecting the user response model to be made consistent with others in the future.



200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/wavefront-sdk/user.rb', line 200

def response_shim(body, status)
  items = JSON.parse(body, symbolize_names: true)

  { response: { items:      items,
                offset:     0,
                limit:      items.size,
                totalItems: items.size,
                modeItems:  false },
    status:   { result:     status == 200 ? 'OK' : 'ERROR',
                message:    extract_api_message(status, items),
                code:       status } }.to_json
end

#revoke(id, pgroup) ⇒ Wavefront::Response

PUT /api/v2/user/id/revoke Revokes a specific user permission.

Raises:

  • (ArgumentError)


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

def revoke(id, pgroup)
  wf_user_id?(id)
  raise ArgumentError unless pgroup.is_a?(String)
  api.post([id, 'revoke'].uri_concat, "group=#{pgroup}",
           'application/x-www-form-urlencoded')
end

#revoke_permission(permission, user_list) ⇒ Wavefront::Response

POST /api/v2/user/revoke/permission Revokes a specific user permission from multiple users See #grant for possible permissions. This method operates on multiple users.

Raises:

  • (ArgumentError)


177
178
179
180
181
182
# File 'lib/wavefront-sdk/user.rb', line 177

def revoke_permission(permission, user_list)
  raise ArgumentError unless user_list.is_a?(Array)
  validate_user_list(user_list)
  api.post(['revoke', permission].uri_concat, user_list,
           'application/json')
end

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

PUT /api/v2/user/id Update a specific user definition.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
# File 'lib/wavefront-sdk/user.rb', line 64

def update(id, body, modify = true)
  wf_user_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