add option to specify sslmode for nats-api pg connection closes #1049

This commit is contained in:
wh1te909
2022-04-05 21:14:22 +00:00
parent 7567042c8a
commit c9135f1573
5 changed files with 10 additions and 3 deletions

View File

@@ -12,6 +12,11 @@ class Command(BaseCommand):
self.stdout.write("Creating configuration for nats-api...")
db = settings.DATABASES["default"]
if hasattr(settings, "DB_SSL"):
ssl = settings.DB_SSL
else:
ssl = "disable"
config = {
"key": settings.SECRET_KEY,
"natsurl": f"tls://{settings.ALLOWED_HOSTS[0]}:4222",
@@ -20,6 +25,7 @@ class Command(BaseCommand):
"host": db["HOST"],
"port": int(db["PORT"]),
"dbname": db["NAME"],
"sslmode": ssl,
}
conf = os.path.join(settings.BASE_DIR, "nats-api.conf")
with open(conf, "w") as f:

View File

@@ -11,7 +11,7 @@ import (
)
var (
version = "3.0.1"
version = "3.0.2"
log = logrus.New()
)

Binary file not shown.

View File

@@ -13,4 +13,5 @@ type DjangoConfig struct {
Host string `json:"host"`
Port int `json:"port"`
DBName string `json:"dbname"`
SSLMode string `json:"sslmode"`
}

View File

@@ -41,8 +41,8 @@ func GetConfig(cfg string) (db *sqlx.DB, r DjangoConfig, err error) {
}
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
r.Host, r.Port, r.User, r.Pass, r.DBName)
"password=%s dbname=%s sslmode=%s",
r.Host, r.Port, r.User, r.Pass, r.DBName, r.SSLMode)
db, err = sqlx.Connect("postgres", psqlInfo)
if err != nil {