mirror of
https://github.com/harness/drone.git
synced 2025-05-08 03:01:19 +08:00

This change adds the initial stepping stones for harness integration: - Authentication: JWT/PAT/SAT support - Authorization: ACL integration (acl currently denies requests as gitness hasn't been integrated yet) - Remote Clients for Token, User, ServiceAccount, ACL - User Integration: Syncs harness users during authentication if unknown - SA integration: syncs harness service accounts during authentication if unknown - Initial harness API: THIS WILL BE CHANGED IN THE FUTURE! - single harness subpackage (all marked with harness build flag) - harness & standalone wire + make build commands
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
// Copyright 2021 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package translator
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/internal/api/middleware/encode"
|
|
)
|
|
|
|
var (
|
|
terminatedPathPrefixesAPI = []string{"/v1/spaces/", "/v1/repos/"}
|
|
)
|
|
|
|
var _ RequestTranslator = (*TerminatedPathTranslator)(nil)
|
|
|
|
// TerminatedPathTranslator translates encoded paths.
|
|
// For example:
|
|
// - /space1/space2/+ -> /space1%2Fspace2
|
|
// - /space1/rep1.git -> /space1%2Frepo1
|
|
//
|
|
// Note: paths are terminated after initial routing.
|
|
type TerminatedPathTranslator struct{}
|
|
|
|
func NewTerminatedPathTranslator() *TerminatedPathTranslator {
|
|
return &TerminatedPathTranslator{}
|
|
}
|
|
|
|
// TranslatePreRouting is called before any routing decisions are made.
|
|
func (t *TerminatedPathTranslator) TranslatePreRouting(r *http.Request) (*http.Request, error) {
|
|
return r, nil
|
|
}
|
|
|
|
// TranslateGit is called for a git related request.
|
|
func (t *TerminatedPathTranslator) TranslateGit(r *http.Request) (*http.Request, error) {
|
|
return r, encode.GitPath(r)
|
|
}
|
|
|
|
// TranslateAPI is called for an API related request.
|
|
func (t *TerminatedPathTranslator) TranslateAPI(r *http.Request) (*http.Request, error) {
|
|
return r, encode.TerminatedPath(terminatedPathPrefixesAPI, r)
|
|
}
|
|
|
|
// TranslateWeb is called for an web related request.
|
|
func (t *TerminatedPathTranslator) TranslateWeb(r *http.Request) (*http.Request, error) {
|
|
return r, nil
|
|
}
|