Skip to content

Commit 47d25bd

Browse files
authored
Merge branch 'main' into gitea-vet
2 parents cf94356 + a82fd98 commit 47d25bd

37 files changed

+1396
-131
lines changed

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/denisenkom/go-mssqldb v0.10.0
3131
github.com/djherbis/buffer v1.2.0
3232
github.com/djherbis/nio/v3 v3.0.1
33-
github.com/duo-labs/webauthn v0.0.0-20211221191814-a22482edaa3b
33+
github.com/duo-labs/webauthn v0.0.0-20220122034320-81aea484c951
3434
github.com/dustin/go-humanize v1.0.0
3535
github.com/editorconfig/editorconfig-core-go/v2 v2.4.2
3636
github.com/emirpasic/gods v1.12.0
@@ -54,7 +54,7 @@ require (
5454
github.com/golang-jwt/jwt/v4 v4.2.0
5555
github.com/golang/snappy v0.0.4 // indirect
5656
github.com/google/go-github/v39 v39.2.0
57-
github.com/google/uuid v1.2.0
57+
github.com/google/uuid v1.3.0
5858
github.com/gorilla/feeds v1.1.1
5959
github.com/gorilla/mux v1.8.0 // indirect
6060
github.com/gorilla/sessions v1.2.1
@@ -145,8 +145,6 @@ replace github.com/markbates/goth v1.68.0 => github.com/zeripath/goth v1.68.1-0.
145145

146146
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
147147

148-
replace github.com/duo-labs/webauthn => github.com/authelia/webauthn v0.0.0-20211225121951-80d1f2a572e4
149-
150148
replace github.com/satori/go.uuid v1.2.0 => github.com/gofrs/uuid v4.2.0+incompatible
151149

152150
exclude github.com/gofrs/uuid v3.2.0+incompatible

go.sum

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:o
131131
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
132132
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
133133
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
134-
github.com/authelia/webauthn v0.0.0-20211225121951-80d1f2a572e4 h1:u3eFvgr4A8IjlAokbFt6XY6VdurX7DEYnQMQ4K2yobc=
135-
github.com/authelia/webauthn v0.0.0-20211225121951-80d1f2a572e4/go.mod h1:EYSpSkwoEcryMmQGfhol2IiB3IMN9IIIaNd/wcAQMGQ=
136134
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
137135
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
138136
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
@@ -276,6 +274,8 @@ github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
276274
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=
277275
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
278276
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
277+
github.com/duo-labs/webauthn v0.0.0-20220122034320-81aea484c951 h1:17esZ09oW+29rklBtCVphIguql2u3NxYH2OasFPPZoo=
278+
github.com/duo-labs/webauthn v0.0.0-20220122034320-81aea484c951/go.mod h1:nHy3JdztZWcsjenDeBuE8gn171OAwg12LBN027UP5AE=
279279
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
280280
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
281281
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
@@ -491,7 +491,6 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
491491
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
492492
github.com/goccy/go-json v0.7.4 h1:B44qRUFwz/vxPKPISQ1KhvzRi9kZ28RAf6YtjriBZ5k=
493493
github.com/goccy/go-json v0.7.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
494-
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
495494
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
496495
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
497496
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -585,8 +584,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
585584
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
586585
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
587586
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
588-
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
589-
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
587+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
588+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
590589
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
591590
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
592591
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=

modules/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func (ctx *Context) PlainTextBytes(status int, bs []byte) {
292292
}
293293
ctx.Resp.WriteHeader(status)
294294
ctx.Resp.Header().Set("Content-Type", "text/plain;charset=utf-8")
295+
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
295296
if _, err := ctx.Resp.Write(bs); err != nil {
296297
log.Error("Write bytes failed: %v", err)
297298
}

modules/indexer/code/indexer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ func Init() {
133133
// Create the Queue
134134
switch setting.Indexer.RepoType {
135135
case "bleve", "elasticsearch":
136-
handler := func(data ...queue.Data) {
136+
handler := func(data ...queue.Data) []queue.Data {
137137
idx, err := indexer.get()
138138
if idx == nil || err != nil {
139139
log.Error("Codes indexer handler: unable to get indexer!")
140-
return
140+
return data
141141
}
142142

143143
for _, datum := range data {
@@ -153,6 +153,7 @@ func Init() {
153153
continue
154154
}
155155
}
156+
return nil
156157
}
157158

158159
indexerQueue = queue.CreateUniqueQueue("code_indexer", handler, &IndexerData{})

modules/indexer/issues/indexer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ func InitIssueIndexer(syncReindex bool) {
103103
// Create the Queue
104104
switch setting.Indexer.IssueType {
105105
case "bleve", "elasticsearch":
106-
handler := func(data ...queue.Data) {
106+
handler := func(data ...queue.Data) []queue.Data {
107107
indexer := holder.get()
108108
if indexer == nil {
109109
log.Error("Issue indexer handler: unable to get indexer!")
110-
return
110+
return data
111111
}
112112

113113
iData := make([]*IndexerData, 0, len(data))
@@ -127,6 +127,7 @@ func InitIssueIndexer(syncReindex bool) {
127127
if err := indexer.Index(iData); err != nil {
128128
log.Error("Error whilst indexing: %v Error: %v", iData, err)
129129
}
130+
return nil
130131
}
131132

132133
issueIndexerQueue = queue.CreateQueue("issue_indexer", handler, &IndexerData{})

modules/indexer/stats/queue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import (
1717
var statsQueue queue.UniqueQueue
1818

1919
// handle passed PR IDs and test the PRs
20-
func handle(data ...queue.Data) {
20+
func handle(data ...queue.Data) []queue.Data {
2121
for _, datum := range data {
2222
opts := datum.(int64)
2323
if err := indexer.Index(opts); err != nil {
2424
log.Error("stats queue indexer.Index(%d) failed: %v", opts, err)
2525
}
2626
}
27+
return nil
2728
}
2829

2930
func initStatsQueue() error {

modules/notification/ui/ui.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ func NewNotifier() base.Notifier {
3838
return ns
3939
}
4040

41-
func (ns *notificationService) handle(data ...queue.Data) {
41+
func (ns *notificationService) handle(data ...queue.Data) []queue.Data {
4242
for _, datum := range data {
4343
opts := datum.(issueNotificationOpts)
4444
if err := models.CreateOrUpdateIssueNotifications(opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
4545
log.Error("Was unable to create issue notification: %v", err)
4646
}
4747
}
48+
return nil
4849
}
4950

5051
func (ns *notificationService) Run() {

modules/queue/bytefifo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type ByteFIFO interface {
1616
Pop(ctx context.Context) ([]byte, error)
1717
// Close this fifo
1818
Close() error
19+
// PushBack pushes data back to the top of the fifo
20+
PushBack(ctx context.Context, data []byte) error
1921
}
2022

2123
// UniqueByteFIFO defines a FIFO that Uniques its contents
@@ -50,6 +52,11 @@ func (*DummyByteFIFO) Len(ctx context.Context) int64 {
5052
return 0
5153
}
5254

55+
// PushBack pushes data back to the top of the fifo
56+
func (*DummyByteFIFO) PushBack(ctx context.Context, data []byte) error {
57+
return nil
58+
}
59+
5360
var _ UniqueByteFIFO = &DummyUniqueByteFIFO{}
5461

5562
// DummyUniqueByteFIFO represents a dummy unique fifo

modules/queue/manager.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ type Flushable interface {
5454
IsEmpty() bool
5555
}
5656

57+
// Pausable represents a pool or queue that is Pausable
58+
type Pausable interface {
59+
// IsPaused will return if the pool or queue is paused
60+
IsPaused() bool
61+
// Pause will pause the pool or queue
62+
Pause()
63+
// Resume will resume the pool or queue
64+
Resume()
65+
// IsPausedIsResumed will return a bool indicating if the pool or queue is paused and a channel that will be closed when it is resumed
66+
IsPausedIsResumed() (paused, resumed <-chan struct{})
67+
}
68+
5769
// ManagedPool is a simple interface to get certain details from a worker pool
5870
type ManagedPool interface {
5971
// AddWorkers adds a number of worker as group to the pool with the provided timeout. A CancelFunc is provided to cancel the group
@@ -192,6 +204,14 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
192204
wg.Done()
193205
continue
194206
}
207+
if pausable, ok := mq.Managed.(Pausable); ok {
208+
// no point flushing paused queues
209+
if pausable.IsPaused() {
210+
wg.Done()
211+
continue
212+
}
213+
}
214+
195215
allEmpty = false
196216
if flushable, ok := mq.Managed.(Flushable); ok {
197217
log.Debug("Flushing (flushable) queue: %s", mq.Name)
@@ -215,7 +235,7 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
215235
log.Debug("All queues are empty")
216236
break
217237
}
218-
// Ensure there are always at least 100ms between loops but not more if we've actually been doing some flushign
238+
// Ensure there are always at least 100ms between loops but not more if we've actually been doing some flushing
219239
// but don't delay cancellation here.
220240
select {
221241
case <-ctx.Done():
@@ -298,6 +318,12 @@ func (q *ManagedQueue) AddWorkers(number int, timeout time.Duration) context.Can
298318
return nil
299319
}
300320

321+
// Flushable returns true if the queue is flushable
322+
func (q *ManagedQueue) Flushable() bool {
323+
_, ok := q.Managed.(Flushable)
324+
return ok
325+
}
326+
301327
// Flush flushes the queue with a timeout
302328
func (q *ManagedQueue) Flush(timeout time.Duration) error {
303329
if flushable, ok := q.Managed.(Flushable); ok {
@@ -315,6 +341,34 @@ func (q *ManagedQueue) IsEmpty() bool {
315341
return true
316342
}
317343

344+
// Pausable returns whether the queue is Pausable
345+
func (q *ManagedQueue) Pausable() bool {
346+
_, ok := q.Managed.(Pausable)
347+
return ok
348+
}
349+
350+
// Pause pauses the queue
351+
func (q *ManagedQueue) Pause() {
352+
if pausable, ok := q.Managed.(Pausable); ok {
353+
pausable.Pause()
354+
}
355+
}
356+
357+
// IsPaused reveals if the queue is paused
358+
func (q *ManagedQueue) IsPaused() bool {
359+
if pausable, ok := q.Managed.(Pausable); ok {
360+
return pausable.IsPaused()
361+
}
362+
return false
363+
}
364+
365+
// Resume resumes the queue
366+
func (q *ManagedQueue) Resume() {
367+
if pausable, ok := q.Managed.(Pausable); ok {
368+
pausable.Resume()
369+
}
370+
}
371+
318372
// NumberOfWorkers returns the number of workers in the queue
319373
func (q *ManagedQueue) NumberOfWorkers() int {
320374
if pool, ok := q.Managed.(ManagedPool); ok {

modules/queue/queue.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type Type string
3636
type Data interface{}
3737

3838
// HandlerFunc is a function that takes a variable amount of data and processes it
39-
type HandlerFunc func(...Data)
39+
type HandlerFunc func(...Data) (unhandled []Data)
4040

4141
// NewQueueFunc is a function that creates a queue
4242
type NewQueueFunc func(handler HandlerFunc, config, exemplar interface{}) (Queue, error)
@@ -61,6 +61,12 @@ type Queue interface {
6161
Push(Data) error
6262
}
6363

64+
// PushBackable queues can be pushed back to
65+
type PushBackable interface {
66+
// PushBack pushes data back to the top of the fifo
67+
PushBack(Data) error
68+
}
69+
6470
// DummyQueueType is the type for the dummy queue
6571
const DummyQueueType Type = "dummy"
6672

0 commit comments

Comments
 (0)