Skip to content

Adding a Provider

balakrishnagatla edited this page Nov 29, 2026 · 1 revision

Adding a Provider

A provider is one class with four read-only methods. Everything else (lifecycle, correlation, MCP tools, reports, savings tracking) comes for free.

from datetime import datetime
from infralens.models import Category, Change, Finding, Severity
from infralens.providers.base import Provider

class GCPProvider(Provider):
    name = "gcp"

    def find_cost_savings(self) -> list[Finding]:
        return [Finding(cloud="gcp", account=project, region=zone,
                        category=Category.SAVINGS, check="unattached_disk",
                        resource_type="persistent_disk", resource_id=disk.name,
                        title=f"{disk.size_gb} GB disk not attached",
                        est_monthly_cost_usd=disk.size_gb * 0.04,
                        evidence={"size_gb": disk.size_gb},
                        recommendation=f"gcloud compute disks delete {disk.name} --zone {zone}",
                        tags=dict(disk.labels))
                for disk in ...]

    def find_incidents(self) -> list[Finding]: ...       # alerts, error spikes
    def recent_changes(self, since: datetime) -> list[Change]: ...   # audit log writes, deploys
    def list_resources(self) -> list[Finding]: ...       # optional: for ownership gaps
    def search_logs(self, query, minutes=60, source=None): ...       # optional

Rules

  • Read-only. Never create, modify or delete anything.
  • Return Finding and Change objects only, never raw SDK objects.
  • Fill tags so owner, team and env resolve and ignore rules apply.
  • Put the numbers an AI needs in evidence.
  • Read thresholds from self.policy and your settings from self.options (provider_options.<name>).
  • Ship the minimum permissions as a file under deploy/.

Register it

In-tree: add it to BUILTIN in src/infralens/providers/__init__.py.

Out-of-tree plugin, in your package's pyproject.toml:

[project.entry-points."infralens.providers"]
gcp = "infralens_gcp:GCPProvider"

Test it

Use fakes or an emulator so tests need no credentials (see tests/test_aws.py with moto and tests/test_azure.py with fakes). Then:

pip install -e ".[aws,k8s,dev]"
pytest -q && ruff check src tests demo

Open a PR. A GCP provider is the most wanted contribution. See CONTRIBUTING.md.

Clone this wiki locally