mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-06 17:40:58 +00:00
implement hmac generation
This commit is contained in:
parent
8bc36fb69a
commit
11006f4ef3
1 changed files with 13 additions and 1 deletions
|
@ -1,6 +1,9 @@
|
|||
package cacheproxy
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
@ -35,9 +38,10 @@ type Handler struct {
|
|||
cacheServerPort uint16
|
||||
|
||||
repositoryName string
|
||||
cacheKey string
|
||||
}
|
||||
|
||||
func StartHandler(repoName string, targetHost string, targetPort uint16, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) {
|
||||
func StartHandler(repoName string, targetHost string, targetPort uint16, outboundIP string, port uint16, cacheKey string, logger logrus.FieldLogger) (*Handler, error) {
|
||||
h := &Handler{}
|
||||
|
||||
if logger == nil {
|
||||
|
@ -49,6 +53,7 @@ func StartHandler(repoName string, targetHost string, targetPort uint16, outboun
|
|||
h.logger = logger
|
||||
|
||||
h.repositoryName = repoName
|
||||
h.cacheKey = h.cacheKey
|
||||
|
||||
if outboundIP != "" {
|
||||
h.outboundIP = outboundIP
|
||||
|
@ -119,6 +124,13 @@ func (h *Handler) Close() error {
|
|||
return retErr
|
||||
}
|
||||
|
||||
func (h *Handler) calculateMAC() string {
|
||||
mac := hmac.New(sha256.New, []byte(h.cacheKey))
|
||||
mac.Write([]byte(h.repositoryName))
|
||||
macBytes := mac.Sum(nil)
|
||||
return hex.EncodeToString(macBytes)
|
||||
}
|
||||
|
||||
// GET /_apis/artifactcache/cache
|
||||
func (h *Handler) find(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||
keys := strings.Split(r.URL.Query().Get("keys"), ",")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue