Fix semgrep sprintf-host-port (#15782)

Signed-off-by: Soumik Majumder <soumikm@vmware.com>
This commit is contained in:
Soumik Majumder 2021-10-14 17:40:27 +05:30 committed by GitHub
parent b4c2ff7768
commit eb7329a471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -16,12 +16,14 @@ package dao
import (
"fmt"
"github.com/goharbor/harbor/src/common/models"
"net"
"net/url"
"os"
"strconv"
"time"
"github.com/goharbor/harbor/src/common/models"
"github.com/astaxie/beego/orm"
"github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/lib/log"
@ -74,7 +76,7 @@ func NewPGSQL(host string, port string, usr string, pwd string, database string,
// Register registers pgSQL to orm with the info wrapped by the instance.
func (p *pgsql) Register(alias ...string) error {
if err := utils.TestTCPConn(fmt.Sprintf("%s:%s", p.host, p.port), 60, 2); err != nil {
if err := utils.TestTCPConn(net.JoinHostPort(p.host, p.port), 60, 2); err != nil {
return err
}
@ -142,7 +144,7 @@ func NewMigrator(database *models.PostGreSQL) (*migrate.Migrate, error) {
dbURL := url.URL{
Scheme: "postgres",
User: url.UserPassword(database.Username, database.Password),
Host: fmt.Sprintf("%s:%d", database.Host, database.Port),
Host: net.JoinHostPort(database.Host, strconv.Itoa(database.Port)),
Path: database.Database,
RawQuery: fmt.Sprintf("sslmode=%s", database.SSLMode),
}

View File

@ -1,9 +1,10 @@
package exporter
import (
"fmt"
"net"
"net/http"
"net/url"
"strconv"
)
var hbrCli *HarborClient
@ -19,7 +20,7 @@ type HarborClient struct {
func (hc HarborClient) harborURL(p string) url.URL {
return url.URL{
Scheme: hc.HarborScheme,
Host: fmt.Sprintf("%s:%d", hc.HarborHost, hc.HarborPort),
Host: net.JoinHostPort(hc.HarborHost, strconv.Itoa(hc.HarborPort)),
Path: p,
}
}