### Quick Start: Apply and Get Secret Resource (YAML & Bash) Source: https://github.com/pragmatiks/providers/blob/main/README.md Demonstrates how to define a Google Cloud secret using a YAML configuration file and then apply it using the Pragma CLI. It also shows how to retrieve the applied secret resource. ```yaml # secret.yaml provider: gcp resource: secret name: db-password config: secret_id: db-password data: "super-secret-value" ``` ```bash pragma resources apply --pending secret.yaml pragma resources get gcp/secret db-password ``` -------------------------------- ### Development Tasks: Install, Test, Check (Bash) Source: https://github.com/pragmatiks/providers/blob/main/README.md Lists the available `task` commands for development, including installing dependencies, running all tests, performing code checks, and running provider-specific tests and checks. ```bash # Install dependencies task install # Run all tests task test # Run all checks task check # Provider-specific tasks task gcp:test task gcp:check ``` -------------------------------- ### Install and Run Provider Tests (Bash) Source: https://github.com/pragmatiks/providers/blob/main/packages/gcp/README.md Commands to install development dependencies and run tests for the GCP provider using uv and pytest. Ensure dependencies are synchronized before executing tests. ```bash # Install dependencies uv sync --dev # Run tests uv run pytest tests/ ``` -------------------------------- ### Install Pragmatiks GCP Provider (Bash) Source: https://github.com/pragmatiks/providers/blob/main/README.md Shows the command to install the Pragmatiks GCP provider package using pip, which is necessary for managing Google Cloud Platform resources. ```bash pip install pragmatiks-gcp-provider ``` -------------------------------- ### Development Workflow with Task Runner (Bash) Source: https://context7.com/pragmatiks/providers/llms.txt Details the development workflow using the task runner for common operations like installing dependencies, running tests, and performing code quality checks. It also covers provider-specific tasks and commands for initializing, syncing, and deploying providers. ```bash # Install all dependencies (workspace-wide) task install # Run all tests across providers task test # Run code quality checks (ruff linting/formatting) task check # Provider-specific operations task gcp:test # Run GCP provider tests only task gcp:check # Check GCP provider code # Initialize a new provider project pragma provider init mycompany cd mycompany-provider # Deploy provider to Pragmatiks platform pragma provider sync # Sync provider definition pragma provider push --deploy # Deploy to platform ``` -------------------------------- ### Manage Resources with Pragmatiks CLI (Bash) Source: https://context7.com/pragmatiks/providers/llms.txt Illustrates how to use the Pragmatiks CLI to manage provider resources. It covers applying resources defined in YAML files, retrieving their status and outputs, and provides an example of the expected output format. This CLI streamlines the deployment and inspection of infrastructure. ```bash # Apply a secret resource (creates or updates) pragma resources apply --pending secret.yaml # Get resource status and outputs pragma resources get gcp/secret db-password # Example output: # Name: db-password # Provider: gcp # Resource: secret # Status: ready # Outputs: # resource_name: projects/my-project/secrets/db-password # version_name: projects/my-project/secrets/db-password/versions/1 # version_id: 1 ``` -------------------------------- ### Test Resource Lifecycle Methods with ProviderHarness (Python) Source: https://github.com/pragmatiks/providers/blob/main/packages/gcp/README.md Example of using ProviderHarness to test the 'create' lifecycle method of a resource. It initializes the harness, invokes the create method with specified resource and configuration, and asserts the success and presence of output details. ```python from pragma_sdk.provider import ProviderHarness from gcp_provider import ExampleResource, ExampleConfig async def test_create(): harness = ProviderHarness() result = await harness.invoke_create( ExampleResource, name="test", config=ExampleConfig(name="my-resource", size=10), ) assert result.success assert result.outputs.url is not None ``` -------------------------------- ### Initialize Custom Provider Project (Bash) Source: https://github.com/pragmatiks/providers/blob/main/README.md Provides the command to initialize a new custom provider project using the Pragma CLI, setting up the basic structure for a new provider. ```bash # Initialize a provider project pragma provider init mycompany ``` -------------------------------- ### Develop and Deploy Custom Provider (Bash) Source: https://github.com/pragmatiks/providers/blob/main/README.md Outlines the steps for developing a custom provider, including navigating to the provider's directory, implementing resources, and deploying it to the Pragma platform using CLI commands. ```bash # Implement your resources cd mycompany-provider # Edit src/mycompany_provider/resources/ # Deploy to the platform pragma provider sync pragma provider push --deploy ``` -------------------------------- ### Build Custom Providers with Pragma SDK (Python) Source: https://context7.com/pragmatiks/providers/llms.txt Shows how to create custom cloud providers using the Pragma SDK. This involves defining a `Provider` namespace, creating typed `Config` and `Outputs` classes, and implementing resource lifecycle methods (`on_create`, `on_update`, `on_delete`). It demonstrates dependency management and resource updates. ```python from typing import ClassVar from pragma_sdk import Provider, Resource, Config, Outputs # Initialize provider namespace mycloud = Provider(name="mycloud") # Define typed configuration class DatabaseConfig(Config): """Configuration for a managed database.""" name: str engine: str # "postgres" | "mysql" size_gb: int = 10 credentials: dict # Cloud credentials # Define typed outputs class DatabaseOutputs(Outputs): """Outputs from database creation.""" connection_string: str host: str port: int # Implement resource with lifecycle methods @mycloud.resource("database") class Database(Resource[DatabaseConfig, DatabaseOutputs]): provider: ClassVar[str] = "mycloud" resource: ClassVar[str] = "database" async def on_create(self) -> DatabaseOutputs: # Create database in cloud provider # ... API calls ... return DatabaseOutputs( connection_string=f"postgresql://user@db.example.com:5432/{self.config.name}", host="db.example.com", port=5432 ) async def on_update(self, previous_config: DatabaseConfig) -> DatabaseOutputs: # Handle updates (e.g., resize) if previous_config.name != self.config.name: raise ValueError("Cannot rename database; delete and recreate") # ... update logic ... return self.outputs async def on_delete(self) -> None: # Clean up cloud resources # ... deletion API calls ... pass ``` -------------------------------- ### Testing Resource Lifecycle with ProviderHarness (Python) Source: https://context7.com/pragmatiks/providers/llms.txt Demonstrates using ProviderHarness to test resource lifecycle methods like create, update, and delete in isolation. It verifies success status and output fields, handling scenarios such as secret creation, data updates creating new versions, and idempotent deletion. ```python import pytest from pragma_sdk.provider import ProviderHarness from gcp_provider import Secret, SecretConfig, SecretOutputs @pytest.fixture def harness() -> ProviderHarness: return ProviderHarness() async def test_create_secret(harness: ProviderHarness, mock_gcp_client): """Test secret creation lifecycle.""" config = SecretConfig( project_id="test-project", secret_id="my-secret", data="secret-value", credentials={"type": "service_account", ...} ) result = await harness.invoke_create( Secret, name="my-secret", config=config ) assert result.success assert result.outputs is not None assert result.outputs.resource_name == "projects/test-project/secrets/my-secret" assert result.outputs.version_id == "1" async def test_update_creates_new_version(harness: ProviderHarness, mock_gcp_client): """Test that data changes create new secret versions.""" previous = SecretConfig(project_id="proj", secret_id="sec", data="old", credentials={...}) current = SecretConfig(project_id="proj", secret_id="sec", data="new", credentials={...}) existing_outputs = SecretOutputs( resource_name="projects/proj/secrets/sec", version_name="projects/proj/secrets/sec/versions/1", version_id="1" ) result = await harness.invoke_update( Secret, name="test", config=current, previous_config=previous, current_outputs=existing_outputs ) assert result.success assert result.outputs.version_id == "2" # New version created async def test_delete_is_idempotent(harness: ProviderHarness, mock_gcp_client): """Test delete succeeds even if resource already gone.""" from google.api_core.exceptions import NotFound mock_gcp_client.delete_secret.side_effect = NotFound("already deleted") config = SecretConfig(project_id="proj", secret_id="sec", data="val", credentials={...}) result = await harness.invoke_delete(Secret, name="test", config=config) assert result.success # Idempotent - no error on NotFound ``` -------------------------------- ### Define GCP Resource with Pragmatiks SDK (Python) Source: https://github.com/pragmatiks/providers/blob/main/packages/gcp/README.md Demonstrates how to define a custom GCP resource using the Pragmatiks SDK. This involves creating configuration, output models, and implementing resource lifecycle methods (create, update, delete). It specifies the provider and resource names. ```python from pragma_sdk import Resource, Config, Outputs, Field from typing import ClassVar class MyResourceConfig(Config): name: Field[str] size: Field[int] = 10 class MyResourceOutputs(Outputs): url: str created_at: str class MyResource(Resource[MyResourceConfig, MyResourceOutputs]): provider: ClassVar[str] = "gcp" resource: ClassVar[str] = "my_resource" async def on_create(self) -> MyResourceOutputs: # Create the resource return MyResourceOutputs(url="...", created_at="...") async def on_update(self, previous_config: MyResourceConfig) -> MyResourceOutputs: # Update the resource return self.outputs async def on_delete(self) -> None: # Delete the resource pass ``` -------------------------------- ### Push GCP Provider to Pragmatiks Platform (Bash) Source: https://github.com/pragmatiks/providers/blob/main/packages/gcp/README.md Command to deploy the developed GCP provider to the Pragmatiks platform. The platform manages the runtime infrastructure, simplifying the deployment process. ```bash pragma provider push ``` -------------------------------- ### Referencing Resource Outputs with FieldReference (Python & YAML) Source: https://context7.com/pragmatiks/providers/llms.txt Illustrates how resources can reference outputs from other resources using FieldReference. This is used for secure credential passing and managing dependencies between resources, shown in both Python and YAML configurations. ```python from pragma_sdk import FieldReference # Python: Reference a secret's data field in app configuration app_config = AppConfig( database_password=FieldReference( provider="gcp", resource="secret", name="db-password", field="data" ) ) ``` ```yaml # YAML: Declare dependencies between resources """ # app-service.yaml provider: myapp resource: service name: api config: db_password: $ref: provider: gcp resource: secret name: db-password field: data db_host: $ref: provider: gcp resource: database name: main-db field: host """ ``` -------------------------------- ### Reference Provider Secrets in YAML (YAML) Source: https://github.com/pragmatiks/providers/blob/main/README.md Demonstrates how to reference a secret resource using YAML syntax with a `$ref` key, specifying the provider, resource, name, and field to retrieve. ```yaml provider: myapp resource: service name: api config: db_password: $ref: provider: gcp resource: secret name: db-password field: data ``` -------------------------------- ### Update Project Template with Copier (Bash) Source: https://github.com/pragmatiks/providers/blob/main/packages/gcp/README.md Command to update the current project to the latest template version using Copier. This is useful for incorporating new features or fixes from the project template. ```bash copier update ``` -------------------------------- ### Provider Architecture: GCP Secret Resource (Python) Source: https://github.com/pragmatiks/providers/blob/main/README.md Shows the Python code structure for defining a custom resource, specifically a 'secret' resource for the 'gcp' provider. It includes the Provider, Resource, Config, and Outputs classes, along with lifecycle methods. ```python from pragma_sdk import Provider, Resource, Config, Outputs gcp = Provider(name="gcp") class SecretConfig(Config): secret_id: str data: str class SecretOutputs(Outputs): resource_name: str version_id: str @gcp.resource("secret") class Secret(Resource[SecretConfig, SecretOutputs]): async def on_create(self) -> SecretOutputs: # Create secret in GCP Secret Manager ... async def on_update(self, previous: SecretConfig) -> SecretOutputs: # Update secret version ... async def on_delete(self) -> None: # Delete secret ... ``` -------------------------------- ### Reference Provider Secrets in Python (Python) Source: https://github.com/pragmatiks/providers/blob/main/README.md Illustrates how to use the `FieldReference` from `pragma_sdk` in Python to reference a secret's data managed by a provider, such as the GCP secret provider. ```python from pragma_sdk import FieldReference config = AppConfig( database_password=FieldReference( provider="gcp", resource="secret", name="db-password", field="data" ) ) ``` -------------------------------- ### Manage GCP Secrets with Pragma SDK (Python) Source: https://context7.com/pragmatiks/providers/llms.txt Demonstrates how to manage secrets in Google Cloud Platform Secret Manager using the Pragma SDK. It shows both YAML and programmatic Python approaches for defining secret resources, including configuration and expected outputs. This resource supports custom service account credentials. ```python from pragma_sdk import Provider from gcp_provider import Secret, SecretConfig, SecretOutputs # Define a secret resource via YAML configuration # secret.yaml """ provider: gcp resource: secret name: db-password config: project_id: my-gcp-project secret_id: db-password data: "super-secret-value" credentials: $ref: provider: pragma resource: secret name: gcp-service-account field: data """ # Or programmatically with Python config = SecretConfig( project_id="my-gcp-project", secret_id="database-credentials", data="super-secret-password-123", credentials={ "type": "service_account", "project_id": "my-gcp-project", "private_key_id": "key123", "private_key": "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----\n", "client_email": "my-sa@my-gcp-project.iam.gserviceaccount.com", "client_id": "123456789", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token" } ) # Outputs after creation: # SecretOutputs( # resource_name="projects/my-gcp-project/secrets/database-credentials", # version_name="projects/my-gcp-project/secrets/database-credentials/versions/1", # version_id="1" # ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.