chore: modernize PostgreSQL connector for baton-admin - #51
Conversation
Upgrade baton-sdk from v0.3.9 to v0.29.0 and prepare the connector for baton-admin's managed CI and metadata generation workflows. SDK and connector compatibility: - Raise the Go requirement to 1.25.2, update dependencies, and regenerate the vendored dependency tree. - Adapt configuration constraints to field.WithConstraints. - Migrate account creation and credential rotation to LocalCredentialOptions and pass context to password generation. - Move the enabled status from the deprecated user trait field to the resource status field, preserving the existing enabled-state behavior. Credential-free capability generation: - Register a zero-value Postgresql connector as the default capabilities builder so metadata generation does not require a DSN or live database. - Allow Default on a nil client pool when constructing capability syncers. - Add a regression test for building the zero-value connector and listing its resource types without database access. - Refresh baton_capabilities.json with the upgraded SDK's output. CI and test maintenance: - Update the PR and main workflows to Go 1.25.x, golangci-lint-action v9, and golangci-lint v2.11.4. - Adopt the baton-admin golangci-lint v2 configuration and resolve the resulting style findings. - Migrate integration tests from the removed C1Z manager API to NewStore and c1zstore.Store, including context-aware store cleanup. - Paginate test resource lookups so resources beyond the first 100 results can be found. Validation: - Full Go test suite passed, including Postgres integration tests. - golangci-lint reported zero issues. - The connector built successfully; credential-free capabilities output matched baton_capabilities.json, and config output succeeded. - Normal execution without a DSN still failed required-flag validation. Validation used local Go 1.27.1 and golangci-lint 2.13.2. The exact CI tool versions and GitHub Actions execution were not verified locally. Deployment of baton-admin's managed workflows remains a separate step.
Connector PR Review: chore: modernize PostgreSQL connector for baton-adminBlocking Issues: 0 | Suggestions: 2 | Threads Resolved: 0 Review SummaryScanned the full PR diff for security and correctness across all 21 non-vendored files (vendored module content excluded from bulk review; I verified the risky parts of the SDK v0.3.9 → v0.29.0 jump against the vendored SDK rather than taking the description at face value: Security IssuesNone found. Correctness IssuesNone found. Suggestions
Prompt for AI agents |
Use the baton CLI published with the baton-sdk version selected by go.mod instead of the legacy standalone release, which cannot read the upgraded connector's Pebble-backed C1Z files. Support the SDK's Linux tarballs and macOS zip archives, and fail installation on HTTP download errors. Make the lifecycle test explicitly use Pebble. Check grant membership with any() so unrelated principals and result ordering cannot produce false failures or false successes. Select Bash explicitly to enable pipefail for the job, and correct the shell options in the user ID lookup so errors from baton cannot be masked by successful jq commands. Remove the Postgres service and BATON_DSN from capability generation to exercise the credential-free, zero-value connector path in CI. Refresh .golangci.yml from the locally updated baton-admin source config with goimports enabled, restoring formatting checks after the v2 migration. The corresponding baton-admin source change must be committed separately. Validation: - All 14 lifecycle steps passed locally against Postgres 16 with Pebble and the baton-sdk v0.29.0 CLI, including grant/revoke/re-grant and account creation, role assignment, and deletion. - All 18 membership and producer-failure checks passed. - Actionlint, shellcheck, golangci-lint, and git diff checks passed. - Credential-free capability output matched baton_capabilities.json. - CGO-disabled builds passed for Linux and macOS on amd64/arm64 and Windows amd64, matching the shared release templates' CGO settings. Lifecycle validation ran on macOS arm64, not the GitHub Ubuntu runner.
Reject empty or multiple role matches before writing NEW_USER_ID to the GitHub environment file, with clear lookup errors. Normalize Linux aarch64 to arm64 when selecting the SDK CLI release asset. Regenerate the config with baton-sdk v0.29.0, including GetString support for byte slices. Validation: all 14 Postgres/Pebble lifecycle steps passed with the rebuilt connector; lookup edge cases, platform asset selection, actionlint, shellcheck, and diff checks passed.
Verify the selected SDK CLI archive against its release SHA-256 manifest before extraction. Support sha256sum and the macOS shasum fallback, and reject missing checksums without accepting unrelated local files. Extend the zero-value connector regression test to exercise GetMetadata and the CLI's preferred GetCapabilities path, including account provisioning and credential rotation details. Validation: capability test, lint, shellcheck, and diff checks passed. Verified valid, corrupt, missing, and malformed checksum cases with both hash tools; checked the actual v0.29.0 release and confirmed failed downloads cannot fall back to stale files.
| // The capabilities subcommand runs without a DSN: it builds the zero-value | ||
| // connector instead of validating the required flag. | ||
| _, cmd, err := configschema.DefineConfiguration(ctx, "baton-postgresql", getConnector, cfg.Config, | ||
| connectorrunner.WithDefaultCapabilitiesConnectorBuilder(&connector.Postgresql{})) |
There was a problem hiding this comment.
I think we have a newer way of doing this - RunConnector.
There was a problem hiding this comment.
we do! this connector is ancient and I figured the v2 migration was fit for another change, since the goal here is to get this connector baton-admin managed and stop drifting.
| POSTGRES_PASSWORD: secretpassword | ||
| env: | ||
| BATON_LOG_LEVEL: debug | ||
| BATON_STORAGE_ENGINE: pebble |
There was a problem hiding this comment.
We default to pebble now, so this isn't really needed.
| @@ -77,19 +81,19 @@ jobs: | |||
| run: ./baton-postgresql --grant-entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --grant-principal "${{ env.CONNECTOR_PRINCIPAL }}" --grant-principal-type "${{ env.CONNECTOR_PRINCIPAL_TYPE }}" | |||
|
|
|||
| - name: Check grant was granted | |||
There was a problem hiding this comment.
It can be in another PR, but we can replace this with the sync test action. Getting that test to pass will require changing main() to use RunConnector though, since it checks the exit code for bad credentials.
| ARCH=$(uname -m) | ||
| if [ "${ARCH}" = "x86_64" ]; then | ||
| ARCH="amd64" | ||
| elif [ "${ARCH}" = "aarch64" ]; then |
There was a problem hiding this comment.
This script can be replaced with the get baton action, but the sync action gets the baton utility, so again it's a change that doesn't need to happen in this PR.
Upgrade baton-sdk from v0.3.9 to v0.29.0 and prepare the connector for baton-admin's managed CI and metadata generation workflows.
SDK and connector compatibility:
Credential-free capability generation:
CI and test maintenance:
Validation:
Validation used local Go 1.27.1 and golangci-lint 2.13.2. The exact CI tool versions and GitHub Actions execution were not verified locally. Deployment of baton-admin's managed workflows remains a separate step.