style: pg cleaning up for things (#3627)
Signed-off-by: Samantha Coyle <sam@diagrid.io>
This commit is contained in:
parent
1e295a7056
commit
dcaa80eef8
|
@ -262,21 +262,8 @@ func (a *StaticAuth) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.C
|
||||||
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
|
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
|
||||||
|
|
||||||
// First, check if there are credentials set explicitly with accesskey and secretkey
|
// First, check if there are credentials set explicitly with accesskey and secretkey
|
||||||
var creds credentials.Value
|
if a.accessKey != nil && a.secretKey != nil {
|
||||||
if a.session != nil {
|
awsCfg := v2creds.NewStaticCredentialsProvider(*a.accessKey, *a.secretKey, a.sessionToken)
|
||||||
var err error
|
|
||||||
creds, err = a.session.Config.Credentials.Get()
|
|
||||||
if err != nil {
|
|
||||||
a.logger.Infof("failed to get access key and secret key, will fallback to reading the default AWS credentials file: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if creds.AccessKeyID != "" && creds.SecretAccessKey != "" {
|
|
||||||
creds, err := a.session.Config.Credentials.Get()
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to retrieve session credentials: %w", err)
|
|
||||||
}
|
|
||||||
awsCfg := v2creds.NewStaticCredentialsProvider(creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken)
|
|
||||||
authenticationToken, err := auth.BuildAuthToken(
|
authenticationToken, err := auth.BuildAuthToken(
|
||||||
ctx, dbEndpoint, *a.region, poolConfig.ConnConfig.User, awsCfg)
|
ctx, dbEndpoint, *a.region, poolConfig.ConnConfig.User, awsCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -312,7 +312,9 @@ func (a *x509) Ses() *SesClients {
|
||||||
func (a *x509) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.Config) (string, error) {
|
func (a *x509) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.Config) (string, error) {
|
||||||
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
|
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
|
||||||
|
|
||||||
// First, check if there are credentials set explicitly with accesskey and secretkey
|
// First, check session credentials.
|
||||||
|
// This should always be what we use to generate the x509 auth credentials for postgres.
|
||||||
|
// However, we can leave the Second and Lastly checks as backup for now.
|
||||||
var creds credentials.Value
|
var creds credentials.Value
|
||||||
if a.session != nil {
|
if a.session != nil {
|
||||||
var err error
|
var err error
|
||||||
|
|
Loading…
Reference in New Issue