Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configuration/postgres/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (m *metadata) InitWithMetadata(meta map[string]string) error {
return fmt.Errorf("invalid table name '%s'. non-alphanumerics or upper cased table names are not supported", m.ConfigTable)
}

// Timeout
if m.Timeout < 1*time.Second {
return errors.New("invalid value for 'timeout': must be greater than 1s")
}

opts := pgauth.InitWithMetadataOpts{
AzureADEnabled: true,
AWSIAMEnabled: true,
Expand Down
28 changes: 21 additions & 7 deletions configuration/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,24 @@ var (
allowedTableNameChars = regexp.MustCompile(`^[a-z0-9./_]*$`)
)

type Options struct {
// Disables support for authenticating with Azure AD
NoAzureAD bool

// Disables support for authenticating with AWS IAM
NoAWSIAM bool
}

func NewPostgresConfigurationStore(logger logger.Logger) configuration.Store {
return NewPostgresConfigurationStoreWithOptions(logger, Options{})
}

// NewPostgresConfigurationStoreWithOptions creates a new instance of PostgreSQL store with options.
func NewPostgresConfigurationStoreWithOptions(logger logger.Logger, opts Options) configuration.Store {
return &ConfigurationStore{
logger: logger,
enableAzureAD: !opts.NoAzureAD,
enableAWSIAM: !opts.NoAWSIAM,
}
}

Expand Down Expand Up @@ -114,21 +129,20 @@ func (p *ConfigurationStore) Init(ctx context.Context, metadata configuration.Me
p.awsAuthProvider.UpdatePostgres(ctx, config)
}

pool, err := pgxpool.NewWithConfig(ctx, config)
connCtx, connCancel := context.WithTimeout(ctx, p.metadata.Timeout)
defer connCancel()
p.client, err = pgxpool.NewWithConfig(connCtx, config)
if err != nil {
return fmt.Errorf("PostgreSQL configuration store connection error: %w", err)
}

err = pool.Ping(ctx)
pingCtx, pingCancel := context.WithTimeout(ctx, p.metadata.Timeout)
defer pingCancel()
err = p.client.Ping(pingCtx)
if err != nil {
return fmt.Errorf("PostgreSQL configuration store ping error: %w", err)
}
p.client = pool

err = p.client.Ping(ctx)
if err != nil {
return fmt.Errorf("unable to connect to configuration store: '%w'", err)
}
// check if table exists
exists := false
err = p.client.QueryRow(ctx, QueryTableExists, p.metadata.ConfigTable).Scan(&exists)
Expand Down
2 changes: 1 addition & 1 deletion state/postgresql/v2/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (m *pgMetadata) InitWithMetadata(meta state.Metadata, opts pgauth.InitWithM
return err
}

// Validate and sanitize inputq
// Validate and sanitize input
err = m.PostgresAuthMetadata.InitWithMetadata(meta.Properties, opts)
if err != nil {
return err
Expand Down