Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1953123

Browse files
committed
Merge branch 'dump-available-databases' into 'master'
fix(engine): by default, dump only databases to which user have access See merge request postgres-ai/database-lab!501
2 parents 18cfa5a + 71aa34f commit 1953123

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

‎engine/internal/retrieval/engine/postgres/logical/dump.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ type dumper interface {
117117
SetConnectionOptions(context.Context, *Connection) error
118118

119119
// GetDatabaseListQuery provides the query to get the list of databases for dumping.
120-
GetDatabaseListQuery() string
120+
GetDatabaseListQuery(usernamestring) string
121121
}
122122

123123
// Connection provides connection options.
@@ -379,7 +379,7 @@ func (d *DumpJob) getDBList(ctx context.Context) (map[string]DumpDefinition, err
379379
return nil, fmt.Errorf("failed to connect to DB: %w", err)
380380
}
381381

382-
rows, err := querier.Query(ctx, d.dumper.GetDatabaseListQuery())
382+
rows, err := querier.Query(ctx, d.dumper.GetDatabaseListQuery(d.config.db.Username))
383383
if err != nil {
384384
return nil, fmt.Errorf("failed to perform query listing databases: %w", err)
385385
}

‎engine/internal/retrieval/engine/postgres/logical/dump_default.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package logical
66

77
import (
88
"context"
9+
"fmt"
910
)
1011

1112
type defaultDumper struct {
@@ -25,6 +26,7 @@ func (d *defaultDumper) SetConnectionOptions(_ context.Context, c *Connection) e
2526
return nil
2627
}
2728

28-
func (d *defaultDumper) GetDatabaseListQuery() string {
29-
return "select datname from pg_catalog.pg_database where not datistemplate"
29+
func (d *defaultDumper) GetDatabaseListQuery(username string) string {
30+
return fmt.Sprintf(`select datname from pg_catalog.pg_database
31+
where not datistemplate and has_database_privilege('%s', datname, 'CONNECT')`, username)
3032
}

‎engine/internal/retrieval/engine/postgres/logical/dump_rds.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (r *rdsDumper) SetConnectionOptions(ctx context.Context, c *Connection) err
108108
return nil
109109
}
110110

111-
func (r *rdsDumper) GetDatabaseListQuery() string {
112-
return "select datname from pg_catalog.pg_database where not datistemplate"
111+
func (r *rdsDumper) GetDatabaseListQuery(username string) string {
112+
return fmt.Sprintf(`select datname from pg_catalog.pg_database
113+
where not datistemplate and has_database_privilege('%s', datname, 'CONNECT')`, username)
113114
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /