1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

add CreateWorkflowData

This commit is contained in:
Kwonunn 2024-11-24 16:17:14 +01:00 committed by Kwonunn
parent d92f9305dc
commit f81731e2d9

View file

@ -47,6 +47,18 @@ type WorkflowData struct {
repositoryMAC string repositoryMAC string
} }
func (h *Handler) CreateWorkflowData(owner string, name string, runnumber string, timestamp string) WorkflowData {
repo := owner + "/" + name
mac := computeMac(h.cacheSecret, repo, runnumber, timestamp)
return WorkflowData{
repositoryOwner: owner,
repositoryName: name,
runNumber: runnumber,
timestamp: timestamp,
repositoryMAC: mac,
}
}
func StartHandler(targetHost string, outboundIP string, port uint16, cacheSecret string, logger logrus.FieldLogger) (*Handler, error) { func StartHandler(targetHost string, outboundIP string, port uint16, cacheSecret string, logger logrus.FieldLogger) (*Handler, error) {
h := &Handler{} h := &Handler{}
@ -59,6 +71,7 @@ func StartHandler(targetHost string, outboundIP string, port uint16, cacheSecret
h.logger = logger h.logger = logger
h.cacheSecret = cacheSecret h.cacheSecret = cacheSecret
h.workflows = make(map[string]WorkflowData)
if outboundIP != "" { if outboundIP != "" {
h.outboundIP = outboundIP h.outboundIP = outboundIP
@ -187,8 +200,8 @@ func (h *Handler) Close() error {
return retErr return retErr
} }
func computeMac(key, repo, run, ts string) string { func computeMac(secret, repo, run, ts string) string {
mac := hmac.New(sha256.New, []byte(key)) mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(repo)) mac.Write([]byte(repo))
mac.Write([]byte(run)) mac.Write([]byte(run))
mac.Write([]byte(ts)) mac.Write([]byte(ts))