LinkinStars commented on code in PR #1244:
URL: https://github.com/apache/answer/pull/1244#discussion_r1986783426
##########
internal/install/install_req.go:
##########
@@ -59,8 +66,22 @@ func (r *CheckDatabaseReq) GetConnection() string {
}
if r.DbType == string(schemas.POSTGRES) {
host, port := parsePgSQLHostPort(r.DbHost)
- return fmt.Sprintf("host=%s port=%s user=%s password=%s
dbname=%s sslmode=disable",
- host, port, r.DbUsername, r.DbPassword, r.DbName)
+ if !r.Ssl {
+ return fmt.Sprintf("host=%s port=%s user=%s password=%s
dbname=%s sslmode=disable",
+ host, port, r.DbUsername, r.DbPassword,
r.DbName)
+ } else if r.SslMode == "require" {
+ return fmt.Sprintf("host=%s port=%s user=%s password=%s
dbname=%s sslmode=%s",
+ host, port, r.DbUsername, r.DbPassword,
r.DbName, r.SslMode)
+ } else if r.SslMode == "verify-ca" || r.SslMode ==
"verify-full" {
+ _, err_server_ca := os.Stat(r.SslCrt)
+ _, err_client_cert := os.Stat(r.SslKey)
+ _, err_client_key := os.Stat(r.SslCrtClient)
+ if err_server_ca == nil || err_client_cert == nil ||
err_client_key == nil {
+ return fmt.Sprintf("host=%s port=%s user=%s
password=%s dbname=%s sslmode=%s sslrootcert=%s sslcert=%s sslkey=%s",
+ host, port, r.DbUsername, r.DbPassword,
r.DbName, r.SslMode, r.SslCrt, r.SslCrtClient, r.SslKey)
+ }
+ log.Fatal("Certificate not Found !!")
Review Comment:
1. Use the `dir.CheckFileExist` instead.
2. You don't need to `log.Fatal` if the file does not exist in this part.
`log.Fatal` will cause panic.
If the file does not exist, the front end will show the error message when
calling the `/installation/db/check` API. You can just log the warning message.
```go
if dir.CheckFileExist(r.SslCrt) {
log.Warnf("ssl crt file not exist: %s", r.SslCrt)
}
if dir.CheckFileExist(r.SslCrtClient) {
log.Warnf("ssl crt client file not exist: %s", r.SslCrtClient)
}
if dir.CheckFileExist(r.SslKey) {
log.Warnf("ssl key file not exist: %s", r.SslKey)
}
return fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s
sslrootcert=%s sslcert=%s sslkey=%s",
host, port, r.DbUsername, r.DbPassword, r.DbName, r.SslMode, r.SslCrt,
r.SslCrtClient, r.SslKey)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]