### Install GCP Provider using pip Source: https://github.com/pragmatiks/pragma-providers/blob/main/packages/gcp/README.md Shows the command to install the GCP provider for Pragmatiks using pip. This is a prerequisite for using the provider in your Python environment. ```bash pip install pragmatiks-gcp-provider ``` -------------------------------- ### Initialize and Deploy Custom Pragma Provider Source: https://github.com/pragmatiks/pragma-providers/blob/main/README.md Guides through the process of initializing a new custom provider project using the Pragma CLI, implementing resources within the project, and subsequently deploying the provider to the platform. ```bash # Initialize a provider project pragma provider init mycompany # 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/pragma-providers/llms.txt Guides on creating custom providers by extending the SDK's base classes (`Provider`, `Resource`, `Config`, `Outputs`) and registering them with a provider namespace. Includes implementation of lifecycle methods and defining resource schemas. ```python from pragma_sdk import Provider, Resource, Config, Outputs # Create provider namespace gcp = Provider(name="gcp") # Define configuration schema class SecretConfig(Config): project_id: str secret_id: str data: str credentials: dict | str # Define output schema class SecretOutputs(Outputs): resource_name: str version_name: str version_id: str # Implement resource with lifecycle methods @gcp.resource("secret") class Secret(Resource[SecretConfig, SecretOutputs]): async def on_create(self) -> SecretOutputs: # Create secret in GCP Secret Manager client = self._get_client() secret = await client.create_secret(...) version = await client.add_secret_version(...) return SecretOutputs( resource_name=secret.name, version_name=version.name, version_id=version.name.split("/")[-1], ) async def on_update(self, previous_config: SecretConfig) -> SecretOutputs: # Validate immutable fields if previous_config.project_id != self.config.project_id: raise ValueError("Cannot change project_id") # Add new version if data changed ... async def on_delete(self) -> None: # Delete secret (idempotent) try: await client.delete_secret(name=self._secret_path()) except NotFound: pass ``` -------------------------------- ### Run Tests for GCP Provider using pytest Source: https://github.com/pragmatiks/pragma-providers/blob/main/packages/gcp/README.md Provides the command to execute tests for the GCP provider using pytest. It assumes dependencies have been installed via `uv sync --dev`. ```bash # Install dependencies uv sync --dev # Run tests uv run pytest tests/ ``` -------------------------------- ### Apply and Get GCP Secret using Pragma CLI Source: https://github.com/pragmatiks/pragma-providers/blob/main/README.md Demonstrates how to apply a secret resource configuration using a YAML file and then retrieve the applied secret using the Pragma CLI. This involves defining the provider, resource type, and configuration details. ```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 ``` -------------------------------- ### Define GCP Secret Resources in YAML Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Provides an example of how to declaratively define a GCP Secret Manager secret resource using YAML. It specifies the provider, resource type, name, configuration including credentials, and demonstrates how to reference external data using `$ref`. ```yaml # 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 ``` -------------------------------- ### Pragma Provider Development Tasks Source: https://github.com/pragmatiks/pragma-providers/blob/main/README.md Lists common development tasks for a Pragma provider project, including installing dependencies, running tests, and executing code checks. It also highlights provider-specific tasks for targeted development and testing. ```bash # Install dependencies task install # Run all tests task test # Run all checks task check # Provider-specific tasks task gcp:test task gcp:check ``` -------------------------------- ### Define GCP Provider with Secret Resource Source: https://github.com/pragmatiks/pragma-providers/blob/main/README.md Provides a Python code example demonstrating how to define a custom Pragma provider for Google Cloud Platform (GCP). It includes the structure for a 'secret' resource with its configuration, outputs, and lifecycle methods (`on_create`, `on_update`, `on_delete`). ```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 ... ``` -------------------------------- ### Manage Custom Providers with Pragma CLI (Bash) Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Provides bash commands for managing custom Pragma providers, including initialization, synchronization, and deployment. This workflow allows for the development and pushing of custom provider resources. ```bash # Initialize and deploy custom provider pragma provider init mycompany cd mycompany-provider # Implement resources in src/mycompany_provider/resources/ pragma provider sync pragma provider push --deploy ``` -------------------------------- ### Unit Test Provider Resources with ProviderHarness (Python) Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Illustrates how to use ProviderHarness for unit testing resource lifecycle methods, including create, update, and delete operations. It utilizes mocked GCP clients for isolated testing of provider logic. ```python import pytest from unittest.mock import MagicMock from pragma_sdk.provider import ProviderHarness from gcp_provider import Secret, SecretConfig, SecretOutputs @pytest.fixture def harness() -> ProviderHarness: return ProviderHarness() @pytest.fixture def mock_secretmanager_client(mocker) -> MagicMock: mock_client = MagicMock() mock_secret = MagicMock() mock_secret.name = "projects/test-project/secrets/test-secret" mock_client.create_secret = mocker.AsyncMock(return_value=mock_secret) mock_version = MagicMock() mock_version.name = "projects/test-project/secrets/test-secret/versions/1" mock_client.add_secret_version = mocker.AsyncMock(return_value=mock_version) mocker.patch( "gcp_provider.resources.secret.SecretManagerServiceAsyncClient", return_value=mock_client, ) return mock_client async def test_create_secret(harness, mock_secretmanager_client, sample_credentials): config = SecretConfig( project_id="test-project", secret_id="my-secret", data="secret-value", credentials=sample_credentials, ) result = await harness.invoke_create(Secret, name="my-secret", config=config) assert result.success assert result.outputs.resource_name == "projects/test-project/secrets/test-secret" assert result.outputs.version_id == "1" async def test_update_secret(harness, mock_secretmanager_client, sample_credentials): previous = SecretConfig(project_id="proj", secret_id="sec", data="old", credentials=sample_credentials) current = SecretConfig(project_id="proj", secret_id="sec", data="new", credentials=sample_credentials) result = await harness.invoke_update( Secret, name="test", config=current, previous_config=previous, current_outputs=SecretOutputs( resource_name="projects/proj/secrets/sec", version_name="projects/proj/secrets/sec/versions/1", version_id="1", ), ) assert result.success mock_secretmanager_client.add_secret_version.assert_called_once() async def test_delete_secret(harness, mock_secretmanager_client, sample_credentials): config = SecretConfig(project_id="proj", secret_id="sec", data="val", credentials=sample_credentials) result = await harness.invoke_delete(Secret, name="test", config=config) assert result.success ``` -------------------------------- ### Manage GCP Resources using Pragma CLI Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Shows common commands for managing GCP resources defined in YAML using the Pragma CLI. This includes applying pending resources and retrieving resource status. ```bash # Apply the resource pragma resources apply --pending secret.yaml # Get resource status pragma resources get gcp/secret db-password # Reference in other resources via FieldReference ``` -------------------------------- ### Deploy GCP Provider to Pragmatiks Platform Source: https://github.com/pragmatiks/pragma-providers/blob/main/packages/gcp/README.md Shows the command to push your developed GCP provider to the Pragmatiks platform. This is the final step for deploying your provider. ```bash pragma provider push ``` -------------------------------- ### Configure GCP Secret Manager Resources with Python Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Illustrates the `SecretConfig` class for defining GCP Secret Manager resources. It shows how to provide project details, secret ID, data, and authentication credentials, accepting both dictionary and JSON string formats for credentials. ```python from gcp_provider import SecretConfig import json # Configuration with dict credentials config = SecretConfig( project_id="production-project", # GCP project ID secret_id="api-key", # Secret identifier (unique per project) data="sk-prod-abc123xyz", # Secret payload to store credentials={ "type": "service_account", "project_id": "production-project", "private_key": "-----BEGIN RSA PRIVATE KEY-----\n...", "client_email": "deployer@production-project.iam.gserviceaccount.com", # ... other credential fields }, ) # Configuration with JSON string credentials (common for env vars) credentials_dict = { "type": "service_account", "project_id": "staging-project", "private_key": "-----BEGIN RSA PRIVATE KEY-----\n...", "client_email": "deployer@staging-project.iam.gserviceaccount.com", } config_with_string_creds = SecretConfig( project_id="staging-project", secret_id="webhook-secret", data="whsec_abc123", credentials=json.dumps(credentials_dict), # JSON string also accepted ) ``` -------------------------------- ### Manage GCP Secret Manager Secrets with Python Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Demonstrates how to define and manage GCP Secret Manager secrets using the Python SDK. It includes defining credentials, creating a Secret resource, and outlines the lifecycle methods (`on_create`, `on_update`, `on_delete`). Expected outputs after creation are also shown. ```python from gcp_provider import Secret, SecretConfig, SecretOutputs # Define GCP service account credentials 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": "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", } # Create a secret resource secret = Secret( name="db-password", config=SecretConfig( project_id="my-gcp-project", secret_id="database-password", data="super-secret-value", credentials=credentials, # Can also be JSON string ), ) # Lifecycle methods are called by the platform: # outputs = await secret.on_create() # outputs = await secret.on_update(previous_config) # await secret.on_delete() # Expected outputs after creation: # SecretOutputs( # resource_name="projects/my-gcp-project/secrets/database-password", # version_name="projects/my-gcp-project/secrets/database-password/versions/1", # version_id="1" # ) ``` -------------------------------- ### Test GCP Secret Creation with ProviderHarness Source: https://github.com/pragmatiks/pragma-providers/blob/main/packages/gcp/README.md Illustrates how to test the creation of a GCP secret using the `ProviderHarness` from `pragma_sdk.provider`. This asynchronous function simulates the invocation of the `create` lifecycle method for a `Secret` resource. ```python from pragma_sdk.provider import ProviderHarness from gcp_provider import Secret, SecretConfig async def test_create_secret(): harness = ProviderHarness() result = await harness.invoke_create( Secret, name="test-secret", config=SecretConfig( project_id="test-project", secret_id="my-secret", data="secret-value", credentials=mock_credentials, ), ) assert result.success assert result.outputs.resource_name is not None ``` -------------------------------- ### Reference GCP Secret in YAML Configuration Source: https://github.com/pragmatiks/pragma-providers/blob/main/README.md Illustrates how to reference a provider resource, such as a GCP secret, within a YAML configuration file using `$ref`. This enables dependency management and dynamic value injection in declarative configurations. ```yaml provider: myapp resource: service name: api config: db_password: $ref: provider: gcp resource: secret name: db-password field: data ``` -------------------------------- ### Access GCP Secret Manager Outputs with Python Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Shows how to use the `SecretOutputs` class to access identifiers for GCP Secret Manager resources after creation or update. It details how to access the full resource name, version name, and version ID. ```python from gcp_provider import SecretOutputs # Outputs returned from on_create or on_update outputs = SecretOutputs( resource_name="projects/my-project/secrets/my-secret", version_name="projects/my-project/secrets/my-secret/versions/3", version_id="3", ) # Access individual fields print(outputs.resource_name) # "projects/my-project/secrets/my-secret" print(outputs.version_name) # "projects/my-project/secrets/my-secret/versions/3" print(outputs.version_id) # "3" ``` -------------------------------- ### Define GCP Secret using Python Source: https://github.com/pragmatiks/pragma-providers/blob/main/packages/gcp/README.md Demonstrates how to define a GCP secret resource using the Python SDK. It includes setting the secret name, project ID, secret ID, data payload, and service account credentials. This is useful for programmatically managing secrets in Google Cloud. ```python from gcp_provider import Secret, SecretConfig # Define a secret secret = Secret( name="my-api-key", config=SecretConfig( project_id="my-gcp-project", secret_id="api-key", data="super-secret-value", credentials={"type": "service_account", ...}, # or JSON string ), ) ``` -------------------------------- ### Inject Secret Values with FieldReference (Python) Source: https://context7.com/pragmatiks/pragma-providers/llms.txt Demonstrates how to use FieldReference to inject secret values into resource configurations, enabling secure credential passing. This is useful for referencing sensitive data stored in external systems like GCP secrets. ```python from pragma_sdk import FieldReference # Reference a secret's data field in application config config = AppConfig( database_password=FieldReference( provider="gcp", resource="secret", name="db-password", field="data", # References the stored secret value ), ) # YAML equivalent with $ref syntax """ provider: myapp resource: service name: api config: db_password: $ref: provider: gcp resource: secret name: db-password field: data """ ``` -------------------------------- ### Reference GCP Secret in Python AppConfig Source: https://github.com/pragmatiks/pragma-providers/blob/main/README.md Shows how to reference a provider resource, specifically a GCP secret, within a Python application configuration using `FieldReference`. This allows dynamic injection of secret values into application settings. ```python from pragma_sdk import FieldReference config = AppConfig( database_password=FieldReference( provider="gcp", resource="secret", name="db-password", field="data" ) ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.