Skip to content

Commit

Permalink
Fix lint warnings, mark safe integer casts, validate currentPage
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Sep 11, 2024
1 parent 8a3fc2b commit c04c5eb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions storage/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func (store *redisStore) Success(ctx context.Context) error {
}

func (store *redisStore) TotalProcessed(ctx context.Context) uint64 {
return uint64(store.rclient.IncrBy(ctx, "processed", 0).Val())
return uint64(store.rclient.IncrBy(ctx, "processed", 0).Val()) // nolint:gosec
}
func (store *redisStore) TotalFailures(ctx context.Context) uint64 {
return uint64(store.rclient.IncrBy(ctx, "failures", 0).Val())
return uint64(store.rclient.IncrBy(ctx, "failures", 0).Val()) // nolint:gosec
}

func (store *redisStore) Failure(ctx context.Context) error {
Expand Down Expand Up @@ -57,7 +57,7 @@ func (store *redisStore) History(ctx context.Context, days int, fn func(day stri
}

for idx := 0; idx < days; idx++ {
fn(daystrs[idx], uint64(procds[idx].Val()), uint64(fails[idx].Val()))
fn(daystrs[idx], uint64(procds[idx].Val()), uint64(fails[idx].Val())) // nolint:gosec
}
return nil
}
2 changes: 1 addition & 1 deletion storage/queue_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (q *redisQueue) init(ctx context.Context) error {
}

func (q *redisQueue) Size(ctx context.Context) uint64 {
return uint64(q.store.rclient.LLen(ctx, q.name).Val())
return uint64(q.store.rclient.LLen(ctx, q.name).Val()) // nolint:gosec
}

func (q *redisQueue) Add(ctx context.Context, job *client.Job) error {
Expand Down
4 changes: 2 additions & 2 deletions storage/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func bootRedis(path string, sock string) (func(), error) {

conffilename := "/tmp/redis.conf"
if _, err := os.Stat(conffilename); err != nil {
if err != nil && os.IsNotExist(err) {
if os.IsNotExist(err) {
// nolint:gosec
err := os.WriteFile("/tmp/redis.conf", []byte(fmt.Sprintf(redisconf, client.Version)), 0o444)
if err != nil {
Expand Down Expand Up @@ -231,7 +231,7 @@ func openRedis(sock string, poolSize uint64) (Store, error) {
Network: "unix",
Addr: sock,
DB: 0,
PoolSize: int(poolSize),
PoolSize: int(poolSize), // nolint:gosec
})
_, err := rclient.Ping(ctx).Result()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion storage/sorted_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (rs *redisSorted) Name() string {
}

func (rs *redisSorted) Size(ctx context.Context) uint64 {
return uint64(rs.store.rclient.ZCard(ctx, rs.name).Val())
return uint64(rs.store.rclient.ZCard(ctx, rs.name).Val()) // nolint:gosec
}

func (rs *redisSorted) Clear(ctx context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions test/go_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestSystem(t *testing.T) {

wg.Wait()
bg := context.Background()
assert.EqualValues(t, 3*each, int(s.Store().TotalProcessed(bg)))
assert.EqualValues(t, 3*(each/100), int(s.Store().TotalFailures(bg)))
assert.EqualValues(t, 3*each, s.Store().TotalProcessed(bg))
assert.EqualValues(t, 3*(each/100), s.Store().TotalFailures(bg))

s.Stop(nil)
}
Expand Down
10 changes: 5 additions & 5 deletions webui/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func t(req *http.Request, word string) string {
return dc.Translation(word)
}

func pageparam(req *http.Request, pageValue uint64) string {
func pageparam(_ *http.Request, pageValue uint64) string {
return fmt.Sprintf("page=%d", pageValue)
}

Expand Down Expand Up @@ -141,7 +141,7 @@ func uintWithDelimiter(val uint64) string {

func queueJobs(r *http.Request, q storage.Queue, count, currentPage uint64, fn func(idx int, key []byte, job *client.Job)) {
c := r.Context()
err := q.Page(c, int64((currentPage-1)*count), int64(count), func(idx int, data []byte) error {
err := q.Page(c, int64((currentPage-1)*count), int64(count), func(idx int, data []byte) error { // nolint:gosec
var job client.Job
err := util.JsonUnmarshal(data, &job)
if err != nil {
Expand Down Expand Up @@ -177,13 +177,13 @@ func unfiltered() bool {
return true
}

func filtering(set string) string {
func filtering(_ string) string {
return ""
}

func setJobs(req *http.Request, set storage.SortedSet, count, currentPage uint64, fn func(idx int, key []byte, job *client.Job)) {
c := req.Context()
_, err := set.Page(c, int((currentPage-1)*count), int(count), func(idx int, entry storage.SortedEntry) error {
_, err := set.Page(c, int((currentPage-1)*count), int(count), func(idx int, entry storage.SortedEntry) error { // nolint:gosec
job, err := entry.Job()
if err != nil {
util.Warnf("Error parsing JSON: %s", string(entry.Value()))
Expand Down Expand Up @@ -464,7 +464,7 @@ func displayLimitedArgs(args []interface{}, limit int) string {
s = data.String()
}
if len(s) > limit {
fmt.Fprintf(&b, s[0:limit])
fmt.Fprintf(&b, "%s", s[0:limit])
b.WriteRune('…')
} else {
fmt.Fprint(&b, s)
Expand Down
16 changes: 8 additions & 8 deletions webui/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ func queueHandler(w http.ResponseWriter, r *http.Request) {
p := r.URL.Query()["page"]
if p != nil {
val, err := strconv.Atoi(p[0])
if err != nil {
if err != nil || val < 0 {
http.Error(w, "Invalid parameter", http.StatusBadRequest)
return
}
currentPage = uint64(val)
currentPage = uint64(val) // nolint:gosec
}
count := uint64(25)

Expand All @@ -147,11 +147,11 @@ func retriesHandler(w http.ResponseWriter, r *http.Request) {
p := r.URL.Query()["page"]
if p != nil {
val, err := strconv.Atoi(p[0])
if err != nil {
if err != nil || val < 0 {
http.Error(w, "Invalid parameter", http.StatusBadRequest)
return
}
currentPage = uint64(val)
currentPage = uint64(val) // nolint:gosec
}
count := uint64(25)

Expand Down Expand Up @@ -228,11 +228,11 @@ func scheduledHandler(w http.ResponseWriter, r *http.Request) {
p := r.URL.Query()["page"]
if p != nil {
val, err := strconv.Atoi(p[0])
if err != nil {
if err != nil || val < 0 {
http.Error(w, "Invalid parameter", http.StatusBadRequest)
return
}
currentPage = uint64(val)
currentPage = uint64(val) // nolint:gosec
}
count := uint64(25)

Expand Down Expand Up @@ -305,11 +305,11 @@ func morgueHandler(w http.ResponseWriter, r *http.Request) {
p := r.URL.Query()["page"]
if p != nil {
val, err := strconv.Atoi(p[0])
if err != nil {
if err != nil || val < 0 {
http.Error(w, "Invalid parameter", http.StatusBadRequest)
return
}
currentPage = uint64(val)
currentPage = uint64(val) // nolint:gosec
}
count := uint64(25)

Expand Down

0 comments on commit c04c5eb

Please sign in to comment.