Skip to content

Commit f3d1b8a

Browse files
CEL Dev Teamcopybara-github
authored andcommitted
Add Goal description and display name to Blueprint.
This information will be used in the UI to describe the goal and what it means for the partner. PiperOrigin-RevId: 781172493
1 parent 8feccc8 commit f3d1b8a

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

policy/src/main/java/dev/cel/policy/CelPolicy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public abstract class CelPolicy {
3636

3737
public abstract ValueString name();
3838

39+
public abstract Optional<ValueString> description();
40+
41+
public abstract Optional<ValueString> displayName();
42+
3943
public abstract Rule rule();
4044

4145
public abstract CelPolicySource policySource();
@@ -57,6 +61,10 @@ public abstract static class Builder {
5761

5862
public abstract Builder setName(ValueString name);
5963

64+
public abstract Builder setDescription(ValueString description);
65+
66+
public abstract Builder setDisplayName(ValueString displayName);
67+
6068
public abstract Builder setRule(Rule rule);
6169

6270
public abstract Builder setPolicySource(CelPolicySource policySource);

policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ public CelPolicy parsePolicy(PolicyParserContext<Node> ctx, Node node) {
115115
case "name":
116116
policyBuilder.setName(ctx.newValueString(valueNode));
117117
break;
118+
case "description":
119+
policyBuilder.setDescription(ctx.newValueString(valueNode));
120+
break;
121+
case "display_name":
122+
policyBuilder.setDisplayName(ctx.newValueString(valueNode));
123+
break;
118124
case "rule":
119125
policyBuilder.setRule(parseRule(ctx, policyBuilder, valueNode));
120126
break;

policy/src/test/java/dev/cel/policy/CelPolicyYamlParserTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,39 @@ public void parser_setEmpty() throws Exception {
4949
assertThrows(CelPolicyValidationException.class, () -> POLICY_PARSER.parse("", ""));
5050
}
5151

52+
@Test
53+
public void parseYamlPolicy_withDescription_atPolicyLevel() throws Exception {
54+
String policySource =
55+
"name: 'policy_with_description'\n"
56+
+ "description: 'this is a description of the policy'\n"
57+
+ "rule:\n"
58+
+ " variables:\n"
59+
+ " - name: 'variable_with_description'\n"
60+
+ " description: 'this is a description of the variable'\n"
61+
+ " expression: 'true'";
62+
63+
CelPolicy policy = POLICY_PARSER.parse(policySource);
64+
65+
assertThat(policy.description())
66+
.hasValue(ValueString.of(5, "this is a description of the policy"));
67+
}
68+
69+
@Test
70+
public void parseYamlPolicy_withDisplayName_atPolicyLevel() throws Exception {
71+
String policySource =
72+
"name: 'policy_with_description'\n"
73+
+ "display_name: 'display name of the policy'\n"
74+
+ "rule:\n"
75+
+ " variables:\n"
76+
+ " - name: 'variable_with_description'\n"
77+
+ " description: 'this is a description of the variable'\n"
78+
+ " expression: 'true'";
79+
80+
CelPolicy policy = POLICY_PARSER.parse(policySource);
81+
82+
assertThat(policy.displayName()).hasValue(ValueString.of(5, "display name of the policy"));
83+
}
84+
5285
@Test
5386
public void parseYamlPolicy_withDescription() throws Exception {
5487
String policySource =

0 commit comments

Comments
 (0)