@@ -32,6 +32,7 @@ import (
32
32
"github.com/stacklok/toolhive/pkg/container"
33
33
"github.com/stacklok/toolhive/pkg/logger"
34
34
"github.com/stacklok/toolhive/pkg/registry"
35
+ "github.com/stacklok/toolhive/pkg/updates"
35
36
"github.com/stacklok/toolhive/pkg/workloads"
36
37
)
37
38
@@ -88,6 +89,28 @@ func headersMiddleware(next http.Handler) http.Handler {
88
89
})
89
90
}
90
91
92
+ // updateCheckMiddleware triggers update checks for API usage
93
+ func updateCheckMiddleware () func (next http.Handler ) http.Handler {
94
+ return func (next http.Handler ) http.Handler {
95
+ return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
96
+ go func () {
97
+ versionClient := updates .NewVersionClient ()
98
+ updateChecker , err := updates .NewUpdateChecker (versionClient )
99
+ if err != nil {
100
+ logger .Warnf ("unable to create update client for API: %s" , err )
101
+ return
102
+ }
103
+
104
+ err = updateChecker .CheckLatestVersion ()
105
+ if err != nil {
106
+ logger .Warnf ("could not check for updates for API: %s" , err )
107
+ }
108
+ }()
109
+ next .ServeHTTP (w , r )
110
+ })
111
+ }
112
+ }
113
+
91
114
// Serve starts the server on the given address and serves the API.
92
115
// It is assumed that the caller sets up appropriate signal handling.
93
116
// If isUnixSocket is true, address is treated as a UNIX socket path.
@@ -108,6 +131,9 @@ func Serve(
108
131
headersMiddleware ,
109
132
)
110
133
134
+ // Add update check middleware
135
+ r .Use (updateCheckMiddleware ())
136
+
111
137
// Add authentication middleware
112
138
authMiddleware , err := auth .GetAuthenticationMiddleware (ctx , oidcConfig , false )
113
139
if err != nil {
0 commit comments