Class: PEClient::Resource::RBACV1::Tokens

Inherits:
Base
  • Object
show all
Defined in:
lib/pe_client/resources/rbac.v1/tokens.rb

Overview

Authentication tokens control access to PE services. Use the auth/token and tokens endpoints to create tokens.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PEClient::Resource::Base

Instance Method Details

#create(lifetime:, description:, client: "PEClient/#{PEClient::VERSION}") ⇒ Hash

Create a token for the authenticated user. Doesn’t allow certificate authentication.

Parameters:

  • lifetime (String)

    The duration that the token is valid for. This is a string that consists of a number followed by a unit, such as “1h” for one hour or “30m” for thirty minutes.

  • description (String)

    A description to identify the token.

  • client (String) (defaults to: "PEClient/#{PEClient::VERSION}")

    Description about the client making the token request, such as “PE console”.

Returns:

  • (Hash)


51
52
53
# File 'lib/pe_client/resources/rbac.v1/tokens.rb', line 51

def create(lifetime:, description:, client: "PEClient/#{PEClient::VERSION}")
  @client.post "#{RBACV1::BASE_PATH}/tokens", body: {lifetime:, description:, client:}.compact
end

#generate(login:, password:, lifetime: nil, label: nil) ⇒ Hash

Note:

PEClient::Client.api_key is not required to use this method.

Generate an authorization token for a user identified by login and password. This token can be used to authenticate requests to Puppet Enterprise (PE) services, such as by using an X-Authentication header or a token query parameter in an API request.

Parameters:

  • login (String)
  • password (String)
  • lifetime (String) (defaults to: nil)

    The duration that the token is valid for. This is a string that consists of a number followed by a unit, such as “1h” for one hour or “30m” for thirty minutes.

  • label (String) (defaults to: nil)

    A label to identify the token.

Returns:

  • (Hash)


38
39
40
# File 'lib/pe_client/resources/rbac.v1/tokens.rb', line 38

def generate(login:, password:, lifetime: nil, label: nil)
  @client.post "#{RBACV1::BASE_PATH}/auth/token", body: {login:, password:, lifetime:, label:}.compact
end