Skip to content
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: 4 additions & 4 deletions docs/docs/python-sdk/reference/templating.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ These filters are provided by the Infrahub SDK for artifact and file object cont
<!-- vale off -->
| Name | CORE | WORKER | LOCAL |
| ---- | ---- | ------ | ----- |
| `artifact_content` | ❌ | ✅ | |
| `file_object_content` | ❌ | ✅ | |
| `file_object_content_by_hfid` | ❌ | ✅ | |
| `file_object_content_by_id` | ❌ | ✅ | |
| `artifact_content` | ❌ | ✅ | |
| `file_object_content` | ❌ | ✅ | |
| `file_object_content_by_hfid` | ❌ | ✅ | |
| `file_object_content_by_id` | ❌ | ✅ | |
| `from_json` | ✅ | ✅ | ✅ |
| `from_yaml` | ✅ | ✅ | ✅ |
<!-- vale on -->
Expand Down
20 changes: 4 additions & 16 deletions infrahub_sdk/template/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,10 @@ def trusted(self) -> bool:


INFRAHUB_FILTERS = [
FilterDefinition(
name="artifact_content", allowed_contexts=ExecutionContext.WORKER | ExecutionContext.LOCAL, source="infrahub"
),
FilterDefinition(
name="file_object_content", allowed_contexts=ExecutionContext.WORKER | ExecutionContext.LOCAL, source="infrahub"
),
FilterDefinition(
name="file_object_content_by_hfid",
allowed_contexts=ExecutionContext.WORKER | ExecutionContext.LOCAL,
source="infrahub",
),
FilterDefinition(
name="file_object_content_by_id",
allowed_contexts=ExecutionContext.WORKER | ExecutionContext.LOCAL,
source="infrahub",
),
FilterDefinition(name="artifact_content", allowed_contexts=ExecutionContext.WORKER, source="infrahub"),
FilterDefinition(name="file_object_content", allowed_contexts=ExecutionContext.WORKER, source="infrahub"),
FilterDefinition(name="file_object_content_by_hfid", allowed_contexts=ExecutionContext.WORKER, source="infrahub"),
FilterDefinition(name="file_object_content_by_id", allowed_contexts=ExecutionContext.WORKER, source="infrahub"),
FilterDefinition(name="from_json", allowed_contexts=ExecutionContext.ALL, source="infrahub"),
FilterDefinition(name="from_yaml", allowed_contexts=ExecutionContext.ALL, source="infrahub"),
]
Expand Down
15 changes: 6 additions & 9 deletions tests/unit/sdk/test_infrahub_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ def test_not_trusted_when_local_only(self) -> None:
fd = FilterDefinition(name="safe", allowed_contexts=ExecutionContext.LOCAL, source="jinja2")
assert fd.trusted is False

def test_not_trusted_when_worker_and_local(self) -> None:
fd = FilterDefinition(
name="artifact_content",
allowed_contexts=ExecutionContext.WORKER | ExecutionContext.LOCAL,
source="infrahub",
)
def test_not_trusted_when_worker_only(self) -> None:
fd = FilterDefinition(name="artifact_content", allowed_contexts=ExecutionContext.WORKER, source="infrahub")
assert fd.trusted is False

def test_not_trusted_when_core_only(self) -> None:
Expand Down Expand Up @@ -114,10 +110,11 @@ def test_context_local_allows_local_only_filters(self) -> None:
jinja = Jinja2Template(template="{{ data | safe }}")
jinja.validate(context=ExecutionContext.LOCAL)

def test_context_local_allows_artifact_content(self) -> None:
"""LOCAL context allows artifact_content (WORKER | LOCAL)."""
def test_context_local_blocks_artifact_content(self) -> None:
"""LOCAL context blocks artifact_content (WORKER only) — these filters require a worker."""
jinja = Jinja2Template(template="{{ sid | artifact_content }}")
jinja.validate(context=ExecutionContext.LOCAL)
with pytest.raises(JinjaTemplateOperationViolationError):
jinja.validate(context=ExecutionContext.LOCAL)

@pytest.mark.parametrize("context", [ExecutionContext.CORE, ExecutionContext.WORKER])
def test_user_filters_always_allowed(self, context: ExecutionContext) -> None:
Expand Down
Loading