Class: Jamf::APIClient

Inherits:
OAPISchemas::ApiIntegrationResponse show all
Extended by:
Filterable
Includes:
CollectionResource
Defined in:
lib/jamf/api/jamf_pro/api_objects/api_client.rb

Overview

An API Role in the Jamf Pro API

API Roles are predefined sets of privileges that can be assigned to API Clients, aka API Integrations.

Constant Summary collapse

SEARCH_RESULT_OBJECT =

The OAPI object class we get back from a ‘list’ query to get the whole collection, or a subset of it. It contains a :results key which is an array of data for objects of the parent class.

Jamf::OAPISchemas::ApiIntegrationSearchResult
POST_OBJECT =

The OAPI object class we send with a POST request to make a new member of the collection in Jamf. This is usually the same as the parent class.

Jamf::OAPISchemas::ApiIntegrationRequest
PUT_OBJECT =

The OAPI object class we send with a PUT request to change an object in Jamf by specifying all its values. Most updates happen this way, and this is usually the same as the parent class

Jamf::OAPISchemas::ApiIntegrationRequest
LIST_PATH =

The path for GETting the list of all objects in the collection, possibly filtered, sorted, and/or paged REQUIRED for all collection resources

GET_PATH, POST_PATH, PUT_PATH, PATCH_PATH, and DELETE_PATH are automatically assumed from the LIST_PATH if they follow the standards:

  • GET_PATH = “#LIST_PATH/id”

    • fetch an object from the collection

  • POST_PATH = LIST_PATH

    • create a new object in the collection

  • PUT_PATH = “#LIST_PATH/id”

    • update an object passing all its values back. Most objects use this or PATCH but not both

  • PATCH_PATH = “#LIST_PATH/id”

    • update an object passing some of its values back Most objects use this or PUT but not both

  • DELETE_PATH = “#LIST_PATH/id”

    • delete an object from the collection

If those paths differ from the standards, the constants must be defined here

'v1/api-integrations'.freeze
NEW_CREDENTIALS_PATH_SUFFIX =

The path that returns a list of all available privs

'client-credentials'
NEW_CREDENTIALS_OBJECT =

When creating new credentials, an instance of this is returned

Jamf::OAPISchemas::OAuthClientCredentials
ALT_IDENTIFIERS =

Identifiers not marked in the superclass’s OAPI_PROPERTIES constant which usually only identifies ‘:id’

%i[displayName].freeze
FILTER_KEYS =

Must define this when extending Filterable

%i[
  id displayName
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cnxJamf::Connection (readonly) Originally defined in module JPAPIResource

Returns the API connection thru which we deal with this resource.

Returns:

  • (Jamf::Connection)

    the API connection thru which we deal with this resource.

#delete_pathString (readonly) Originally defined in module CollectionResource

Returns The path for deleting a this item from the collection in the JPAPI.

Returns:

  • (String)

    The path for deleting a this item from the collection in the JPAPI

#get_pathString (readonly) Originally defined in module JPAPIResource

Returns The path for fetching this thing from the JPAPI

this gets set in the constructor in the CollectionResource or SingletonResource mixins.

Returns:

  • (String)

    The path for fetching this thing from the JPAPI

    this gets set in the constructor in the CollectionResource or SingletonResource mixins

#post_pathString (readonly) Originally defined in module CollectionResource

Returns The path for creating a new item in the collection in the JPAPI.

Returns:

  • (String)

    The path for creating a new item in the collection in the JPAPI

#update_pathString (readonly) Originally defined in module JPAPIResource

Returns The path for updating this thing from the JPAPI

this gets set in the constructor in the CollectionResource or SingletonResource mixins

We use ‘update_path’ because some items are updated via a PUT_PATH and others via a PATCH_PATH. When this gets set, it will contain the appropriate one.

Returns:

  • (String)

    The path for updating this thing from the JPAPI

    this gets set in the constructor in the CollectionResource or SingletonResource mixins

    We use ‘update_path’ because some items are updated via a PUT_PATH and others via a PATCH_PATH. When this gets set, it will contain the appropriate one.

Class Method Details

.filter_keysObject Originally defined in module Filterable

.rotate_secret(client_ident, cnx: Jamf.cnx) ⇒ String

For the given API Client, replace the existing clientSecret with a new one, to be used with the clientID for generating a connection token.

IMPORTANT: When you do this, the previous secret becomes immediately invalid and can no longer be used for generating connection tokens. BE SURE to capture the output in a variable, or display it somewhere immediately, as it will not be available ever again. See the Jamf Pro docs at learn.jamf.com/bundle/jamf-pro-documentation-current/page/API_Roles_and_Clients.html

Parameters:

  • client_ident (String, Integer)

    The displayName or id of the APIClient for which to generate a new secret.

  • cnx (Jamf::APIConnection) (defaults to: Jamf.cnx)

    The API connection through which to perform the operation

Returns:

  • (String)

    The new valid secret for use with the clientId

Raises:



129
130
131
132
133
134
135
# File 'lib/jamf/api/jamf_pro/api_objects/api_client.rb', line 129

def self.rotate_secret(client_ident, cnx: Jamf.cnx)
  valid_id = valid_id(client_ident, cnx: cnx)
  raise Jamf::NoSuchItemError, "No APIClient matching '#{client_ident}'" unless valid_id

  creds = NEW_CREDENTIALS_OBJECT.new cnx.jp_post("#{LIST_PATH}/#{valid_id}/#{NEW_CREDENTIALS_PATH_SUFFIX}", nil)
  creds.clientSecret
end

Instance Method Details

#deleteObject Originally defined in module CollectionResource

#exist?Boolean Originally defined in module CollectionResource

Returns:

  • (Boolean)

#initialize(**data) ⇒ Object Originally defined in module CollectionResource

Constructor

#pretty_print_instance_variablesArray Originally defined in module JPAPIResource

Remove large cached items from the instance_variables used to create pretty-print (pp) output.

Returns:

  • (Array)

    the desired instance_variables

#rotate_secretString

For this API Client, replace the existing clientSecret with a new one, to be used with the clientID for generating a connection token.

IMPORTANT: When you do this, the previous secret becomes immediately invalid and can no longer be used for generating connection tokens. BE SURE to capture the output in a variable, or display it somewhere immediately, as it will not be available ever again. See the Jamf Pro docs at learn.jamf.com/bundle/jamf-pro-documentation-current/page/API_Roles_and_Clients.html

Returns:

  • (String)

    The new valid secret for use with the clientId



155
156
157
# File 'lib/jamf/api/jamf_pro/api_objects/api_client.rb', line 155

def rotate_secret
  self.class.rotate_secret(id, cnx: cnx)
end

#saveObject Originally defined in module JPAPIResource

TODO: error handling

#to_sString Originally defined in module CollectionResource

A meaningful string representation of this object

Returns: