Skip to content

Commit 8718453

Browse files
evanbijoy251claude
andcommitted
feat: add Rego wire models and feature flag to core
Adds HookBundle and AllPoliciesResponse Pydantic wire models for the /all-policies/{tenant_id} endpoint alongside PolicyResponse. Adds REGO_FEATURE_FLAG / is_rego_enabled() mirroring the existing GOVERNANCE_FEATURE_FLAG / is_governance_enabled() pattern. Bumps uipath-core to 0.5.31. Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 22f5687 commit 8718453

4 files changed

Lines changed: 79 additions & 1 deletion

File tree

packages/uipath-core/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-core"
3-
version = "0.5.30"
3+
version = "0.5.31"
44
description = "UiPath Core abstractions"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-core/src/uipath/core/governance/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
from .config import (
1111
GOVERNANCE_FEATURE_FLAG,
12+
REGO_FEATURE_FLAG,
1213
is_governance_enabled,
14+
is_rego_enabled,
1315
)
1416
from .exceptions import (
1517
GovernanceBlockException,
@@ -19,10 +21,12 @@
1921
)
2022
from .models import Action, AuditRecord, EnforcementMode, LifecycleHook, RuleEvaluation
2123
from .providers import (
24+
AllPoliciesResponse,
2225
FiredRule,
2326
GovernanceCompensationProvider,
2427
GovernancePolicyProvider,
2528
GovernRequest,
29+
HookBundle,
2630
PolicyContext,
2731
PolicyResponse,
2832
)
@@ -36,17 +40,21 @@
3640
"RuleEvaluation",
3741
# Config
3842
"GOVERNANCE_FEATURE_FLAG",
43+
"REGO_FEATURE_FLAG",
3944
"is_governance_enabled",
45+
"is_rego_enabled",
4046
# Exceptions
4147
"GovernanceBlockException",
4248
"GovernanceConfigError",
4349
"GovernanceViolation",
4450
"Severity",
4551
# Provider protocols + wire models
52+
"AllPoliciesResponse",
4653
"FiredRule",
4754
"GovernanceCompensationProvider",
4855
"GovernancePolicyProvider",
4956
"GovernRequest",
57+
"HookBundle",
5058
"PolicyContext",
5159
"PolicyResponse",
5260
]

packages/uipath-core/src/uipath/core/governance/config.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# same toggle.
1919
GOVERNANCE_FEATURE_FLAG = "EnablePythonGovernanceChecker"
2020

21+
# Feature flag name controlling whether the Rego/WASM evaluator runs.
22+
# Independent of the native evaluator flag — both can be enabled simultaneously.
23+
REGO_FEATURE_FLAG = "EnablePythonGovernanceRegoEvaluator"
24+
2125

2226
def is_governance_enabled() -> bool:
2327
"""Return whether the ``EnablePythonGovernanceChecker`` flag is enabled.
@@ -35,3 +39,21 @@ def is_governance_enabled() -> bool:
3539
2. Default ``False`` (governance disabled).
3640
"""
3741
return FeatureFlags.is_flag_enabled(GOVERNANCE_FEATURE_FLAG, default=False)
42+
43+
44+
def is_rego_enabled() -> bool:
45+
"""Return whether the ``EnablePythonGovernanceRegoEvaluator`` flag is enabled.
46+
47+
Rego evaluation is **off by default** — the flag must be explicitly
48+
set to ``true`` (programmatically via the ``FeatureFlags`` registry,
49+
or via the ``UIPATH_FEATURE_EnablePythonGovernanceRegoEvaluator`` env
50+
var) for this function to return ``True``.
51+
52+
Resolution order:
53+
54+
1. :meth:`uipath.core.feature_flags.FeatureFlagsManager.is_flag_enabled` -
55+
the in-process programmatic registry (typically populated from
56+
gitops) and its own ``UIPATH_FEATURE_<name>`` env-var fallback.
57+
2. Default ``False`` (Rego evaluation disabled).
58+
"""
59+
return FeatureFlags.is_flag_enabled(REGO_FEATURE_FLAG, default=False)

packages/uipath-core/src/uipath/core/governance/providers.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,54 @@ def _coerce_mode(cls, value: object) -> EnforcementMode | None:
7878
return None
7979

8080

81+
class HookBundle(BaseModel):
82+
"""Metadata for one hook's WASM policy bundle.
83+
84+
Returned as an element of :class:`AllPoliciesResponse` from the
85+
``/all-policies/{tenant_id}`` endpoint.
86+
87+
Attributes:
88+
hook_type: Lifecycle hook identifier (e.g. ``"before_agent"``).
89+
bundle_url: Pre-signed URL for the WASM ``.tar.gz`` bundle.
90+
No platform auth required — the URL carries its own credentials.
91+
etag: Server-assigned ETag for the bundle. Used by the Rego loader
92+
to skip unchanged bundles on background refresh. ``None`` when
93+
the server does not provide one.
94+
"""
95+
96+
model_config = ConfigDict(populate_by_name=True, extra="ignore")
97+
98+
hook_type: str = Field(alias="hookType")
99+
bundle_url: str = Field(alias="bundleUrl")
100+
etag: str | None = Field(default=None)
101+
102+
103+
class AllPoliciesResponse(BaseModel):
104+
"""Parsed response from the ``/all-policies/{tenant_id}`` endpoint.
105+
106+
Wire envelope::
107+
108+
{
109+
"hookBundles": [
110+
{
111+
"hookType": "before_agent",
112+
"bundleUrl": "https://url.example.com/...",
113+
"etag": "abc123"
114+
}
115+
]
116+
}
117+
118+
Attributes:
119+
hook_bundles: One entry per lifecycle hook that has a compiled
120+
WASM bundle. Empty when no policies are configured for the
121+
tenant.
122+
"""
123+
124+
model_config = ConfigDict(populate_by_name=True, extra="ignore")
125+
126+
hook_bundles: list[HookBundle] = Field(default_factory=list, alias="hookBundles")
127+
128+
81129
class FiredRule(BaseModel):
82130
"""Per-rule metadata carried in the ``/runtime/govern`` payload.
83131

0 commit comments

Comments
 (0)