MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / rewriteRepositoryBase

Method rewriteRepositoryBase

src/cmd/linuxkit/registry/remote.go:288–324  ·  view source on GitHub ↗
(repo name.Repository)

Source from the content-addressed store, hash-verified

286}
287
288func (r *Remote) rewriteRepositoryBase(repo name.Repository) (string, []name.Option, error) {
289 originalRegistry := repo.RegistryStr()
290 mirror := r.resolveMirror(originalRegistry)
291
292 // No rewrite needed
293 if mirror == "" || mirror == originalRegistry {
294 return repo.RepositoryStr(), nil, nil
295 }
296
297 // get mirror protocol and separate host+path
298 var (
299 rest string
300 insecure bool
301 opts []name.Option
302 )
303
304 switch {
305 case strings.HasPrefix(mirror, "http://"):
306 insecure = true
307 rest = mirror[len("http://"):]
308 case strings.HasPrefix(mirror, "https://"):
309 insecure = false
310 rest = mirror[len("https://"):]
311 default:
312 insecure = false // Default to https if no protocol is specified
313 rest = mirror
314 }
315 if insecure {
316 opts = append(opts, name.Insecure)
317 }
318 opts = append(opts, name.WeakValidation)
319 // Build the new repository: mirror/foo/bar
320 // strip off trailing slash if present, so we do not end up with double slashes
321 newRepo := strings.TrimSuffix(rest, "/") + "/" + repo.RepositoryStr()
322
323 return newRepo, opts, nil
324}
325
326func (r *Remote) resolveMirror(registry string) string {
327 if r.proxy == nil {

Callers 3

rewriteReferenceMethod · 0.95
rewriteRepositoryMethod · 0.95
rewriteDigestMethod · 0.95

Calls 1

resolveMirrorMethod · 0.95

Tested by

no test coverage detected