mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-22 23:22:27 -04:00
Fix db connection of auth
This commit is contained in:
@@ -6,8 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
@@ -78,7 +76,7 @@ func (s *MetadataService) setupDb() (*pgxpool.Pool, error) {
|
||||
connectionString := os.Getenv("POSTGRES_URL")
|
||||
config, err := pgxpool.ParseConfig(connectionString)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to create postgres config from environment variables")
|
||||
return nil, fmt.Errorf("failed to create postgres config from environment variables: %v", err)
|
||||
}
|
||||
|
||||
// Set default values
|
||||
@@ -88,19 +86,6 @@ func (s *MetadataService) setupDb() (*pgxpool.Pool, error) {
|
||||
if config.ConnConfig.Database == "" {
|
||||
config.ConnConfig.Database = "kyoo"
|
||||
}
|
||||
// The pgx library will set the username to the name of the current user if not provided via
|
||||
// environment variable or connection string. Make a best-effort attempt to see if the user
|
||||
// was explicitly specified, without implementing full connection string parsing. If not, set
|
||||
// the username to the default value of "kyoo".
|
||||
if os.Getenv("PGUSER") == "" {
|
||||
currentUserName, _ := user.Current()
|
||||
// If the username matches the current user and it's not in the connection string, then it was set
|
||||
// by the pgx library. This doesn't cover the case where the system username happens to be in some other part
|
||||
// of the connection string, but this cannot be checked without full connection string parsing.
|
||||
if currentUserName.Username == config.ConnConfig.User && !strings.Contains(connectionString, currentUserName.Username) {
|
||||
config.ConnConfig.User = "kyoo"
|
||||
}
|
||||
}
|
||||
if _, ok := config.ConnConfig.RuntimeParams["application_name"]; !ok {
|
||||
config.ConnConfig.RuntimeParams["application_name"] = "gocoder"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user