MCPcopy
hub / github.com/harness/harness / processGitRequest

Function processGitRequest

app/api/middleware/encode/encode.go:58–120  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

56}
57
58func processGitRequest(r *http.Request) (bool, error) {
59 const infoRefsPath = "/info/refs"
60 const uploadPack = "git-upload-pack"
61 const uploadPackPath = "/" + uploadPack
62 const receivePack = "git-receive-pack"
63 const receivePackPath = "/" + receivePack
64 const serviceParam = "service"
65
66 const lfsTransferPath = "/info/lfs/objects"
67 const lfsTransferBatchPath = lfsTransferPath + "/batch"
68
69 const oidParam = "oid"
70 const sizeParam = "size"
71
72 allowedServices := []string{
73 uploadPack,
74 receivePack,
75 }
76
77 urlPath := r.URL.Path
78 if r.URL.RawPath != "" {
79 urlPath = r.URL.RawPath
80 }
81
82 switch r.Method {
83 case http.MethodGet:
84 // check if request is coming from git client
85 if strings.HasSuffix(urlPath, infoRefsPath) && r.URL.Query().Has(serviceParam) {
86 service := r.URL.Query().Get(serviceParam)
87 if !slices.Contains(allowedServices, service) {
88 return false, errors.InvalidArgument("git request allows only %v service, got: %s",
89 allowedServices, service)
90 }
91 return pathTerminatedWithMarkerAndURL(r, "", infoRefsPath, infoRefsPath, urlPath)
92 }
93 // check if request is coming from git lfs client
94 if strings.HasSuffix(urlPath, lfsTransferPath) && r.URL.Query().Has(oidParam) {
95 return pathTerminatedWithMarkerAndURL(r, "", lfsTransferPath, lfsTransferPath, urlPath)
96 }
97
98 case http.MethodPost:
99 if strings.HasSuffix(urlPath, uploadPackPath) {
100 return pathTerminatedWithMarkerAndURL(r, "", uploadPackPath, uploadPackPath, urlPath)
101 }
102
103 if strings.HasSuffix(urlPath, receivePackPath) {
104 return pathTerminatedWithMarkerAndURL(r, "", receivePackPath, receivePackPath, urlPath)
105 }
106
107 if strings.HasSuffix(urlPath, lfsTransferBatchPath) {
108 return pathTerminatedWithMarkerAndURL(r, "", lfsTransferBatchPath, lfsTransferBatchPath, urlPath)
109 }
110
111 case http.MethodPut:
112 if strings.HasSuffix(urlPath, lfsTransferPath) &&
113 r.URL.Query().Has(oidParam) && r.URL.Query().Has(sizeParam) {
114 return pathTerminatedWithMarkerAndURL(r, "", lfsTransferPath, lfsTransferPath, urlPath)
115 }

Callers 1

GitPathBeforeFunction · 0.85

Calls 4

InvalidArgumentFunction · 0.92
GetMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…