-
Notifications
You must be signed in to change notification settings - Fork 2
CXH-2381: document Db2 setup, correct the supported-database list, and fix the help link #150
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
base: main
Are you sure you want to change the base?
Changes from all commits
185feae
37b4e0c
3b9c320
fde489f
2f22821
8de4cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,9 @@ func (c *Connector) Validate(ctx context.Context) (annotations.Annotations, erro | |
|
|
||
| for name, db := range c.dbs { | ||
| if err := db.PingContext(ctx); err != nil { | ||
| if authErr := database.AuthError(err); authErr != nil { | ||
| return nil, authErr | ||
| } | ||
|
Comment on lines
+100
to
+102
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. 🟡 Suggestion: this early return discards both the database name and the driver's message, so a multi-database config that fails auth on one connection logs only |
||
| return nil, fmt.Errorf("database %q ping failed: %w", name, err) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strings" | ||
|
|
||
| "github.com/go-sql-driver/mysql" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| const mysqlAccessDenied = 1045 | ||
|
|
||
| // AuthError returns an Unauthenticated gRPC status when err is a database | ||
| // authentication/authorization failure, or nil otherwise. SQLSTATE class 28 | ||
| // ("invalid authorization") is the ANSI code drivers report on bad credentials | ||
| // (Postgres/Redshift/Vertica/etc. surface it via SQLState()); MySQL is the | ||
| // exception, reporting error 1045 with no SQLSTATE. | ||
| func AuthError(err error) error { | ||
| if err == nil { | ||
| return nil | ||
| } | ||
|
|
||
| var sqlState interface{ SQLState() string } | ||
| if errors.As(err, &sqlState) && strings.HasPrefix(sqlState.SQLState(), "28") { | ||
| return status.Error(codes.Unauthenticated, "database authentication failed") | ||
| } | ||
|
Comment on lines
+14
to
+27
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. 🟡 Suggestion: the |
||
|
|
||
| var myErr *mysql.MySQLError | ||
| if errors.As(err, &myErr) && myErr.Number == mysqlAccessDenied { | ||
| return status.Error(codes.Unauthenticated, "database authentication failed") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/go-sql-driver/mysql" | ||
| "github.com/jackc/pgx/v5/pgconn" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| func TestAuthError(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| err error | ||
| want codes.Code // codes.OK means expect nil | ||
| }{ | ||
| {"nil", nil, codes.OK}, | ||
| {"postgres invalid_password 28P01", &pgconn.PgError{Code: "28P01"}, codes.Unauthenticated}, | ||
| {"postgres invalid_authorization 28000", &pgconn.PgError{Code: "28000"}, codes.Unauthenticated}, | ||
| {"postgres non-auth relation missing 42P01", &pgconn.PgError{Code: "42P01"}, codes.OK}, | ||
| {"postgres auth error wrapped", fmt.Errorf("ping: %w", &pgconn.PgError{Code: "28P01"}), codes.Unauthenticated}, | ||
| {"mysql access denied 1045", &mysql.MySQLError{Number: 1045}, codes.Unauthenticated}, | ||
| {"mysql other 1146", &mysql.MySQLError{Number: 1146}, codes.OK}, | ||
| {"plain error", errors.New("boom"), codes.OK}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := AuthError(tt.err) | ||
| if tt.want == codes.OK { | ||
| if got != nil { | ||
| t.Fatalf("want nil, got %v", got) | ||
| } | ||
| return | ||
| } | ||
| if status.Code(got) != tt.want { | ||
| t.Fatalf("want %v, got %v", tt.want, status.Code(got)) | ||
| } | ||
| }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.