Class: Wavefront::User
- Includes:
- Mixin::User
- Defined in:
- lib/wavefront-sdk/user.rb
Overview
In line with the API changes in the 2020-06 release of Wavefront, this class has been deprecated.
Please use Wavefront::Account to manage users.
docs.wavefront.com/2020.06.x_release_notes.html
Manage and query Wavefront users
Instance Attribute Summary
Attributes inherited from CoreApi
Instance Method Summary collapse
-
#add_groups_to_user(id, group_list = []) ⇒ Wavefront::Response
POST /api/v2/user/id/addUserGroups Adds specific user groups to the user.
-
#business_functions(id) ⇒ Wavefront::Response
GET /api/v2/user/id/businessFunctions Returns business functions of a specific user.
-
#construct_response(body_obj, status) ⇒ Object
Construct a response almost from scratch.
-
#create(body, send_email = false) ⇒ Wavefront::Response
POST /api/v2/user Creates or updates a user.
-
#delete(id) ⇒ Wavefront::Response
DELETE /api/v2/user/id Delete a specific user.
-
#delete_users(user_list) ⇒ Wavefront::Response
POST /api/v2/user/deleteUsers Deletes multiple users.
- #deprecation_warning ⇒ Object
-
#describe(id) ⇒ Wavefront::Response
GET /api/v2/user/id Retrieves a user by identifier (email addr).
-
#everything ⇒ Object
the user API class does not support pagination.
-
#grant(id, pgroup) ⇒ Wavefront::Response
POST /api/v2/user/id/grant Grants a specific user permission.
-
#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.
-
#invite(body) ⇒ Wavefront::Response
POST /api/v2/user/invite Invite users with given user groups and permissions.
- #itemize_response(body_obj) ⇒ Object
-
#list ⇒ Object
GET /api/v2/user Get all users.
- #post_initialize(_creds, _opts) ⇒ Object
-
#remove_groups_from_user(id, group_list = []) ⇒ Wavefront::Response
POST /api/v2/user/id/removeUserGroups Removes specific user groups from the user.
-
#response_shim(body, status) ⇒ String
Fake a response which looks like we get from all the other paths.
-
#revoke(id, pgroup) ⇒ Wavefront::Response
POST /api/v2/user/id/revoke Revokes a specific user permission.
-
#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.
-
#update(id, body, modify = true) ⇒ Wavefront::Response
PUT /api/v2/user/id Update a specific user definition.
- #update_keys ⇒ Object
-
#validate_users(id_list) ⇒ Wavefront::Response
POST /api/v2/user/validateUsers Returns valid users and service accounts, also invalid identifiers from the given list.
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_groups_to_user(id, group_list = []) ⇒ Wavefront::Response
POST /api/v2/user/id/addUserGroups Adds specific user groups to the user
105 106 107 108 109 110 111 |
# File 'lib/wavefront-sdk/user.rb', line 105 def add_groups_to_user(id, group_list = []) deprecation_warning wf_user_id?(id) validate_usergroup_list(group_list) api.post([id, 'addUserGroups'].uri_concat, group_list, 'application/json') end |
#business_functions(id) ⇒ Wavefront::Response
GET /api/v2/user/id/businessFunctions Returns business functions of a specific user.
239 240 241 242 243 |
# File 'lib/wavefront-sdk/user.rb', line 239 def business_functions(id) deprecation_warning wf_user_id?(id) api.get([id, 'businessFunctions'].uri_concat) end |
#construct_response(body_obj, status) ⇒ Object
Construct a response almost from scratch. Used for ‘list’, among others.
282 283 284 285 286 287 288 289 290 291 |
# File 'lib/wavefront-sdk/user.rb', line 282 def construct_response(body_obj, status) { status: { result: status.to_s.start_with?('2') ? 'OK' : 'ERROR', message: (status, body_obj), code: status }, response: { items: [body_obj].flatten, offset: 0, limit: body_obj.size, totalItems: body_obj.size, moreItems: false } }.to_json end |
#create(body, send_email = false) ⇒ Wavefront::Response
POST /api/v2/user Creates or updates a user
45 46 47 48 49 50 |
# File 'lib/wavefront-sdk/user.rb', line 45 def create(body, send_email = false) deprecation_warning 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.
58 59 60 61 62 |
# File 'lib/wavefront-sdk/user.rb', line 58 def delete(id) deprecation_warning 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.
176 177 178 179 180 181 182 |
# File 'lib/wavefront-sdk/user.rb', line 176 def delete_users(user_list) deprecation_warning raise ArgumentError unless user_list.is_a?(Array) validate_user_list(user_list) api.post('deleteUsers', user_list, 'application/json') end |
#deprecation_warning ⇒ Object
20 21 22 23 |
# File 'lib/wavefront-sdk/user.rb', line 20 def deprecation_warning logger.log('Wavefront::User is deprecated and will be removed from the ' \ 'next major release. Please use Wavefront::Account.', :warn) end |
#describe(id) ⇒ Wavefront::Response
GET /api/v2/user/id Retrieves a user by identifier (email addr).
70 71 72 73 74 |
# File 'lib/wavefront-sdk/user.rb', line 70 def describe(id) deprecation_warning wf_user_id?(id) api.get(id) end |
#everything ⇒ Object
the user API class does not support pagination. Be up-front about that.
296 297 298 |
# File 'lib/wavefront-sdk/user.rb', line 296 def everything raise NoMethodError end |
#grant(id, pgroup) ⇒ Wavefront::Response
POST /api/v2/user/id/grant Grants a specific user permission.
141 142 143 144 145 146 147 148 |
# File 'lib/wavefront-sdk/user.rb', line 141 def grant(id, pgroup) deprecation_warning 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.
193 194 195 196 197 198 199 200 |
# File 'lib/wavefront-sdk/user.rb', line 193 def (, user_list) deprecation_warning raise ArgumentError unless user_list.is_a?(Array) validate_user_list(user_list) api.post(['grant', ].uri_concat, user_list, 'application/json') end |
#invite(body) ⇒ Wavefront::Response
POST /api/v2/user/invite Invite users with given user groups and permissions.
226 227 228 229 230 231 232 |
# File 'lib/wavefront-sdk/user.rb', line 226 def invite(body) deprecation_warning raise ArgumentError unless body.is_a?(Array) raise ArgumentError unless body.first.is_a?(Hash) api.post('invite', body, 'application/json') end |
#itemize_response(body_obj) ⇒ Object
275 276 277 278 |
# File 'lib/wavefront-sdk/user.rb', line 275 def itemize_response(body_obj) { status: body_obj[:status], response: { items: [body_obj[:response]].flatten } }.to_json end |
#list ⇒ Object
GET /api/v2/user Get all users.
32 33 34 35 |
# File 'lib/wavefront-sdk/user.rb', line 32 def list deprecation_warning api.get('') end |
#post_initialize(_creds, _opts) ⇒ Object
25 26 27 |
# File 'lib/wavefront-sdk/user.rb', line 25 def post_initialize(_creds, _opts) deprecation_warning end |
#remove_groups_from_user(id, group_list = []) ⇒ Wavefront::Response
POST /api/v2/user/id/removeUserGroups Removes specific user groups from the user
119 120 121 122 123 124 125 |
# File 'lib/wavefront-sdk/user.rb', line 119 def remove_groups_from_user(id, group_list = []) deprecation_warning wf_user_id?(id) validate_usergroup_list(group_list) api.post([id, 'removeUserGroups'].uri_concat, group_list, 'application/json') end |
#response_shim(body, status) ⇒ String
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.
261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/wavefront-sdk/user.rb', line 261 def response_shim(body, status) body_obj = JSON.parse(body, symbolize_names: true) if body_obj.is_a?(Hash) && body_obj.key?(:status) if response_looks_right?(body_obj) body else itemize_response(body_obj) end else construct_response(body_obj, status) end end |
#revoke(id, pgroup) ⇒ Wavefront::Response
POST /api/v2/user/id/revoke Revokes a specific user permission.
159 160 161 162 163 164 165 166 |
# File 'lib/wavefront-sdk/user.rb', line 159 def revoke(id, pgroup) deprecation_warning 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.
211 212 213 214 215 216 217 218 |
# File 'lib/wavefront-sdk/user.rb', line 211 def (, user_list) deprecation_warning raise ArgumentError unless user_list.is_a?(Array) validate_user_list(user_list) api.post(['revoke', ].uri_concat, user_list, 'application/json') end |
#update(id, body, modify = true) ⇒ Wavefront::Response
PUT /api/v2/user/id Update a specific user definition.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/wavefront-sdk/user.rb', line 87 def update(id, body, modify = true) deprecation_warning 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 |
#update_keys ⇒ Object
300 301 302 |
# File 'lib/wavefront-sdk/user.rb', line 300 def update_keys %i[identifier groups userGroups] end |
#validate_users(id_list) ⇒ Wavefront::Response
POST /api/v2/user/validateUsers Returns valid users and service accounts, also invalid identifiers from the given list
251 252 253 254 |
# File 'lib/wavefront-sdk/user.rb', line 251 def validate_users(id_list) deprecation_warning api.post('validateUsers', id_list, 'application/json') end |