Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 8 policy/src/main/java/dev/cel/policy/CelPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public abstract class CelPolicy {

public abstract ValueString name();

public abstract Optional<ValueString> description();

public abstract Optional<ValueString> displayName();

public abstract Rule rule();

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

public abstract Builder setName(ValueString name);

public abstract Builder setDescription(ValueString description);

public abstract Builder setDisplayName(ValueString displayName);

public abstract Builder setRule(Rule rule);

public abstract Builder setPolicySource(CelPolicySource policySource);
Expand Down
6 changes: 6 additions & 0 deletions 6 policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public CelPolicy parsePolicy(PolicyParserContext<Node> ctx, Node node) {
case "name":
policyBuilder.setName(ctx.newValueString(valueNode));
break;
case "description":
policyBuilder.setDescription(ctx.newValueString(valueNode));
break;
case "display_name":
policyBuilder.setDisplayName(ctx.newValueString(valueNode));
break;
case "rule":
policyBuilder.setRule(parseRule(ctx, policyBuilder, valueNode));
break;
Expand Down
33 changes: 33 additions & 0 deletions 33 policy/src/test/java/dev/cel/policy/CelPolicyYamlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,39 @@ public void parser_setEmpty() throws Exception {
assertThrows(CelPolicyValidationException.class, () -> POLICY_PARSER.parse("", ""));
}

@Test
public void parseYamlPolicy_withDescription_atPolicyLevel() throws Exception {
String policySource =
"name: 'policy_with_description'\n"
+ "description: 'this is a description of the policy'\n"
+ "rule:\n"
+ " variables:\n"
+ " - name: 'variable_with_description'\n"
+ " description: 'this is a description of the variable'\n"
+ " expression: 'true'";

CelPolicy policy = POLICY_PARSER.parse(policySource);

assertThat(policy.description())
.hasValue(ValueString.of(5, "this is a description of the policy"));
}

@Test
public void parseYamlPolicy_withDisplayName_atPolicyLevel() throws Exception {
String policySource =
"name: 'policy_with_description'\n"
+ "display_name: 'display name of the policy'\n"
+ "rule:\n"
+ " variables:\n"
+ " - name: 'variable_with_description'\n"
+ " description: 'this is a description of the variable'\n"
+ " expression: 'true'";

CelPolicy policy = POLICY_PARSER.parse(policySource);

assertThat(policy.displayName()).hasValue(ValueString.of(5, "display name of the policy"));
}

@Test
public void parseYamlPolicy_withDescription() throws Exception {
String policySource =
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.