Class: Hawkular::Token::Client

Inherits:
BaseClient show all
Defined in:
lib/hawkular/tokens/tokens_api.rb

Overview

Client class to interact with the Secret Store

Instance Attribute Summary

Attributes inherited from BaseClient

#tenants

Instance Method Summary collapse

Methods inherited from BaseClient

#admin_header, #base_64_credentials, #generate_query_params, #http_delete, #http_get, #http_post, #http_put, #normalize_entrypoint_url, #now, #url_with_websocket_scheme

Methods included from ClientUtils

#hawk_escape, #hawk_escape_id

Constructor Details

#initialize(entrypoint, credentials = {}, options = {}) ⇒ Client

Create a new Secret Store client

Parameters:

  • entrypoint (String)

    base url of Hawkular - e.g localhost:8080

  • credentials (Hash{String=>String}) (defaults to: {})

    Hash of username, password

  • options (Hash{String=>String}) (defaults to: {})

    Additional rest client options



11
12
13
# File 'lib/hawkular/tokens/tokens_api.rb', line 11

def initialize(entrypoint, credentials = {}, options = {})
  super(entrypoint, credentials, options)
end

Instance Method Details

#create_token(credentials = {}, persona = nil, name = 'Token created via Hawkular Ruby Client', expires_at = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/hawkular/tokens/tokens_api.rb', line 25

def create_token(credentials = {}, persona = nil, name = 'Token created via Hawkular Ruby Client', expires_at = nil)
  creds = credentials.empty? ? @credentials : credentials
  auth_header = { Authorization: base_64_credentials(creds) }
  auth_header['Hawkular-Persona'] = persona if persona

  token_attributes = { expiresAt: expires_at, attributes: { name: name } }
  http_post('/secret-store/v1/tokens/create', token_attributes, auth_header)
end

#get_tokens(credentials = {}) ⇒ String

Retrieve the tenant id for the passed credentials. If no credentials are passed, the ones from the constructor are used

Parameters:

  • credentials (Hash{String=>String}) (defaults to: {})

    Hash of username, password, token(optional)

Returns:

  • (String)

    tenant id



19
20
21
22
23
# File 'lib/hawkular/tokens/tokens_api.rb', line 19

def get_tokens(credentials = {})
  creds = credentials.empty? ? @credentials : credentials
  auth_header = { Authorization: base_64_credentials(creds) }
  http_get('/secret-store/v1/tokens', auth_header)
end