MCPcopy
hub / github.com/harness/harness / NewGitHandler

Function NewGitHandler

app/router/git.go:44–110  ·  view source on GitHub ↗

NewGitHandler returns a new GitHandler.

(
	config *types.Config,
	urlProvider url.Provider,
	authenticator authn.Authenticator,
	repoCtrl *repo.Controller,
	usageSender usage.Sender,
	lfsCtrl *lfs.Controller,
)

Source from the content-addressed store, hash-verified

42
43// NewGitHandler returns a new GitHandler.
44func NewGitHandler(
45 config *types.Config,
46 urlProvider url.Provider,
47 authenticator authn.Authenticator,
48 repoCtrl *repo.Controller,
49 usageSender usage.Sender,
50 lfsCtrl *lfs.Controller,
51) http.Handler {
52 // maxRepoDepth depends on config
53 maxRepoDepth := check.MaxRepoPathDepth
54 if !config.NestedSpacesEnabled {
55 maxRepoDepth = 2
56 }
57
58 // Use go-chi router for inner routing.
59 r := chi.NewRouter()
60
61 // Apply common api middleware.
62 r.Use(middleware.NoCache)
63 r.Use(middleware.Recoverer)
64
65 // configure logging middleware.
66 r.Use(logging.URLHandler("http.url"))
67 r.Use(hlog.MethodHandler("http.method"))
68 r.Use(logging.HLogRequestIDHandler())
69 r.Use(logging.HLogAccessLogHandler())
70
71 // for now always attempt auth - enforced per operation.
72 r.Use(middlewareauthn.Attempt(authenticator))
73
74 r.Route(fmt.Sprintf("/{%s}", request.PathParamRepoRef), func(r chi.Router) {
75 r.Use(goget.Middleware(maxRepoDepth, repoCtrl, urlProvider))
76 // routes that aren't coming from git
77 r.Group(func(r chi.Router) {
78 // redirect to repo (meant for UI, in case user navigates to clone url in browser)
79 r.Get("/", handlerrepo.HandleGitRedirect(urlProvider))
80 })
81
82 // routes that are coming from git (where we block the usage of session tokens)
83 r.Group(func(r chi.Router) {
84 r.Use(middlewareauthz.BlockSessionToken)
85 r.Use(usage.Middleware(usageSender))
86 // smart protocol
87 r.Post("/git-upload-pack", handlerrepo.HandleGitServicePack(
88 enum.GitServiceTypeUploadPack, repoCtrl, urlProvider))
89 r.Post("/git-receive-pack", handlerrepo.HandleGitServicePack(
90 enum.GitServiceTypeReceivePack, repoCtrl, urlProvider))
91 r.Get("/info/refs", handlerrepo.HandleGitInfoRefs(repoCtrl, urlProvider))
92
93 // dumb protocol
94 r.Get("/HEAD", stubGitHandler())
95 r.Get("/objects/info/alternates", stubGitHandler())
96 r.Get("/objects/info/http-alternates", stubGitHandler())
97 r.Get("/objects/info/packs", stubGitHandler())
98 r.Get("/objects/info/{file:[^/]*}", stubGitHandler())
99 r.Get("/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", stubGitHandler())
100 r.Get("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", stubGitHandler())
101 r.Get("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", stubGitHandler())

Callers 1

ProvideRouterFunction · 0.85

Calls 10

URLHandlerFunction · 0.92
HLogRequestIDHandlerFunction · 0.92
HLogAccessLogHandlerFunction · 0.92
MiddlewareFunction · 0.92
MiddlewareFunction · 0.92
GitPathBeforeFunction · 0.92
stubGitHandlerFunction · 0.85
GitLFSHandlerFunction · 0.85
PostMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…