Object and File Store
Relevant source files
The following files were used as context for generating this wiki page:
The Object and File Store provides an abstraction for interacting with infrastructure artifacts and file data within Infrahub. It manages the retrieval, storage, and classification of artifacts, schemas, and collections. The system facilitates programmatic access to data Native Python objects, supporting both asynchronous and synchronous operations as required by the Infrahub Python SDK Constitution.
Sources: AGENTS.md, dev/constitution.md:20-22, dev/specs/infp-504-artifact-composition/tasks.md
Core Architecture and Data Flow
The architecture centralizes API interactions for data transformation and domain rules. The Object Store specifically handles artifact retrieval from Infrahub's internal storage and marketplace data via defined REST endpoints.
Request Flow for Artifact Retrieval
The following diagram illustrates the sequence for retrieving artifact content through the SDK.
Component Overview
Object Store Implementation
The ObjectStore manages interaction with the file-based storage backend of Infrahub. It includes methods for fetching artifacts by their storage identifiers.
| Component | Description |
|---|---|
artifact_content | An async filter method that retrieves rendered sub-artifact content using a storage ID. |
file_object_content | Retrieves file object content while performing binary content rejection to ensure text-based processing. |
get_file_by_storage_id | An internal method targeting the GET /api/files/by-storage-id/{storage_id} endpoint. |
Sources: dev/specs/infp-504-artifact-composition/tasks.md:46-60
Content Type Validation
The system validates incoming content types to prevent the processing of binary data where text or structured formats (JSON/YAML) are expected.
| Allowed Content-Types | Validation Logic |
|---|---|
text/* | Permitted for all artifact and file operations. |
application/json | Permitted; can be chained with from_json filters. |
application/yaml | Permitted; can be chained with from_yaml filters. |
| Others | Rejected with a descriptive error. |
Sources: dev/specs/infp-504-artifact-composition/tasks.md:57-58
Marketplace Data Management
The marketplace component manages external schemas and collections. It includes auto-detection logic to distinguish between different types of infrastructure identifiers.
The marketplace CLI allows users to download these artifacts with the following command structure:
infrahubctl marketplace get <namespace>/<name>.
Sources: infrahub_sdk/ctl/marketplace.py, dev/specs/001-marketplace-api-update/tasks.md:45-55
Template Composition and Security
The SDK uses Jinja2 filters to compose artifact content within templates. Access to these storage operations is governed by an ExecutionContext.
- CORE Context: Blocks storage filters to maintain schema integrity at load time.
- WORKER Context: Allows artifact and file retrieval for rendering during execution.
- LOCAL Context: Permitted for local development and testing.
Sources: dev/specs/infp-504-artifact-composition/tasks.md:38-44, dev/specs/infp-504-artifact-composition/tasks.md:85-88
Security Logic
A JinjaFilterError is raised if a storage operation is attempted without a valid InfrahubClient or if the security context prohibits the action.
Sources: dev/specs/infp-504-artifact-composition/tasks.md:36-37
Summary
The Object and File Store system provides a unified interface for infrastructure data lifecycle management. By enforcing content-type validation and context-aware security gates, it ensures that developers can safely retrieve and compose artifacts into native Python objects and rendered templates across the Infrahub ecosystem.