fix deadcode lint & update golangci-lint.yaml (#16896)

* fix deadcode lint & update golangci-lint.yaml

Signed-off-by: yminer <yminer@vmmware.com>

mock.go

Signed-off-by: yminer <yminer@vmmware.com>

commentfmt

Signed-off-by: yminer <yminer@vmmware.com>

mock.go update

Signed-off-by: yminer <yminer@vmmware.com>

update makefile

Signed-off-by: yminer <yminer@vmmware.com>

* update /pkg/allowlist/validator.go

Signed-off-by: yminer <yminer@vmmware.com>

Co-authored-by: yminer <yminer@vmmware.com>
This commit is contained in:
MinerYang 2022-05-26 10:32:07 +08:00 committed by GitHub
parent d26b5792c0
commit 9d8e9158de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 14 additions and 69 deletions

View File

@ -537,7 +537,7 @@ GOLANGCI_LINT := $(shell go env GOPATH)/bin/golangci-lint
lint: lint:
@echo checking lint @echo checking lint
@echo $(GOLANGCI_LINT) @echo $(GOLANGCI_LINT)
@$(GOLANGCI_LINT) -v run ./src/... @cd ./src/; $(GOLANGCI_LINT) -v run ./...;
pushimage: pushimage:
@echo "pushing harbor images ..." @echo "pushing harbor images ..."

View File

@ -27,12 +27,12 @@ linters:
# - nolintlint # - nolintlint
# - revive # - revive
# - whitespace # - whitespace
# - bodyclose - bodyclose
# - deadcode - deadcode
# - errcheck # - errcheck
# - gosec # - gosec
# - gosimple # - gosimple
# - govet - govet
# - noctx # - noctx
# - rowserrcheck # - rowserrcheck
# - staticcheck # - staticcheck
@ -47,8 +47,8 @@ run:
skip-files: skip-files:
- ".*_test.go" - ".*_test.go"
- ".*test.go" - ".*test.go"
skip-dir: skip-dirs:
- "./testing/" - "testing/"
timeout: 5m timeout: 5m
issue: issue:

View File

@ -29,7 +29,6 @@ const (
defaultRepo = "library" defaultRepo = "library"
rootUploadingEndpoint = "/api/chartrepo/charts" rootUploadingEndpoint = "/api/chartrepo/charts"
rootIndexEndpoint = "/chartrepo/index.yaml"
chartRepoHealthEndpoint = "/api/chartrepo/health" chartRepoHealthEndpoint = "/api/chartrepo/health"
) )

View File

