Skip to content

Commit 3727522

Browse files
committed
document expressions
1 parent de7510b commit 3727522

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

schema/openapi.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,10 @@ paths:
15331533
- Auth
15341534
/api/v4/matchExpressions:
15351535
get:
1536+
description: |
1537+
Retrieve a list of all currently defined Match Expressions. These objects cannot be created
1538+
independently in the current API definition, so each of these expressions will be associated with
1539+
an Automated Rule or Stored Credential.
15361540
responses:
15371541
"200":
15381542
content:
@@ -1549,9 +1553,15 @@ paths:
15491553
description: Not Allowed
15501554
security:
15511555
- SecurityScheme: []
1556+
summary: Retrieve a list of all currently defined Match Expressions
15521557
tags:
15531558
- Match Expressions
15541559
post:
1560+
description: |
1561+
Given a list of Target IDs, retrieve each Target instance from the database, then return the list
1562+
filtered by the Targets which satisfy the Match Expression. If a given ID does not exist in the
1563+
database then the whole request will fail. The expression must evaluate to a boolean value for each
1564+
target. The match expression will not be stored.
15551565
requestBody:
15561566
content:
15571567
application/json:
@@ -1570,6 +1580,7 @@ paths:
15701580
description: Not Allowed
15711581
security:
15721582
- SecurityScheme: []
1583+
summary: Test a MatchExpression against a list of Targets
15731584
tags:
15741585
- Match Expressions
15751586
/api/v4/matchExpressions/{id}:
@@ -1594,6 +1605,7 @@ paths:
15941605
description: Not Allowed
15951606
security:
15961607
- SecurityScheme: []
1608+
summary: Retrieve a single Match Expression
15971609
tags:
15981610
- Match Expressions
15991611
/api/v4/probes:

src/main/java/io/cryostat/expressions/MatchExpression.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
import org.jboss.logging.Logger;
4646
import org.projectnessie.cel.tools.ScriptException;
4747

48+
/**
49+
* Match Expressions contain small snippets of Common Expression Language and are used to evaluate
50+
* other resources' applicability to {@link io.cryostat.target.Target}s. {@link
51+
* io.cryostat.rules.Rule}s and {@link io.cryostat.credentials.Credential}s use Match Expressions to
52+
* determine the set of Targets they should apply to. When evaluating a Match Expression, Cryostat
53+
* passes a slightly slimmed down and read-only representation of the Target instance into the
54+
* expression context so that the expression can make assertions about the Target's properties.
55+
*/
4856
@Entity
4957
@EntityListeners(MatchExpression.Listener.class)
5058
public class MatchExpression extends PanacheEntity {

src/main/java/io/cryostat/expressions/MatchExpressionEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static class MatchExpressionApplies extends Event {
233233
public static class ScriptCreation extends Event {}
234234

235235
/**
236-
* Restricted view of a {@link io.cryostat.targets.Target} with only particular
236+
* Restricted read-only view of a {@link io.cryostat.targets.Target} with only particular
237237
* expression-relevant fields exposed, connection URI exposed as a String, etc.
238238
*/
239239
private static record SimplifiedTarget(

src/main/java/io/cryostat/expressions/MatchExpressions.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import jakarta.ws.rs.GET;
3131
import jakarta.ws.rs.POST;
3232
import jakarta.ws.rs.Path;
33+
import org.eclipse.microprofile.openapi.annotations.Operation;
3334
import org.jboss.logging.Logger;
3435
import org.jboss.resteasy.reactive.RestPath;
3536
import org.projectnessie.cel.tools.ScriptException;
@@ -43,6 +44,15 @@ public class MatchExpressions {
4344
@POST
4445
@RolesAllowed("read")
4546
@Blocking
47+
@Operation(
48+
summary = "Test a MatchExpression against a list of Targets",
49+
description =
50+
"""
51+
Given a list of Target IDs, retrieve each Target instance from the database, then return the list
52+
filtered by the Targets which satisfy the Match Expression. If a given ID does not exist in the
53+
database then the whole request will fail. The expression must evaluate to a boolean value for each
54+
target. The match expression will not be stored.
55+
""")
4656
public MatchedExpression test(RequestData requestData) throws ScriptException {
4757
var targets = new HashSet<Target>();
4858
if (requestData.targetIds == null) {
@@ -56,11 +66,20 @@ public MatchedExpression test(RequestData requestData) throws ScriptException {
5666
@GET
5767
@RolesAllowed("read")
5868
@Blocking
69+
@Operation(
70+
summary = "Retrieve a list of all currently defined Match Expressions",
71+
description =
72+
"""
73+
Retrieve a list of all currently defined Match Expressions. These objects cannot be created
74+
independently in the current API definition, so each of these expressions will be associated with
75+
an Automated Rule or Stored Credential.
76+
""")
5977
public Multi<Map<String, Object>> list() {
6078
List<MatchExpression> exprs = MatchExpression.listAll();
6179
// FIXME hack so that this endpoint renders the response as the entity object with id and
6280
// script fields, rather than allowing Jackson serialization to handle it normally where it
63-
// will be encoded as only the script as a raw string
81+
// will be encoded as only the script as a raw string. This should be done using a JsonView
82+
// or similar technique instead
6483
return Multi.createFrom()
6584
.items(exprs.stream().map(expr -> Map.of("id", expr.id, "script", expr.script)));
6685
}
@@ -69,6 +88,7 @@ public Multi<Map<String, Object>> list() {
6988
@Path("/{id}")
7089
@RolesAllowed("read")
7190
@Blocking
91+
@Operation(summary = "Retrieve a single Match Expression")
7292
public MatchedExpression get(@RestPath long id) throws ScriptException {
7393
return targetMatcher.match(MatchExpression.find("id", id).singleResult());
7494
}

0 commit comments

Comments
 (0)