From 595efd0c66dbc166dd9f15ea49dda54667d894c6 Mon Sep 17 00:00:00 2001 From: speatzle Date: Sun, 5 May 2024 17:14:39 +0200 Subject: [PATCH] Add Worker Version Check --- constants/constants.go | 3 +++ server/worker.go | 4 ++++ worker/worker.go | 1 + 3 files changed, 8 insertions(+) diff --git a/constants/constants.go b/constants/constants.go index 6521c44..a1f5cf3 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -1,5 +1,8 @@ package constants +const WORKER_VERSION = "v1" + +const WORKER_VERSION_HEADER = "morffix-version" const SHARED_SECRET_HEADER = "morffix-secret" const NAME_HEADER = "morffix-name" const UUID_HEADER = "morffix-uuid" diff --git a/server/worker.go b/server/worker.go index 0390462..e79c2ea 100644 --- a/server/worker.go +++ b/server/worker.go @@ -32,6 +32,10 @@ func handleWorkerWebsocket(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusUnauthorized) return } + if r.Header.Get(constants.WORKER_VERSION_HEADER) != constants.WORKER_VERSION { + w.WriteHeader(http.StatusNotImplemented) + return + } c, err := websocket.Accept(w, r, &websocket.AcceptOptions{ InsecureSkipVerify: true, }) diff --git a/worker/worker.go b/worker/worker.go index 3f42d47..670ef2a 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -59,6 +59,7 @@ func connectToServer(ctx context.Context, uuid uuid.UUID) { headers.Add(constants.SHARED_SECRET_HEADER, conf.SharedSecret) headers.Add(constants.NAME_HEADER, conf.Worker.Name) headers.Add(constants.UUID_HEADER, uuid.String()) + headers.Add(constants.WORKER_VERSION_HEADER, constants.WORKER_VERSION) c, res, err := websocket.Dial(ctx, conf.Worker.Address, &websocket.DialOptions{ HTTPHeader: headers,