Skip to content

Commit 1c09c95

Browse files
adegroffaarondegroffyaron2
authored
FIX: Add options for Azure AD and AWS IAM in configuration.postgresql/v1 (#3977)
Signed-off-by: aarondegroff <[email protected]> Signed-off-by: Aaron DeGroff <[email protected]> Co-authored-by: aarondegroff <[email protected]> Co-authored-by: Yaron Schneider <[email protected]>
1 parent ab1dd7f commit 1c09c95

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

configuration/postgres/metadata.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func (m *metadata) InitWithMetadata(meta map[string]string) error {
6363
return fmt.Errorf("invalid table name '%s'. non-alphanumerics or upper cased table names are not supported", m.ConfigTable)
6464
}
6565

66+
// Timeout
67+
if m.Timeout < 1*time.Second {
68+
return errors.New("invalid value for 'timeout': must be greater than 1s")
69+
}
70+
6671
opts := pgauth.InitWithMetadataOpts{
6772
AzureADEnabled: true,
6873
AWSIAMEnabled: true,

configuration/postgres/postgres.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,24 @@ var (
7676
allowedTableNameChars = regexp.MustCompile(`^[a-z0-9./_]*$`)
7777
)
7878

79+
type Options struct {
80+
// Disables support for authenticating with Azure AD
81+
NoAzureAD bool
82+
83+
// Disables support for authenticating with AWS IAM
84+
NoAWSIAM bool
85+
}
86+
7987
func NewPostgresConfigurationStore(logger logger.Logger) configuration.Store {
88+
return NewPostgresConfigurationStoreWithOptions(logger, Options{})
89+
}
90+
91+
// NewPostgresConfigurationStoreWithOptions creates a new instance of PostgreSQL store with options.
92+
func NewPostgresConfigurationStoreWithOptions(logger logger.Logger, opts Options) configuration.Store {
8093
return &ConfigurationStore{
8194
logger: logger,
95+
enableAzureAD: !opts.NoAzureAD,
96+
enableAWSIAM: !opts.NoAWSIAM,
8297
}
8398
}
8499

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

117-
pool, err := pgxpool.NewWithConfig(ctx, config)
132+
connCtx, connCancel := context.WithTimeout(ctx, p.metadata.Timeout)
133+
defer connCancel()
134+
p.client, err = pgxpool.NewWithConfig(connCtx, config)
118135
if err != nil {
119136
return fmt.Errorf("PostgreSQL configuration store connection error: %w", err)
120137
}
121138

122-
err = pool.Ping(ctx)
139+
pingCtx, pingCancel := context.WithTimeout(ctx, p.metadata.Timeout)
140+
defer pingCancel()
141+
err = p.client.Ping(pingCtx)
123142
if err != nil {
124143
return fmt.Errorf("PostgreSQL configuration store ping error: %w", err)
125144
}
126-
p.client = pool
127145

128-
err = p.client.Ping(ctx)
129-
if err != nil {
130-
return fmt.Errorf("unable to connect to configuration store: '%w'", err)
131-
}
132146
// check if table exists
133147
exists := false
134148
err = p.client.QueryRow(ctx, QueryTableExists, p.metadata.ConfigTable).Scan(&exists)

state/postgresql/v2/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (m *pgMetadata) InitWithMetadata(meta state.Metadata, opts pgauth.InitWithM
6060
return err
6161
}
6262

63-
// Validate and sanitize inputq
63+
// Validate and sanitize input
6464
err = m.PostgresAuthMetadata.InitWithMetadata(meta.Properties, opts)
6565
if err != nil {
6666
return err

0 commit comments

Comments
 (0)