0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-01-06 22:40:28 -05:00

build: fix mgmt and userprefs when building them separately (#1601)

move queryHasParams in common package
fixes building mgmt and userprefs separately

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
peusebiu 2023-07-10 19:40:14 +03:00 committed by GitHub
parent 94ba538e69
commit aaf03c75fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View file

@ -2,6 +2,7 @@ package common
import (
"net/http"
"net/url"
"strconv"
"strings"
"time"
@ -82,6 +83,16 @@ func WriteData(w http.ResponseWriter, status int, mediaType string, data []byte)
_, _ = w.Write(data)
}
func QueryHasParams(values url.Values, params []string) bool {
for _, param := range params {
if !values.Has(param) {
return false
}
}
return true
}
/*
GetAuthUserFromRequestSession returns identity
and auth status if on the request's cookie session is a logged in user.

View file

@ -99,7 +99,7 @@ func (mgmt *mgmt) handler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var resource string
if queryHasParams(r.URL.Query(), []string{"resource"}) {
if zcommon.QueryHasParams(r.URL.Query(), []string{"resource"}) {
resource = r.URL.Query().Get("resource")
} else {
resource = ConfigResource // default value of "resource" query param
@ -181,7 +181,7 @@ func (mgmt *mgmt) HandleGetConfig(w http.ResponseWriter, r *http.Request) {
// @Failure 400 {string} string "bad request".
// @Failure 500 {string} string "internal server error".
func HandleCertificatesAndPublicKeysUploads(response http.ResponseWriter, request *http.Request) {
if !queryHasParams(request.URL.Query(), []string{"tool"}) {
if !zcommon.QueryHasParams(request.URL.Query(), []string{"tool"}) {
response.WriteHeader(http.StatusBadRequest)
return
@ -207,13 +207,13 @@ func HandleCertificatesAndPublicKeysUploads(response http.ResponseWriter, reques
case signatures.NotationSignature:
var truststoreType string
if !queryHasParams(request.URL.Query(), []string{"truststoreName"}) {
if !zcommon.QueryHasParams(request.URL.Query(), []string{"truststoreName"}) {
response.WriteHeader(http.StatusBadRequest)
return
}
if queryHasParams(request.URL.Query(), []string{"truststoreType"}) {
if zcommon.QueryHasParams(request.URL.Query(), []string{"truststoreType"}) {
truststoreType = request.URL.Query().Get("truststoreType")
} else {
truststoreType = "ca" // default value of "truststoreType" query param

View file

@ -6,7 +6,6 @@ package extensions
import (
"errors"
"net/http"
"net/url"
"github.com/gorilla/mux"
@ -59,7 +58,7 @@ func SetupUserPreferencesRoutes(config *config.Config, router *mux.Router, store
// @Failure 400 {string} string "bad request".
func HandleUserPrefs(repoDB repodb.RepoDB, log log.Logger) func(w http.ResponseWriter, r *http.Request) {
return func(rsp http.ResponseWriter, req *http.Request) {
if !queryHasParams(req.URL.Query(), []string{"action"}) {
if !zcommon.QueryHasParams(req.URL.Query(), []string{"action"}) {
rsp.WriteHeader(http.StatusBadRequest)
return
@ -85,7 +84,7 @@ func HandleUserPrefs(repoDB repodb.RepoDB, log log.Logger) func(w http.ResponseW
}
func PutStar(rsp http.ResponseWriter, req *http.Request, repoDB repodb.RepoDB, log log.Logger) {
if !queryHasParams(req.URL.Query(), []string{"repo"}) {
if !zcommon.QueryHasParams(req.URL.Query(), []string{"repo"}) {
rsp.WriteHeader(http.StatusBadRequest)
return
@ -120,7 +119,7 @@ func PutStar(rsp http.ResponseWriter, req *http.Request, repoDB repodb.RepoDB, l
}
func PutBookmark(rsp http.ResponseWriter, req *http.Request, repoDB repodb.RepoDB, log log.Logger) {
if !queryHasParams(req.URL.Query(), []string{"repo"}) {
if !zcommon.QueryHasParams(req.URL.Query(), []string{"repo"}) {
rsp.WriteHeader(http.StatusBadRequest)
return
@ -153,13 +152,3 @@ func PutBookmark(rsp http.ResponseWriter, req *http.Request, repoDB repodb.RepoD
rsp.WriteHeader(http.StatusOK)
}
func queryHasParams(values url.Values, params []string) bool {
for _, param := range params {
if !values.Has(param) {
return false
}
}
return true
}