@@ -11,6 +11,7 @@ import (
1111 "github.com/mandelsoft/goutils/sliceutils"
1212 "github.com/opencontainers/go-digest"
1313
14+ cfgctx "ocm.software/ocm/api/config"
1415 "ocm.software/ocm/api/oci"
1516 "ocm.software/ocm/api/oci/artdesc"
1617 "ocm.software/ocm/api/oci/extensions/repositories/artifactset"
@@ -23,10 +24,13 @@ import (
2324 "ocm.software/ocm/api/ocm/extensions/accessmethods/localociblob"
2425 "ocm.software/ocm/api/ocm/extensions/accessmethods/ociartifact"
2526 "ocm.software/ocm/api/ocm/extensions/accessmethods/ociblob"
27+ "ocm.software/ocm/api/ocm/extensions/accessmethods/relativeociref"
2628 "ocm.software/ocm/api/ocm/extensions/attrs/compatattr"
2729 "ocm.software/ocm/api/ocm/extensions/attrs/keepblobattr"
2830 "ocm.software/ocm/api/ocm/extensions/attrs/mapocirepoattr"
31+ "ocm.software/ocm/api/ocm/extensions/attrs/preferrelativeattr"
2932 storagecontext "ocm.software/ocm/api/ocm/extensions/blobhandler/handlers/oci"
33+ "ocm.software/ocm/api/ocm/extensions/blobhandler/handlers/oci/ocirepo/config"
3034 "ocm.software/ocm/api/utils/accessobj"
3135 "ocm.software/ocm/api/utils/blobaccess/blobaccess"
3236)
@@ -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