mirror of
https://github.com/harness/drone.git
synced 2025-05-04 16:52:22 +08:00

* Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into AH-307-plus-url-support-2 * [AH-307]: Comments * Merge commit * Merge commit * Merge commit * Added comments * Revert changes * Merge commit * Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into AH-307-plus-url-support-2 * Merge branch 'AH-306d' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into AH-307-plus-url-support-2 * fix space path handling * Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into AH-307-plus-url-support-2 * Updated URLs to support slashes with + separator * fix: [AH-306c]: fix anonymous flow * fix: [AH-306c]: fix anonymous flow * feat: [AH-307]: plus url support on UI (cherry picked from commit 3fb6add3ce03498b6668b5f8f6d547e1acedaec4) * [AH-307]: Added examples (cherry picked from commit e83e41303da536f421be333be04aed09fbf75f5f) * [AH-307]: Added Regex request rewrite support (cherry picked from commit ed7b155256bdcd1134bc228b5705556a1233add6) * fix: [AH-306c]: fix anonymous flow
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
// Copyright 2023 Harness, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package router
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/harness/gitness/registry/utils"
|
|
)
|
|
|
|
const RegistryMount = "/api/v1/registry"
|
|
const APIMount = "/api"
|
|
|
|
type RegistryRouter struct {
|
|
handler http.Handler
|
|
}
|
|
|
|
func NewRegistryRouter(handler http.Handler) *RegistryRouter {
|
|
return &RegistryRouter{handler: handler}
|
|
}
|
|
|
|
func (r *RegistryRouter) Handle(w http.ResponseWriter, req *http.Request) {
|
|
r.handler.ServeHTTP(w, req)
|
|
}
|
|
|
|
func (r *RegistryRouter) IsEligibleTraffic(req *http.Request) bool {
|
|
urlPath := req.URL.Path
|
|
if req.URL.RawPath != "" {
|
|
urlPath = req.URL.RawPath
|
|
}
|
|
if utils.HasAnyPrefix(urlPath, []string{RegistryMount, "/v2/", "/registry/"}) ||
|
|
(strings.HasPrefix(urlPath, APIMount+"/v1/spaces/") &&
|
|
utils.HasAnySuffix(urlPath, []string{"/artifacts", "/registries"})) {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (r *RegistryRouter) Name() string {
|
|
return "registry"
|
|
}
|