mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-05 06:21:22 +01:00
fix: fix codeql alerts
Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
parent
6f1f2c0395
commit
b37a987073
@ -24,6 +24,8 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/goharbor/harbor/src/jobservice/common/query"
|
||||
"github.com/goharbor/harbor/src/jobservice/common/utils"
|
||||
"github.com/goharbor/harbor/src/jobservice/core"
|
||||
@ -31,7 +33,6 @@ import (
|
||||
"github.com/goharbor/harbor/src/jobservice/job"
|
||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -78,7 +78,7 @@ func (br *BaseRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
if authErr == nil {
|
||||
authErr = errors.Errorf("unauthorized: %s", err)
|
||||
}
|
||||
logger.Errorf("Serve http request '%s %s' failed with error: %s", req.Method, req.URL.String(), authErr.Error())
|
||||
logger.Errorf("Serve http request '%q %q' failed with error: %s", req.Method, req.URL.String(), authErr.Error())
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
writeDate(w, []byte(authErr.Error()))
|
||||
return
|
||||
|
@ -119,10 +119,10 @@ func (bs *basicScheduler) UnSchedule(policyID string) error {
|
||||
// Failure errors will be only logged here
|
||||
eKey := rds.KeyUpstreamJobAndExecutions(bs.namespace, policyID)
|
||||
if eIDs, err := getPeriodicExecutions(conn, eKey); err != nil {
|
||||
logger.Errorf("Get executions for periodic job %s error: %s", policyID, err)
|
||||
logger.Errorf("Get executions for periodic job %q error: %s", policyID, err)
|
||||
} else {
|
||||
if len(eIDs) == 0 {
|
||||
logger.Debugf("no stopped executions: %s", policyID)
|
||||
logger.Debugf("no stopped executions: %q", policyID)
|
||||
}
|
||||
|
||||
for _, eID := range eIDs {
|
||||
@ -150,7 +150,7 @@ func (bs *basicScheduler) UnSchedule(policyID string) error {
|
||||
if err := eTracker.Stop(); err != nil {
|
||||
logger.Errorf("Stop execution %s error: %s", eID, err)
|
||||
} else {
|
||||
logger.Debugf("Stop execution %s of periodic job %s", eID, policyID)
|
||||
logger.Debugf("Stop execution %q of periodic job %s", eID, policyID)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -164,7 +164,7 @@ func (bs *basicScheduler) UnSchedule(policyID string) error {
|
||||
}
|
||||
|
||||
if removed == 0 {
|
||||
logger.Warningf("No periodic job with ID=%s and numeric ID=%d removed from the periodic job policy set", policyID, numericID)
|
||||
logger.Warningf("No periodic job with ID=%q and numeric ID=%d removed from the periodic job policy set", policyID, numericID)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -199,7 +199,7 @@ func (bs *basicScheduler) locatePolicy(policyID string, conn redis.Conn) (int64,
|
||||
// Switch the job stats to stopped if the job stats existing
|
||||
// Should not block the next clear action
|
||||
if err := tracker.Stop(); err != nil {
|
||||
logger.Errorf("Stop periodic job %s failed with error: %s", policyID, err)
|
||||
logger.Errorf("Stop periodic job %q failed with error: %s", policyID, err)
|
||||
}
|
||||
|
||||
return tracker.NumericID()
|
||||
|
@ -163,7 +163,7 @@ func (e *enqueuer) scheduleNextJobs(p *Policy, conn redis.Conn) {
|
||||
// The cron spec should be already checked at upper layers.
|
||||
// Just in cases, if error occurred, ignore it
|
||||
e.lastEnqueueErr = err
|
||||
logger.Errorf("Invalid corn spec in periodic policy %s %s: %s", p.JobName, p.ID, err)
|
||||
logger.Errorf("Invalid corn spec in periodic policy %q %s: %s", p.JobName, p.ID, err)
|
||||
} else {
|
||||
for t := schedule.Next(nowTime); t.Before(horizon); t = schedule.Next(t) {
|
||||
epoch := t.Unix()
|
||||
@ -222,7 +222,7 @@ func (e *enqueuer) scheduleNextJobs(p *Policy, conn redis.Conn) {
|
||||
break // Probably redis connection is broken
|
||||
}
|
||||
|
||||
logger.Debugf("Scheduled execution for periodic job %s:%s at %d", j.Name, p.ID, epoch)
|
||||
logger.Debugf("Scheduled execution for periodic job %q:%s at %d", j.Name, p.ID, epoch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ func (w *basicWorker) StopJob(jobID string) error {
|
||||
// We need to delete the scheduled job in the queue if it is not running yet
|
||||
if err := w.client.DeleteScheduledJob(t.Job().Info.RunAt, jobID); err != nil {
|
||||
// Job is already running?
|
||||
logger.Warningf("scheduled job %s (run at = %d) is not found in the queue, is it running?", jobID, t.Job().Info.RunAt)
|
||||
logger.Warningf("scheduled job %q (run at = %d) is not found in the queue, is it running?", jobID, t.Job().Info.RunAt)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,13 @@ package client
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/p2p/preheat/provider/auth"
|
||||
@ -128,7 +128,7 @@ func (hc *HTTPClient) get(url string, cred *auth.Credential, parmas map[string]s
|
||||
|
||||
if (res.StatusCode / 100) != 2 {
|
||||
// Return the server error content in the error.
|
||||
return nil, fmt.Errorf("%s '%s' error: %s %s", http.MethodGet, res.Request.URL.String(), res.Status, bytes)
|
||||
return nil, errors.Errorf("%s %q error: %s %s", http.MethodGet, res.Request.URL.String(), res.Status, bytes)
|
||||
}
|
||||
|
||||
return bytes, nil
|
||||
@ -194,7 +194,7 @@ func (hc *HTTPClient) post(url string, cred *auth.Credential, body interface{},
|
||||
|
||||
if (res.StatusCode / 100) != 2 {
|
||||
// Return the server error content in the error.
|
||||
return nil, fmt.Errorf("%s '%s' error: %s %s", http.MethodPost, res.Request.URL.String(), res.Status, bytes)
|
||||
return nil, errors.Errorf("%s %q error: %s %s", http.MethodPost, res.Request.URL.String(), res.Status, bytes)
|
||||
} else if res.StatusCode == http.StatusAlreadyReported {
|
||||
// Currently because if image was already preheated at least once, Dragonfly will return StatusAlreadyReported.
|
||||
// And we should preserve http status code info to process this case later.
|
||||
|
@ -23,10 +23,12 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"net/url"
|
||||
|
||||
common_http "github.com/goharbor/harbor/src/common/http"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/pkg/reg/filter"
|
||||
"github.com/goharbor/harbor/src/pkg/reg/model"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type label struct {
|
||||
@ -179,7 +181,7 @@ func (a *Adapter) DownloadChart(name, version, contentURL string) (io.ReadCloser
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("failed to download the chart %s: %d %s", req.URL.String(), resp.StatusCode, string(body))
|
||||
return nil, errors.Errorf("failed to download the chart %q: %d %s", req.URL.String(), resp.StatusCode, string(body))
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
@ -16,12 +16,13 @@ package helmhub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/goharbor/harbor/src/pkg/reg/filter"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/reg/filter"
|
||||
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/reg/model"
|
||||
@ -138,7 +139,7 @@ func (a *adapter) download(version *chartVersion) (io.ReadCloser, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("failed to download the chart %s: %d %s", req.URL.String(), resp.StatusCode, string(body))
|
||||
return nil, errors.Errorf("failed to download the chart %q: %d %s", req.URL.String(), resp.StatusCode, string(body))
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
commonhttp "github.com/goharbor/harbor/src/common/http"
|
||||
"github.com/goharbor/harbor/src/lib/errors"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
adp "github.com/goharbor/harbor/src/pkg/reg/adapter"
|
||||
"github.com/goharbor/harbor/src/pkg/reg/filter"
|
||||
@ -183,7 +184,7 @@ func (a *adapter) DownloadChart(name, version, contentURL string) (rc io.ReadClo
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("[tencent-tcr.DownloadChart.failed] chart=%s, status=%d, body=%s", req.URL.String(), resp.StatusCode, string(body))
|
||||
err = errors.Errorf("[tencent-tcr.DownloadChart.failed] chart=%q, status=%d, body=%s", req.URL.String(), resp.StatusCode, string(body))
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user