-
Notifications
You must be signed in to change notification settings - Fork 1
chore: modernize PostgreSQL connector for baton-admin #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d65a85e
chore: modernize PostgreSQL connector for baton-admin
jugonzalez12 8877fc8
fix: modernize CI validation for Pebble and credential-free metadata
jugonzalez12 1bec85a
fix: validate CI user lookup and refresh SDK-generated config
jugonzalez12 f4c0c29
fix: verify SDK CLI checksums and test capability metadata
jugonzalez12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,18 +7,18 @@ jobs: | |
| - name: Install Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: 1.23.x | ||
| go-version: 1.25.x | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Run linters | ||
| uses: golangci/golangci-lint-action@v3 | ||
| uses: golangci/golangci-lint-action@v9 | ||
| with: | ||
| version: latest | ||
| version: v2.11.4 | ||
| args: --timeout=10m | ||
| go-test: | ||
| strategy: | ||
| matrix: | ||
| go-version: [1.23.x] | ||
| go-version: [1.25.x] | ||
| platform: [ubuntu-latest] | ||
| runs-on: ${{ matrix.platform }} | ||
| steps: | ||
|
|
@@ -38,6 +38,9 @@ jobs: | |
| test-results: test.json | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| shell: bash | ||
| services: | ||
| postgres: | ||
| image: postgres:16 | ||
|
|
@@ -47,6 +50,7 @@ jobs: | |
| POSTGRES_PASSWORD: secretpassword | ||
| env: | ||
| BATON_LOG_LEVEL: debug | ||
| BATON_STORAGE_ENGINE: pebble | ||
| BATON_DSN: "postgres://postgres:secretpassword@localhost:5432/postgres" | ||
| CONNECTOR_GRANT: "grant:entitlement:role:3375:member:role:10" | ||
| CONNECTOR_ENTITLEMENT: "entitlement:role:3375:member" | ||
|
|
@@ -57,7 +61,7 @@ jobs: | |
| - name: Install Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: 1.23.x | ||
| go-version: 1.25.x | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| - name: Install postgres client | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| run: ./baton-postgresql && baton grants --entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\"" | ||
| run: ./baton-postgresql && baton grants --entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status --arg principal "${{ env.CONNECTOR_PRINCIPAL }}" 'any(.grants[]?; .principal.id.resource == $principal)' | ||
|
|
||
| - name: Revoke grant | ||
| run: ./baton-postgresql --revoke-grant "${{ env.CONNECTOR_GRANT }}" | ||
|
|
||
| - name: Check grant was revoked | ||
| run: ./baton-postgresql && baton grants --entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status "if .grants then .grants[]?.principal.id.resource != \"${{ env.CONNECTOR_PRINCIPAL }}\" else . end" | ||
| run: ./baton-postgresql && baton grants --entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status --arg principal "${{ env.CONNECTOR_PRINCIPAL }}" 'any(.grants[]?; .principal.id.resource == $principal) | not' | ||
|
|
||
| - name: Grant entitlement | ||
| run: ./baton-postgresql --grant-entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --grant-principal "${{ env.CONNECTOR_PRINCIPAL }}" --grant-principal-type "${{ env.CONNECTOR_PRINCIPAL_TYPE }}" | ||
|
|
||
| - name: Check grant was re-granted | ||
| run: ./baton-postgresql && baton grants --entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\"" | ||
| run: ./baton-postgresql && baton grants --entitlement "${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status --arg principal "${{ env.CONNECTOR_PRINCIPAL }}" 'any(.grants[]?; .principal.id.resource == $principal)' | ||
|
|
||
| - name: Create user | ||
| run: ./baton-postgresql --create-account-login "${{ env.CONNECTOR_NEW_USER }}" | ||
|
|
@@ -100,8 +104,16 @@ jobs: | |
| - name: Fetch user id | ||
| shell: bash | ||
| run: | | ||
| set -eub pipefail | ||
| set -euo pipefail | ||
| NEW_USER_ID=$(baton resources -t role -o json | jq -r --arg login "${{ env.CONNECTOR_NEW_USER }}" '.resources[].resource | select(any(.annotations[]?; .["@type"]=="type.googleapis.com/c1.connector.v2.UserTrait" and .login==$login)) | .id.resource') | ||
| if [ -z "$NEW_USER_ID" ]; then | ||
| echo "No role found for login '$CONNECTOR_NEW_USER'" >&2 | ||
| exit 1 | ||
| fi | ||
| if [ "$(printf '%s\n' "$NEW_USER_ID" | wc -l)" -ne 1 ]; then | ||
| echo "Expected exactly one role for login '$CONNECTOR_NEW_USER', but found multiple matches" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "NEW_USER_ID=$NEW_USER_ID" >> "$GITHUB_ENV" | ||
|
jugonzalez12 marked this conversation as resolved.
|
||
|
|
||
| - name: Grant role to user | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,128 @@ | ||
| #AUTO GENERATED CODE. UPDATE THE CONFIG IN BATON-TEMPLATE FIRST | ||
| linters-settings: | ||
| exhaustive: | ||
| default-signifies-exhaustive: true | ||
| gocritic: | ||
| enabled-checks: | ||
| - ruleguard | ||
| # The list of supported checkers can be find in https://go-critic.github.io/overview. | ||
| settings: | ||
| underef: | ||
| # Whether to skip (*x).method() calls where x is a pointer receiver. | ||
| skipRecvDeref: false | ||
| ruleguard: | ||
| rules: "${configDir}/tools/rules.go" | ||
| govet: | ||
| enable-all: true | ||
| disable: | ||
| - fieldalignment # too strict | ||
| - shadow # complains too much about shadowing errors. All research points to this being fine. | ||
| nakedret: | ||
| max-func-lines: 0 | ||
| nolintlint: | ||
| allow-no-explanation: [forbidigo, tracecheck, gomnd, gochecknoinits, makezero] | ||
| require-explanation: true | ||
| require-specific: true | ||
| revive: | ||
| ignore-generated-header: true | ||
| severity: error | ||
| rules: | ||
| - name: atomic | ||
| - name: line-length-limit | ||
| arguments: [200] | ||
| # These are functions that we use without checking the errors often. Most of these can't return an error even | ||
| # though they implement an interface that can. | ||
| - name: unhandled-error | ||
| arguments: | ||
| - fmt.Printf | ||
| - fmt.Println | ||
| - fmt.Fprint | ||
| - fmt.Fprintf | ||
| - fmt.Fprintln | ||
| - os.Stderr.Sync | ||
| - sb.WriteString | ||
| - buf.WriteString | ||
| - hasher.Write | ||
| - os.Setenv | ||
| - os.RemoveAll | ||
| - name: var-naming | ||
| arguments: [["ID", "URL", "HTTP", "API"], []] | ||
| tenv: | ||
| all: true | ||
| # This file is managed by baton-admin. DO NOT EDIT!!! | ||
| version: "2" | ||
| run: | ||
| modules-download-mode: readonly | ||
| linters: | ||
| disable-all: true | ||
| default: none | ||
| enable: | ||
| - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases | ||
| - gosimple # Linter for Go source code that specializes in simplifying a code | ||
| - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string | ||
| - ineffassign # Detects when assignments to existing variables are not used | ||
| - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks | ||
| - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code | ||
| - unused # Checks Go code for unused constants, variables, functions and types | ||
| - asasalint # Check for pass []any as any in variadic func(...any) | ||
| - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers | ||
| - bidichk # Checks for dangerous unicode character sequences | ||
| - bodyclose # checks whether HTTP response body is closed successfully | ||
| - durationcheck # check for two durations multiplied together | ||
| - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. | ||
| - exhaustive # check exhaustiveness of enum switch statements | ||
| - forbidigo # Forbids identifiers | ||
| - gochecknoinits # Checks that no init functions are present in Go code | ||
| - goconst # Finds repeated strings that could be replaced by a constant | ||
| - gocritic # Provides diagnostics that check for bugs, performance and style issues. | ||
| - godot # Check if comments end in a period | ||
| - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. | ||
| - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. | ||
| - goprintffuncname # Checks that printf-like functions are named with f at the end | ||
| - gosec # Inspects source code for security problems | ||
| - nakedret # Finds naked returns in functions greater than a specified function length | ||
| - nilerr # Finds the code that returns nil even if it checks that the error is not nil. | ||
| - noctx # noctx finds sending http request without context.Context | ||
| - nolintlint # Reports ill-formed or insufficient nolint directives | ||
| - nonamedreturns # Reports all named returns | ||
| - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. | ||
| - predeclared # find code that shadows one of Go's predeclared identifiers | ||
| - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. | ||
| - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 | ||
| - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes | ||
| - unconvert # Remove unnecessary type conversions | ||
| - usestdlibvars # detect the possibility to use variables/constants from the Go standard library | ||
| - whitespace # Tool for detection of leading and trailing whitespace | ||
| - asasalint | ||
| - asciicheck | ||
| - bidichk | ||
| - bodyclose | ||
| - durationcheck | ||
| - errcheck | ||
| - errorlint | ||
| - exhaustive | ||
| - forbidigo | ||
| - gochecknoinits | ||
| - goconst | ||
| - gocritic | ||
| - godot | ||
| - gomoddirectives | ||
| - goprintffuncname | ||
| - gosec | ||
| - govet | ||
| - ineffassign | ||
| - nakedret | ||
| - nilerr | ||
| - noctx | ||
| - nolintlint | ||
| - nonamedreturns | ||
| - nosprintfhostport | ||
| - predeclared | ||
| - revive | ||
| - staticcheck | ||
| - tparallel | ||
| - unconvert | ||
| - unused | ||
| - usestdlibvars | ||
| - whitespace | ||
| settings: | ||
| exhaustive: | ||
| default-signifies-exhaustive: true | ||
| gocritic: | ||
| enabled-checks: | ||
| - ruleguard | ||
| settings: | ||
| ruleguard: | ||
| rules: ${base-path}/tools/rules.go | ||
| underef: | ||
| skipRecvDeref: false | ||
| govet: | ||
| disable: | ||
| - fieldalignment | ||
| - shadow | ||
| enable-all: true | ||
| nakedret: | ||
| max-func-lines: 0 | ||
| nolintlint: | ||
| require-explanation: true | ||
| require-specific: true | ||
| allow-no-explanation: | ||
| - forbidigo | ||
| - tracecheck | ||
| - gomnd | ||
| - gochecknoinits | ||
| - makezero | ||
| revive: | ||
| severity: error | ||
| rules: | ||
| - name: atomic | ||
| - name: line-length-limit | ||
| arguments: | ||
| - 200 | ||
| - name: unhandled-error | ||
| arguments: | ||
| - fmt.Printf | ||
| - fmt.Println | ||
| - fmt.Fprint | ||
| - fmt.Fprintf | ||
| - fmt.Fprintln | ||
| - os.Stderr.Sync | ||
| - sb.WriteString | ||
| - buf.WriteString | ||
| - hasher.Write | ||
| - os.Setenv | ||
| - os.RemoveAll | ||
| - name: var-naming | ||
| arguments: | ||
| - - ID | ||
| - URL | ||
| - HTTP | ||
| - API | ||
| - [] | ||
| exclusions: | ||
| generated: lax | ||
| presets: | ||
| - comments | ||
| - common-false-positives | ||
| - legacy | ||
| - std-error-handling | ||
| rules: | ||
| - linters: | ||
| - godot | ||
| source: (TODO) | ||
| - path: _test\.go$ | ||
| linters: | ||
| - goconst | ||
| - path: (.+)\.go$ | ||
| text: third_party$ | ||
| - path: (.+)\.go$ | ||
| text: builtin$ | ||
| - path: (.+)\.go$ | ||
| text: examples$ | ||
| paths: | ||
| - third_party$ | ||
| - builtin$ | ||
| - examples$ | ||
| issues: | ||
| max-same-issues: 50 | ||
| exclude-rules: | ||
| # Don't require TODO comments to end in a period | ||
| - source: "(TODO)" | ||
| linters: [godot] | ||
| formatters: | ||
|
jugonzalez12 marked this conversation as resolved.
|
||
| enable: | ||
| - goimports | ||
| exclusions: | ||
| generated: lax | ||
| paths: | ||
| - third_party$ | ||
| - builtin$ | ||
| - examples$ | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We default to pebble now, so this isn't really needed.