MCPcopy
hub / github.com/harness/harness / ProxyBlob

Method ProxyBlob

registry/app/remote/controller/proxy/controller.go:293–337  ·  view source on GitHub ↗
(
	ctx context.Context, art pkg.RegistryInfo, repoKey string, proxy types.UpstreamProxy,
)

Source from the content-addressed store, hash-verified

291}
292
293func (c *controller) ProxyBlob(
294 ctx context.Context, art pkg.RegistryInfo, repoKey string, proxy types.UpstreamProxy,
295) (int64, io.ReadCloser, error) {
296 rHelper, err := NewRemoteHelper(ctx, c.spaceFinder, c.secretService, repoKey, proxy)
297 if err != nil {
298 return 0, nil, err
299 }
300
301 art.Image, err = rHelper.GetImageName(ctx, c.spaceFinder, art.Image)
302 if err != nil {
303 return 0, nil, err
304 }
305
306 remoteImage := getRemoteRepo(art)
307 log.Ctx(ctx).Debug().Msgf("The blob doesn't exist, proxy the request to the target server, url:%v", remoteImage)
308
309 size, bReader, err := rHelper.BlobReader(ctx, remoteImage, art.Digest)
310 if err != nil {
311 log.Ctx(ctx).Error().Stack().Err(err).Msgf("failed to pull blob, error %v", err)
312 return 0, nil, errcode.ErrorCodeBlobUnknown.WithDetail(art.Digest)
313 }
314 desc := manifest.Descriptor{Size: size, Digest: digest.Digest(art.Digest)}
315
316 // This GoRoutine is to push the blob from Remote to Local registry. No retry logic is defined here.
317 go func(art pkg.RegistryInfo) {
318 // Cloning Context.
319 session, ok := request.AuthSessionFrom(ctx)
320 if !ok {
321 log.Ctx(ctx).Error().Stack().Err(err).Msg("failed to get auth session from context")
322 return
323 }
324 ctx2 := request.WithAuthSession(ctx, session)
325 ctx2 = context.WithoutCancel(ctx2)
326 ctx2 = context.WithValue(ctx2, cfg.GoRoutineKey, "AddBlob")
327 ctx2 = log.Ctx(ctx2).With().Logger().WithContext(ctx2)
328 err := c.putBlobToLocal(ctx2, art, remoteImage, repoKey, desc, rHelper)
329 if err != nil {
330 log.Ctx(ctx2).Error().Stack().Err(err).
331 Msgf("error while putting blob to localRegistry registry, %v", err)
332 return
333 }
334 log.Ctx(ctx2).Info().Msgf("Successfully updated the cache for digest %s", art.Digest)
335 }(art)
336 return size, bReader, nil
337}
338
339func (c *controller) putBlobToLocal(
340 ctx context.Context,

Callers

nothing calls this directly

Calls 14

putBlobToLocalMethod · 0.95
AuthSessionFromFunction · 0.92
WithAuthSessionFunction · 0.92
getRemoteRepoFunction · 0.85
MsgfMethod · 0.80
MsgMethod · 0.80
NewRemoteHelperFunction · 0.70
GetImageNameMethod · 0.65
DebugMethod · 0.65
BlobReaderMethod · 0.65
ErrMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected