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) ⇒ Wavefront::Response

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

Parameters:

  • body (Hash)

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

Returns:

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) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the user

Returns:



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) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the user

Returns:



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) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the user

  • group (String)

    group to add user to. We do not validate this so that changes to the API do not mandate changes to the SDK. At the time of writing, valid values are browse, agent_management, alerts_management, dashboard_management, embedded_charts, events_management, external_links_management, host_tag_management, metrics_management, user_management,

Returns:

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) ⇒ Wavefront::Response

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

Parameters:

  • id (String)

    ID of the user

  • group (String)

    group to add user to. We do not validate this so that changes to the API do not mandate changes to the SDK. See #update for valid values.

Returns:

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