mirror of
https://github.com/containrrr/watchtower.git
synced 2026-01-30 20:35:16 +01:00
feat(api): add updates API v2
This commit is contained in:
parent
47091761a5
commit
4a922f5a32
4 changed files with 73 additions and 33 deletions
37
pkg/api/updates/updates_v2.go
Normal file
37
pkg/api/updates/updates_v2.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package updates
|
||||
|
||||
import (
|
||||
. "github.com/containrrr/watchtower/pkg/api/prelude"
|
||||
"github.com/containrrr/watchtower/pkg/filters"
|
||||
"github.com/containrrr/watchtower/pkg/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func postV2(onInvoke InvokedFunc, updateLock *sync.Mutex, monitorOnly bool) HandlerFunc {
|
||||
return func(c *Context) Response {
|
||||
log.Info("Updates triggered by HTTP API request.")
|
||||
|
||||
images := parseImages(c.Request.URL)
|
||||
|
||||
if updateLock.TryLock() {
|
||||
defer updateLock.Unlock()
|
||||
|
||||
result := onInvoke(func(up *types.UpdateParams) {
|
||||
up.Filter = filters.FilterByImage(images, up.Filter)
|
||||
up.MonitorOnly = monitorOnly
|
||||
})
|
||||
return OK(result)
|
||||
} else {
|
||||
return Error(ErrUpdateRunning)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PostV2Check(onInvoke InvokedFunc, updateLock *sync.Mutex) HandlerFunc {
|
||||
return postV2(onInvoke, updateLock, true)
|
||||
}
|
||||
|
||||
func PostV2Apply(onInvoke InvokedFunc, updateLock *sync.Mutex) HandlerFunc {
|
||||
return postV2(onInvoke, updateLock, false)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue