Skip to content

Commit

Permalink
remove keys from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Apr 24, 2024
1 parent 9bb6c67 commit 47809ad
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 37 deletions.
10 changes: 1 addition & 9 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ func (s *Source) Configure(_ context.Context, cfg map[string]string) error {
if err != nil {
return err
}
s.tableKeys, err = s.config.Validate()
if err != nil {
return err
}
return nil
return s.config.Validate()
}

func (s *Source) Open(ctx context.Context, pos sdk.Position) error {
Expand All @@ -81,10 +77,6 @@ func (s *Source) Open(ctx context.Context, pos sdk.Position) error {

// ensure we have keys for all tables
for _, tableName := range s.config.Tables {
// get unprovided table keys
if _, ok := s.tableKeys[tableName]; ok {
continue // key was provided manually
}
s.tableKeys[tableName], err = s.getTableKeys(ctx, tableName)
if err != nil {
return fmt.Errorf("failed to find key for table %s (try specifying it manually): %w", tableName, err)
Expand Down
21 changes: 4 additions & 17 deletions source/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package source

import (
"fmt"
"strings"

"github.com/jackc/pgx/v5"
)

Expand Down Expand Up @@ -53,8 +51,6 @@ type Config struct {
// Tables is a List of table names to read from, separated by a comma, e.g.:"table1,table2".
// Use "*" if you'd like to listen to all tables.
Tables []string `json:"table" validate:"required"`
// Key is a list of Key column names per table, e.g.:"table1:key1,table2:key2", records should use the key values for their `Key` fields.
Key []string `json:"key"`

// SnapshotMode is whether the plugin will take a snapshot of the entire table before starting cdc mode.
SnapshotMode SnapshotMode `json:"snapshotMode" validate:"inclusion=initial|never" default:"initial"`
Expand All @@ -70,24 +66,15 @@ type Config struct {
}

// Validate validates the provided config values.
func (c Config) Validate() (map[string]string, error) {
func (c Config) Validate() error {
// try parsing the url
_, err := pgx.ParseConfig(c.URL)
if err != nil {
return nil, fmt.Errorf("invalid url: %w", err)
return fmt.Errorf("invalid url: %w", err)
}
// TODO: when cdcMode "auto" is implemented, change this check
if len(c.Tables) != 1 && c.CDCMode == CDCModeLongPolling {
return nil, fmt.Errorf("multi-tables are only supported for logrepl CDCMode, please provide only one table")
}
tableKeys := make(map[string]string, len(c.Tables))
for _, pair := range c.Key {
// Split each pair into key and value
parts := strings.Split(pair, ":")
if len(parts) != 2 {
return nil, fmt.Errorf("wrong format for the configuration %q, use comma separated pairs of tables and keys, example: table1:key1,table2:key2", "key")
}
tableKeys[parts[0]] = parts[1]
return fmt.Errorf("multi-tables are only supported for logrepl CDCMode, please provide only one table")
}
return tableKeys, nil
return nil
}
6 changes: 1 addition & 5 deletions source/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func TestConfig_Validate(t *testing.T) {
cfg: Config{
URL: "postgresql://meroxauser:[email protected]:5432/meroxadb",
Tables: []string{"table1", "table2"},
Key: []string{"table1:key1"},
CDCMode: CDCModeLogrepl,
},
wantErr: false,
Expand All @@ -40,7 +39,6 @@ func TestConfig_Validate(t *testing.T) {
cfg: Config{
URL: "postgresql",
Tables: []string{"table1", "table2"},
Key: []string{"table1:key1"},
CDCMode: CDCModeLogrepl,
},
wantErr: true,
Expand All @@ -49,7 +47,6 @@ func TestConfig_Validate(t *testing.T) {
cfg: Config{
URL: "postgresql://meroxauser:[email protected]:5432/meroxadb",
Tables: []string{"table1", "table2"},
Key: []string{"table1:key1"},
CDCMode: CDCModeLongPolling,
},
wantErr: true,
Expand All @@ -58,7 +55,6 @@ func TestConfig_Validate(t *testing.T) {
cfg: Config{
URL: "postgresql://meroxauser:[email protected]:5432/meroxadb",
Tables: []string{"table1", "table2"},
Key: []string{"key1,key2"},
CDCMode: CDCModeLogrepl,
},
wantErr: true,
Expand All @@ -67,7 +63,7 @@ func TestConfig_Validate(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
is := is.New(t)
_, err := tc.cfg.Validate()
err := tc.cfg.Validate()
if tc.wantErr {
is.True(err != nil)
return
Expand Down
6 changes: 0 additions & 6 deletions source/paramgen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 47809ad

Please sign in to comment.