Class: Wavefront::ApiToken

Inherits:
CoreApi
  • Object
show all
Defined in:
lib/wavefront-sdk/apitoken.rb

Overview

View and manage API tokens for one’s own user, and for service accounts.

Instance Attribute Summary

Attributes inherited from CoreApi

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

Instance Method Summary collapse

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_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_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

#createWavefront::Response

POST /api/v2/apitoken Create a new api token

Returns:



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

def create
  api.post('', nil, 'application/json')
end

#delete(id) ⇒ Wavefront::Response

DELETE /api/v2/apitoken/id Delete the specified api token

Parameters:

  • id (String)

    ID of the api token

Returns:



34
35
36
37
# File 'lib/wavefront-sdk/apitoken.rb', line 34

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

#listWavefront::Response

GET /api/v2/apitoken Get all api tokens for a user

Returns:



15
16
17
# File 'lib/wavefront-sdk/apitoken.rb', line 15

def list
  api.get('')
end

#rename(id, name) ⇒ Wavefront::Response

PUT /api/v2/apitoken/id Update the name of the specified api token

Parameters:

  • id (String)

    ID of the API token

  • name (String)

    name of the API token

Returns:



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

def rename(id, name)
  wf_apitoken_id?(id)
  api.put(id, { tokenID: id, tokenName: name }, 'application/json')
end

#sa_create(id, name = nil) ⇒ Wavefront::Response

POST /api/v2/apitoken/serviceaccount/id Create a new api token for the service account

Parameters:

  • id (String)

    service account ID

  • name (String) (defaults to: nil)

    optional name for token

Returns:



69
70
71
72
73
# File 'lib/wavefront-sdk/apitoken.rb', line 69

def sa_create(id, name = nil)
  wf_serviceaccount_id?(id)
  body = {}.tap { |b| b[:tokenName] = name if name }
  api.post(['serviceaccount', id].uri_concat, body, 'application/json')
end

#sa_delete(id, token_id) ⇒ Wavefront::Response

DELETE /api/v2/apitoken/serviceaccount/id/token Delete the specified api token of the given service account

Parameters:

  • id (String)

    service account ID

  • token_id (String)

    ID of the api token

Returns:



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

def sa_delete(id, token_id)
  wf_serviceaccount_id?(id)
  wf_apitoken_id?(token_id)
  api.delete(['serviceaccount', id, token_id].uri_concat)
end

#sa_list(id) ⇒ Wavefront::Response

GET /api/v2/apitoken/serviceaccount/id Get all api tokens for the given service account

Parameters:

  • id (String)

    service account ID

Returns:



57
58
59
60
# File 'lib/wavefront-sdk/apitoken.rb', line 57

def sa_list(id)
  wf_serviceaccount_id?(id)
  api.get(['serviceaccount', id].uri_concat)
end

#sa_rename(id, token_id, name) ⇒ Wavefront::Response

PUT /api/v2/apitoken/serviceaccount/id/token Update the name of the specified api token for the given service account

Parameters:

  • id (String)

    service account ID

  • token_id (String)

    ID of the api token

Returns:



96
97
98
99
100
101
# File 'lib/wavefront-sdk/apitoken.rb', line 96

def sa_rename(id, token_id, name)
  wf_serviceaccount_id?(id)
  wf_apitoken_id?(token_id)
  api.put(['serviceaccount', id, token_id].uri_concat,
          { tokenID: token_id, tokenName: name }, 'application/json')
end