mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
chore(refactor): add common.RandName to keep name generation DRY
This commit is contained in:
parent
7eb547faa5
commit
6e59f129c1
4 changed files with 25 additions and 14 deletions
|
@ -5,7 +5,6 @@ package cacheproxy
|
|||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
@ -170,12 +169,10 @@ func (h *Handler) ExternalURL() string {
|
|||
// The function returns the 32-bit random key which the run will use to identify itself.
|
||||
func (h *Handler) AddRun(data RunData) (string, error) {
|
||||
for retries := 0; retries < 3; retries++ {
|
||||
keyBytes := make([]byte, 4)
|
||||
_, err := rand.Read(keyBytes)
|
||||
key, err := common.RandName(4)
|
||||
if err != nil {
|
||||
return "", errors.New("Could not generate the run id")
|
||||
}
|
||||
key := hex.EncodeToString(keyBytes)
|
||||
|
||||
_, loaded := h.runs.LoadOrStore(key, data)
|
||||
if !loaded {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue