11 lines
1.0 KiB
Go
11 lines
1.0 KiB
Go
package schedulerbridge
|
|
|
|
import("crypto/hmac";"crypto/sha256";"encoding/hex";"fmt";"net/url";"strings")
|
|
const ConfigPath="/etc/sea-vhost/scheduler.json"
|
|
const TickPath="/api/v1/system/scheduler/tick"
|
|
const Command="exec /opt/sea-vhost/bin/sea-vhost-scheduler tick >/dev/null 2>&1"
|
|
const CronName="Sea vHost 系统调度器"
|
|
type Config struct{Controller string `json:"controller"`;NodeID uint64 `json:"nodeId"`;Key string `json:"key"`}
|
|
func(c Config)Validate()error{u,e:=url.Parse(c.Controller);if e!=nil||u.Scheme!="https"||u.Hostname()==""||u.User!=nil||u.RawQuery!=""||u.Fragment!=""||(u.Path!=""&&u.Path!="/")||strings.ContainsAny(c.Controller,"\r\n\x00")||c.NodeID==0{return fmt.Errorf("invalid controller configuration")};key,e:=hex.DecodeString(c.Key);if e!=nil||len(key)!=32{return fmt.Errorf("invalid trigger identity")};return nil}
|
|
func Signature(key,node,stamp,nonce string)string{mac:=hmac.New(sha256.New,[]byte(key));fmt.Fprintf(mac,"POST\n%s\n%s\n%s\n%s",TickPath,node,stamp,nonce);return hex.EncodeToString(mac.Sum(nil))}
|