Skip to content

Commit

Permalink
refactor!: enable gosec linter (#348)
Browse files Browse the repository at this point in the history
Also remove unused functions.
  • Loading branch information
bfabio authored Mar 24, 2023
1 parent f3accb4 commit 5897a17
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ linters:
- gomoddirectives
- gomodguard
- goprintffuncname
# - gosec
- gosec
- grouper
- importas
- interfacebloat
Expand Down
32 changes: 0 additions & 32 deletions common/repository.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package common

import (
"crypto/sha1"
"fmt"
"net/url"
"strings"

log "github.com/sirupsen/logrus"
)

// Repository is a single code repository. FileRawURL contains the direct url to the raw file.
Expand All @@ -19,30 +14,3 @@ type Repository struct {
Publisher Publisher
Headers map[string]string
}

// generateID generates a hash based on unique git repo URL.
func (repo *Repository) GenerateID() string {
hash := sha1.New()
_, err := hash.Write([]byte(repo.URL.String()))
if err != nil {
log.Errorf("Error generating the repository hash: %+v", err)

return ""
}

return fmt.Sprintf("%x", hash.Sum(nil))
}

// generateSlug generates a readable unique string based on repository name.
func (repo *Repository) GenerateSlug() string {
vendorAndName := strings.ReplaceAll(repo.Name, "/", "-")
vendorAndName = strings.ReplaceAll(vendorAndName, ".", "_")

if repo.Publisher.Id == "" {
ID := repo.GenerateID()

return fmt.Sprintf("%s-%s", vendorAndName, ID[0:6])
}

return fmt.Sprintf("%s-%s", repo.Publisher.Id, vendorAndName)
}
2 changes: 1 addition & 1 deletion metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func RegisterPrometheusCounter(name, helpText, namespace string) {
func StartPrometheusMetricsServer() {
http.Handle("/metrics", promhttp.Handler())

err := http.ListenAndServe(":8081", nil)
err := http.ListenAndServe(":8081", nil) //nolint:gosec
if err != nil {
log.Warningf("monitoring endpoint non available: %v: ", err)
}
Expand Down
2 changes: 1 addition & 1 deletion scanner/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func secondaryRateLimit(err *github.AbuseRateLimitError) {
if err.RetryAfter != nil {
duration = *err.RetryAfter
} else {
duration = time.Duration(rand.Intn(100)) * time.Second
duration = time.Duration(rand.Intn(100)) * time.Second //nolint:gosec
}

log.Infof("GitHub secondary rate limit hit, for %s", duration)
Expand Down

0 comments on commit 5897a17

Please sign in to comment.