MCPcopy
hub / github.com/git-lfs/git-lfs / getCredURLForAPI

Function getCredURLForAPI

lfsapi/auth.go:199–238  ·  view source on GitHub ↗
(ef EndpointFinder, operation, remote string, apiEndpoint lfshttp.Endpoint, req *http.Request)

Source from the content-addressed store, hash-verified

197}
198
199func getCredURLForAPI(ef EndpointFinder, operation, remote string, apiEndpoint lfshttp.Endpoint, req *http.Request) (*url.URL, error) {
200 apiURL, err := url.Parse(apiEndpoint.Url)
201 if err != nil {
202 return nil, err
203 }
204
205 // if the LFS request doesn't match the current LFS url, don't bother
206 // attempting to set the Authorization header from the LFS or Git remote URLs.
207 if req.URL.Scheme != apiURL.Scheme ||
208 req.URL.Host != apiURL.Host {
209 return req.URL, nil
210 }
211
212 if setRequestAuthFromURL(req, apiURL) {
213 return nil, nil
214 }
215
216 if len(remote) > 0 {
217 if u := ef.GitRemoteURL(remote, operation == "upload"); u != "" {
218 schemedUrl, _ := fixSchemelessURL(u)
219
220 gitRemoteURL, err := url.Parse(schemedUrl)
221 if err != nil {
222 return nil, err
223 }
224
225 if gitRemoteURL.Scheme == apiURL.Scheme &&
226 gitRemoteURL.Host == apiURL.Host {
227
228 if setRequestAuthFromURL(req, gitRemoteURL) {
229 return nil, nil
230 }
231
232 return gitRemoteURL, nil
233 }
234 }
235 }
236
237 return apiURL, nil
238}
239
240// fixSchemelessURL prepends an empty scheme "//" if none was found in
241// the URL and replaces the first colon with a slash in order to satisfy RFC

Callers 1

getCredsMethod · 0.85

Calls 3

setRequestAuthFromURLFunction · 0.85
fixSchemelessURLFunction · 0.85
GitRemoteURLMethod · 0.65

Tested by

no test coverage detected