mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 02:15:02 +01:00
* webhook: share the default target settings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * webhook: managed webhook targets with a drainable queue Targets kept as JSON (name, endpoint, token, filters, retry and worker settings) build their own queue; Close waits for queued and in-flight deliveries before stopping it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: run webhook targets stored in /etc/seaweedfs when notification.webhook.managed is set The targets in /etc/seaweedfs/notification_webhooks.json start with the filer and are rebuilt from the store whenever the file changes on any filer, alongside notification.toml. The previous queue drains before it stops. Events for the file itself, which holds bearer tokens, are not sent to notification queues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * admin: manage filer webhook targets A Webhooks page under Management lists, adds, edits and deletes the targets kept in /etc/seaweedfs/notification_webhooks.json. Bearer tokens are write-only: the API reports whether one is set, and an empty token on edit keeps the stored one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: keep the webhook queue when the stored targets did not change Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: keep a replaced webhook queue open until its senders hand over Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * admin: read chunk-backed webhook targets before editing them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: keep the stored webhook targets out of fs.meta.notify Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * webhook: reject negative managed target settings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * webhook: no signal handler on queues that reloads replace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: swap the webhook queue without waiting behind blocked senders The read lock held across SendMessage made a reload wait for any sender blocked on a saturated target, and the waiting writer stalled every other filer write with it, which is when an operator disables that target. Close now refuses new sends and waits for the senders already inside SendMessage, and a send that hits the closing queue retries on its replacement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * webhook: release blocked test handlers before the server shuts down Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: always run the webhook targets managed in the admin UI Drop the notification.webhook.managed switch: every filer loads and live reloads the stored targets. Without stored targets no queue is created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scaffold: place the admin-managed webhook note above enabled Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scaffold: separate the admin-managed webhook note Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scaffold: note that admin-managed webhooks follow the notification queue Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: retry loading webhook targets after a failed read Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * filer: retire the admin-managed webhook queue on shutdown Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
213 lines
9.1 KiB
Go
213 lines
9.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/gorilla/sessions"
|
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
|
)
|
|
|
|
func TestSetupRoutes_RegistersPluginSchedulerStatesAPI_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
if !hasRoute(router, http.MethodGet, "/api/plugin/scheduler-states") {
|
|
t.Fatalf("expected GET /api/plugin/scheduler-states to be registered in no-auth mode")
|
|
}
|
|
if !hasRoute(router, http.MethodGet, "/api/plugin/jobs/example/detail") {
|
|
t.Fatalf("expected GET /api/plugin/jobs/:jobId/detail to be registered in no-auth mode")
|
|
}
|
|
if !hasRoute(router, http.MethodPost, "/api/plugin/jobs/example/expire") {
|
|
t.Fatalf("expected POST /api/plugin/jobs/:jobId/expire to be registered in no-auth mode")
|
|
}
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersPluginSchedulerStatesAPI_WithAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, true, "admin", "password", "", "", true)
|
|
|
|
if !hasRoute(router, http.MethodGet, "/api/plugin/scheduler-states") {
|
|
t.Fatalf("expected GET /api/plugin/scheduler-states to be registered in auth mode")
|
|
}
|
|
if !hasRoute(router, http.MethodGet, "/api/plugin/jobs/example/detail") {
|
|
t.Fatalf("expected GET /api/plugin/jobs/:jobId/detail to be registered in auth mode")
|
|
}
|
|
if !hasRoute(router, http.MethodPost, "/api/plugin/jobs/example/expire") {
|
|
t.Fatalf("expected POST /api/plugin/jobs/:jobId/expire to be registered in auth mode")
|
|
}
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersBucketLifecycleAPI_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/s3/buckets/example/lifecycle")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/s3/buckets/example/lifecycle")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/s3/buckets/example/lifecycle")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersBucketLifecycleAPI_WithAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, true, "admin", "password", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/s3/buckets/example/lifecycle")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/s3/buckets/example/lifecycle")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/s3/buckets/example/lifecycle")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersNotificationWebhooks(t *testing.T) {
|
|
for _, authRequired := range []bool{false, true} {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, authRequired, "admin", "password", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/notifications/webhooks")
|
|
assertHasRoute(t, router, http.MethodGet, "/api/notifications/webhooks")
|
|
assertHasRoute(t, router, http.MethodPost, "/api/notifications/webhooks")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/notifications/webhooks/example")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/notifications/webhooks/example")
|
|
}
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersBucketPolicyAPI_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/s3/buckets/example/policy")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/s3/buckets/example/policy")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/s3/buckets/example/policy")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersBucketPolicyAPI_WithAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, true, "admin", "password", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/s3/buckets/example/policy")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/s3/buckets/example/policy")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/s3/buckets/example/policy")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersPolicyAPI_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/object-store/policies")
|
|
assertHasRoute(t, router, http.MethodPost, "/api/object-store/policies")
|
|
assertHasRoute(t, router, http.MethodGet, "/api/object-store/policies/example")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/object-store/policies/example")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/object-store/policies/example")
|
|
assertHasRoute(t, router, http.MethodPost, "/api/object-store/policies/validate")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersPolicyAPI_WithAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, true, "admin", "password", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/object-store/policies")
|
|
assertHasRoute(t, router, http.MethodPost, "/api/object-store/policies")
|
|
assertHasRoute(t, router, http.MethodGet, "/api/object-store/policies/example")
|
|
assertHasRoute(t, router, http.MethodPut, "/api/object-store/policies/example")
|
|
assertHasRoute(t, router, http.MethodDelete, "/api/object-store/policies/example")
|
|
assertHasRoute(t, router, http.MethodPost, "/api/object-store/policies/validate")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersPrincipalsAPI_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/principals")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersFilesListFoldersAPI_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/api/files/list-folders")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersPluginPages_NoAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, false, "", "", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/configuration")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/queue")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/detection")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/execution")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/monitoring")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default/configuration")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default/queue")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default/detection")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default/execution")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default/monitoring")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/default/workers")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/lifecycle")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/lifecycle/configuration")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/lifecycle/workers")
|
|
}
|
|
|
|
func TestSetupRoutes_RegistersPluginPages_WithAuth(t *testing.T) {
|
|
router := mux.NewRouter()
|
|
|
|
newRouteTestAdminHandlers().SetupRoutes(router, true, "admin", "password", "", "", true)
|
|
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/configuration")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/queue")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/detection")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/execution")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/monitoring")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg/configuration")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg/queue")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg/detection")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg/execution")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg/monitoring")
|
|
assertHasRoute(t, router, http.MethodGet, "/plugin/lanes/iceberg/workers")
|
|
}
|
|
|
|
func newRouteTestAdminHandlers() *AdminHandlers {
|
|
adminServer := &dash.AdminServer{}
|
|
store := sessions.NewCookieStore([]byte("test-session-key"))
|
|
return &AdminHandlers{
|
|
adminServer: adminServer,
|
|
sessionStore: store,
|
|
authHandlers: &AuthHandlers{adminServer: adminServer, sessionStore: store},
|
|
clusterHandlers: &ClusterHandlers{adminServer: adminServer},
|
|
fileBrowserHandlers: &FileBrowserHandlers{adminServer: adminServer},
|
|
userHandlers: &UserHandlers{adminServer: adminServer},
|
|
policyHandlers: &PolicyHandlers{adminServer: adminServer},
|
|
pluginHandlers: &PluginHandlers{adminServer: adminServer},
|
|
mqHandlers: &MessageQueueHandlers{adminServer: adminServer},
|
|
serviceAccountHandlers: &ServiceAccountHandlers{adminServer: adminServer},
|
|
}
|
|
}
|
|
|
|
func hasRoute(router *mux.Router, method string, path string) bool {
|
|
req := httptest.NewRequest(method, path, nil)
|
|
var match mux.RouteMatch
|
|
return router.Match(req, &match)
|
|
}
|
|
|
|
func assertHasRoute(t *testing.T, router *mux.Router, method string, path string) {
|
|
t.Helper()
|
|
if !hasRoute(router, method, path) {
|
|
t.Fatalf("expected %s %s to be registered", method, path)
|
|
}
|
|
}
|