Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(data-warehouse): implement vultr import source (#70023)

Tom Owersa72a06ee9bc2
diff --git a/frontend/public/services/vultr.svg b/frontend/public/services/vultr.svg
new file mode 100644
index 000000000000..b8df0c7c950b
--- /dev/null
+++ b/frontend/public/services/vultr.svg
@@ -0,0 +1 @@
+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Vultr</title><path fill="#007BFC" d="M8.36 2.172A1.194 1.194 0 007.348 1.6H1.2A1.2 1.2 0 000 2.8a1.211 1.211 0 00.182.64l11.6 18.4a1.206 1.206 0 002.035 0l3.075-4.874a1.229 1.229 0 00.182-.64 1.211 1.211 0 00-.182-.642zm10.349 8.68a1.206 1.206 0 002.035 0L21.8 9.178l2.017-3.2a1.211 1.211 0 00.183-.64 1.229 1.229 0 00-.183-.64l-1.6-2.526a1.206 1.206 0 00-1.016-.571h-6.148a1.2 1.2 0 00-1.201 1.2 1.143 1.143 0 00.188.64z"/></svg>
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md b/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md
index 7658d28841be..cc3903b8a918 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/SOURCES.md
@@ -430,6 +430,7 @@ the row lists both.
| vellum | HTTP | requests | ✅ |
| vercel | HTTP | requests | ✅ |
| vitally | HTTP | requests + `rest_source.RESTClient` | ✅ |
+| vultr | HTTP | requests + `rest_source.RESTClient` | ✅ |
| webflow | HTTP | requests | ✅ |
| windmill | HTTP | requests | ✅ |
| woocommerce | HTTP | requests + `rest_source.RESTClient` | ✅ |
@@ -942,7 +943,6 @@ doesn't conflict with concurrent PRs.
- veracode
- vespa
- visma_economic
-- vultr
- vwo
- waiteraid
- wasabi
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py
index 22aea56ae2b5..1b7c9cca6b1f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/generated_configs.py
@@ -4437,7 +4437,7 @@ class VitallySourceConfig(config.Config):
@config.config
class VultrSourceConfig(config.Config):
- pass
+ api_key: str
@config.config
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/api_inventory.md b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/api_inventory.md
new file mode 100644
index 000000000000..a706e8eecb3d
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/api_inventory.md
@@ -0,0 +1,50 @@
+# Vultr API inventory
+
+Source: Vultr API v2 (<https://www.vultr.com/api/>), cross-checked against the official
+[govultr](https://github.com/vultr/govultr) Go client for exact response shapes and field names.
+
+- **Base URL:** `https://api.vultr.com` (single global host, no regional variants).
+- **Auth:** `Authorization: Bearer <api_key>`. One personal access token per account, generated in the
+ customer portal (**Account > API**). Grants full account access (no per-product scopes). The portal
+ offers an IP access-control list, so a customer may need to allowlist PostHog egress IPs.
+- **Pagination:** cursor in the response body at `meta.links.next` (empty string when exhausted),
+ replayed as the `cursor` query param. Page size via `per_page` (default 100, max 500).
+- **Rate limit:** ~30 req/s per source IP; HTTP 429 above that.
+- **Incremental sync:** none. No list endpoint accepts an updated-since / created-since filter, and
+ there are no webhooks. All endpoints are full-refresh (`write_disposition="replace"`).
+
+## Endpoints
+
+| Schema name | Path | Response array key | Primary key | Stable date field |
+| --------------------- | ------------------------- | ------------------ | ----------- | ----------------- |
+| `instances` | `/v2/instances` | `instances` | `id` | `date_created` |
+| `bare_metals` | `/v2/bare-metals` | `bare_metals` | `id` | `date_created` |
+| `kubernetes_clusters` | `/v2/kubernetes/clusters` | `vke_clusters` | `id` | `date_created` |
+| `block_storage` | `/v2/blocks` | `blocks` | `id` | `date_created` |
+| `snapshots` | `/v2/snapshots` | `snapshots` | `id` | `date_created` |
+| `load_balancers` | `/v2/load-balancers` | `load_balancers` | `id` | `date_created` |
+| `managed_databases` | `/v2/databases` | `databases` | `id` | `date_created` |
+| `users` | `/v2/users` | `users` | `id` | (none) |
+| `billing_history` | `/v2/billing/history` | `billing_history` | `id` | `date` |
+| `invoices` | `/v2/billing/invoices` | `billing_invoices` | `id` | `date` |
+
+All `id` values are unique per account, so `["id"]` is a table-wide unique primary key on every
+endpoint (no fan-out children). `id` is an integer on the billing endpoints and a string elsewhere.
+
+## Sensitive fields
+
+Some list objects embed live credentials for the resource they describe:
+instance and bare-metal objects carry `default_password`,
+and managed-database objects carry the admin `password` plus, for Kafka, `access_key` / `access_cert` (sometimes nested under credential sub-objects).
+`vultr.py` strips these fields (`SECRET_FIELD_NAMES`) from every row at any depth before it is written to the warehouse,
+and the source opts out of HTTP sample capture so raw responses never land in captured samples either.
+When adding an endpoint, extend `SECRET_FIELD_NAMES` if its objects expose any new credential-bearing fields.
+
+## Verification note
+
+The endpoint paths, response wrapper keys, and field names above were verified against the govultr
+client structs (`instance.go`, `bare_metal_server.go`, `kubernetes.go`, `block_storage.go`,
+`snapshot.go`, `load_balancer.go`, `database.go`, `user.go`, `billing.go`) and the API reference.
+Live-curl verification against the API was not possible without an account API key; the full-refresh
+design is conservative and does not depend on any silently-ignored query params (we send only
+`per_page` and the paginator's `cursor`).
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/canonical_descriptions.py
new file mode 100644
index 000000000000..26abbc20b6d1
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/canonical_descriptions.py
@@ -0,0 +1,151 @@
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (
+ CanonicalDescriptions,
+)
+
+# Sourced from the Vultr API v2 reference (https://www.vultr.com/api/) and the official govultr client.
+CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
+ "instances": {
+ "description": "Cloud compute and GPU instances (virtual machines) in your Vultr account.",
+ "docs_url": "https://www.vultr.com/api/#tag/instances",
+ "columns": {
+ "id": "Unique identifier for the instance.",
+ "region": "Region ID where the instance is deployed.",
+ "plan": "Plan ID the instance runs on.",
+ "date_created": "Date and time the instance was created (ISO 8601).",
+ "status": "Current provisioning status of the instance.",
+ "power_status": "Whether the instance is running or stopped.",
+ "server_status": "Health of the server's OS/applications.",
+ "main_ip": "Primary IPv4 address of the instance.",
+ "vcpu_count": "Number of vCPUs allocated to the instance.",
+ "ram": "Memory allocated to the instance, in MB.",
+ "disk": "Disk size allocated to the instance, in GB.",
+ "os": "Operating system name.",
+ "label": "User-defined label for the instance.",
+ "hostname": "Hostname assigned to the instance.",
+ "tags": "User-defined tags applied to the instance.",
+ },
+ },
+ "bare_metals": {
+ "description": "Bare metal (dedicated) servers in your Vultr account.",
+ "docs_url": "https://www.vultr.com/api/#tag/bare-metal",
+ "columns": {
+ "id": "Unique identifier for the bare metal server.",
+ "region": "Region ID where the server is deployed.",
+ "plan": "Plan ID the server runs on.",
+ "date_created": "Date and time the server was created (ISO 8601).",
+ "status": "Current provisioning status of the server.",
+ "main_ip": "Primary IPv4 address of the server.",
+ "cpu_count": "Number of CPU cores on the server.",
+ "ram": "Memory of the server.",
+ "disk": "Disk of the server.",
+ "os": "Operating system name.",
+ "label": "User-defined label for the server.",
+ },
+ },
+ "kubernetes_clusters": {
+ "description": "Vultr Kubernetes Engine (VKE) managed clusters.",
+ "docs_url": "https://www.vultr.com/api/#tag/kubernetes",
+ "columns": {
+ "id": "Unique identifier for the cluster.",
+ "label": "User-defined label for the cluster.",
+ "date_created": "Date and time the cluster was created (ISO 8601).",
+ "region": "Region ID where the cluster is deployed.",
+ "version": "Kubernetes version running on the cluster.",
+ "status": "Current status of the cluster.",
+ "ip": "Cluster control-plane IP address.",
+ "endpoint": "Cluster API endpoint.",
+ "node_pools": "Node pools attached to the cluster.",
+ },
+ },
+ "block_storage": {
+ "description": "Block storage volumes in your Vultr account.",
+ "docs_url": "https://www.vultr.com/api/#tag/block",
+ "columns": {
+ "id": "Unique identifier for the block storage volume.",
+ "date_created": "Date and time the volume was created (ISO 8601).",
+ "region": "Region ID where the volume is deployed.",
+ "size_gb": "Size of the volume, in GB.",
+ "status": "Current status of the volume.",
+ "cost": "Monthly cost of the volume.",
+ "attached_to_instance": "ID of the instance the volume is attached to, if any.",
+ "block_type": "Storage class of the volume.",
+ "label": "User-defined label for the volume.",
+ },
+ },
+ "snapshots": {
+ "description": "Instance snapshots stored in your Vultr account.",
+ "docs_url": "https://www.vultr.com/api/#tag/snapshot",
+ "columns": {
+ "id": "Unique identifier for the snapshot.",
+ "date_created": "Date and time the snapshot was taken (ISO 8601).",
+ "description": "User-defined description of the snapshot.",
+ "size": "Uncompressed size of the snapshot, in bytes.",
+ "compressed_size": "Compressed size of the snapshot, in bytes.",
+ "status": "Current status of the snapshot.",
+ },
+ },
+ "load_balancers": {
+ "description": "Load balancers in your Vultr account.",
+ "docs_url": "https://www.vultr.com/api/#tag/load-balancer",
+ "columns": {
+ "id": "Unique identifier for the load balancer.",
+ "date_created": "Date and time the load balancer was created (ISO 8601).",
+ "region": "Region ID where the load balancer is deployed.",
+ "label": "User-defined label for the load balancer.",
+ "status": "Current status of the load balancer.",
+ "ipv4": "IPv4 address of the load balancer.",
+ "ipv6": "IPv6 address of the load balancer.",
+ "instances": "Instance IDs attached to the load balancer.",
+ },
+ },
+ "managed_databases": {
+ "description": "Vultr Managed Databases (MySQL, PostgreSQL, Valkey, Kafka).",
+ "docs_url": "https://www.vultr.com/api/#tag/managed-databases",
+ "columns": {
+ "id": "Unique identifier for the managed database.",
+ "date_created": "Date and time the database was created (ISO 8601).",
+ "plan": "Plan ID the database runs on.",
+ "region": "Region ID where the database is deployed.",
+ "database_engine": "Database engine (e.g. mysql, pg, valkey, kafka).",
+ "database_engine_version": "Version of the database engine.",
+ "status": "Current status of the database.",
+ "label": "User-defined label for the database.",
+ "host": "Connection host for the database.",
+ "port": "Connection port for the database.",
+ },
+ },
+ "users": {
+ "description": "Sub-users configured on your Vultr account.",
+ "docs_url": "https://www.vultr.com/api/#tag/users",
+ "columns": {
+ "id": "Unique identifier for the user.",
+ "name": "Display name of the user.",
+ "email": "Email address of the user.",
+ "api_enabled": "Whether API access is enabled for the user.",
+ "acls": "Access control list granted to the user.",
+ },
+ },
+ "billing_history": {
+ "description": "Append-only account billing history line items (charges and payments).",
+ "docs_url": "https://www.vultr.com/api/#tag/billing",
+ "columns": {
+ "id": "Unique identifier for the billing history entry.",
+ "date": "Date and time of the billing entry (ISO 8601).",
+ "type": "Type of the entry (e.g. invoice, payment).",
+ "description": "Description of the billing entry.",
+ "amount": "Amount of the entry in account currency.",
+ "balance": "Account balance after the entry.",
+ },
+ },
+ "invoices": {
+ "description": "Account invoices.",
+ "docs_url": "https://www.vultr.com/api/#tag/billing",
+ "columns": {
+ "id": "Unique identifier for the invoice.",
+ "date": "Date and time the invoice was issued (ISO 8601).",
+ "description": "Description of the invoice.",
+ "amount": "Total amount of the invoice in account currency.",
+ "balance": "Account balance after the invoice.",
+ },
+ },
+}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/settings.py
new file mode 100644
index 000000000000..e3cb48a653b9
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/settings.py
@@ -0,0 +1,34 @@
+from dataclasses import dataclass, field
+
+
+@dataclass
+class VultrEndpointConfig:
+ name: str
+ # API path, appended to the Vultr base URL (https://api.vultr.com).
+ path: str
+ # JSONPath to the row array in the response body (e.g. "instances", "vke_clusters").
+ data_selector: str
+ primary_keys: list[str] = field(default_factory=lambda: ["id"])
+
+
+# Vultr API v2 has no server-side updated-since / created-since filter and no webhooks on any list
+# endpoint, so every endpoint is full-refresh (write_disposition="replace"). Per-account entity counts
+# are small, so a full pull per run is fine. See the source-local api_inventory.md for the survey notes.
+ENDPOINTS: dict[str, VultrEndpointConfig] = {
+ "instances": VultrEndpointConfig(name="instances", path="/v2/instances", data_selector="instances"),
+ "bare_metals": VultrEndpointConfig(name="bare_metals", path="/v2/bare-metals", data_selector="bare_metals"),
+ "kubernetes_clusters": VultrEndpointConfig(
+ name="kubernetes_clusters", path="/v2/kubernetes/clusters", data_selector="vke_clusters"
+ ),
+ "block_storage": VultrEndpointConfig(name="block_storage", path="/v2/blocks", data_selector="blocks"),
+ "snapshots": VultrEndpointConfig(name="snapshots", path="/v2/snapshots", data_selector="snapshots"),
+ "load_balancers": VultrEndpointConfig(
+ name="load_balancers", path="/v2/load-balancers", data_selector="load_balancers"
+ ),
+ "managed_databases": VultrEndpointConfig(name="managed_databases", path="/v2/databases", data_selector="databases"),
+ "users": VultrEndpointConfig(name="users", path="/v2/users", data_selector="users"),
+ "billing_history": VultrEndpointConfig(
+ name="billing_history", path="/v2/billing/history", data_selector="billing_history"
+ ),
+ "invoices": VultrEndpointConfig(name="invoices", path="/v2/billing/invoices", data_selector="billing_invoices"),
+}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/source.py
index e54081b5fbdd..0f89b7e7101a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/source.py
@@ -1,31 +1,126 @@
-from typing import cast
+from typing import Optional, cast
from posthog.schema import (
DataWarehouseSourceCategory,
ExternalDataSourceType as SchemaExternalDataSourceType,
+ ReleaseStatus,
SourceConfig,
+ SourceFieldInputConfig,
+ SourceFieldInputConfigType,
)
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import (
+ SourceInputs,
+ SourceResponse,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, SimpleSource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (
+ CanonicalDescriptions,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.registry import SourceRegistry
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import SourceSchema
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import VultrSourceConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.settings import ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.vultr import (
+ validate_credentials as validate_vultr_credentials,
+ vultr_source,
+)
from products.warehouse_sources.backend.types import ExternalDataSourceType
@SourceRegistry.register
class VultrSource(SimpleSource[VultrSourceConfig]):
+ # get_schemas is a static endpoint catalog with no I/O, so the table list is safe for public docs.
+ lists_tables_without_credentials = True
+
@property
def source_type(self) -> ExternalDataSourceType:
return ExternalDataSourceType.VULTR
+ def get_non_retryable_errors(self) -> dict[str, str | None]:
+ return {
+ "401 Client Error: Unauthorized for url": "Your Vultr API key is invalid or has been revoked. Generate a new key in the Vultr customer portal and reconnect.",
+ "403 Client Error: Forbidden for url": "Your Vultr API key is being blocked. Check the API key's IP access control list in the Vultr customer portal and reconnect.",
+ }
+
+ def get_canonical_descriptions(self) -> CanonicalDescriptions:
+ from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.canonical_descriptions import (
+ CANONICAL_DESCRIPTIONS,
+ )
+
+ return CANONICAL_DESCRIPTIONS
+
+ def get_schemas(
+ self,
+ config: VultrSourceConfig,
+ team_id: int,
+ with_counts: bool = False,
+ names: list[str] | None = None,
+ force_refresh: bool = False,
+ ) -> list[SourceSchema]:
+ # Every Vultr list endpoint is full-refresh: the API exposes no server-side timestamp filter.
+ schemas = [
+ SourceSchema(
+ name=endpoint,
+ supports_incremental=False,
+ supports_append=False,
+ incremental_fields=[],
+ )
+ for endpoint in ENDPOINTS
+ ]
+
+ if names is not None:
+ names_set = set(names)
+ schemas = [s for s in schemas if s.name in names_set]
+
+ return schemas
+
+ def validate_credentials(
+ self, config: VultrSourceConfig, team_id: int, schema_name: Optional[str] = None
+ ) -> tuple[bool, str | None]:
+ return validate_vultr_credentials(config.api_key, schema_name)
+
+ def source_for_pipeline(self, config: VultrSourceConfig, inputs: SourceInputs) -> SourceResponse:
+ resource = vultr_source(
+ api_key=config.api_key,
+ endpoint=inputs.schema_name,
+ team_id=inputs.team_id,
+ job_id=inputs.job_id,
+ )
+ return SourceResponse(
+ name=resource.name,
+ items=lambda: resource,
+ primary_keys=ENDPOINTS[inputs.schema_name].primary_keys,
+ column_hints=resource.column_hints,
+ )
+
@property
def get_source_config(self) -> SourceConfig:
return SourceConfig(
name=SchemaExternalDataSourceType.VULTR,
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="Vultr",
- iconPath="/static/services/vultr.png",
+ caption=(
+ "Import your Vultr cloud infrastructure and billing data. Generate a personal access token "
+ "under **Account > API** in the [Vultr customer portal](https://my.vultr.com/settings/#settingsapi). "
+ "The token grants full account access; if API access is restricted, add PostHog's egress IPs to the "
+ "API key's access control list."
+ ),
+ docsUrl="https://posthog.com/docs/cdp/sources/vultr",
+ iconPath="/static/services/vultr.svg",
keywords=["cloud", "infrastructure", "billing", "compute"],
- fields=cast(list[FieldType], []),
- unreleasedSource=True,
+ releaseStatus=ReleaseStatus.ALPHA,
+ fields=cast(
+ list[FieldType],
+ [
+ SourceFieldInputConfig(
+ name="api_key",
+ label="API key",
+ type=SourceFieldInputConfigType.PASSWORD,
+ required=True,
+ placeholder="",
+ secret=True,
+ ),
+ ],
+ ),
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/tests/test_vultr.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/tests/test_vultr.py
new file mode 100644
index 000000000000..2d84830c671b
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/tests/test_vultr.py
@@ -0,0 +1,199 @@
+import json
+from typing import Any, cast
+
+import pytest
+from unittest.mock import MagicMock, patch
+
+from requests import Request, Response
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resource
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.settings import ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.vultr import (
+ VULTR_PER_PAGE,
+ _cursor_paginator,
+ _redact_secrets,
+ get_resource,
+ validate_credentials,
+ vultr_source,
+)
+
+VULTR_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.vultr.vultr"
+
+
+def _make_response(json_body: dict[str, Any] | None = None, status_code: int = 200) -> Response:
+ resp = Response()
+ resp.status_code = status_code
+ resp.headers["Content-Type"] = "application/json"
+ resp._content = json.dumps(json_body or {}).encode()
+ return resp
+
+
+def _endpoint(resource: Any) -> dict[str, Any]:
+ return cast(dict[str, Any], resource["endpoint"])
+
+
+class TestGetResource:
+ @pytest.mark.parametrize("endpoint", list(ENDPOINTS))
+ def test_resource_matches_settings(self, endpoint: str) -> None:
+ config = ENDPOINTS[endpoint]
+ resource = get_resource(endpoint)
+
+ assert resource["name"] == config.name
+ assert resource["table_name"] == config.name
+ assert resource["table_format"] == "delta"
+ # Vultr exposes no server-side time filter, so every endpoint is full-refresh.
+ assert resource["write_disposition"] == "replace"
+
+ ep = _endpoint(resource)
+ assert ep["path"] == config.path
+ assert ep["data_selector"] == config.data_selector
+ assert ep["params"] == {"per_page": VULTR_PER_PAGE}
+
+ def test_per_page_is_within_vultr_max(self) -> None:
+ # Vultr rejects per_page above 500.
+ assert 0 < VULTR_PER_PAGE <= 500
+
+
+class TestCursorPaginator:
+ def test_advances_on_non_empty_next_cursor(self) -> None:
+ p = _cursor_paginator()
+ p.update_state(_make_response({"instances": [{"id": "a"}], "meta": {"links": {"next": "CURSOR2", "prev": ""}}}))
+
+ assert p.has_next_page is True
+
+ request = Request(method="GET", url="https://api.vultr.com/v2/instances", params={"per_page": VULTR_PER_PAGE})
+ p.update_request(request)
+ assert request.params["cursor"] == "CURSOR2"
+ # The page size must survive alongside the cursor.
+ assert request.params["per_page"] == VULTR_PER_PAGE
+
+ @pytest.mark.parametrize(
+ "body",
+ [
+ pytest.param({"instances": [], "meta": {"links": {"next": "", "prev": ""}}}, id="empty_next_string"),
+ pytest.param({"instances": [], "meta": {"links": {}}}, id="missing_next"),
+ pytest.param({"instances": []}, id="missing_meta"),
+ ],
+ )
+ def test_stops_when_no_next_cursor(self, body: dict[str, Any]) -> None:
+ p = _cursor_paginator()
+ p.update_state(_make_response(body))
+ assert p.has_next_page is False
+
+
+class TestValidateCredentials:
+ @pytest.mark.parametrize(
+ "status_code,schema_name,expected_valid",
+ [
+ pytest.param(200, None, True, id="200_create"),
+ pytest.param(200, "instances", True, id="200_schema"),
+ pytest.param(401, None, False, id="401_invalid_token"),
+ pytest.param(401, "instances", False, id="401_invalid_token_schema"),
+ # A token that 403s on both the account and the data endpoint can never sync, so it is
+ # rejected even at create rather than saved as a source that fails every run.
+ pytest.param(403, None, False, id="403_create_fully_blocked"),
+ pytest.param(403, "instances", False, id="403_rejected_per_schema"),
+ pytest.param(500, None, False, id="5xx_unexpected"),
+ ],
+ )
+ def test_status_code_mapping(self, status_code: int, schema_name: str | None, expected_valid: bool) -> None:
+ session = MagicMock()
+ session.get.return_value = _make_response(status_code=status_code)
+
+ with patch(f"{VULTR_MODULE}.make_tracked_session", return_value=session):
+ valid, error = validate_credentials("key", schema_name)
+
+ assert valid is expected_valid
+ if expected_valid:
+ assert error is None
+ else:
+ assert error is not None
+
+ def test_create_403_accepts_subuser_token_when_data_endpoint_readable(self) -> None:
+ # A sub-user token whose ACL blocks /v2/account but permits /v2/instances is usable, so a
+ # create-time 403 on the account endpoint is confirmed against a real data endpoint.
+ session = MagicMock()
+ session.get.side_effect = [_make_response(status_code=403), _make_response(status_code=200)]
+
+ with patch(f"{VULTR_MODULE}.make_tracked_session", return_value=session):
+ valid, error = validate_credentials("key", None)
+
+ assert valid is True
+ assert error is None
+ assert session.get.call_count == 2
+ assert session.get.call_args_list[1][0][0].endswith("/v2/instances")
+
+ def test_sends_bearer_token_to_account_endpoint(self) -> None:
+ session = MagicMock()
+ session.get.return_value = _make_response(status_code=200)
+
+ with patch(f"{VULTR_MODULE}.make_tracked_session", return_value=session):
+ validate_credentials("secret-key")
+
+ called_url = session.get.call_args[0][0]
+ headers = session.get.call_args.kwargs["headers"]
+ assert called_url.endswith("/v2/account")
+ assert headers["Authorization"] == "Bearer secret-key"
+
+ def test_network_error_is_not_fatal(self) -> None:
+ session = MagicMock()
+ session.get.side_effect = ConnectionError("boom")
+
+ with patch(f"{VULTR_MODULE}.make_tracked_session", return_value=session):
+ valid, error = validate_credentials("key")
+
+ assert valid is False
+ assert error is not None
+
+
+class TestRedactSecrets:
+ @pytest.mark.parametrize(
+ "row,expected",
+ [
+ pytest.param(
+ {"id": "i-1", "default_password": "hunter2", "label": "web"},
+ {"id": "i-1", "label": "web"},
+ id="instance_default_password",
+ ),
+ pytest.param(
+ {"id": "db-1", "password": "s3cret", "access_key": "ak", "access_cert": "ac", "host": "h"},
+ {"id": "db-1", "host": "h"},
+ id="managed_database_credentials",
+ ),
+ pytest.param(
+ # Managed databases nest read-replica objects that carry their own credentials.
+ {
+ "id": "db-1",
+ "read_replicas": [{"id": "r-1", "password": "p"}],
+ "ferretdb_credentials": {"password": "p2", "user": "u"},
+ },
+ {"id": "db-1", "read_replicas": [{"id": "r-1"}], "ferretdb_credentials": {"user": "u"}},
+ id="nested_credentials",
+ ),
+ pytest.param(
+ {"id": "b-1", "amount": 10, "description": "invoice"},
+ {"id": "b-1", "amount": 10, "description": "invoice"},
+ id="no_secrets_untouched",
+ ),
+ ],
+ )
+ def test_strips_secret_fields_at_any_depth(self, row: dict[str, Any], expected: dict[str, Any]) -> None:
+ assert _redact_secrets(row) == expected
+
+
+class TestVultrSourceWiring:
+ @patch(f"{VULTR_MODULE}.rest_api_resource")
+ @patch(f"{VULTR_MODULE}.make_tracked_session")
+ def test_source_redacts_rows_and_disables_sample_capture(
+ self, mock_session: MagicMock, mock_rest: MagicMock
+ ) -> None:
+ page = [{"id": "i-1", "default_password": "hunter2", "label": "web"}]
+ mock_rest.return_value = Resource(lambda: iter([page]), name="instances", hints={})
+
+ resource = vultr_source(api_key="k", endpoint="instances", team_id=1, job_id="j")
+ rows = [row for chunk in resource for row in chunk]
+
+ # Credentials are stripped before rows reach the warehouse table.
+ assert rows == [{"id": "i-1", "label": "web"}]
+ # Raw responses carry secrets, so the source must opt out of HTTP sample capture.
+ assert mock_session.call_args.kwargs["capture"] is False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/tests/test_vultr_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/tests/test_vultr_source.py
new file mode 100644
index 000000000000..101a5f2ee726
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/tests/test_vultr_source.py
@@ -0,0 +1,129 @@
+from typing import Any
+
+import pytest
+from unittest import mock
+
+from posthog.schema import (
+ DataWarehouseSourceCategory,
+ ReleaseStatus,
+ SourceFieldInputConfig,
+ SourceFieldInputConfigType,
+)
+
+from products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline.typings import SourceInputs
+from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs import VultrSourceConfig
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.canonical_descriptions import (
+ CANONICAL_DESCRIPTIONS,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.settings import ENDPOINTS
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.source import VultrSource
+from products.warehouse_sources.backend.types import ExternalDataSourceType
+
+SOURCE_MODULE = "products.warehouse_sources.backend.temporal.data_imports.sources.vultr.source"
+
+
+def _make_inputs(**overrides: Any) -> SourceInputs:
+ defaults: dict[str, Any] = {
+ "schema_name": "instances",
+ "schema_id": "schema-1",
+ "source_id": "source-1",
+ "team_id": 123,
+ "should_use_incremental_field": False,
+ "db_incremental_field_last_value": None,
+ "db_incremental_field_earliest_value": None,
+ "incremental_field": None,
+ "incremental_field_type": None,
+ "job_id": "job-1",
+ "logger": mock.MagicMock(),
+ "reset_pipeline": False,
+ }
+ defaults.update(overrides)
+ return SourceInputs(**defaults)
+
+
+class TestVultrSource:
+ def setup_method(self) -> None:
+ self.source = VultrSource()
+ self.team_id = 123
+ self.config = VultrSourceConfig(api_key="test-key")
+
+ def test_source_type(self) -> None:
+ assert self.source.source_type == ExternalDataSourceType.VULTR
+
+ def test_get_source_config(self) -> None:
+ config = self.source.get_source_config
+
+ assert config.name.value == "Vultr"
+ assert config.category == DataWarehouseSourceCategory.ENGINEERING___MONITORING
+ assert config.releaseStatus == ReleaseStatus.ALPHA
+ assert config.iconPath == "/static/services/vultr.svg"
+ assert config.docsUrl == "https://posthog.com/docs/cdp/sources/vultr"
+
+ assert len(config.fields) == 1
+ (api_key_field,) = config.fields
+ assert isinstance(api_key_field, SourceFieldInputConfig)
+ assert api_key_field.name == "api_key"
+ # The single account token is confidential, so it must render as a masked, secret field.
+ assert api_key_field.type == SourceFieldInputConfigType.PASSWORD
+ assert api_key_field.required is True
+ assert api_key_field.secret is True
+
+ @pytest.mark.parametrize("expected_key", ["401 Client Error", "403 Client Error"])
+ def test_non_retryable_errors(self, expected_key: str) -> None:
+ errors = self.source.get_non_retryable_errors()
+ assert any(expected_key in key for key in errors)
+
+ def test_get_schemas_all_full_refresh(self) -> None:
+ schemas = self.source.get_schemas(self.config, self.team_id)
+
+ assert {s.name for s in schemas} == set(ENDPOINTS)
+ # Vultr has no server-side timestamp filter, so nothing supports incremental sync.
+ assert all(not s.supports_incremental for s in schemas)
+ assert all(not s.supports_append for s in schemas)
+ assert all(s.incremental_fields == [] for s in schemas)
+
+ def test_get_schemas_filtered_by_names(self) -> None:
+ schemas = self.source.get_schemas(self.config, self.team_id, names=["invoices"])
+ assert [s.name for s in schemas] == ["invoices"]
+
+ @pytest.mark.parametrize(
+ ("mock_return", "expected"),
+ [
+ ((True, None), (True, None)),
+ ((False, "Invalid Vultr API key."), (False, "Invalid Vultr API key.")),
+ ],
+ )
+ @mock.patch(f"{SOURCE_MODULE}.validate_vultr_credentials")
+ def test_validate_credentials_plumbing(
+ self, mock_validate: mock.MagicMock, mock_return: tuple[bool, str | None], expected: tuple[bool, str | None]
+ ) -> None:
+ mock_validate.return_value = mock_return
+ result = self.source.validate_credentials(self.config, self.team_id, schema_name="instances")
+
+ assert result == expected
+ mock_validate.assert_called_once_with("test-key", "instances")
+
+ @pytest.mark.parametrize("schema_name", list(ENDPOINTS))
+ @mock.patch(f"{SOURCE_MODULE}.vultr_source")
+ def test_source_for_pipeline_maps_primary_keys(self, mock_vultr_source: mock.MagicMock, schema_name: str) -> None:
+ resource = mock.MagicMock()
+ resource.name = schema_name
+ resource.column_hints = None
+ mock_vultr_source.return_value = resource
+
+ response = self.source.source_for_pipeline(self.config, _make_inputs(schema_name=schema_name))
+
+ assert response.name == schema_name
+ # Every Vultr id is globally unique per account, so ["id"] is the table-wide key.
+ assert response.primary_keys == ENDPOINTS[schema_name].primary_keys
+ mock_vultr_source.assert_called_once_with(api_key="test-key", endpoint=schema_name, team_id=123, job_id="job-1")
+
+ def test_documented_tables_cover_every_endpoint(self) -> None:
+ # lists_tables_without_credentials is True, so the public docs catalog must render statically.
+ assert self.source.lists_tables_without_credentials is True
+ tables = self.source.get_documented_tables()
+ assert {t["name"] for t in tables} == set(ENDPOINTS)
+
+ def test_canonical_descriptions_keys_are_valid_endpoints(self) -> None:
+ # A description keyed to a non-existent endpoint would silently never apply.
+ assert set(CANONICAL_DESCRIPTIONS).issubset(set(ENDPOINTS))
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/vultr.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/vultr.py
new file mode 100644
index 000000000000..561448cc4dfb
--- /dev/null
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vultr/vultr.py
@@ -0,0 +1,132 @@
+from typing import Any, Optional
+
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source import (
+ RESTAPIConfig,
+ rest_api_resource,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
+ JSONResponseCursorPaginator,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.resource import Resource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import EndpointResource
+from products.warehouse_sources.backend.temporal.data_imports.sources.vultr.settings import ENDPOINTS
+
+VULTR_BASE_URL = "https://api.vultr.com"
+# Vultr caps per_page at 500 (default 100). Fewer requests keeps us well under the ~30 req/s rate limit.
+VULTR_PER_PAGE = 500
+
+# Vultr list objects embed live credentials for the resource they describe: instance and bare-metal
+# objects carry `default_password`, and managed-database objects carry the admin `password` plus, for
+# Kafka, `access_key`/`access_cert` (sometimes nested under credential sub-objects). Persisting these
+# to warehouse tables would expose customer server and database credentials to any project member who
+# can query the table, so we strip them from every row (at any depth) before it is yielded, and we
+# disable HTTP sample capture for the source so raw responses never land in captured samples either.
+SECRET_FIELD_NAMES: frozenset[str] = frozenset({"default_password", "password", "access_key", "access_cert", "api_key"})
+
+
+def _redact_value(value: Any) -> Any:
+ if isinstance(value, dict):
+ return {key: _redact_value(sub) for key, sub in value.items() if key not in SECRET_FIELD_NAMES}
+ if isinstance(value, list):
+ return [_redact_value(item) for item in value]
+ return value
+
+
+def _redact_secrets(row: dict[str, Any]) -> dict[str, Any]:
+ return {key: _redact_value(value) for key, value in row.items() if key not in SECRET_FIELD_NAMES}
+
+
+def _cursor_paginator() -> JSONResponseCursorPaginator:
+ # Vultr paginates via a body cursor at meta.links.next, replayed as the `cursor` query param.
+ # The final page returns an empty string, which the paginator treats as "no next page".
+ return JSONResponseCursorPaginator(cursor_path="meta.links.next", cursor_param="cursor")
+
+
+def get_resource(endpoint: str) -> EndpointResource:
+ config = ENDPOINTS[endpoint]
+ return {
+ "name": config.name,
+ "table_name": config.name,
+ # No server-side time filter exists on any Vultr list endpoint, so we always full-refresh.
+ "write_disposition": "replace",
+ "endpoint": {
+ "data_selector": config.data_selector,
+ "path": config.path,
+ "params": {"per_page": VULTR_PER_PAGE},
+ },
+ "table_format": "delta",
+ }
+
+
+def vultr_source(
+ api_key: str,
+ endpoint: str,
+ team_id: int,
+ job_id: str,
+) -> Resource:
+ config: RESTAPIConfig = {
+ "client": {
+ "base_url": VULTR_BASE_URL,
+ "auth": {"type": "bearer", "token": api_key},
+ "paginator": _cursor_paginator(),
+ # Responses carry live server/database credentials the name-based sample scrubbers don't
+ # cover, so we opt the whole source out of HTTP sample capture. `redact_values` keeps the
+ # bearer token masked in logs (a pre-built session skips RESTClient's auth-value default).
+ "session": make_tracked_session(redact_values=(api_key,), capture=False),
+ },
+ "resource_defaults": {"write_disposition": "replace"},
+ "resources": [get_resource(endpoint)],
+ }
+
+ resource = rest_api_resource(config, team_id, job_id, db_incremental_field_last_value=None)
+ # Strip embedded credentials before rows reach the warehouse table.
+ return resource.add_map(_redact_secrets)
+
+
+VULTR_IP_BLOCK_ERROR = (
+ "Your Vultr API key is being blocked. Check the API key's IP access control list in the Vultr customer portal."
+)
+
+
+def _probe(api_key: str, path: str, params: Optional[dict[str, Any]] = None) -> tuple[Optional[int], Optional[str]]:
+ """GET a Vultr endpoint, returning (status_code, error). error is set only on transport failure."""
+ try:
+ response = make_tracked_session().get(
+ f"{VULTR_BASE_URL}{path}",
+ headers={"Authorization": f"Bearer {api_key}"},
+ params=params,
+ timeout=30,
+ )
+ except Exception as e:
+ return None, str(e)
+ return response.status_code, None
+
+
+def validate_credentials(api_key: str, schema_name: Optional[str] = None) -> tuple[bool, str | None]:
+ """Probe the account endpoint to confirm the API key is genuine.
+
+ A single Vultr API key grants full account access (no per-product scoping), so a 403 is almost
+ always the portal's IP access-control list blocking our egress IPs — in which case every request
+ (validation and sync alike) is refused and the source would never sync. The one legitimate
+ exception is a sub-user token whose ACL excludes the account endpoint but still permits the data
+ endpoints. So on a create-time 403 we probe a real data endpoint (`/v2/instances`): if that also
+ 403s, the token cannot read anything from our IPs and we reject it now rather than saving a
+ source that silently fails every run; if it succeeds, the token is a usable sub-user token and we
+ accept it. Sync-time 403s remain surfaced by `get_non_retryable_errors`.
+ """
+ status, error = _probe(api_key, "/v2/account")
+ if error is not None:
+ return False, error
+
+ if status == 200:
+ return True, None
+ if status == 401:
+ return False, "Invalid Vultr API key. Generate a new key in the Vultr customer portal and try again."
+ if status == 403:
+ if schema_name is None:
+ data_status, data_error = _probe(api_key, "/v2/instances", params={"per_page": 1})
+ if data_error is None and data_status == 200:
+ return True, None
+ return False, VULTR_IP_BLOCK_ERROR
+ return False, f"Unexpected response from Vultr (HTTP {status})."