mirror of
https://github.com/harness/drone.git
synced 2025-05-08 00:42:58 +00:00
This commit contains the following: - Improve and simplify error handling (remove unnecessary wrappers, make it feel like go) - Add extra validation for path creation and resource moving (path has to be within same top space, no top space alias allowed) - Add access logging for rest api and git api
30 lines
495 B
Go
30 lines
495 B
Go
package request
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/go-chi/chi"
|
|
)
|
|
|
|
const (
|
|
SpaceRefParamName = "sref"
|
|
)
|
|
|
|
var (
|
|
ErrSpaceReferenceNotFound = errors.New("No space reference found in request.")
|
|
)
|
|
|
|
func GetSpaceRef(r *http.Request) (string, error) {
|
|
rawRef := chi.URLParam(r, SpaceRefParamName)
|
|
if rawRef == "" {
|
|
return "", ErrSpaceReferenceNotFound
|
|
}
|
|
|
|
// paths are unescaped and lower
|
|
ref, err := url.PathUnescape(rawRef)
|
|
return strings.ToLower(ref), err
|
|
}
|