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
6 changes: 6 additions & 0 deletions 6 policy/src/main/java/dev/cel/policy/CelPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public abstract static class Variable {

public abstract Optional<ValueString> description();

public abstract Optional<ValueString> displayName();

/** Builder for {@link Variable}. */
@AutoValue.Builder
public abstract static class Builder implements RequiredFieldsChecker {
Expand All @@ -244,12 +246,16 @@ public abstract static class Builder implements RequiredFieldsChecker {

abstract Optional<ValueString> description();

abstract Optional<ValueString> displayName();

public abstract Builder setName(ValueString name);

public abstract Builder setExpression(ValueString expression);

public abstract Builder setDescription(ValueString description);

public abstract Builder setDisplayName(ValueString displayName);

@Override
public ImmutableList<RequiredField> requiredFields() {
return ImmutableList.of(
Expand Down
3 changes: 3 additions & 0 deletions 3 policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ public CelPolicy.Variable parseVariable(
case "description":
builder.setDescription(ctx.newValueString(valueNode));
break;
case "display_name":
builder.setDisplayName(ctx.newValueString(valueNode));
break;
default:
tagVisitor.visitVariableTag(ctx, keyId, keyName, valueNode, policyBuilder, builder);
break;
Expand Down
16 changes: 16 additions & 0 deletions 16 policy/src/test/java/dev/cel/policy/CelPolicyYamlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ public void parseYamlPolicy_withDescription() throws Exception {
.hasValue(ValueString.of(10, "this is a description of the variable"));
}

@Test
public void parseYamlPolicy_withDisplayName() throws Exception {
String policySource =
"rule:\n"
+ " variables:\n"
+ " - name: 'variable_with_description'\n"
+ " display_name: 'Display Name'\n"
+ " expression: 'true'";

CelPolicy policy = POLICY_PARSER.parse(policySource);

assertThat(policy.rule().variables()).hasSize(1);
assertThat(Iterables.getOnlyElement(policy.rule().variables()).displayName())
.hasValue(ValueString.of(10, "Display Name"));
}

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