MCPcopy
hub / github.com/harness/harness / regexPathTerminatedWithMarker

Function regexPathTerminatedWithMarker

app/api/middleware/encode/encode.go:240–262  ·  view source on GitHub ↗

regexPathTerminatedWithMarker is similar to pathTerminatedWithMarker but with regex prefix support. Example: 1. Path: "/registry/app1%2Fremote2/artifact/foo/bar/+/summary" Prefix: => "^/registry/([^/]+)/artifact/" Marker: => "/+" MarkerReplacement: => "" ==> "/registry/app1%2Fremote2/artifact/foo%2

(
	r *http.Request,
	regexPrefix string,
	marker string,
	markerReplacement string,
)

Source from the content-addressed store, hash-verified

238// ==> "/registry/abc/artifact/foo%2Fbar/summary"
239
240func regexPathTerminatedWithMarker(
241 r *http.Request,
242 regexPrefix string,
243 marker string,
244 markerReplacement string,
245) (bool, error) {
246 prefixPattern := regexp.MustCompile(regexPrefix)
247
248 matches := prefixPattern.FindStringSubmatch(r.URL.Path)
249 // In case path doesn't start with prefix - nothing to encode
250 if len(matches) == 0 {
251 return false, nil
252 }
253
254 // We only care about the first match as we provide prefix
255 prefix := matches[0]
256
257 urlPath := r.URL.Path
258 if r.URL.RawPath != "" {
259 urlPath = r.URL.RawPath
260 }
261 return pathTerminatedWithMarkerAndURL(r, prefix, marker, markerReplacement, urlPath)
262}
263
264// cutOutTerminatedPath cuts out the resource path terminated with the provided marker (path segment suffix).
265// e.g. subPath: "/space1/space2/+/authToken", marker: "/+" => "/space1/space2"

Callers 1

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…