Skip to content

Internal changes #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
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
Internal changes
PiperOrigin-RevId: 784671936
  • Loading branch information
l46kok authored and copybara-github committed Jul 18, 2025
commit 57f8218a7f70fd8fe4e0154851225bc223c47ede
2 changes: 2 additions & 0 deletions policy/src/main/java/dev/cel/policy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ java_library(
],
deps = [
":policy",
"//:auto_value",
"//common/formats:parser_context",
"//policy:source",
],
)

Expand Down
14 changes: 10 additions & 4 deletions policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ private CelPolicy parseYaml() throws CelPolicyValidationException {
}

@Override
public CelPolicy parsePolicy(PolicyParserContext<Node> ctx, Node node) {
CelPolicy.Builder policyBuilder = CelPolicy.newBuilder();
public NewPolicyMetadata newPolicy(Node node) {
long id = ctx.collectMetadata(node);
if (!assertYamlType(ctx, id, node, YamlNodeType.MAP)) {
return policyBuilder.setPolicySource(policySource).build();
return NewPolicyMetadata.create(policySource, id);
}

@Override
public CelPolicy parsePolicy(PolicyParserContext<Node> ctx, Node node) {
NewPolicyMetadata newPolicyMetadata = newPolicy(node);
CelPolicy.Builder policyBuilder = newPolicyMetadata.policyBuilder();
if (!assertYamlType(ctx, newPolicyMetadata.id(), node, YamlNodeType.MAP)) {
return policyBuilder.build();
}

MappingNode rootNode = (MappingNode) node;
Expand Down
20 changes: 20 additions & 0 deletions policy/src/main/java/dev/cel/policy/PolicyParserContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package dev.cel.policy;

import com.google.auto.value.AutoValue;
import dev.cel.common.formats.ParserContext;
import dev.cel.policy.CelPolicy.Match;
import dev.cel.policy.CelPolicy.Rule;
Expand All @@ -24,6 +25,25 @@
* for {@link CelPolicy}.
*/
public interface PolicyParserContext<T> extends ParserContext<T> {

/**
* Wrapper for a new instance of {@link CelPolicy.Builder} and the associated node ID. The
* CelPolicy builder also has a policy source set by the parser.
*/
@AutoValue
abstract class NewPolicyMetadata {
public abstract CelPolicy.Builder policyBuilder();

public abstract long id();

static NewPolicyMetadata create(CelPolicySource source, long id) {
return new AutoValue_PolicyParserContext_NewPolicyMetadata(
CelPolicy.newBuilder().setPolicySource(source), id);
}
}

NewPolicyMetadata newPolicy(T node);

CelPolicy parsePolicy(PolicyParserContext<T> ctx, T node);

Rule parseRule(PolicyParserContext<T> ctx, CelPolicy.Builder policyBuilder, T node);
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy