@@ -6,6 +6,10 @@ import (
66 "strings"
77
88 . "github.com/mandelsoft/goutils/finalizer"
9+ cfgctx "ocm.software/ocm/api/config"
10+ "ocm.software/ocm/api/ocm/extensions/accessmethods/relativeociref"
11+ "ocm.software/ocm/api/ocm/extensions/attrs/preferrelativeattr"
12+ "ocm.software/ocm/api/ocm/extensions/blobhandler/handlers/oci/ocirepo/config"
913
1014 "github.com/mandelsoft/goutils/errors"
1115 "github.com/mandelsoft/goutils/sliceutils"
@@ -226,6 +230,14 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, artType, hint string, g
226230
227231 keep := keepblobattr .Get (ctx .GetContext ())
228232
233+ opts , _ := cfgctx.GetConfigured [config.UploadOptions ](ctx .GetContext ())
234+ if opts == nil {
235+ opts = & config.UploadOptions {}
236+ }
237+ // this attribute (only if set) overrides the enabling set in the
238+ // config.
239+ preferrelativeattr .ApplyTo (ctx .GetContext (), & opts .PreferRelativeAccess )
240+
229241 if m , ok := blob .(blobaccess.AnnotatedBlobAccess [accspeccpi.AccessMethodView ]); ok {
230242 // prepare for optimized point to point implementation
231243 log .Debug ("oci artifact handler with ocm access source" ,
@@ -340,6 +352,10 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, artType, hint string, g
340352 if tag != "" {
341353 tag = ":" + tag
342354 }
355+ if opts .PreferRelativeAccessFor (base ) {
356+ ref := namespace .GetNamespace () + tag + version
357+ return relativeociref .New (ref ), nil
358+ }
343359 ref := scheme + path .Join (base , namespace .GetNamespace ()) + tag + version
344360 return ociartifact .New (ref ), nil
345361}
0 commit comments