@ -10,11 +10,6 @@ import (
"strings" "strings"
) )
const (
contentTypeHeader = "content-type"
contentTypeJSON = "application/json"
)
// Extract error object '{"error": "****---***"}' from the content if existing // Extract error object '{"error": "****---***"}' from the content if existing
// nil error will be returned if it does exist // nil error will be returned if it does exist
func extractError(content []byte) (text string, err error) { func extractError(content []byte) (text string, err error) {

View File

@ -27,7 +27,6 @@ const (
internalVerifyClientCert = "INTERNAL_VERIFY_CLIENT_CERT" internalVerifyClientCert = "INTERNAL_VERIFY_CLIENT_CERT"
internalTLSKeyPath = "INTERNAL_TLS_KEY_PATH" internalTLSKeyPath = "INTERNAL_TLS_KEY_PATH"
internalTLSCertPath = "INTERNAL_TLS_CERT_PATH" internalTLSCertPath = "INTERNAL_TLS_CERT_PATH"
internalTrustCAPath = "INTERNAL_TLS_TRUST_CA_PATH"
) )
// InternalTLSEnabled returns true if internal TLS enabled // InternalTLSEnabled returns true if internal TLS enabled

View File

@ -14,11 +14,12 @@
package flow package flow
import ( import "github.com/goharbor/harbor/src/pkg/reg/adapter"
"github.com/goharbor/harbor/src/pkg/reg/adapter"
)
// define a new interface to combine the two interfaces of adapter for mockery to generate the mocks // define a new interface to combine the two interfaces of adapter for mockery to generate the mocks
// nolint:deadcode
// for make gen_mocks use
type registryAdapter interface { type registryAdapter interface {
adapter.Adapter adapter.Adapter
adapter.ArtifactRegistry adapter.ArtifactRegistry

View File

@ -39,12 +39,6 @@ const (
rootIndexEndpoint = "/chartrepo/index.yaml" rootIndexEndpoint = "/chartrepo/index.yaml"
chartRepoHealthEndpoint = "/api/chartrepo/health" chartRepoHealthEndpoint = "/api/chartrepo/health"
accessLevelPublic = iota
accessLevelRead
accessLevelWrite
accessLevelAll
accessLevelSystem
formFieldNameForChart = "chart" formFieldNameForChart = "chart"
formFiledNameForProv = "prov" formFiledNameForProv = "prov"
headerContentType = "Content-Type" headerContentType = "Content-Type"

View File

@ -48,12 +48,6 @@ func (cc *CommonController) Render() error {
// Prepare overwrites the Prepare func in api.BaseController to ignore unnecessary steps // Prepare overwrites the Prepare func in api.BaseController to ignore unnecessary steps
func (cc *CommonController) Prepare() {} func (cc *CommonController) Prepare() {}
type messageDetail struct {
Hint string
URL string
UUID string
}
func redirectForOIDC(ctx context.Context, username string) bool { func redirectForOIDC(ctx context.Context, username string) bool {
if lib.GetAuthMode(ctx) != common.OIDCAuth { if lib.GetAuthMode(ctx) != common.OIDCAuth {
return false return false

View File

@ -41,17 +41,10 @@ func IsInvalidErr(err error) bool {
return ok return ok
} }
const cveIDPattern = `^CVE-\d{4}-\d+$`
// Validate help validates the CVE allowlist, to ensure the CVE ID is valid and there's no duplication // Validate help validates the CVE allowlist, to ensure the CVE ID is valid and there's no duplication
func Validate(wl models2.CVEAllowlist) error { func Validate(wl models2.CVEAllowlist) error {
m := map[string]struct{}{} m := map[string]struct{}{}
// re := regexp.MustCompile(cveIDPattern)
for _, it := range wl.Items { for _, it := range wl.Items {
// Bypass the cve format checking
// if !re.MatchString(it.CVEID) {
// return &invalidErr{fmt.Sprintf("invalid CVE ID: %s", it.CVEID)}
// }
if _, ok := m[it.CVEID]; ok { if _, ok := m[it.CVEID]; ok {
return &invalidErr{fmt.Sprintf("duplicate CVE ID in allowlist: %s", it.CVEID)} return &invalidErr{fmt.Sprintf("duplicate CVE ID in allowlist: %s", it.CVEID)}
} }

View File

@ -13,7 +13,6 @@ const (
dialConnectionTimeout = 30 * time.Second dialConnectionTimeout = 30 * time.Second
dialReadTimeout = 10 * time.Second dialReadTimeout = 10 * time.Second
dialWriteTimeout = 10 * time.Second dialWriteTimeout = 10 * time.Second
pageItemNum = 20.0
) )
var ( var (

View File

@ -3,7 +3,7 @@ package aliacr
import "time" import "time"
const ( const (
defaultTemporaryTokenExpiredTime = time.Hour * 1 defaultTemporaryTokenExpiredTime = time.Hour * 1 // nolint:deadcode
registryEndpointTpl = "https://registry.%s.aliyuncs.com" registryEndpointTpl = "https://registry.%s.aliyuncs.com"
endpointTpl = "cr.%s.aliyuncs.com" endpointTpl = "cr.%s.aliyuncs.com"
) )

View File

@ -24,19 +24,6 @@ const (
// ErrHTTPNotFound defines the return error when receiving 404 response code // ErrHTTPNotFound defines the return error when receiving 404 response code
var ErrHTTPNotFound = errors.New("not found") var ErrHTTPNotFound = errors.New("not found")
func searchPackages(kind, offset, limit int, queryString string) string {
if len(queryString) == 0 {
return fmt.Sprintf("/api/v1/packages/search?kind=%d&limit=%d&offset=%d",
kind, limit, offset)
}
return fmt.Sprintf("/api/v1/packages/search?kind=%d&limit=%d&offset=%d&ts_query_web=%s",
kind, limit, offset, queryString)
}
func getHelmPackageDetail(fullName string) string {
return fmt.Sprintf("/api/v1/packages/helm/%s", fullName)
}
func getHelmVersion(fullName, version string) string { func getHelmVersion(fullName, version string) string {
return fmt.Sprintf("/api/v1/packages/helm/%s/%s", fullName, version) return fmt.Sprintf("/api/v1/packages/helm/%s/%s", fullName, version)
} }

View File

@ -17,10 +17,6 @@ import (
common_http "github.com/goharbor/harbor/src/common/http" common_http "github.com/goharbor/harbor/src/common/http"
) )
const (
scheme = "bearer"
)
// Client is a client to interact with GitLab // Client is a client to interact with GitLab
type Client struct { type Client struct {
client *common_http.Client client *common_http.Client
@ -55,9 +51,6 @@ func NewClient(registry *model.Registry) (*Client, error) {
return client, nil return client, nil
} }
func buildPingURL(endpoint string) string {
return fmt.Sprintf("%s/v2/", endpoint)
}
func (c *Client) newRequest(method, url string, body io.Reader) (*http.Request, error) { func (c *Client) newRequest(method, url string, body io.Reader) (*http.Request, error) {
req, err := http.NewRequest(method, url, body) req, err := http.NewRequest(method, url, body)
if err != nil { if err != nil {

View File

@ -25,7 +25,7 @@ import (
var ( var (
errInvalidTcrEndpoint error = errors.New("[tencent-tcr.newAdapter] Invalid TCR instance endpoint") errInvalidTcrEndpoint error = errors.New("[tencent-tcr.newAdapter] Invalid TCR instance endpoint")
errPingTcrEndpointFailed error = errors.New("[tencent-tcr.newAdapter] Ping TCR instance endpoint failed") errPingTcrEndpointFailed error = errors.New("[tencent-tcr.newAdapter] Ping TCR instance endpoint failed") // nolint:deadcode
) )
func init() { func init() {

View File

@ -299,7 +299,3 @@ func toVulnerabilityItem(record *scan.VulnerabilityRecord, artifactDigest string
return item return item
} }
func convertingKey(reportUUID string) string {
return fmt.Sprintf("converting:%s", reportUUID)
}

View File

@ -16,7 +16,6 @@ package report
import ( import (
"context" "context"
"time"
"github.com/goharbor/harbor/src/lib/errors" "github.com/goharbor/harbor/src/lib/errors"
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
@ -103,10 +102,6 @@ type Manager interface {
List(ctx context.Context, query *q.Query) ([]*scan.Report, error) List(ctx context.Context, query *q.Query) ([]*scan.Report, error)
} }
const (
reportTimeout = 1 * time.Hour
)
// basicManager is a default implementation of report manager. // basicManager is a default implementation of report manager.
type basicManager struct { type basicManager struct {
dao scan.DAO dao scan.DAO

View File

@ -2,14 +2,14 @@ package dao
import ( import (
"context" "context"
"github.com/goharbor/harbor/src/lib/orm" "github.com/goharbor/harbor/src/lib/orm"
"github.com/goharbor/harbor/src/lib/q" "github.com/goharbor/harbor/src/lib/q"
"github.com/goharbor/harbor/src/pkg/systemartifact/model" "github.com/goharbor/harbor/src/pkg/systemartifact/model"
) )
const ( const (
sizeQuery = "select sum(size) as total_size from system_artifact" sizeQuery = "select sum(size) as total_size from system_artifact"
totalSizeColumn = "total_size"
) )
// DAO defines an data access interface for manging the CRUD and read of system // DAO defines an data access interface for manging the CRUD and read of system