Forming node classifier API requests
Requests to the node classifier API must be well-formed HTTP(S) requests.
By default, the node classifier service listens on port 4433 and all
endpoints are relative to the /classifier-api/
path. For example, the full URL for the /v1/groups
endpoint on localhost would be https://localhost:4433/classifier-api/v1/groups
.
If needed, you can change the port the classifier API listens on.
URI
path
following the
pattern:https://<DNS>:4433/classifier-api/<VERSION>/<ENDPOINT>
-
DNS
: Your PE console host's DNS name. You can uselocalhost
, manually enter the DNS name, or use apuppet
command (as explained in Using example commands). -
VERSION
: Eitherv1
orv2
. Refer to Node classifier API v2 for v2 endpoints. -
ENDPOINT
: One or more sections specifying the endpoint, such asgroups
orclasses
. Some endpoints require additional sections, such as the GET /v1/environments/<environment>/classes endpoint.
https://$(puppet config print server):4433/classifier-api/v1/classes
https://localhost:4433/classifier-api/v1/classes
https://puppet.example.dns:4433/classifier-api/v1/classes
To form a complete curl command, you need to provide appropriate curl arguments, authentication, and you might need to supply the content type and/or additional parameters specific to the endpoint you are calling.
For general information about forming curl commands, authentication in commands, and Windows modifications, go to Using example commands.
Rule condition grammar
condition : [ {bool} {condition}+ ] | [ "not" {condition} ] | {operation}
bool : "and" | "or"
operation : [ {operator} {fact-path} {value} ]
operator : "=" | "~" | ">" | ">=" | "<" | "<="
fact-path : {field-name} | [ {path-type} {field-name} {path-component}+ ]
path-type : "trusted" | "fact"
path-component : field-name | number
field-name : string
For the regex operator "~"
, the value is interpreted as a Java
regular expression. You must use literal backslashes to escape regex characters in
order to match those characters in the fact value.
For the numeric comparison operators (">"
,
">="
, "<"
, and
"<="
), the fact value (which is always a string) is coerced to a
number (either integral or floating-point). If the value can't be coerced to a
number, the numeric operation evaluates to false.
For the fact-path
, the rule can be either a string
representing a top level field (such as name
,
representing the node name) or a list of strings and indices that represent looking
up a field in a nested data structure. When passing a list of strings or indices,
the first and second entries in the list must be strings and subsequent entries can
be indices.
Regular facts start with "fact"
(for example,
["fact", "architecture"]
) and trusted facts start with "trusted"
(for example, ["trusted",
"certname"]
).
Node classifier API authentication
You must authenticate node classifier API requests. You can do this using RBAC authentication tokens or with the list of allowed RBAC certificates.
Authenticating with tokens
You can make requests to the node classifier API using RBAC authentication tokens.
For instructions on generating, configuring, revoking, and deleting authentication tokens in PE, go to Token-based authentication.
puppet-access login
to
call the GET /v1/groups
endpoint:auth_header="X-Authentication: $(puppet-access show)"
uri="https://$(puppet config print server):4433/classifier-api/v1/groups"
curl --insecure --header "$auth_header" "$uri"
For general information about forming curl commands, authentication in commands, and Windows modifications, go to Using example commands.
uri="https://$(puppet config print server):4433/classifier-api/v1/groups?token=$(puppet-access show)"
curl --insecure "$uri"
Authenticating with an allowed certificate
You can also authenticate requests using a certificate listed in RBAC's certificate allowlist.
The RBAC allowlist is located at
/etc/puppetlabs/console-services/rbac-certificate-allowlist
. If
you edit this file, you must reload the pe-console-services
service
for your changes to take effect by running: sudo service pe-console-services
reload
/etc/puppetlabs/console-services/rbac-certificate-allowlist
.
For
example:type_header='Content-Type: application/json'
cert="$(puppet config print hostcert)"
cacert="$(puppet config print localcacert)"
key="$(puppet config print hostprivkey)"
uri="https://$(puppet config print server):4433/classifier-api/v1/groups"
curl --header "$type_header" --cert "$cert" --cacert "$cacert" --key "$key" GET "$uri"
You do not need to use an agent certificate for authentication.
You can use puppet cert generate
to
create a new certificate specifically for use with the API.
Using pagination parameters
If your installation has a large number of groups, classes, nodes, node check-ins, or environments, then node classifier API GET requests might return an excessively large results.
limit
and
offset
parameters to your request URI paths:-
limit
: Set the maximum number of items allowed to be returned in the response. The value must be a non-negative integer. -
offset
: Specify the number of items to skip from the beginning of the possible results. The value must be a zero-indexed, non-negative integer. The response begins returning results from the point specified, for example ifoffset=10
, the response skips the first 10 results and starts the response with the 11th record.
20
with a limit of
10
(as shown in the example below) the first 20
records are skipped, and the response returns records 21 through 30:
type_header='Content-Type: application/json'
cert="$(puppet config print hostcert)"
cacert="$(puppet config print localcacert)"
key="$(puppet config print hostprivkey)"
uri="https://$(puppet config print server):4433/classifier-api/v1/groups?limit=10&offset=20"
curl --header "$type_header" --cert "$cert" --cacert "$cacert" --key $key "$uri"
Supplying non-integer values for these parameters returns a 400 Bad request response.
For general information about forming curl commands, authentication in commands, and Windows modifications, go to Using example commands.