|
76 | 76 | allowedTableNameChars = regexp.MustCompile(`^[a-z0-9./_]*$`) |
77 | 77 | ) |
78 | 78 |
|
| 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 | + |
79 | 87 | 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 { |
80 | 93 | return &ConfigurationStore{ |
81 | 94 | logger: logger, |
| 95 | + enableAzureAD: !opts.NoAzureAD, |
| 96 | + enableAWSIAM: !opts.NoAWSIAM, |
82 | 97 | } |
83 | 98 | } |
84 | 99 |
|
@@ -114,21 +129,20 @@ func (p *ConfigurationStore) Init(ctx context.Context, metadata configuration.Me |
114 | 129 | p.awsAuthProvider.UpdatePostgres(ctx, config) |
115 | 130 | } |
116 | 131 |
|
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) |
118 | 135 | if err != nil { |
119 | 136 | return fmt.Errorf("PostgreSQL configuration store connection error: %w", err) |
120 | 137 | } |
121 | 138 |
|
122 | | - err = pool.Ping(ctx) |
| 139 | + pingCtx, pingCancel := context.WithTimeout(ctx, p.metadata.Timeout) |
| 140 | + defer pingCancel() |
| 141 | + err = p.client.Ping(pingCtx) |
123 | 142 | if err != nil { |
124 | 143 | return fmt.Errorf("PostgreSQL configuration store ping error: %w", err) |
125 | 144 | } |
126 | | - p.client = pool |
127 | 145 |
|
128 | | - err = p.client.Ping(ctx) |
129 | | - if err != nil { |
130 | | - return fmt.Errorf("unable to connect to configuration store: '%w'", err) |
131 | | - } |
132 | 146 | // check if table exists |
133 | 147 | exists := false |
134 | 148 | err = p.client.QueryRow(ctx, QueryTableExists, p.metadata.ConfigTable).Scan(&exists) |
|
0 commit comments