first commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
api(project(":main-contract-subjects"))
|
||||
api(project(":gateway-module-policy:policy-contract-subjects"))
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package net.bquarkz.ai.gateway.policy.api;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyEvaluationResult;
|
||||
|
||||
public interface PolicyEvaluator {
|
||||
PolicyEvaluationResult evaluate(ToolExecutionRequest request, GatewayContext context);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
api(project(":main-infrastructure"))
|
||||
api(project(":main-contract-subjects"))
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package net.bquarkz.ai.gateway.policy.contracts;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class PolicyConfig {
|
||||
private String apiVersion;
|
||||
private String kind;
|
||||
private Map<String, String> metadata;
|
||||
private Spec spec;
|
||||
|
||||
@Data
|
||||
public static class Spec {
|
||||
private PolicyDecision defaultDecision;
|
||||
private Map<String, Object> data;
|
||||
private List<Map<String, Object>> rules;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package net.bquarkz.ai.gateway.policy.contracts;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import java.util.List;
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
public class PolicyEvaluationResult {
|
||||
PolicyDecision decision;
|
||||
List<String> matchedRules;
|
||||
List<String> reasons;
|
||||
|
||||
public static PolicyEvaluationResult allow() {
|
||||
return PolicyEvaluationResult.builder()
|
||||
.decision(PolicyDecision.ALLOW)
|
||||
.matchedRules(List.of())
|
||||
.reasons(List.of())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static PolicyEvaluationResult deny(String rule, String reason) {
|
||||
return PolicyEvaluationResult.builder()
|
||||
.decision(PolicyDecision.DENY)
|
||||
.matchedRules(List.of(rule))
|
||||
.reasons(List.of(reason))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package net.bquarkz.ai.gateway.policy.contracts;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
public class PolicyRule {
|
||||
private String name;
|
||||
private String type;
|
||||
private String tool;
|
||||
private PolicyDecision decision;
|
||||
private String reason;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
implementation(project(":gateway-module-policy:policy-api"))
|
||||
implementation(project(":gateway-module-policy:policy-shared"))
|
||||
implementation(project(":gateway-module-policy:policy-model-and-data"))
|
||||
implementation(project(":main-contract-subjects"))
|
||||
implementation("org.springframework.boot:spring-boot-starter")
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyConfig;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.model.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class PolicyConfigParser {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<PolicyRule> parse(PolicyConfig config) {
|
||||
List<PolicyRule> rules = new ArrayList<>();
|
||||
Map<String, Object> data = config.getSpec().getData();
|
||||
|
||||
for (Map<String, Object> ruleMap : config.getSpec().getRules()) {
|
||||
String type = (String) ruleMap.get("type");
|
||||
String name = (String) ruleMap.get("name");
|
||||
String tool = (String) ruleMap.get("tool");
|
||||
PolicyDecision decision = ruleMap.containsKey("decision")
|
||||
? PolicyDecision.valueOf(((String) ruleMap.get("decision")).toUpperCase())
|
||||
: null;
|
||||
String reason = (String) ruleMap.get("reason");
|
||||
|
||||
PolicyRule rule = switch (type) {
|
||||
case "scope" -> ScopeRule.builder()
|
||||
.name(name).type(type).tool(tool).decision(decision).reason(reason)
|
||||
.requiredScope((String) ruleMap.get("required_scope"))
|
||||
.actions((List<String>) ruleMap.get("actions"))
|
||||
.build();
|
||||
case "environment" -> {
|
||||
Map<String, String> whenRaw = (Map<String, String>) ruleMap.get("when");
|
||||
Map<String, PolicyDecision> when = new java.util.LinkedHashMap<>();
|
||||
whenRaw.forEach((k, v) -> when.put(k, PolicyDecision.valueOf(v.toUpperCase())));
|
||||
yield EnvironmentRule.builder()
|
||||
.name(name).type(type).tool(tool).decision(decision).reason(reason)
|
||||
.when(when)
|
||||
.build();
|
||||
}
|
||||
case "argument_allowlist" -> {
|
||||
List<String> allowlist = resolveList(ruleMap.get("allowlist"), data);
|
||||
yield ArgumentAllowlistRule.builder()
|
||||
.name(name).type(type).tool(tool).decision(decision).reason(reason)
|
||||
.argument((String) ruleMap.get("argument"))
|
||||
.allowlist(allowlist)
|
||||
.build();
|
||||
}
|
||||
case "time_window" -> {
|
||||
Map<String, String> windowMap = (Map<String, String>) ruleMap.get("window");
|
||||
TimeWindowRule.TimeWindow window = new TimeWindowRule.TimeWindow();
|
||||
window.setStart(windowMap.get("start"));
|
||||
window.setEnd(windowMap.get("end"));
|
||||
window.setTimezone(windowMap.get("timezone"));
|
||||
yield TimeWindowRule.builder()
|
||||
.name(name).type(type).tool(tool).decision(decision).reason(reason)
|
||||
.window(window)
|
||||
.build();
|
||||
}
|
||||
case "rate_limit" -> RateLimitRule.builder()
|
||||
.name(name).type(type).tool(tool).decision(decision).reason(reason)
|
||||
.maxPerMinute((Integer) ruleMap.get("max_per_minute"))
|
||||
.build();
|
||||
case "block" -> BlockRule.builder()
|
||||
.name(name).type(type).tool(tool).decision(decision).reason(reason)
|
||||
.build();
|
||||
default -> throw new IllegalArgumentException("Unknown rule type: " + type);
|
||||
};
|
||||
|
||||
rules.add(rule);
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<String> resolveList(Object value, Map<String, Object> data) {
|
||||
if (value instanceof String strVal && strVal.startsWith("$data.")) {
|
||||
String key = strVal.substring("$data.".length());
|
||||
Object resolved = data.get(key);
|
||||
if (resolved instanceof List) {
|
||||
return (List<String>) resolved;
|
||||
}
|
||||
throw new IllegalArgumentException("$data." + key + " is not a list");
|
||||
}
|
||||
if (value instanceof List) {
|
||||
return (List<String>) value;
|
||||
}
|
||||
throw new IllegalArgumentException("Expected list or $data reference, got: " + value);
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.api.PolicyEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyConfig;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyEvaluationResult;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PolicyEvaluatorImpl implements PolicyEvaluator {
|
||||
private final Supplier<PolicyConfig> policyConfigSupplier;
|
||||
private final PolicyConfigParser configParser;
|
||||
private final List<RuleEvaluator> ruleEvaluators;
|
||||
|
||||
@Override
|
||||
public PolicyEvaluationResult evaluate(ToolExecutionRequest request, GatewayContext context) {
|
||||
PolicyConfig policyConfig = policyConfigSupplier.get();
|
||||
List<PolicyRule> loadedRules = configParser.parse(policyConfig);
|
||||
PolicyDecision defaultDecision = policyConfig.getSpec().getDefaultDecision();
|
||||
|
||||
List<String> denyRules = new ArrayList<>();
|
||||
List<String> denyReasons = new ArrayList<>();
|
||||
List<String> approvalRules = new ArrayList<>();
|
||||
List<String> approvalReasons = new ArrayList<>();
|
||||
List<String> allowRules = new ArrayList<>();
|
||||
|
||||
for (PolicyRule rule : loadedRules) {
|
||||
if (!matchesTool(rule.getTool(), request.tool())) {
|
||||
continue;
|
||||
}
|
||||
for (RuleEvaluator evaluator : ruleEvaluators) {
|
||||
if (evaluator.supports(rule)) {
|
||||
PolicyDecision decision = evaluator.evaluate(rule, request, context);
|
||||
if (decision != null) {
|
||||
switch (decision) {
|
||||
case DENY -> {
|
||||
denyRules.add(rule.getName());
|
||||
denyReasons.add(rule.getReason() != null ? rule.getReason() : rule.getName());
|
||||
}
|
||||
case REQUIRE_APPROVAL -> {
|
||||
approvalRules.add(rule.getName());
|
||||
approvalReasons.add(rule.getReason() != null ? rule.getReason() : rule.getName());
|
||||
}
|
||||
case ALLOW -> allowRules.add(rule.getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deny-overrides strategy
|
||||
if (!denyRules.isEmpty()) {
|
||||
return PolicyEvaluationResult.builder()
|
||||
.decision(PolicyDecision.DENY)
|
||||
.matchedRules(denyRules)
|
||||
.reasons(denyReasons)
|
||||
.build();
|
||||
}
|
||||
if (!approvalRules.isEmpty()) {
|
||||
return PolicyEvaluationResult.builder()
|
||||
.decision(PolicyDecision.REQUIRE_APPROVAL)
|
||||
.matchedRules(approvalRules)
|
||||
.reasons(approvalReasons)
|
||||
.build();
|
||||
}
|
||||
if (!allowRules.isEmpty()) {
|
||||
return PolicyEvaluationResult.builder()
|
||||
.decision(PolicyDecision.ALLOW)
|
||||
.matchedRules(allowRules)
|
||||
.reasons(List.of())
|
||||
.build();
|
||||
}
|
||||
|
||||
return PolicyEvaluationResult.builder()
|
||||
.decision(defaultDecision)
|
||||
.matchedRules(List.of())
|
||||
.reasons(List.of("No matching rules; default decision applied"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private boolean matchesTool(String pattern, String toolName) {
|
||||
if (pattern == null || pattern.equals("*")) {
|
||||
return true;
|
||||
}
|
||||
if (pattern.endsWith(".*")) {
|
||||
String prefix = pattern.substring(0, pattern.length() - 2);
|
||||
return toolName.startsWith(prefix + ".");
|
||||
}
|
||||
return pattern.equals(toolName);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain.evaluators;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.model.ArgumentAllowlistRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ArgumentAllowlistRuleEvaluator implements RuleEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean supports(PolicyRule rule) {
|
||||
return rule instanceof ArgumentAllowlistRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context) {
|
||||
ArgumentAllowlistRule allowlistRule = (ArgumentAllowlistRule) rule;
|
||||
if (request.arguments() == null) {
|
||||
return null;
|
||||
}
|
||||
Object value = request.arguments().get(allowlistRule.getArgument());
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String strValue = value.toString();
|
||||
boolean allowed = allowlistRule.getAllowlist().stream()
|
||||
.anyMatch(pattern -> matchesGlob(pattern, strValue));
|
||||
if (!allowed) {
|
||||
return PolicyDecision.DENY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean matchesGlob(String pattern, String value) {
|
||||
if (pattern.contains("*")) {
|
||||
String regex = pattern.replace(".", "\\.").replace("*", ".*");
|
||||
return value.matches(regex);
|
||||
}
|
||||
return pattern.equals(value);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain.evaluators;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.model.BlockRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BlockRuleEvaluator implements RuleEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean supports(PolicyRule rule) {
|
||||
return rule instanceof BlockRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context) {
|
||||
return PolicyDecision.DENY;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain.evaluators;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.model.EnvironmentRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class EnvironmentRuleEvaluator implements RuleEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean supports(PolicyRule rule) {
|
||||
return rule instanceof EnvironmentRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context) {
|
||||
EnvironmentRule envRule = (EnvironmentRule) rule;
|
||||
String environment = context.getContext().getEnvironment();
|
||||
return envRule.getWhen().get(environment);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain.evaluators;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.model.RateLimitRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RateLimitRuleEvaluator implements RuleEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean supports(PolicyRule rule) {
|
||||
return rule instanceof RateLimitRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context) {
|
||||
RateLimitRule rateLimitRule = (RateLimitRule) rule;
|
||||
if (context.getContext().getRate() != null
|
||||
&& context.getContext().getRate().getCurrent() > rateLimitRule.getMaxPerMinute()) {
|
||||
return PolicyDecision.DENY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain.evaluators;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.model.ScopeRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScopeRuleEvaluator implements RuleEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean supports(PolicyRule rule) {
|
||||
return rule instanceof ScopeRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context) {
|
||||
ScopeRule scopeRule = (ScopeRule) rule;
|
||||
boolean hasScope = context.getSubject().getScopes().contains(scopeRule.getRequiredScope());
|
||||
if (!hasScope) {
|
||||
return null;
|
||||
}
|
||||
if (scopeRule.getActions() != null && !scopeRule.getActions().isEmpty()) {
|
||||
if (!scopeRule.getActions().contains(request.action())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return scopeRule.getDecision();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package net.bquarkz.ai.gateway.policy.domain.evaluators;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import net.bquarkz.ai.gateway.policy.internal.RuleEvaluator;
|
||||
import net.bquarkz.ai.gateway.policy.model.TimeWindowRule;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@Component
|
||||
public class TimeWindowRuleEvaluator implements RuleEvaluator {
|
||||
|
||||
@Override
|
||||
public boolean supports(PolicyRule rule) {
|
||||
return rule instanceof TimeWindowRule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context) {
|
||||
TimeWindowRule timeRule = (TimeWindowRule) rule;
|
||||
TimeWindowRule.TimeWindow window = timeRule.getWindow();
|
||||
|
||||
LocalTime start = LocalTime.parse(window.getStart());
|
||||
LocalTime end = LocalTime.parse(window.getEnd());
|
||||
ZoneId zone = ZoneId.of(window.getTimezone());
|
||||
|
||||
ZonedDateTime now = context.getContext().getTimestamp().atZoneSameInstant(zone);
|
||||
LocalTime currentTime = now.toLocalTime();
|
||||
|
||||
boolean insideWindow;
|
||||
if (start.isBefore(end)) {
|
||||
insideWindow = !currentTime.isBefore(start) && currentTime.isBefore(end);
|
||||
} else {
|
||||
insideWindow = !currentTime.isBefore(start) || currentTime.isBefore(end);
|
||||
}
|
||||
|
||||
if (!insideWindow) {
|
||||
return PolicyDecision.DENY;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
api(project(":gateway-module-policy:policy-contract-subjects"))
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package net.bquarkz.ai.gateway.policy.model;
|
||||
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ArgumentAllowlistRule extends PolicyRule {
|
||||
private String argument;
|
||||
private List<String> allowlist;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package net.bquarkz.ai.gateway.policy.model;
|
||||
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BlockRule extends PolicyRule {
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package net.bquarkz.ai.gateway.policy.model;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class EnvironmentRule extends PolicyRule {
|
||||
private Map<String, PolicyDecision> when;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package net.bquarkz.ai.gateway.policy.model;
|
||||
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class RateLimitRule extends PolicyRule {
|
||||
private int maxPerMinute;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package net.bquarkz.ai.gateway.policy.model;
|
||||
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ScopeRule extends PolicyRule {
|
||||
private String requiredScope;
|
||||
private List<String> actions;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package net.bquarkz.ai.gateway.policy.model;
|
||||
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class TimeWindowRule extends PolicyRule {
|
||||
private TimeWindow window;
|
||||
|
||||
@Data
|
||||
public static class TimeWindow {
|
||||
private String start;
|
||||
private String end;
|
||||
private String timezone;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
plugins { id("java-library-conventions") }
|
||||
dependencies {
|
||||
api(project(":main-contract-subjects"))
|
||||
api(project(":gateway-module-policy:policy-contract-subjects"))
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package net.bquarkz.ai.gateway.policy.internal;
|
||||
|
||||
import net.bquarkz.ai.gateway.contracts.GatewayContext;
|
||||
import net.bquarkz.ai.gateway.contracts.PolicyDecision;
|
||||
import net.bquarkz.ai.gateway.contracts.ToolExecutionRequest;
|
||||
import net.bquarkz.ai.gateway.policy.contracts.PolicyRule;
|
||||
|
||||
public interface RuleEvaluator {
|
||||
boolean supports(PolicyRule rule);
|
||||
PolicyDecision evaluate(PolicyRule rule, ToolExecutionRequest request, GatewayContext context);
|
||||
}
|
||||
Reference in New Issue
Block a user