Skip to content

Commit dcaa80e

Browse files
authored
style: pg cleaning up for things (#3627)
Signed-off-by: Samantha Coyle <[email protected]>
1 parent 1e295a7 commit dcaa80e

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

common/authentication/aws/static.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,8 @@ func (a *StaticAuth) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.C
262262
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
263263

264264
// First, check if there are credentials set explicitly with accesskey and secretkey
265-
var creds credentials.Value
266-
if a.session != nil {
267-
var err error
268-
creds, err = a.session.Config.Credentials.Get()
269-
if err != nil {
270-
a.logger.Infof("failed to get access key and secret key, will fallback to reading the default AWS credentials file: %w", err)
271-
}
272-
}
273-
274-
if creds.AccessKeyID != "" && creds.SecretAccessKey != "" {
275-
creds, err := a.session.Config.Credentials.Get()
276-
if err != nil {
277-
return "", fmt.Errorf("failed to retrieve session credentials: %w", err)
278-
}
279-
awsCfg := v2creds.NewStaticCredentialsProvider(creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken)
265+
if a.accessKey != nil && a.secretKey != nil {
266+
awsCfg := v2creds.NewStaticCredentialsProvider(*a.accessKey, *a.secretKey, a.sessionToken)
280267
authenticationToken, err := auth.BuildAuthToken(
281268
ctx, dbEndpoint, *a.region, poolConfig.ConnConfig.User, awsCfg)
282269
if err != nil {

common/authentication/aws/x509.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ func (a *x509) Ses() *SesClients {
312312
func (a *x509) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.Config) (string, error) {
313313
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
314314

315-
// First, check if there are credentials set explicitly with accesskey and secretkey
315+
// First, check session credentials.
316+
// This should always be what we use to generate the x509 auth credentials for postgres.
317+
// However, we can leave the Second and Lastly checks as backup for now.
316318
var creds credentials.Value
317319
if a.session != nil {
318320
var err error

0 commit comments

Comments
 (0)