drone/internal/api/request/repo.go
Johannes Batzill 4812beedc6 Enforce max path length on store layer to avoid racing condition, (#12)
Add enforcement of the path length to the store layer before writing the path, move errs to internal, and adds a comms package under internal/api.
2022-09-09 00:45:41 -07:00

26 lines
447 B
Go

package request
import (
"net/http"
"net/url"
"strings"
"github.com/go-chi/chi"
"github.com/harness/gitness/internal/errs"
)
const (
RepoRefParamName = "rref"
)
func GetRepoRef(r *http.Request) (string, error) {
rawRef := chi.URLParam(r, RepoRefParamName)
if rawRef == "" {
return "", errs.RepoReferenceNotFoundInRequest
}
// paths are unescaped and lower
ref, err := url.PathUnescape(rawRef)
return strings.ToLower(ref), err
}