add option to specify sslmode for nats-api pg connection closes #1049
This commit is contained in:
		@@ -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:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							@@ -11,7 +11,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	version = "3.0.1"
 | 
			
		||||
	version = "3.0.2"
 | 
			
		||||
	log     = logrus.New()
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							@@ -13,4 +13,5 @@ type DjangoConfig struct {
 | 
			
		||||
	Host    string `json:"host"`
 | 
			
		||||
	Port    int    `json:"port"`
 | 
			
		||||
	DBName  string `json:"dbname"`
 | 
			
		||||
	SSLMode string `json:"sslmode"`
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user