class Wavefront::User

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

Public Instance Methods

add_groups_to_user(id, group_list = []) click to toggle source

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

@param id [String] ID of the user @param group_list [Array] list of groups to add @return [Wavefront::Response]

# 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) click to toggle source

GET /api/v2/user/{id}/businessFunctions Returns business functions of a specific user. @param id [String] user ID @return [Wavefront::Response]

# 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) click to toggle source

Construct a response almost from scratch. Used for 'list', among others.

# 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: extract_api_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) click to toggle source

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

@param body [Hash] a hash of parameters describing the user.

Please refer to the Wavefront Swagger docs for key:value
information

@return [Wavefront::Response]

# 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) click to toggle source

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

@param id [String] ID of the user @return [Wavefront::Response]

# 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) click to toggle source

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. @param user_list [Array] list of user IDs @return [Wavefront::Response]

# 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() click to toggle source
# 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) click to toggle source

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

@param id [String] ID of the user @return [Wavefront::Response]

# File lib/wavefront-sdk/user.rb, line 70
def describe(id)
  deprecation_warning
  wf_user_id?(id)
  api.get(id)
end
everything() click to toggle source

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

# File lib/wavefront-sdk/user.rb, line 296
def everything
  raise NoMethodError
end
grant(id, pgroup) click to toggle source

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

@param id [String] ID of the user @param pgroup [String] permission group to grant to user. 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,

@return [Wavefront::Response]

# 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) click to toggle source

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. @param permission [String] permission to grant @param user_list [Array] users who should receive the

permission

@return [Wavefront::Response]

# File lib/wavefront-sdk/user.rb, line 193
def grant_permission(permission, user_list)
  deprecation_warning
  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) click to toggle source

POST /api/v2/user/invite Invite users with given user groups and permissions. @param body [Array] array of hashes describing a user.

See API docs for more details.

@return [Wavefront::Response]

# 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) click to toggle source
# 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() click to toggle source

GET /api/v2/user Get all users.

# File lib/wavefront-sdk/user.rb, line 32
def list
  deprecation_warning
  api.get('')
end
post_initialize(_creds, _opts) click to toggle source
# File lib/wavefront-sdk/user.rb, line 25
def post_initialize(_creds, _opts)
  deprecation_warning
end
remove_groups_from_user(id, group_list = []) click to toggle source

POST /api/v2/user/{id}/removeUserGroups Removes specific user groups from the user @param id [String] ID of the user @param group_list [Array] list of groups to remove @return [Wavefront::Response]

# 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) click to toggle source

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. @return [String] of JSON

# 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) click to toggle source

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

@param id [String] ID of the user @param pgroup [String] permission group to revoke from the

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

@return [Wavefront::Response]

# 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) click to toggle source

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. @param permission [String] permission to revoke @param user_list [Array] users who should lose the

permission

@return [Wavefront::Response]

# File lib/wavefront-sdk/user.rb, line 211
def revoke_permission(permission, user_list)
  deprecation_warning
  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) click to toggle source

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

@param id [String] a Wavefront user ID @param body [Hash] key-value hash of the parameters you wish

to change

@param modify [true, false] 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.

@return [Wavefront::Response]

# 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() click to toggle source
# File lib/wavefront-sdk/user.rb, line 300
def update_keys
  %i[identifier groups userGroups]
end
validate_users(id_list) click to toggle source

POST /api/v2/user/validateUsers Returns valid users and service accounts, also invalid identifiers from the given list @param id_list [Array] list of user IDs @return [Wavefront::Response]

# File lib/wavefront-sdk/user.rb, line 251
def validate_users(id_list)
  deprecation_warning
  api.post('validateUsers', id_list, 'application/json')
end

Private Instance Methods

extract_api_message(status, items) click to toggle source
# File lib/wavefront-sdk/user.rb, line 313
def extract_api_message(status, items)
  return '' if status < 300

  items.fetch(:message, 'no message from API')
end
response_looks_right?(body_obj) click to toggle source
# File lib/wavefront-sdk/user.rb, line 306
def response_looks_right?(body_obj)
  body_obj.key?(:response) &&
    body_obj[:response].is_a?(Hash) &&
    body_obj[:response].key?(:items) &&
    body_obj[:response][:items].is_a?(Array)
end