Add Worker Version Check
This commit is contained in:
parent
a0f3d5e439
commit
595efd0c66
3 changed files with 8 additions and 0 deletions
|
@ -1,5 +1,8 @@
|
||||||
package constants
|
package constants
|
||||||
|
|
||||||
|
const WORKER_VERSION = "v1"
|
||||||
|
|
||||||
|
const WORKER_VERSION_HEADER = "morffix-version"
|
||||||
const SHARED_SECRET_HEADER = "morffix-secret"
|
const SHARED_SECRET_HEADER = "morffix-secret"
|
||||||
const NAME_HEADER = "morffix-name"
|
const NAME_HEADER = "morffix-name"
|
||||||
const UUID_HEADER = "morffix-uuid"
|
const UUID_HEADER = "morffix-uuid"
|
||||||
|
|
|
@ -32,6 +32,10 @@ func handleWorkerWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
return
|
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{
|
c, err := websocket.Accept(w, r, &websocket.AcceptOptions{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
})
|
})
|
||||||
|
|
|
@ -59,6 +59,7 @@ func connectToServer(ctx context.Context, uuid uuid.UUID) {
|
||||||
headers.Add(constants.SHARED_SECRET_HEADER, conf.SharedSecret)
|
headers.Add(constants.SHARED_SECRET_HEADER, conf.SharedSecret)
|
||||||
headers.Add(constants.NAME_HEADER, conf.Worker.Name)
|
headers.Add(constants.NAME_HEADER, conf.Worker.Name)
|
||||||
headers.Add(constants.UUID_HEADER, uuid.String())
|
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{
|
c, res, err := websocket.Dial(ctx, conf.Worker.Address, &websocket.DialOptions{
|
||||||
HTTPHeader: headers,
|
HTTPHeader: headers,
|
||||||
|
|
Loading…
Add table
Reference in a new issue