Class: Wavefront::User

Inherits:
Base
  • Object
show all
Defined in:
lib/wavefront-sdk/user.rb

Overview

Manage and query Wavefront users

Instance Attribute Summary

Attributes inherited from Base

#api_base, #conn, #debug, #logger, #net, #noop, #opts, #update_keys, #verbose

Instance Method Summary collapse

Methods inherited from Base

#api_delete, #api_get, #api_post, #api_put, #hash_for_update, #initialize, #log, #mk_conn, #respond, #time_to_ms

Methods included from Mixins

#parse_time

Methods included from Validators

#wf_alert_id?, #wf_alert_severity?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_ms_ts?, #wf_name?, #wf_point?, #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_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::Base

Instance Method Details

#create(body, send_email = false) ⇒ Hash

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

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/wavefront-sdk/user.rb', line 24

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

#delete(id) ⇒ Hash

DELETE /api/v2/user/id Delete a specific user.



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

def delete(id)
  wf_user_id?(id)
  api_delete(id)
end

#describe(id) ⇒ Hash

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



46
47
48
49
# File 'lib/wavefront-sdk/user.rb', line 46

def describe(id)
  wf_user_id?(id)
  api_get(id)
end

#grant(id, group) ⇒ Hash

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

Raises:

  • (ArgumentError)


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

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

#listObject

GET /api/v2/user Get all users.



12
13
14
# File 'lib/wavefront-sdk/user.rb', line 12

def list
  api_get('')
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.



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

def response_shim(body, status)
  { response: JSON.parse(body),
    status:   { result:  status == 200 ? 'OK' : 'ERROR',
                message: '',
                code:    status },
  }.to_json
end

#revoke(id, group) ⇒ Hash

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

Raises:

  • (ArgumentError)


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

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