From 8389139516c23fb476972ed19f9158c932791a96 Mon Sep 17 00:00:00 2001 From: Uwe Krueger Date: Mon, 10 Jun 2024 17:28:15 +0200 Subject: [PATCH] separate internal and external usage --- .../common/inputs/types/binary/spec.go | 2 +- .../common/inputs/types/directory/spec.go | 2 +- .../common/inputs/types/docker/spec.go | 2 +- .../common/inputs/types/dockermulti/spec.go | 3 +- .../ocmcmds/common/inputs/types/helm/spec.go | 2 +- .../ocmcmds/common/inputs/types/maven/spec.go | 2 +- .../common/inputs/types/ociartifact/spec.go | 14 +- .../ocmcmds/common/inputs/types/utf8/spec.go | 2 +- .../ocmcmds/common/inputs/types/wget/spec.go | 2 +- .../commands/ocmcmds/sources/add/cmd_test.go | 2 +- .../commands/toicmds/package/bootstrap/cmd.go | 4 +- examples/lib/creds.md | 2 +- examples/lib/ctf/example.go | 2 +- .../01-basic-componentversion-creation.go | 2 +- .../03-working-with-credentials/common.go | 2 +- .../common.go | 2 +- .../06-signing-component-versions/common.go | 2 +- examples/lib/transfer1/example.go | 2 +- .../{standard => blobaccess}/access.go | 6 +- .../{ => blobaccess}/blobaccess_test.go | 5 +- pkg/blobaccess/{ => blobaccess}/cached.go | 9 +- pkg/blobaccess/{ => blobaccess}/compress.go | 46 ++-- .../{ => blobaccess}/compress_test.go | 2 +- pkg/blobaccess/blobaccess/data.go | 65 +++++ .../{standard => blobaccess}/dataaccess.go | 11 +- pkg/blobaccess/blobaccess/deprecated.go | 21 ++ pkg/blobaccess/{ => blobaccess}/digest.go | 4 +- pkg/blobaccess/blobaccess/doc.go | 11 + pkg/blobaccess/blobaccess/interface.go | 30 +++ .../{standard.go => blobaccess/other.go} | 60 ++--- pkg/blobaccess/blobaccess/standard.go | 38 +++ pkg/blobaccess/{ => blobaccess}/suite_test.go | 0 pkg/blobaccess/{ => blobaccess}/utils.go | 58 ----- pkg/blobaccess/bpi/interface.go | 13 + pkg/blobaccess/deprecated.go | 11 + pkg/blobaccess/dirtree/access.go | 10 +- pkg/blobaccess/dirtree/deprecated.go | 17 ++ pkg/blobaccess/doc.go | 11 +- pkg/blobaccess/dockerdaemon/access.go | 15 +- pkg/blobaccess/dockerdaemon/deprecated.go | 17 ++ pkg/blobaccess/dockerdaemon/options.go | 8 +- pkg/blobaccess/dockermulti/access.go | 6 +- pkg/blobaccess/dockermulti/deprecated.go | 17 ++ pkg/blobaccess/file/access.go | 59 +++-- pkg/blobaccess/file/options.go | 76 ++++++ .../{standard => file}/suite_test.go | 2 +- .../{standard => file}/temp_test.go | 7 +- pkg/blobaccess/forward.go | 233 +++++++++++++++--- .../helm/{resource.go => access.go} | 14 +- pkg/blobaccess/helm/deprecated.go | 17 ++ pkg/blobaccess/helm/options.go | 7 + pkg/blobaccess/maven/access.go | 18 +- pkg/blobaccess/maven/access_test.go | 14 +- pkg/blobaccess/maven/deprecated.go | 36 +++ pkg/blobaccess/maven/utils.go | 6 +- .../ociartifact/{resource.go => access.go} | 6 +- pkg/blobaccess/ociartifact/deprecated.go | 17 ++ pkg/blobaccess/wget/access.go | 14 +- pkg/blobaccess/wget/deprecated.go | 23 ++ pkg/common/accessio/access.go | 131 ---------- pkg/common/accessio/cache.go | 52 ++-- pkg/common/accessio/cache_test.go | 9 +- pkg/common/accessio/deprecated.go | 233 ++++++++++++++++++ pkg/common/accessio/digestreader.go | 44 ---- pkg/common/accessio/digestwriter.go | 22 -- pkg/common/accessio/utils.go | 38 --- pkg/common/accessio/wrapper.go | 8 +- pkg/common/accessobj/accessstate.go | 5 +- pkg/common/accessobj/cachedblob.go | 25 +- pkg/common/accessobj/filesystemaccess.go | 9 +- pkg/contexts/config/cpi/content.go | 2 +- pkg/contexts/oci/annotations/annotations.go | 16 +- pkg/contexts/oci/artdesc/artifact.go | 2 +- pkg/contexts/oci/artdesc/config.go | 2 +- pkg/contexts/oci/artdesc/index.go | 2 +- pkg/contexts/oci/artdesc/manifest.go | 2 +- pkg/contexts/oci/artdesc/utils.go | 2 +- pkg/contexts/oci/cpi/interface.go | 6 +- pkg/contexts/oci/cpi/support/artifact.go | 2 +- .../oci/cpi/support/artifactsetblobaccess.go | 2 +- pkg/contexts/oci/cpi/support/base.go | 2 +- pkg/contexts/oci/cpi/support/flavor_index.go | 2 +- pkg/contexts/oci/cpi/support/namespace.go | 2 +- .../oci/identity/{creds.go => deprecated.go} | 0 pkg/contexts/oci/interface.go | 2 +- pkg/contexts/oci/internal/errors.go | 2 +- pkg/contexts/oci/internal/repository.go | 2 +- pkg/contexts/oci/ociutils/helm/art_test.go | 2 +- pkg/contexts/oci/ociutils/helm/artifact.go | 5 +- pkg/contexts/oci/ociutils/info.go | 2 +- pkg/contexts/oci/ociutils/print.go | 2 +- .../repositories/artifactset/artifactset.go | 12 +- .../artifactset/filesystemaccess.go | 2 +- .../oci/repositories/artifactset/format.go | 2 +- .../oci/repositories/artifactset/repo_test.go | 2 +- .../artifactset/utils_synthesis.go | 5 +- pkg/contexts/oci/repositories/ctf/ctf_test.go | 2 +- pkg/contexts/oci/repositories/ctf/format.go | 2 +- .../oci/repositories/ctf/namespace.go | 2 +- .../oci/repositories/ctf/synthesis_test.go | 2 +- .../oci/repositories/docker/artifact.go | 4 +- .../oci/repositories/docker/convert.go | 6 +- .../oci/repositories/docker/namespace.go | 2 +- pkg/contexts/oci/repositories/ocireg/blobs.go | 5 +- .../oci/repositories/ocireg/namespace.go | 2 +- pkg/contexts/oci/repositories/ocireg/utils.go | 4 +- pkg/contexts/oci/types/interface.go | 87 +++++++ .../ocm/accessmethods/compose/method.go | 2 +- .../ocm/accessmethods/github/method.go | 2 +- pkg/contexts/ocm/accessmethods/helm/method.go | 2 +- .../ocm/accessmethods/maven/method.go | 4 +- pkg/contexts/ocm/accessmethods/npm/method.go | 2 +- .../ocm/accessmethods/ociartifact/method.go | 2 +- .../accessmethods/ociartifact/method_test.go | 2 +- .../ocm/accessmethods/ociblob/method.go | 2 +- .../ocm/accessmethods/plugin/method.go | 2 +- .../relativeociref/method_test.go | 2 +- pkg/contexts/ocm/accessmethods/s3/method.go | 2 +- pkg/contexts/ocm/accessmethods/wget/method.go | 4 +- .../generic/maven/blobhandler_test.go | 4 +- .../handlers/generic/ocirepo/blobhandler.go | 2 +- .../handlers/oci/ocirepo/blobhandler.go | 2 +- .../ocm/blobhandler/handlers/ocm/ctx.go | 2 +- .../{extra_identities.go => deprecated.go} | 0 pkg/contexts/ocm/cpi/accspeccpi/method.go | 2 +- pkg/contexts/ocm/cpi/accspeccpi/methodview.go | 2 +- pkg/contexts/ocm/cpi/compose_test.go | 2 +- pkg/contexts/ocm/cpi/repocpi/blobcache.go | 2 +- pkg/contexts/ocm/cpi/repocpi/bridge_c.go | 2 +- pkg/contexts/ocm/cpi/repocpi/bridge_cv.go | 2 +- pkg/contexts/ocm/cpi/repocpi/view_cv.go | 2 +- pkg/contexts/ocm/cpi/utils.go | 2 +- pkg/contexts/ocm/cpi/view_rsc.go | 2 +- .../digester/digesters/artifact/digester.go | 2 +- .../download/handlers/blueprint/extractor.go | 2 +- .../download/handlers/blueprint/handler.go | 2 +- .../ocm/download/handlers/helm/handler.go | 2 +- .../artifactblob/datablob/resource.go | 2 +- .../artifactblob/dirtreeblob/resource.go | 2 +- .../artifactblob/dockerdaemonblob/resource.go | 2 +- .../artifactblob/dockermultiblob/resource.go | 2 +- .../artifactblob/fileblob/resource.go | 9 +- .../artifactblob/genericblob/resource.go | 2 +- .../artifactblob/helmblob/resource.go | 2 +- .../artifactblob/mavenblob/resource.go | 2 +- .../artifactblob/ociartifactblob/resource.go | 2 +- .../artifactblob/wgetblob/resource.go | 2 +- pkg/contexts/ocm/interface.go | 2 +- pkg/contexts/ocm/internal/repository.go | 2 +- pkg/contexts/ocm/plugin/utils.go | 3 +- .../comparch/accessmethod_localfs.go | 2 +- .../repositories/comparch/comparch_test.go | 2 +- .../repositories/comparch/componentarchive.go | 2 +- .../ocm/repositories/comparch/repository.go | 2 +- .../repositories/composition/repository.go | 2 +- .../composition/repository_test.go | 2 +- .../ocm/repositories/ctf/repo_test.go | 2 +- .../genericocireg/accessmethod_localblob.go | 2 +- .../ocm/repositories/genericocireg/info.go | 2 +- .../ocm/repositories/genericocireg/state.go | 2 +- .../virtual/accessmethod_localblob.go | 2 +- .../repositories/virtual/example/example.go | 5 +- .../ocm/repositories/virtual/repo_test.go | 2 +- pkg/contexts/ocm/signing/deprecated.go | 8 + pkg/contexts/ocm/signing/options.go | 7 - .../transferhandler/standard/handler_test.go | 2 +- pkg/contexts/ocm/utils/resource.go | 2 +- pkg/env/builder/blob.go | 2 +- pkg/env/builder/builder.go | 2 +- pkg/env/builder/oci_config.go | 2 +- pkg/env/builder/oci_layer.go | 2 +- pkg/env/builder/ocm_resource.go | 2 +- pkg/env/builder/ocm_source.go | 2 +- pkg/helm/chartaccess.go | 5 +- pkg/helm/loader/access.go | 2 +- pkg/helm/loader/loader.go | 5 +- pkg/iotools/deprecated.go | 12 + pkg/iotools/readerwriter.go | 6 - pkg/signing/cert.go | 22 -- pkg/signing/deprecated.go | 23 ++ pkg/signing/signutils/certs_test.go | 2 +- pkg/signing/signutils/utils.go | 2 +- pkg/toi/drivers/docker/driver.go | 2 +- pkg/toi/install/execute.go | 2 +- pkg/toi/install/interface.go | 2 +- 185 files changed, 1353 insertions(+), 759 deletions(-) rename pkg/blobaccess/{standard => blobaccess}/access.go (93%) rename pkg/blobaccess/{ => blobaccess}/blobaccess_test.go (89%) rename pkg/blobaccess/{ => blobaccess}/cached.go (62%) rename pkg/blobaccess/{ => blobaccess}/compress.go (71%) rename pkg/blobaccess/{ => blobaccess}/compress_test.go (96%) create mode 100644 pkg/blobaccess/blobaccess/data.go rename pkg/blobaccess/{standard => blobaccess}/dataaccess.go (84%) create mode 100644 pkg/blobaccess/blobaccess/deprecated.go rename pkg/blobaccess/{ => blobaccess}/digest.go (68%) create mode 100644 pkg/blobaccess/blobaccess/doc.go create mode 100644 pkg/blobaccess/blobaccess/interface.go rename pkg/blobaccess/{standard.go => blobaccess/other.go} (62%) create mode 100644 pkg/blobaccess/blobaccess/standard.go rename pkg/blobaccess/{ => blobaccess}/suite_test.go (100%) rename pkg/blobaccess/{ => blobaccess}/utils.go (59%) create mode 100644 pkg/blobaccess/deprecated.go create mode 100644 pkg/blobaccess/dirtree/deprecated.go create mode 100644 pkg/blobaccess/dockerdaemon/deprecated.go create mode 100644 pkg/blobaccess/dockermulti/deprecated.go create mode 100644 pkg/blobaccess/file/options.go rename pkg/blobaccess/{standard => file}/suite_test.go (89%) rename pkg/blobaccess/{standard => file}/temp_test.go (98%) rename pkg/blobaccess/helm/{resource.go => access.go} (84%) create mode 100644 pkg/blobaccess/helm/deprecated.go create mode 100644 pkg/blobaccess/maven/deprecated.go rename pkg/blobaccess/ociartifact/{resource.go => access.go} (82%) create mode 100644 pkg/blobaccess/ociartifact/deprecated.go create mode 100644 pkg/blobaccess/wget/deprecated.go create mode 100644 pkg/common/accessio/deprecated.go delete mode 100644 pkg/common/accessio/digestreader.go delete mode 100644 pkg/common/accessio/digestwriter.go rename pkg/contexts/oci/identity/{creds.go => deprecated.go} (100%) create mode 100644 pkg/contexts/oci/types/interface.go rename pkg/contexts/ocm/consts/{extra_identities.go => deprecated.go} (100%) create mode 100644 pkg/contexts/ocm/signing/deprecated.go create mode 100644 pkg/iotools/deprecated.go diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/spec.go index e7b33599cc..2869075a2a 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/binary/spec.go @@ -36,5 +36,5 @@ func (s *Spec) Validate(fldPath *field.Path, ctx inputs.Context, inputFilePath s } func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (blobaccess.BlobAccess, string, error) { - return s.ProcessBlob(ctx, blobaccess.DataAccessForBytes([]byte(s.Data)), ctx.FileSystem()) + return s.ProcessBlob(ctx, blobaccess.DataAccessForData([]byte(s.Data)), ctx.FileSystem()) } diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go index 4084b544ab..d37eff1036 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go @@ -64,7 +64,7 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (bloba return nil, "", fmt.Errorf("resource type is dir but a file was provided") } - access, err := dirtree.BlobAccessForDirTree(inputPath, + access, err := dirtree.BlobAccess(inputPath, dirtree.WithMimeType(s.MediaType), dirtree.WithFileSystem(fs), dirtree.WithCompressWithGzip(s.Compress()), diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/docker/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/docker/spec.go index a8a34ffd9c..78d4cfdee2 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/docker/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/docker/spec.go @@ -47,7 +47,7 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (bloba if err != nil { return nil, "", err } - blob, version, err := dockerdaemon.BlobAccessForImageFromDockerDaemon(s.Path, dockerdaemon.WithVersion(info.ComponentVersion.GetVersion()), dockerdaemon.WithOrigin(info.ComponentVersion)) + blob, version, err := dockerdaemon.BlobAccess(s.Path, dockerdaemon.WithVersion(info.ComponentVersion.GetVersion()), dockerdaemon.WithOrigin(info.ComponentVersion)) if err != nil { return nil, "", err } diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/dockermulti/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/dockermulti/spec.go index 58941c122b..e01530de5e 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/dockermulti/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/dockermulti/spec.go @@ -4,7 +4,6 @@ import ( "fmt" . "github.com/mandelsoft/goutils/finalizer" - "k8s.io/apimachinery/pkg/util/validation/field" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs" @@ -92,7 +91,7 @@ func (s *Spec) getVariant(ctx clictx.Context, finalize *Finalizer, variant strin } func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (blobaccess.BlobAccess, string, error) { - blob, err := dockermulti.BlobAccessForMultiImageFromDockerDaemon( + blob, err := dockermulti.BlobAccess( dockermulti.WithContext(ctx), dockermulti.WithPrinter(ctx.Printer()), dockermulti.WithVariants(s.Variants...), diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/helm/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/helm/spec.go index 18fdcd9f8c..77835344d3 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/helm/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/helm/spec.go @@ -99,7 +99,7 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (blob override = false } - blob, name, vers, err := helm.BlobAccessForHelmChart(path, + blob, name, vers, err := helm.BlobAccess(path, helm.WithContext(ctx), helm.WithFileSystem(ctx.FileSystem()), helm.WithPrinter(ctx.Printer()), diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go index dc3fe396a8..7d34144446 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go @@ -89,7 +89,7 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (bloba return nil, "", err } } - access, err := mavenblob.BlobAccessForMavenCoords(repo, &s.Coordinates, + access, err := mavenblob.BlobAccessForCoords(repo, &s.Coordinates, mavenblob.WithCredentialContext(ctx), mavenblob.WithLoggingContext(ctx), mavenblob.WithCachingFileSystem(vfsattr.Get(ctx)), diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/ociartifact/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/ociartifact/spec.go index 3809ec45c5..af1ff65a32 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/ociartifact/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/ociartifact/spec.go @@ -8,7 +8,7 @@ import ( "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/cpi" "github.com/open-component-model/ocm/pkg/blobaccess" - ociartifact2 "github.com/open-component-model/ocm/pkg/blobaccess/ociartifact" + ociartifactblob "github.com/open-component-model/ocm/pkg/blobaccess/ociartifact" "github.com/open-component-model/ocm/pkg/contexts/oci/grammar" "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/docker" "github.com/open-component-model/ocm/pkg/contexts/oci/transfer/filters" @@ -47,7 +47,7 @@ func (s *Spec) Validate(fldPath *field.Path, ctx inputs.Context, inputFilePath s return allErrs } -func (s *Spec) CreateFilter() ociartifact2.Option { +func (s *Spec) CreateFilter() ociartifactblob.Option { var filter []filters.Filter for _, v := range s.Platforms { @@ -57,18 +57,18 @@ func (s *Spec) CreateFilter() ociartifact2.Option { } } if len(filter) > 0 { - return ociartifact2.WithFilter(filters.Or(filter...)) + return ociartifactblob.WithFilter(filters.Or(filter...)) } return nil } func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (blobaccess.BlobAccess, string, error) { filter := s.CreateFilter() - blob, version, err := ociartifact2.BlobAccessForOCIArtifact(s.Path, + blob, version, err := ociartifactblob.BlobAccess(s.Path, filter, - ociartifact2.WithContext(ctx), - ociartifact2.WithPrinter(ctx.Printer()), - ociartifact2.WithVersion(info.ComponentVersion.GetVersion()), + ociartifactblob.WithContext(ctx), + ociartifactblob.WithPrinter(ctx.Printer()), + ociartifactblob.WithVersion(info.ComponentVersion.GetVersion()), ) if err != nil { return nil, "", err diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/spec.go index e94c614c73..22a7b49776 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8/spec.go @@ -121,7 +121,7 @@ func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (bloba if err != nil { return nil, "", err } - return s.ProcessBlob(ctx, blobaccess.DataAccessForBytes(data), ctx.FileSystem()) + return s.ProcessBlob(ctx, blobaccess.DataAccessForData(data), ctx.FileSystem()) } func Prepare(raw []byte) (interface{}, error) { diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/spec.go index 3c58a9d8a1..2b58d1590f 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/wget/spec.go @@ -55,7 +55,7 @@ func (s *Spec) Validate(fldPath *field.Path, ctx inputs.Context, inputFilePath s } func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (blobaccess.BlobAccess, string, error) { - access, err := wget.BlobAccessForWget(s.URL, + access, err := wget.BlobAccess(s.URL, wget.WithCredentialContext(ctx), wget.WithLoggingContext(ctx), wget.WithMimeType(s.MimeType), diff --git a/cmds/ocm/commands/ocmcmds/sources/add/cmd_test.go b/cmds/ocm/commands/ocmcmds/sources/add/cmd_test.go index 631c1b125e..9b8635fbfc 100644 --- a/cmds/ocm/commands/ocmcmds/sources/add/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/sources/add/cmd_test.go @@ -9,8 +9,8 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/cmds/ocm/testhelper" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" diff --git a/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go b/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go index 8555d8bdde..20299b98a4 100644 --- a/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go +++ b/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go @@ -200,7 +200,7 @@ func (o *Command) Complete(args []string) error { if err != nil { return errors.Wrapf(err, "failed reading credentials file %q", o.CredentialsFile) } - o.Credentials = blobaccess.DataAccessForBytes(data, o.CredentialsFile) + o.Credentials = blobaccess.DataAccessForData(data, o.CredentialsFile) } if len(o.ParameterFile) == 0 { if ok, _ := vfs.FileExists(o.FileSystem(), DEFAULT_PARAMETER_FILE); ok { @@ -212,7 +212,7 @@ func (o *Command) Complete(args []string) error { if err != nil { return errors.Wrapf(err, "failed reading parameter file %q", o.ParameterFile) } - o.Parameters = blobaccess.DataAccessForBytes(data, o.ParameterFile) + o.Parameters = blobaccess.DataAccessForData(data, o.ParameterFile) } return nil } diff --git a/examples/lib/creds.md b/examples/lib/creds.md index ed3e2af60e..f526a3c133 100644 --- a/examples/lib/creds.md +++ b/examples/lib/creds.md @@ -120,7 +120,7 @@ consumer ids always feature the attribute `type`, describing the kind of context. For example, to describe the request for credentials for -an [OCI registry](../../pkg/contexts/oci/identity/identity.go) and repository, +an [OCI registry](../../pkg/contexts/credentials/builtin/oci/identity/identity.go) and repository, the type value is `oci.CONSUMER_TYPE`. Additionally, the following attributes are used to fully describe the usage context. diff --git a/examples/lib/ctf/example.go b/examples/lib/ctf/example.go index c00d1a6e7d..7defc0cef7 100644 --- a/examples/lib/ctf/example.go +++ b/examples/lib/ctf/example.go @@ -6,8 +6,8 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/vfs/pkg/memoryfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/ocm" diff --git a/examples/lib/tour/02-composing-a-component-version/01-basic-componentversion-creation.go b/examples/lib/tour/02-composing-a-component-version/01-basic-componentversion-creation.go index da13cdc0bb..bcdb5f60d1 100644 --- a/examples/lib/tour/02-composing-a-component-version/01-basic-componentversion-creation.go +++ b/examples/lib/tour/02-composing-a-component-version/01-basic-componentversion-creation.go @@ -6,8 +6,8 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact" diff --git a/examples/lib/tour/03-working-with-credentials/common.go b/examples/lib/tour/03-working-with-credentials/common.go index 86151feab0..84d2e03b76 100644 --- a/examples/lib/tour/03-working-with-credentials/common.go +++ b/examples/lib/tour/03-working-with-credentials/common.go @@ -6,8 +6,8 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/ocm" diff --git a/examples/lib/tour/05-transporting-component-versions/common.go b/examples/lib/tour/05-transporting-component-versions/common.go index 81fdab6c30..df0297bf66 100644 --- a/examples/lib/tour/05-transporting-component-versions/common.go +++ b/examples/lib/tour/05-transporting-component-versions/common.go @@ -6,8 +6,8 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact" diff --git a/examples/lib/tour/06-signing-component-versions/common.go b/examples/lib/tour/06-signing-component-versions/common.go index f0d013f572..0b96555bcb 100644 --- a/examples/lib/tour/06-signing-component-versions/common.go +++ b/examples/lib/tour/06-signing-component-versions/common.go @@ -8,9 +8,9 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" + "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/examples/lib/helper" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact" diff --git a/examples/lib/transfer1/example.go b/examples/lib/transfer1/example.go index ff534fc62b..30243752aa 100644 --- a/examples/lib/transfer1/example.go +++ b/examples/lib/transfer1/example.go @@ -8,10 +8,10 @@ import ( "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/examples/lib/helper" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" diff --git a/pkg/blobaccess/standard/access.go b/pkg/blobaccess/blobaccess/access.go similarity index 93% rename from pkg/blobaccess/standard/access.go rename to pkg/blobaccess/blobaccess/access.go index b4d826756e..4d64c9b47b 100644 --- a/pkg/blobaccess/standard/access.go +++ b/pkg/blobaccess/blobaccess/access.go @@ -1,4 +1,4 @@ -package standard +package blobaccess import ( "bytes" @@ -12,10 +12,6 @@ import ( mimetypes "github.com/open-component-model/ocm/pkg/mime" ) -type _nopCloser = iotools.NopCloser - -//////////////////////////////////////////////////////////////////////////////// - type bytesAccess struct { _nopCloser data []byte diff --git a/pkg/blobaccess/blobaccess_test.go b/pkg/blobaccess/blobaccess/blobaccess_test.go similarity index 89% rename from pkg/blobaccess/blobaccess_test.go rename to pkg/blobaccess/blobaccess/blobaccess_test.go index 501c32787a..3693b47db3 100644 --- a/pkg/blobaccess/blobaccess_test.go +++ b/pkg/blobaccess/blobaccess/blobaccess_test.go @@ -10,8 +10,9 @@ import ( "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/mime" ) @@ -43,7 +44,7 @@ var _ = Describe("blob access ref counting", func() { temp := Must(os.CreateTemp("", "testfile*")) path := temp.Name() temp.Close() - blob := blobaccess.ForTemporaryFilePath(mime.MIME_TEXT, path, osfs.OsFs) + blob := file.BlobAccessForTemporaryFilePath(mime.MIME_TEXT, path) Expect(vfs.FileExists(osfs.OsFs, path)).To(BeTrue()) diff --git a/pkg/blobaccess/cached.go b/pkg/blobaccess/blobaccess/cached.go similarity index 62% rename from pkg/blobaccess/cached.go rename to pkg/blobaccess/blobaccess/cached.go index d71748a367..c3a297c102 100644 --- a/pkg/blobaccess/cached.go +++ b/pkg/blobaccess/blobaccess/cached.go @@ -5,6 +5,7 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/utils" ) @@ -17,15 +18,15 @@ func ForCachedBlobAccess(blob BlobAccess, fss ...vfs.FileSystem) (BlobAccess, er } defer r.Close() - file, err := vfs.TempFile(fs, "", "cachedBlob*") + f, err := vfs.TempFile(fs, "", "cachedBlob*") if err != nil { return nil, err } - _, err = io.Copy(file, r) + _, err = io.Copy(f, r) if err != nil { return nil, err } - file.Close() + f.Close() - return ForTemporaryFilePath(blob.MimeType(), file.Name(), fs), nil + return file.BlobAccessForTemporaryFilePath(blob.MimeType(), f.Name(), file.WithFileSystem(fs)), nil } diff --git a/pkg/blobaccess/compress.go b/pkg/blobaccess/blobaccess/compress.go similarity index 71% rename from pkg/blobaccess/compress.go rename to pkg/blobaccess/blobaccess/compress.go index f8c5c67b07..c841c292a9 100644 --- a/pkg/blobaccess/compress.go +++ b/pkg/blobaccess/blobaccess/compress.go @@ -10,29 +10,29 @@ import ( "github.com/opencontainers/go-digest" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" - compression2 "github.com/open-component-model/ocm/pkg/common/compression" + "github.com/open-component-model/ocm/pkg/common/compression" "github.com/open-component-model/ocm/pkg/mime" ) //////////////////////////////////////////////////////////////////////////////// -type compression struct { - blob BlobAccess +type _compression struct { + blob bpi.BlobAccess } -var _ bpi.BlobAccessBase = (*compression)(nil) +var _ bpi.BlobAccessBase = (*_compression)(nil) -func (c *compression) Close() error { +func (c *_compression) Close() error { return c.blob.Close() } -func (c *compression) Get() ([]byte, error) { +func (c *_compression) Get() ([]byte, error) { r, err := c.blob.Reader() if err != nil { return nil, err } defer r.Close() - rr, _, err := compression2.AutoDecompress(r) + rr, _, err := compression.AutoDecompress(r) if err != nil { return nil, err } @@ -59,13 +59,13 @@ func (r *reader) Close() error { return errors.Join(err, r.err) } -func (c *compression) Reader() (io.ReadCloser, error) { +func (c *_compression) Reader() (io.ReadCloser, error) { r, err := c.blob.Reader() if err != nil { return nil, err } defer r.Close() - rr, _, err := compression2.AutoDecompress(r) + rr, _, err := compression.AutoDecompress(r) if err != nil { return nil, err } @@ -83,11 +83,11 @@ func (c *compression) Reader() (io.ReadCloser, error) { return outr, nil } -func (c *compression) Digest() digest.Digest { - return BLOB_UNKNOWN_DIGEST +func (c *_compression) Digest() digest.Digest { + return bpi.BLOB_UNKNOWN_DIGEST } -func (c *compression) MimeType() string { +func (c *_compression) MimeType() string { m := c.blob.MimeType() if mime.IsGZip(m) { return m @@ -95,20 +95,20 @@ func (c *compression) MimeType() string { return m + "+gzip" } -func (c *compression) DigestKnown() bool { +func (c *_compression) DigestKnown() bool { return false } -func (c *compression) Size() int64 { - return BLOB_UNKNOWN_SIZE +func (c *_compression) Size() int64 { + return bpi.BLOB_UNKNOWN_SIZE } -func WithCompression(blob BlobAccess) (BlobAccess, error) { +func WithCompression(blob bpi.BlobAccess) (bpi.BlobAccess, error) { b, err := blob.Dup() if err != nil { return nil, err } - return bpi.NewBlobAccessForBase(&compression{ + return bpi.NewBlobAccessForBase(&_compression{ blob: b, }), nil } @@ -116,7 +116,7 @@ func WithCompression(blob BlobAccess) (BlobAccess, error) { //////////////////////////////////////////////////////////////////////////////// type decompression struct { - blob BlobAccess + blob bpi.BlobAccess } var _ bpi.BlobAccessBase = (*decompression)(nil) @@ -131,7 +131,7 @@ func (c *decompression) Get() ([]byte, error) { return nil, err } defer r.Close() - rr, _, err := compression2.AutoDecompress(r) + rr, _, err := compression.AutoDecompress(r) if err != nil { return nil, err } @@ -149,12 +149,12 @@ func (c *decompression) Reader() (io.ReadCloser, error) { return nil, err } defer r.Close() - rr, _, err := compression2.AutoDecompress(r) + rr, _, err := compression.AutoDecompress(r) return rr, err } func (c *decompression) Digest() digest.Digest { - return BLOB_UNKNOWN_DIGEST + return bpi.BLOB_UNKNOWN_DIGEST } func (c *decompression) MimeType() string { @@ -170,10 +170,10 @@ func (c *decompression) DigestKnown() bool { } func (c *decompression) Size() int64 { - return BLOB_UNKNOWN_SIZE + return bpi.BLOB_UNKNOWN_SIZE } -func WithDecompression(blob BlobAccess) (BlobAccess, error) { +func WithDecompression(blob bpi.BlobAccess) (bpi.BlobAccess, error) { b, err := blob.Dup() if err != nil { return nil, err diff --git a/pkg/blobaccess/compress_test.go b/pkg/blobaccess/blobaccess/compress_test.go similarity index 96% rename from pkg/blobaccess/compress_test.go rename to pkg/blobaccess/blobaccess/compress_test.go index bb8f2aebb2..4487bb6ca9 100644 --- a/pkg/blobaccess/compress_test.go +++ b/pkg/blobaccess/blobaccess/compress_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/mime" ) diff --git a/pkg/blobaccess/blobaccess/data.go b/pkg/blobaccess/blobaccess/data.go new file mode 100644 index 0000000000..9c2e56ddd2 --- /dev/null +++ b/pkg/blobaccess/blobaccess/data.go @@ -0,0 +1,65 @@ +package blobaccess + +import ( + "bytes" + "io" + + "github.com/mandelsoft/goutils/errors" + + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +type GenericData = interface{} + +type GenericDataGetter interface { + Get() (GenericData, error) +} + +const KIND_DATASOURCE = "data source" + +// GetData provides data as byte sequence from some generic +// data sources like byte arrays, strings, DataReader and +// DataGetters. This means we can pass all BlobAccess or DataAccess +// objects. +// If no an unknown data source is passes an ErrInvalid(KIND_DATASOURCE) +// is returned. +func GetData(src GenericData) ([]byte, error) { + switch t := src.(type) { + case []byte: + return t, nil + case string: + return []byte(t), nil + case bpi.DataGetter: + return t.Get() + case bpi.DataReader: + var buf bytes.Buffer + r, err := t.Reader() + if err != nil { + return nil, err + } + defer r.Close() + _, err = io.Copy(&buf, r) + if err != nil { + return nil, err + } + return buf.Bytes(), nil + } + return nil, errors.ErrInvalidType(KIND_DATASOURCE, src) +} + +// GetGenericData evaluates some input provided by well-known +// types or interfaces and provides some data output +// by mapping the input to either a byte sequence or +// some specialized object. +// If the input type is not known an ErrInvalid(KIND_DATASOURCE) +// // is returned. +// In extension to GetData, it additionally evaluates the interface +// GenericDataGetter to map the input to some evaluated object. +func GetGenericData(src GenericData) (interface{}, error) { + switch t := src.(type) { + case GenericDataGetter: + return t.Get() + default: + return GetData(src) + } +} diff --git a/pkg/blobaccess/standard/dataaccess.go b/pkg/blobaccess/blobaccess/dataaccess.go similarity index 84% rename from pkg/blobaccess/standard/dataaccess.go rename to pkg/blobaccess/blobaccess/dataaccess.go index f2a29cb50e..84ea641605 100644 --- a/pkg/blobaccess/standard/dataaccess.go +++ b/pkg/blobaccess/blobaccess/dataaccess.go @@ -1,14 +1,15 @@ -package standard +package blobaccess import ( "bytes" "io" "github.com/mandelsoft/goutils/errors" - - "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/mandelsoft/goutils/ioutils" ) +type _nopCloser = ioutils.NopCloser + //////////////////////////////////////////////////////////////////////////////// type readerAccess struct { @@ -17,9 +18,9 @@ type readerAccess struct { origin string } -var _ bpi.DataSource = (*readerAccess)(nil) +var _ DataSource = (*readerAccess)(nil) -func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) bpi.DataAccess { +func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) DataAccess { return &readerAccess{reader: reader, origin: origin} } diff --git a/pkg/blobaccess/blobaccess/deprecated.go b/pkg/blobaccess/blobaccess/deprecated.go new file mode 100644 index 0000000000..f6d4aea828 --- /dev/null +++ b/pkg/blobaccess/blobaccess/deprecated.go @@ -0,0 +1,21 @@ +package blobaccess + +import ( + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/opencontainers/go-digest" + + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/blobaccess/file" +) + +// ForTemporaryFile wraps a temporary file into a BlobAccess, which does not need a close. +// Deprecated: ForTemporaryFile. +func ForTemporaryFileWithMeta(mime string, digest digest.Digest, size int64, temp vfs.File, fss ...vfs.FileSystem) bpi.BlobAccess { + return file.BlobAccessForTemporaryFile(mime, temp, file.WithFileSystem(fss...), file.WithDigest(digest), file.WithSize(size)) +} + +// ForTemporaryFile wraps a temporary file into a BlobAccess, which does not need a close. +// Deprecated: ForTemporaryFilePath. +func ForTemporaryFilePathWithMeta(mime string, digest digest.Digest, size int64, temp string, fss ...vfs.FileSystem) BlobAccess { + return file.BlobAccessForTemporaryFilePath(mime, temp, file.WithFileSystem(fss...), file.WithDigest(digest), file.WithSize(size)) +} diff --git a/pkg/blobaccess/digest.go b/pkg/blobaccess/blobaccess/digest.go similarity index 68% rename from pkg/blobaccess/digest.go rename to pkg/blobaccess/blobaccess/digest.go index d42f952b41..5e02a5d1ba 100644 --- a/pkg/blobaccess/digest.go +++ b/pkg/blobaccess/blobaccess/digest.go @@ -2,9 +2,11 @@ package blobaccess import ( "github.com/opencontainers/go-digest" + + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" ) -func Digest(access DataAccess) (digest.Digest, error) { +func Digest(access bpi.DataAccess) (digest.Digest, error) { reader, err := access.Reader() if err != nil { return "", err diff --git a/pkg/blobaccess/blobaccess/doc.go b/pkg/blobaccess/blobaccess/doc.go new file mode 100644 index 0000000000..ca9a7e7e5e --- /dev/null +++ b/pkg/blobaccess/blobaccess/doc.go @@ -0,0 +1,11 @@ +// Package blobaccess provides the basic set of types and supporting +// functions for using BlobAccess implementations. +// It is intended to be used by generic BlobAccess users not referring to +// dedicated implementations. +// Dedicated implementations can be accessed using the appropriate implementation +// package. THis separation is required to avoid cycle for BlobAccess implementations +// using again BlobAccess consumers. +// Alternatively, the parent package can be used, if there are no cycles. The +// parent package provide thes ebasic functionality plus +// access the to various implementation flavors in one package. +package blobaccess diff --git a/pkg/blobaccess/blobaccess/interface.go b/pkg/blobaccess/blobaccess/interface.go new file mode 100644 index 0000000000..ea6084f763 --- /dev/null +++ b/pkg/blobaccess/blobaccess/interface.go @@ -0,0 +1,30 @@ +package blobaccess + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/internal" +) + +const ( + KIND_BLOB = internal.KIND_BLOB + KIND_MEDIATYPE = internal.KIND_MEDIATYPE + + BLOB_UNKNOWN_SIZE = internal.BLOB_UNKNOWN_SIZE + BLOB_UNKNOWN_DIGEST = internal.BLOB_UNKNOWN_DIGEST +) + +type ( + DataAccess = internal.DataAccess + DataReader = internal.DataReader + DataGetter = internal.DataGetter +) + +type ( + BlobAccess = internal.BlobAccess + BlobAccessProvider = internal.BlobAccessProvider + + DataSource = internal.DataSource + DigestSource = internal.DigestSource + MimeType = internal.MimeType +) + +type FileLocation = internal.FileLocation diff --git a/pkg/blobaccess/standard.go b/pkg/blobaccess/blobaccess/other.go similarity index 62% rename from pkg/blobaccess/standard.go rename to pkg/blobaccess/blobaccess/other.go index 4922bfa55f..32e09b5661 100644 --- a/pkg/blobaccess/standard.go +++ b/pkg/blobaccess/blobaccess/other.go @@ -1,53 +1,25 @@ +// Package blobutils provides some utility types and functions +// for blobaccesses, which cannot be put into the blobaccess package, +// because this would introduce cycles in some blobaccess implementation +// packages. package blobaccess import ( - "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" - "github.com/open-component-model/ocm/pkg/refmgmt" "github.com/open-component-model/ocm/pkg/runtimefinalizer" - "github.com/open-component-model/ocm/pkg/utils" ) -var ErrClosed = refmgmt.ErrClosed - -func ErrBlobNotFound(digest digest.Digest) error { - return errors.ErrNotFound(KIND_BLOB, digest.String()) -} - -func IsErrBlobNotFound(err error) bool { - return errors.IsErrNotFoundKind(err, KIND_BLOB) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Validatable is an optional interface for DataAccess -// implementations or any other object, which might reach -// an error state. The error can then be queried with -// the method ErrorProvider.Validate. -// This is used to support objects with access methods not -// returning an error. If the object is not valid, -// those methods return an unknown/default state, but -// the object should be queryable for its state. -type Validatable = utils.Validatable - -// Validate checks whether a blob access -// is in error state. If yes, an appropriate -// error is returned. -func Validate(o BlobAccess) error { - return utils.ValidateObject(o) -} - //////////////////////////////////////////////////////////////////////////////// type blobprovider struct { - blob BlobAccess + blob bpi.BlobAccess } -var _ BlobAccessProvider = (*blobprovider)(nil) +var _ bpi.BlobAccessProvider = (*blobprovider)(nil) -func (b *blobprovider) BlobAccess() (BlobAccess, error) { +func (b *blobprovider) BlobAccess() (bpi.BlobAccess, error) { return b.blob.Dup() } @@ -65,21 +37,21 @@ func (b *blobprovider) Close() error { // To be on the safe side, this method should only be called // with static blob access, featuring a NOP closer without // anny attached external resources, which should be released. -func ProviderForBlobAccess(blob BlobAccess) *blobprovider { +func ProviderForBlobAccess(blob bpi.BlobAccess) *blobprovider { return &blobprovider{blob} } -type _blobAccess = BlobAccess +type _blobAccess = bpi.BlobAccess //////////////////////////////////////////////////////////////////////////////// // AnnotatedBlobAccess provides access to the original underlying data source. -type AnnotatedBlobAccess[T DataAccess] interface { +type AnnotatedBlobAccess[T bpi.DataAccess] interface { _blobAccess Source() T } -type annotatedBlobAccessView[T DataAccess] struct { +type annotatedBlobAccessView[T bpi.DataAccess] struct { _blobAccess id runtimefinalizer.ObjectIdentity annotation T @@ -89,7 +61,7 @@ func (a *annotatedBlobAccessView[T]) Close() error { return a._blobAccess.Close() } -func (a *annotatedBlobAccessView[T]) Dup() (BlobAccess, error) { +func (a *annotatedBlobAccessView[T]) Dup() (bpi.BlobAccess, error) { b, err := a._blobAccess.Dup() if err != nil { return nil, err @@ -109,7 +81,7 @@ func (a *annotatedBlobAccessView[T]) Source() T { // It closes the wrapped access, if closed. // If the wrapped data access does not need a close, the BlobAccess // does not need a close, also. -func ForDataAccess[T DataAccess](digest digest.Digest, size int64, mimeType string, access T) AnnotatedBlobAccess[T] { +func ForDataAccess[T bpi.DataAccess](digest digest.Digest, size int64, mimeType string, access T) AnnotatedBlobAccess[T] { a := bpi.BaseAccessForDataAccessAndMeta(mimeType, access, digest, size) return &annotatedBlobAccessView[T]{ @@ -130,11 +102,11 @@ type mimeBlob struct { // by wrapping the given blob access. It does NOT provide // a new view for the given blob access, so closing the resulting // blob access will directly close the backing blob access. -func WithMimeType(mimeType string, blob BlobAccess) BlobAccess { +func WithMimeType(mimeType string, blob bpi.BlobAccess) bpi.BlobAccess { return &mimeBlob{blob, mimeType} } -func (b *mimeBlob) Dup() (BlobAccess, error) { +func (b *mimeBlob) Dup() (bpi.BlobAccess, error) { n, err := b._blobAccess.Dup() if err != nil { return nil, err @@ -152,7 +124,7 @@ type blobNopCloser struct { _blobAccess } -func NonClosable(blob BlobAccess) BlobAccess { +func NonClosable(blob bpi.BlobAccess) bpi.BlobAccess { return &blobNopCloser{blob} } diff --git a/pkg/blobaccess/blobaccess/standard.go b/pkg/blobaccess/blobaccess/standard.go new file mode 100644 index 0000000000..bba5f30fe4 --- /dev/null +++ b/pkg/blobaccess/blobaccess/standard.go @@ -0,0 +1,38 @@ +package blobaccess + +import ( + "github.com/mandelsoft/goutils/errors" + "github.com/opencontainers/go-digest" + + "github.com/open-component-model/ocm/pkg/refmgmt" + "github.com/open-component-model/ocm/pkg/utils" +) + +var ErrClosed = refmgmt.ErrClosed + +func ErrBlobNotFound(digest digest.Digest) error { + return errors.ErrNotFound(KIND_BLOB, digest.String()) +} + +func IsErrBlobNotFound(err error) bool { + return errors.IsErrNotFoundKind(err, KIND_BLOB) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Validatable is an optional interface for DataAccess +// implementations or any other object, which might reach +// an error state. The error can then be queried with +// the method ErrorProvider.Validate. +// This is used to support objects with access methods not +// returning an error. If the object is not valid, +// those methods return an unknown/default state, but +// the object should be queryable for its state. +type Validatable = utils.Validatable + +// Validate checks whether a blob access +// is in error state. If yes, an appropriate +// error is returned. +func Validate(o BlobAccess) error { + return utils.ValidateObject(o) +} diff --git a/pkg/blobaccess/suite_test.go b/pkg/blobaccess/blobaccess/suite_test.go similarity index 100% rename from pkg/blobaccess/suite_test.go rename to pkg/blobaccess/blobaccess/suite_test.go diff --git a/pkg/blobaccess/utils.go b/pkg/blobaccess/blobaccess/utils.go similarity index 59% rename from pkg/blobaccess/utils.go rename to pkg/blobaccess/blobaccess/utils.go index 52b24a98b3..002a80c6e5 100644 --- a/pkg/blobaccess/utils.go +++ b/pkg/blobaccess/blobaccess/utils.go @@ -1,11 +1,8 @@ package blobaccess import ( - "bytes" "io" - "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess/bpi" "github.com/open-component-model/ocm/pkg/iotools" ) @@ -79,58 +76,3 @@ func MimeReaderFromProvider(s BlobAccessProvider) (io.ReadCloser, string, error) } return iotools.AddReaderCloser(r, blob), mime, nil } - -type GenericData interface{} - -type GenericDataGetter interface { - Get() (interface{}, error) -} - -const KIND_DATASOURCE = "data source" - -// GetData provides data as byte sequence from some generic -// data sources like byte arrays, strings, DataReader and -// DataGetters. This means we can pass all BlobAccess or DataAccess -// objects. -// If no an unknown data source is passes an ErrInvalid(KIND_DATASOURCE) -// is returned. -func GetData(src GenericData) ([]byte, error) { - switch t := src.(type) { - case []byte: - return t, nil - case string: - return []byte(t), nil - case DataGetter: - return t.Get() - case DataReader: - var buf bytes.Buffer - r, err := t.Reader() - if err != nil { - return nil, err - } - defer r.Close() - _, err = io.Copy(&buf, r) - if err != nil { - return nil, err - } - return buf.Bytes(), nil - } - return nil, errors.ErrInvalidType(KIND_DATASOURCE, src) -} - -// GetGenericData evaluates some input provided by well-known -// types or interfaces and provides some data output -// by mapping the input to either a byte sequence or -// some specialized object. -// If the input type is not known an ErrInvalid(KIND_DATASOURCE) -// // is returned. -// In extension to GetData, it additionally evaluates the interface -// GenericDataGetter to map the input to some evaluated object. -func GetGenericData(src GenericData) (interface{}, error) { - switch t := src.(type) { - case GenericDataGetter: - return t.Get() - default: - return GetData(src) - } -} diff --git a/pkg/blobaccess/bpi/interface.go b/pkg/blobaccess/bpi/interface.go index 2e1164910a..75af2f9491 100644 --- a/pkg/blobaccess/bpi/interface.go +++ b/pkg/blobaccess/bpi/interface.go @@ -1,6 +1,9 @@ package bpi import ( + "github.com/mandelsoft/goutils/errors" + "github.com/opencontainers/go-digest" + "github.com/open-component-model/ocm/pkg/blobaccess/internal" "github.com/open-component-model/ocm/pkg/refmgmt" "github.com/open-component-model/ocm/pkg/utils" @@ -25,6 +28,8 @@ type ( Validatable = utils.Validatable + DataReader = internal.DataReader + DataGetter = internal.DataGetter DataSource = internal.DataSource DigestSource = internal.DigestSource MimeType = internal.MimeType @@ -37,3 +42,11 @@ type BlobAccessProviderFunction func() (BlobAccess, error) func (p BlobAccessProviderFunction) BlobAccess() (BlobAccess, error) { return p() } + +func ErrBlobNotFound(digest digest.Digest) error { + return errors.ErrNotFound(KIND_BLOB, digest.String()) +} + +func IsErrBlobNotFound(err error) bool { + return errors.IsErrNotFoundKind(err, KIND_BLOB) +} diff --git a/pkg/blobaccess/deprecated.go b/pkg/blobaccess/deprecated.go new file mode 100644 index 0000000000..30d1bf48c1 --- /dev/null +++ b/pkg/blobaccess/deprecated.go @@ -0,0 +1,11 @@ +package blobaccess + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" +) + +// DataAccessForBytes wraps a bytes slice into a DataAccess. +// Deprecated: used DataAccessForData. +func DataAccessForBytes(data []byte, origin ...string) DataSource { + return blobaccess.DataAccessForData(data, origin...) +} diff --git a/pkg/blobaccess/dirtree/access.go b/pkg/blobaccess/dirtree/access.go index c6bac02d26..4da131a9fd 100644 --- a/pkg/blobaccess/dirtree/access.go +++ b/pkg/blobaccess/dirtree/access.go @@ -15,15 +15,15 @@ import ( "github.com/open-component-model/ocm/pkg/utils/tarutils" ) -func DataAccessForDirTree(path string, opts ...Option) (bpi.DataAccess, error) { - blobAccess, err := BlobAccessForDirTree(path, opts...) +func DataAccess(path string, opts ...Option) (bpi.DataAccess, error) { + blobAccess, err := BlobAccess(path, opts...) if err != nil { return nil, err } return blobAccess, nil } -func BlobAccessForDirTree(path string, opts ...Option) (_ bpi.BlobAccess, rerr error) { +func BlobAccess(path string, opts ...Option) (_ bpi.BlobAccess, rerr error) { eff := optionutils.EvalOptions(opts...) fs := utils.FileSystem(eff.FileSystem) @@ -70,8 +70,8 @@ func BlobAccessForDirTree(path string, opts ...Option) (_ bpi.BlobAccess, rerr e return temp.AsBlob(eff.MimeType), nil } -func BlobAccessProviderForDirTree(path string, opts ...Option) bpi.BlobAccessProvider { +func Provider(path string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - return BlobAccessForDirTree(path, opts...) + return BlobAccess(path, opts...) }) } diff --git a/pkg/blobaccess/dirtree/deprecated.go b/pkg/blobaccess/dirtree/deprecated.go new file mode 100644 index 0000000000..e5b32baacc --- /dev/null +++ b/pkg/blobaccess/dirtree/deprecated.go @@ -0,0 +1,17 @@ +package dirtree + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +// BlobAccessForDirTree returns a BlobAccess for the given directory tree. +// Deprecated: use BlobAccess. +func BlobAccessForDirTree(path string, opts ...Option) (_ bpi.BlobAccess, rerr error) { + return BlobAccess(path, opts...) +} + +// BlobAccessProviderForDirTree returns a BlobAccessProvider for the given directory tree. +// Deprecated: use Provider. +func BlobAccessProviderForDirTree(path string, opts ...Option) bpi.BlobAccessProvider { + return Provider(path, opts...) +} diff --git a/pkg/blobaccess/doc.go b/pkg/blobaccess/doc.go index 08b20b1e74..560545bb62 100644 --- a/pkg/blobaccess/doc.go +++ b/pkg/blobaccess/doc.go @@ -1,2 +1,11 @@ -// Package blobaccess provides the basic set of the most commonly needed BlobAccess implementations. +// Package blobaccess provides various flavors of BlobAccess implementations. +// It is used to access blobs in a uniform way. Additionally, it provides +// the basic types provided by the sub package with the same name. +// This package just provides the basic types for +// BlobAccess implementations. It is provided for generic BlobAccess users not +// referring to dedicated implementation. This separation is required to avoid cycles +// for blobaccess users which are also used again to implement some of the BlobAccess +// variants. +// Alternatively, the sub package and the various implementation packages +// can be used in combination. package blobaccess diff --git a/pkg/blobaccess/dockerdaemon/access.go b/pkg/blobaccess/dockerdaemon/access.go index 793b97906c..e7cb29fb9c 100644 --- a/pkg/blobaccess/dockerdaemon/access.go +++ b/pkg/blobaccess/dockerdaemon/access.go @@ -6,15 +6,15 @@ import ( "github.com/mandelsoft/goutils/optionutils" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" - "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/annotations" "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset" "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/docker" + cpi "github.com/open-component-model/ocm/pkg/contexts/oci/types" ) -func (o *Options) OCIContext() oci.Context { +func (o *Options) OCIContext() cpi.Context { if o.Context == nil { - return oci.DefaultContext() + return cpi.DefaultContext() } return o.Context } @@ -36,14 +36,15 @@ func ImageInfoFor(name string, opts ...Option) (locator string, version string, return locator, version, nil } -func BlobAccessProviderForImageFromDockerDaemon(name string, opts ...Option) bpi.BlobAccessProvider { +func Provider(name string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - b, _, err := BlobAccessForImageFromDockerDaemon(name, opts...) + b, _, err := BlobAccess(name, opts...) return b, err }) } -func BlobAccessForImageFromDockerDaemon(name string, opts ...Option) (bpi.BlobAccess, string, error) { +// BlobAccess returns a BlobAccess for the image with the given name. +func BlobAccess(name string, opts ...Option) (bpi.BlobAccess, string, error) { eff := optionutils.EvalOptions(opts...) ctx := eff.OCIContext() @@ -61,7 +62,7 @@ func BlobAccessForImageFromDockerDaemon(name string, opts ...Option) (bpi.BlobAc return nil, "", err } blob, err := artifactset.SynthesizeArtifactBlob(ns, version, - func(art oci.ArtifactAccess) error { + func(art cpi.ArtifactAccess) error { if eff.Origin != nil { art.Artifact().SetAnnotation(annotations.COMPVERS_ANNOTATION, eff.Origin.String()) } diff --git a/pkg/blobaccess/dockerdaemon/deprecated.go b/pkg/blobaccess/dockerdaemon/deprecated.go new file mode 100644 index 0000000000..9ceb05f600 --- /dev/null +++ b/pkg/blobaccess/dockerdaemon/deprecated.go @@ -0,0 +1,17 @@ +package dockerdaemon + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +// BlobAccessProviderForImageFromDockerDaemon returns a BlobAccessProvider for the image with the given name. +// Deprecated: use Provider. +func BlobAccessProviderForImageFromDockerDaemon(name string, opts ...Option) bpi.BlobAccessProvider { + return Provider(name, opts...) +} + +// BlobAccessForImageFromDockerDaemon returns a BlobAccess for the image with the given name. +// Decrecated: use BlobAccess. +func BlobAccessForImageFromDockerDaemon(name string, opts ...Option) (bpi.BlobAccess, string, error) { + return BlobAccess(name, opts...) +} diff --git a/pkg/blobaccess/dockerdaemon/options.go b/pkg/blobaccess/dockerdaemon/options.go index 60703913c1..b9e8da91a3 100644 --- a/pkg/blobaccess/dockerdaemon/options.go +++ b/pkg/blobaccess/dockerdaemon/options.go @@ -4,14 +4,14 @@ import ( "github.com/mandelsoft/goutils/optionutils" "github.com/open-component-model/ocm/pkg/common" - "github.com/open-component-model/ocm/pkg/contexts/oci" + cpi "github.com/open-component-model/ocm/pkg/contexts/oci/types" "github.com/open-component-model/ocm/pkg/utils" ) type Option = optionutils.Option[*Options] type Options struct { - Context oci.Context + Context cpi.Context Name string Version string OverrideVersion *bool @@ -42,14 +42,14 @@ func (o *Options) ApplyTo(opts *Options) { //////////////////////////////////////////////////////////////////////////////// type context struct { - oci.Context + cpi.Context } func (o context) ApplyTo(opts *Options) { opts.Context = o } -func WithContext(ctx oci.ContextProvider) Option { +func WithContext(ctx cpi.ContextProvider) Option { return context{ctx.OCIContext()} } diff --git a/pkg/blobaccess/dockermulti/access.go b/pkg/blobaccess/dockermulti/access.go index 848587f92c..cc8d5dd284 100644 --- a/pkg/blobaccess/dockermulti/access.go +++ b/pkg/blobaccess/dockermulti/access.go @@ -53,7 +53,7 @@ func (s *Options) getVariant(ctx oci.Context, finalize *Finalizer, variant strin return art, nil } -func BlobAccessForMultiImageFromDockerDaemon(opts ...Option) (bpi.BlobAccess, error) { +func BlobAccess(opts ...Option) (bpi.BlobAccess, error) { eff := optionutils.EvalOptions(opts...) ctx := eff.OCIContext() @@ -149,8 +149,8 @@ func BlobAccessForMultiImageFromDockerDaemon(opts ...Option) (bpi.BlobAccess, er return blob, nil } -func BlobAccessProviderForMultiImageFromDockerDaemon(opts ...Option) bpi.BlobAccessProvider { +func Provider(opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - return BlobAccessForMultiImageFromDockerDaemon(opts...) + return BlobAccess(opts...) }) } diff --git a/pkg/blobaccess/dockermulti/deprecated.go b/pkg/blobaccess/dockermulti/deprecated.go new file mode 100644 index 0000000000..4ef55d48b3 --- /dev/null +++ b/pkg/blobaccess/dockermulti/deprecated.go @@ -0,0 +1,17 @@ +package dockermulti + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +// BlobAccessForMultiImageFromDockerDaemon returns a BlobAccess for the image with the given name. +// Deprecated: use BlobAccess. +func BlobAccessForMultiImageFromDockerDaemon(opts ...Option) (bpi.BlobAccess, error) { + return BlobAccess(opts...) +} + +// BlobAccessProviderForMultiImageFromDockerDaemon returns a BlobAccessProvider for the image with the given name. +// Deprecated: use Provider. +func BlobAccessProviderForMultiImageFromDockerDaemon(opts ...Option) bpi.BlobAccessProvider { + return Provider(opts...) +} diff --git a/pkg/blobaccess/file/access.go b/pkg/blobaccess/file/access.go index e2a38375af..1a8f80f546 100644 --- a/pkg/blobaccess/file/access.go +++ b/pkg/blobaccess/file/access.go @@ -5,6 +5,7 @@ import ( "sync" "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/goutils/optionutils" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" @@ -51,6 +52,9 @@ func (a *fileDataAccess) Reader() (io.ReadCloser, error) { return file, nil } +// Validate checks if the access is valid, meaning +// it can provide data. Here, this means +// that the file exists. func (a *fileDataAccess) Validate() error { ok, err := vfs.Exists(a.fs, a.path) if err != nil { @@ -128,7 +132,7 @@ func BlobAccess(mime string, path string, fss ...vfs.FileSystem) bpi.BlobAccess } } -func ProviderForFile(mime string, path string, fss ...vfs.FileSystem) bpi.BlobAccessProvider { +func Provider(mime string, path string, fss ...vfs.FileSystem) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { return BlobAccess(mime, path, fss...), nil }) @@ -224,49 +228,39 @@ func (b *temporaryFileBlob) Path() string { return b.path } -func ForTemporaryFile(mime string, temp vfs.File, fss ...vfs.FileSystem) bpi.BlobAccess { - return bpi.NewBlobAccessForBase(&temporaryFileBlob{ - _blobAccess: BlobAccess(mime, temp.Name(), fss...), - filesystem: utils.FileSystem(fss...), +func BlobAccessForTemporaryFile(mime string, temp vfs.File, opts ...Option) bpi.BlobAccess { + eff := optionutils.EvalOptions(opts...) + t := &temporaryFileBlob{ + _blobAccess: BlobAccess(mime, temp.Name(), eff.FileSystem), + filesystem: utils.FileSystem(eff.FileSystem), path: temp.Name(), file: temp, - }) -} - -func ForTemporaryFileWithMeta(mime string, digest digest.Digest, size int64, temp vfs.File, fss ...vfs.FileSystem) bpi.BlobAccess { - return bpi.NewBlobAccessForBase(bpi.BaseAccessForDataAccessAndMeta(mime, &temporaryFileBlob{ - _blobAccess: BlobAccess(mime, temp.Name(), fss...), - filesystem: utils.FileSystem(fss...), - path: temp.Name(), - file: temp, - }, digest, size)) -} - -func ForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) bpi.BlobAccess { - return bpi.NewBlobAccessForBase(&temporaryFileBlob{ - _blobAccess: BlobAccess(mime, temp, fss...), - filesystem: utils.FileSystem(fss...), - path: temp, - }) + } + // TODO: handle FileLocation interface in combination with partially set meta data. + if eff.Digest != "" || eff.GetSize() != bpi.BLOB_UNKNOWN_SIZE { + return bpi.NewBlobAccessForBase(bpi.BaseAccessForDataAccessAndMeta(mime, t, eff.Digest, eff.GetSize())) + } + return bpi.NewBlobAccessForBase(t) } -func ForTemporaryFilePathWithMeta(mime string, digest digest.Digest, size int64, temp string, fss ...vfs.FileSystem) bpi.BlobAccess { +func BlobAccessForTemporaryFilePath(mime string, temp string, opts ...Option) bpi.BlobAccess { + eff := optionutils.EvalOptions(opts...) return bpi.NewBlobAccessForBase(bpi.BaseAccessForDataAccessAndMeta(mime, &temporaryFileBlob{ - _blobAccess: BlobAccess(mime, temp, fss...), - filesystem: utils.FileSystem(fss...), + _blobAccess: BlobAccess(mime, temp, eff.FileSystem), + filesystem: utils.FileSystem(eff.FileSystem), path: temp, - }, digest, size)) + }, eff.Digest, eff.GetSize())) } //////////////////////////////////////////////////////////////////////////////// // TempFile holds a temporary file that should be kept open. // Close should never be called directly. -// It can be passed to another responsibility realm by calling Release +// It can be passed to another responsibility realm by calling Release- // For example to be transformed into a TemporaryBlobAccess. // Close will close and remove an unreleased file and does // nothing if it has been released. -// If it has been releases the new realm is responsible. +// If it has been released the new realm is responsible. // to close and remove it. type TempFile struct { lock sync.Mutex @@ -298,6 +292,9 @@ func (t *TempFile) FileSystem() vfs.FileSystem { return t.filesystem } +// Release passes the responsibility for closing and removing +// the temporary file to another realm. After calling this method +// the TempFile object will not handle these operations anymore, if it is closed. func (t *TempFile) Release() vfs.File { t.lock.Lock() defer t.lock.Unlock() @@ -322,9 +319,11 @@ func (t *TempFile) Sync() error { } func (t *TempFile) AsBlob(mime string) bpi.BlobAccess { - return ForTemporaryFile(mime, t.Release(), t.filesystem) + return BlobAccessForTemporaryFile(mime, t.Release(), WithFileSystem(t.filesystem)) } +// Close closes and removes the temporary file as long it has not +// been released before by calling Release. func (t *TempFile) Close() error { t.lock.Lock() defer t.lock.Unlock() diff --git a/pkg/blobaccess/file/options.go b/pkg/blobaccess/file/options.go new file mode 100644 index 0000000000..5a23976547 --- /dev/null +++ b/pkg/blobaccess/file/options.go @@ -0,0 +1,76 @@ +package file + +import ( + "github.com/mandelsoft/goutils/generics" + "github.com/mandelsoft/goutils/optionutils" + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/opencontainers/go-digest" + + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/utils" +) + +type Option = optionutils.Option[*Options] + +type Options struct { + // FileSystem defines the file system that contains the specified directory. + FileSystem vfs.FileSystem + Digest digest.Digest + Size *int64 +} + +func (o *Options) GetSize() int64 { + if o.Size == nil { + return bpi.BLOB_UNKNOWN_SIZE + } + return *o.Size +} + +func (o *Options) ApplyTo(opts *Options) { + if opts == nil { + return + } + if o.FileSystem != nil { + opts.FileSystem = o.FileSystem + } + if o.Digest != "" { + opts.Digest = o.Digest + } + optionutils.ApplyOption(o.Size, &opts.Size) +} + +//////////////////////////////////////////////////////////////////////////////// + +type fileSystem struct { + fs vfs.FileSystem +} + +func (o *fileSystem) ApplyTo(opts *Options) { + opts.FileSystem = o.fs +} + +func WithFileSystem(fss ...vfs.FileSystem) Option { + return &fileSystem{fs: utils.FileSystem(fss...)} +} + +//////////////////////////////////////////////////////////////////////////////// + +type size int64 + +func (o size) ApplyTo(opts *Options) { + opts.Size = generics.Pointer(int64(o)) +} + +func WithSize(s int64) Option { + return size(s) +} + +type _digest digest.Digest + +func (o _digest) ApplyTo(opts *Options) { + opts.Digest = digest.Digest(o) +} + +func WithDigest(d digest.Digest) Option { + return _digest(d) +} diff --git a/pkg/blobaccess/standard/suite_test.go b/pkg/blobaccess/file/suite_test.go similarity index 89% rename from pkg/blobaccess/standard/suite_test.go rename to pkg/blobaccess/file/suite_test.go index a14598f80a..b57764e1be 100644 --- a/pkg/blobaccess/standard/suite_test.go +++ b/pkg/blobaccess/file/suite_test.go @@ -1,4 +1,4 @@ -package standard_test +package file_test import ( "testing" diff --git a/pkg/blobaccess/standard/temp_test.go b/pkg/blobaccess/file/temp_test.go similarity index 98% rename from pkg/blobaccess/standard/temp_test.go rename to pkg/blobaccess/file/temp_test.go index dfa3087d68..ed968704fe 100644 --- a/pkg/blobaccess/standard/temp_test.go +++ b/pkg/blobaccess/file/temp_test.go @@ -1,13 +1,12 @@ -package standard_test +package file_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + me "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" - - me "github.com/open-component-model/ocm/pkg/blobaccess" ) var _ = Describe("temp file management", func() { @@ -58,7 +57,7 @@ var _ = Describe("temp file management", func() { Expect(blob.Close()).To(Succeed()) Expect(vfs.FileExists(tempfs, name)).To(BeFalse()) }) - + It("temp file blob access", func() { value := []byte("this is a test") tmp, err := me.NewTempFile("", "test*.tmp", tempfs) diff --git a/pkg/blobaccess/forward.go b/pkg/blobaccess/forward.go index 62920af1be..ef6bdfb931 100644 --- a/pkg/blobaccess/forward.go +++ b/pkg/blobaccess/forward.go @@ -6,50 +6,47 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/blobaccess/dirtree" + "github.com/open-component-model/ocm/pkg/blobaccess/dockerdaemon" + "github.com/open-component-model/ocm/pkg/blobaccess/dockermulti" "github.com/open-component-model/ocm/pkg/blobaccess/file" - "github.com/open-component-model/ocm/pkg/blobaccess/standard" + "github.com/open-component-model/ocm/pkg/blobaccess/helm" + "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "github.com/open-component-model/ocm/pkg/blobaccess/ociartifact" + "github.com/open-component-model/ocm/pkg/blobaccess/wget" ) /////////// // Standard /////////// -func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) bpi.DataAccess { - return standard.DataAccessForReaderFunction(reader, origin) -} - -// DataAccessForBytes wraps a bytes slice into a DataAccess. -// Deprecated: used DataAccessForData. -func DataAccessForBytes(data []byte, origin ...string) bpi.DataSource { - return standard.DataAccessForData(data, origin...) -} - // DataAccessForData wraps a bytes slice into a DataAccess. -func DataAccessForData(data []byte, origin ...string) bpi.DataSource { - return standard.DataAccessForData(data, origin...) +func DataAccessForData(data []byte, origin ...string) DataSource { + return blobaccess.DataAccessForData(data, origin...) } -func DataAccessForString(data string, origin ...string) bpi.DataSource { - return standard.DataAccessForString(data, origin...) +func DataAccessForString(data string, origin ...string) DataSource { + return blobaccess.DataAccessForString(data, origin...) } // ForString wraps a string into a BlobAccess, which does not need a close. func ForString(mime string, data string) BlobAccess { - return standard.ForString(mime, data) + return blobaccess.ForString(mime, data) } func ProviderForString(mime, data string) BlobAccessProvider { - return standard.ProviderForString(mime, data) + return blobaccess.ProviderForString(mime, data) } // ForData wraps data into a BlobAccess, which does not need a close. func ForData(mime string, data []byte) BlobAccess { - return standard.ForData(mime, data) + return blobaccess.ForData(mime, data) } func ProviderForData(mime string, data []byte) BlobAccessProvider { - return standard.ProviderForData(mime, data) + return blobaccess.ProviderForData(mime, data) } /////////// @@ -60,32 +57,24 @@ func DataAccessForFile(fs vfs.FileSystem, path string) DataAccess { return file.DataAccess(fs, path) } -func ForFile(mime string, path string, fss ...vfs.FileSystem) bpi.BlobAccess { +func ForFile(mime string, path string, fss ...vfs.FileSystem) BlobAccess { return file.BlobAccess(mime, path, fss...) } -func ProviderForFile(mime string, path string, fss ...vfs.FileSystem) bpi.BlobAccessProvider { - return file.ProviderForFile(mime, path, fss...) +func ProviderForFile(mime string, path string, fss ...vfs.FileSystem) BlobAccessProvider { + return file.Provider(mime, path, fss...) } -func ForFileWithCloser(closer io.Closer, mime string, path string, fss ...vfs.FileSystem) bpi.BlobAccess { +func ForFileWithCloser(closer io.Closer, mime string, path string, fss ...vfs.FileSystem) BlobAccess { return file.BlobAccessWithCloser(closer, mime, path, fss...) } -func ForTemporaryFile(mime string, temp vfs.File, fss ...vfs.FileSystem) bpi.BlobAccess { - return file.ForTemporaryFile(mime, temp, fss...) -} - -func ForTemporaryFileWithMeta(mime string, digest digest.Digest, size int64, temp vfs.File, fss ...vfs.FileSystem) bpi.BlobAccess { - return file.ForTemporaryFileWithMeta(mime, digest, size, temp, fss...) +func ForTemporaryFile(mime string, temp vfs.File, opts ...file.Option) BlobAccess { + return file.BlobAccessForTemporaryFile(mime, temp, opts...) } -func ForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) BlobAccess { - return file.ForTemporaryFilePath(mime, temp, fss...) -} - -func ForTemporaryFilePathWithMeta(mime string, digest digest.Digest, size int64, temp string, fss ...vfs.FileSystem) BlobAccess { - return file.ForTemporaryFilePathWithMeta(mime, digest, size, temp, fss...) +func ForTemporaryFilePath(mime string, temp string, opts ...file.Option) BlobAccess { + return file.BlobAccessForTemporaryFilePath(mime, temp, opts...) } // TempFile holds a temporary file that should be kept open. @@ -101,3 +90,177 @@ type TempFile = file.TempFile func NewTempFile(dir string, pattern string, fss ...vfs.FileSystem) (*TempFile, error) { return file.NewTempFile(dir, pattern, fss...) } + +/////////// +// DirTree +/////////// + +func DataAccessForDirTree(path string, opts ...dirtree.Option) (DataAccess, error) { + return dirtree.DataAccess(path, opts...) +} + +func ForDirTree(path string, opts ...dirtree.Option) (BlobAccess, error) { + return dirtree.BlobAccess(path, opts...) +} + +func ProviderForDirTree(path string, opts ...dirtree.Option) BlobAccessProvider { + return dirtree.Provider(path, opts...) +} + +/////////// +// Docker Daemon +/////////// + +func ForImageFromDockerDaemon(name string, opts ...dockerdaemon.Option) (BlobAccess, string, error) { + return dockerdaemon.BlobAccess(name, opts...) +} + +func ProviderForImageFromDockerDaemon(name string, opts ...dockerdaemon.Option) BlobAccessProvider { + return dockerdaemon.Provider(name, opts...) +} + +/////////// +// Docker Multi +/////////// + +func ForMultiImageFromDockerDaemon(opts ...dockermulti.Option) (BlobAccess, error) { + return dockermulti.BlobAccess(opts...) +} + +func ProviderForMultiImageFromDockerDaemon(opts ...dockermulti.Option) BlobAccessProvider { + return dockermulti.Provider(opts...) +} + +/////////// +// Helm Chart +/////////// + +func ForHelmChart(path string, opts ...helm.Option) (blob BlobAccess, name, version string, err error) { + return helm.BlobAccess(path, opts...) +} + +func ProviderForHelmChart(path string, opts ...helm.Option) BlobAccessProvider { + return helm.Provider(path, opts...) +} + +/////////// +// Maven +/////////// + +func DataAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...maven.Option) (DataAccess, error) { + return maven.DataAccess(repo, groupId, artifactId, version, opts...) +} + +func ForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...maven.Option) (BlobAccess, error) { + return maven.BlobAccess(repo, groupId, artifactId, version, opts...) +} + +func ForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...maven.Option) (BlobAccess, error) { + return maven.BlobAccessForCoords(repo, coords, opts...) +} + +func ProviderForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...maven.Option) BlobAccessProvider { + return maven.Provider(repo, groupId, artifactId, version, opts...) +} + +/////////// +// OCI Artifact +/////////// + +func ForOCIArtifact(refname string, opts ...ociartifact.Option) (BlobAccess, string, error) { + return ociartifact.BlobAccess(refname, opts...) +} + +func ProviderForOCIArtifact(name string, opts ...ociartifact.Option) BlobAccessProvider { + return ociartifact.Provider(name, opts...) +} + +/////////// +// WGet +/////////// + +func DataAccessForWget(url string, opts ...wget.Option) (DataAccess, error) { + return wget.DataAccess(url, opts...) +} + +func ForWget(url string, opts ...wget.Option) (_ BlobAccess, rerr error) { + return wget.BlobAccess(url, opts...) +} + +func ProviderForWget(url string, opts ...wget.Option) BlobAccessProvider { + return wget.Provider(url, opts...) +} + +//////////////////////////////////////////////////////////////////////////////// + +type _blobAccess = BlobAccess + +// AnnotatedBlobAccess provides access to the original underlying data source. +type AnnotatedBlobAccess[T bpi.DataAccess] interface { + _blobAccess + Source() T +} + +func ForDataAccess[T bpi.DataAccess](digest digest.Digest, size int64, mimeType string, access T) AnnotatedBlobAccess[T] { + return blobaccess.ForDataAccess(digest, size, mimeType, access) +} + +func ProviderForBlobAccess(blob bpi.BlobAccess) BlobAccessProvider { + return blobaccess.ProviderForBlobAccess(blob) +} + +//////////////////////////////////////////////////////////////////////////////// + +func BlobData(blob DataGetter, err ...error) ([]byte, error) { + return blobaccess.BlobData(blob, err...) +} + +func BlobReader(blob DataReader, err ...error) (io.ReadCloser, error) { + return blobaccess.BlobReader(blob, err...) +} + +func Digest(access DataAccess) (digest.Digest, error) { + return blobaccess.Digest(access) +} + +func WithCompression(blob BlobAccess) (BlobAccess, error) { + return blobaccess.WithCompression(blob) +} + +func WithDecompression(blob BlobAccess) (BlobAccess, error) { + return blobaccess.WithDecompression(blob) +} + +func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) DataAccess { + return blobaccess.DataAccessForReaderFunction(reader, origin) +} + +//////////////////////////////////////////////////////////////////////////////// + +type GenericData = blobaccess.GenericData + +type GenericDataGetter = blobaccess.GenericDataGetter + +const KIND_DATASOURCE = blobaccess.KIND_DATASOURCE + +// GetData provides data as byte sequence from some generic +// data sources like byte arrays, strings, DataReader and +// DataGetters. This means we can pass all BlobAccess or DataAccess +// objects. +// If no an unknown data source is passes an ErrInvalid(KIND_DATASOURCE) +// is returned. +func GetData(src GenericData) ([]byte, error) { + return blobaccess.GetData(src) +} + +// GetGenericData evaluates some input provided by well-known +// types or interfaces and provides some data output +// by mapping the input to either a byte sequence or +// some specialized object. +// If the input type is not known an ErrInvalid(KIND_DATASOURCE) +// // is returned. +// In extension to GetData, it additionally evaluates the interface +// GenericDataGetter to map the input to some evaluated object. +func GetGenericData(src GenericData) (interface{}, error) { + return blobaccess.GetGenericData(src) +} diff --git a/pkg/blobaccess/helm/resource.go b/pkg/blobaccess/helm/access.go similarity index 84% rename from pkg/blobaccess/helm/resource.go rename to pkg/blobaccess/helm/access.go index ca9cdcbe8a..d64e78a162 100644 --- a/pkg/blobaccess/helm/resource.go +++ b/pkg/blobaccess/helm/access.go @@ -10,21 +10,13 @@ import ( "github.com/open-component-model/ocm/pkg/blobaccess/bpi" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/helm/identity" - "github.com/open-component-model/ocm/pkg/contexts/oci" ocihelm "github.com/open-component-model/ocm/pkg/contexts/oci/ociutils/helm" "github.com/open-component-model/ocm/pkg/helm" "github.com/open-component-model/ocm/pkg/helm/loader" "github.com/open-component-model/ocm/pkg/utils" ) -func (o *Options) OCIContext() oci.Context { - if o.Context == nil { - return oci.DefaultContext() - } - return o.Context -} - -func BlobAccessForHelmChart(path string, opts ...Option) (blob bpi.BlobAccess, name, version string, err error) { +func BlobAccess(path string, opts ...Option) (blob bpi.BlobAccess, name, version string, err error) { eff := optionutils.EvalOptions(opts...) ctx := eff.OCIContext() fs := utils.FileSystem(eff.FileSystem) @@ -81,9 +73,9 @@ func BlobAccessForHelmChart(path string, opts ...Option) (blob bpi.BlobAccess, n return blob, chart.Name(), vers, err } -func BlobAccessProviderForHelmChart(name string, opts ...Option) bpi.BlobAccessProvider { +func Provider(name string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - b, _, _, err := BlobAccessForHelmChart(name, opts...) + b, _, _, err := BlobAccess(name, opts...) return b, err }) } diff --git a/pkg/blobaccess/helm/deprecated.go b/pkg/blobaccess/helm/deprecated.go new file mode 100644 index 0000000000..f731f80c5e --- /dev/null +++ b/pkg/blobaccess/helm/deprecated.go @@ -0,0 +1,17 @@ +package helm + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +// BlobAccessForHelmChart returns a BlobAccess for the Helm chart with the given path. +// Deprecated: use BlobAccess. +func BlobAccessForHelmChart(path string, opts ...Option) (blob bpi.BlobAccess, name, version string, err error) { + return BlobAccess(path, opts...) +} + +// BlobAccessProviderForHelmChart returns a BlobAccessProvider for the Helm chart with the given name. +// Deprecated: use Provider. +func BlobAccessProviderForHelmChart(name string, opts ...Option) bpi.BlobAccessProvider { + return Provider(name, opts...) +} diff --git a/pkg/blobaccess/helm/options.go b/pkg/blobaccess/helm/options.go index afb45f0c54..e752471404 100644 --- a/pkg/blobaccess/helm/options.go +++ b/pkg/blobaccess/helm/options.go @@ -53,6 +53,13 @@ func (o *Options) ApplyTo(opts *Options) { } } +func (o *Options) OCIContext() oci.Context { + if o.Context == nil { + return oci.DefaultContext() + } + return o.Context +} + //////////////////////////////////////////////////////////////////////////////// type context struct { diff --git a/pkg/blobaccess/maven/access.go b/pkg/blobaccess/maven/access.go index 876e411efe..d66e26ad9f 100644 --- a/pkg/blobaccess/maven/access.go +++ b/pkg/blobaccess/maven/access.go @@ -7,11 +7,11 @@ import ( "github.com/open-component-model/ocm/pkg/maven" ) -func DataAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (bpi.DataAccess, error) { - return BlobAccessForMaven(repo, groupId, artifactId, version, opts...) +func DataAccess(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (bpi.DataAccess, error) { + return BlobAccess(repo, groupId, artifactId, version, opts...) } -func BlobAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (bpi.BlobAccess, error) { +func BlobAccess(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (bpi.BlobAccess, error) { eff := optionutils.EvalOptions(opts...) s := &spec{ coords: maven.NewCoordinates(groupId, artifactId, version, maven.WithOptionalClassifier(eff.Classifier), maven.WithOptionalExtension(eff.Extension)), @@ -21,17 +21,17 @@ func BlobAccessForMaven(repo *maven.Repository, groupId, artifactId, version str return s.getBlobAccess() } -func BlobAccessForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) (bpi.BlobAccess, error) { - return BlobAccessForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) +func BlobAccessForCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) (bpi.BlobAccess, error) { + return BlobAccess(repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) } -func BlobAccessProviderForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { +func Provider(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - b, err := BlobAccessForMaven(repo, groupId, artifactId, version, opts...) + b, err := BlobAccess(repo, groupId, artifactId, version, opts...) return b, err }) } -func BlobAccessProviderForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { - return BlobAccessProviderForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) +func ProviderCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { + return Provider(repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) } diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index c0694eb53b..61a8169917 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -43,7 +43,7 @@ var _ = Describe("blobaccess for maven", func() { It("blobaccess for gav", func() { coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - b := Must(me.BlobAccessForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, me.WithCachingFileSystem(env.FileSystem()))) + b := Must(me.BlobAccess(repo, coords.GroupId, coords.ArtifactId, coords.Version, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf( @@ -58,7 +58,7 @@ var _ = Describe("blobaccess for maven", func() { coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithClassifier("random-content")) - b := Must(me.BlobAccessForMavenCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0-random-content.txt", @@ -69,7 +69,7 @@ var _ = Describe("blobaccess for maven", func() { coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithClassifier("")) - b := Must(me.BlobAccessForMavenCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0.pom", @@ -80,7 +80,7 @@ var _ = Describe("blobaccess for maven", func() { coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithExtension("jar")) - b := Must(me.BlobAccessForMavenCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0-sources.jar", @@ -91,7 +91,7 @@ var _ = Describe("blobaccess for maven", func() { coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithExtension("txt")) - b := Must(me.BlobAccessForMavenCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0-random-content.txt")) @@ -101,7 +101,7 @@ var _ = Describe("blobaccess for maven", func() { coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithClassifier("random-content"), maven.WithExtension("json")) - b := Must(me.BlobAccessForMavenCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) }) @@ -115,7 +115,7 @@ var _ = Describe("blobaccess for maven", func() { }) It("blobaccess for gav", func() { repo := Must(maven.NewUrlRepository(MAVEN_CENTRAL)) - b := Must(me.BlobAccessForMavenCoords(repo, coords)) + b := Must(me.BlobAccessForCoords(repo, coords)) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf( diff --git a/pkg/blobaccess/maven/deprecated.go b/pkg/blobaccess/maven/deprecated.go new file mode 100644 index 0000000000..fc48da8f36 --- /dev/null +++ b/pkg/blobaccess/maven/deprecated.go @@ -0,0 +1,36 @@ +package maven + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/maven" +) + +// DataAccessForMaven returns a DataAccess for the Maven artifact with the given coordinates. +// Deprecated: use DataAccess. +func DataAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (bpi.DataAccess, error) { + return DataAccess(repo, groupId, artifactId, version, opts...) +} + +// BlobAccessForMaven returns a BlobAccess for the Maven artifact with the given coordinates. +// Deprecated: use BlobAccess. +func BlobAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (bpi.BlobAccess, error) { + return BlobAccess(repo, groupId, artifactId, version, opts...) +} + +// BlobAccessForMavenCoords returns a BlobAccessProvider for the Maven artifact with the given coordinates. +// Deprecated: use BlobAccessForCoords. +func BlobAccessForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) (bpi.BlobAccess, error) { + return BlobAccessForCoords(repo, coords, opts...) +} + +// BlobAccessProviderForMaven returns a BlobAccessProvider for the Maven artifact with the given coordinates. +// Deprecated: use Provider. +func BlobAccessProviderForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { + return Provider(repo, groupId, artifactId, version, opts...) +} + +// BlobAccessProviderForMavenCoords returns a BlobAccessProvider for the Maven artifact with the given coordinates. +// Deprecated: use ProviderCoords. +func BlobAccessProviderForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { + return ProviderCoords(repo, coords, opts...) +} diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index e51d3883dd..6c2fdc6ac6 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -10,9 +10,9 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" "github.com/open-component-model/ocm/pkg/blobaccess/file" - "github.com/open-component-model/ocm/pkg/blobaccess/standard" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/credentials" @@ -124,7 +124,7 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { return nil, err } log.Debug("created", "file", tgz.Name()) - return file.ForTemporaryFilePathWithMeta(mime.MIME_TGZ, dw.Digest(), dw.Size(), tgz.Name(), fs), nil + return file.BlobAccessForTemporaryFilePath(mime.MIME_TGZ, tgz.Name(), file.WithFileSystem(fs), file.WithDigest(dw.Digest()), file.WithSize(dw.Size())), nil } func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts *Options) (bpi.BlobAccess, error) { @@ -141,7 +141,7 @@ func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts return iotools.VerifyingReaderWithHash(readCloser, meta.HashType, meta.Hash), nil } } - acc := standard.DataAccessForReaderFunction(reader, meta.Location.String()) + acc := blobaccess.DataAccessForReaderFunction(reader, meta.Location.String()) return accessobj.CachedBlobAccessForWriterWithCache(opts.Cache(), meta.MimeType, accessio.NewDataAccessWriter(acc)), nil } diff --git a/pkg/blobaccess/ociartifact/resource.go b/pkg/blobaccess/ociartifact/access.go similarity index 82% rename from pkg/blobaccess/ociartifact/resource.go rename to pkg/blobaccess/ociartifact/access.go index fc5da58f30..f224e0f08a 100644 --- a/pkg/blobaccess/ociartifact/resource.go +++ b/pkg/blobaccess/ociartifact/access.go @@ -10,7 +10,7 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset" ) -func BlobAccessForOCIArtifact(refname string, opts ...Option) (bpi.BlobAccess, string, error) { +func BlobAccess(refname string, opts ...Option) (bpi.BlobAccess, string, error) { eff := optionutils.EvalOptions(opts...) eff.Printf("image %s\n", refname) @@ -47,9 +47,9 @@ func BlobAccessForOCIArtifact(refname string, opts ...Option) (bpi.BlobAccess, s return blob, version, nil } -func BlobAccessProviderForOCIArtifact(name string, opts ...Option) bpi.BlobAccessProvider { +func Provider(name string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - b, _, err := BlobAccessForOCIArtifact(name, opts...) + b, _, err := BlobAccess(name, opts...) return b, err }) } diff --git a/pkg/blobaccess/ociartifact/deprecated.go b/pkg/blobaccess/ociartifact/deprecated.go new file mode 100644 index 0000000000..7531805def --- /dev/null +++ b/pkg/blobaccess/ociartifact/deprecated.go @@ -0,0 +1,17 @@ +package ociartifact + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +// BlobAccessForOCIArtifact returns a BlobAccess for the OCI artifact with the given refname. +// Deprecated: use BlobAccess. +func BlobAccessForOCIArtifact(refname string, opts ...Option) (bpi.BlobAccess, string, error) { + return BlobAccess(refname, opts...) +} + +// BlobAccessProviderForOCIArtifact returns a BlobAccessProvider for the OCI artifact with the given name. +// Deprecated: use Provider. +func BlobAccessProviderForOCIArtifact(name string, opts ...Option) bpi.BlobAccessProvider { + return Provider(name, opts...) +} diff --git a/pkg/blobaccess/wget/access.go b/pkg/blobaccess/wget/access.go index 8956da8895..b982b97e4b 100644 --- a/pkg/blobaccess/wget/access.go +++ b/pkg/blobaccess/wget/access.go @@ -11,9 +11,9 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/optionutils" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" "github.com/open-component-model/ocm/pkg/blobaccess/file" - "github.com/open-component-model/ocm/pkg/blobaccess/standard" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/wget/identity" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" @@ -25,15 +25,15 @@ const ( CACHE_CONTENT_THRESHOLD = 4096 ) -func DataAccessForWget(url string, opts ...Option) (bpi.DataAccess, error) { - blobAccess, err := BlobAccessForWget(url, opts...) +func DataAccess(url string, opts ...Option) (bpi.DataAccess, error) { + blobAccess, err := BlobAccess(url, opts...) if err != nil { return nil, err } return blobAccess, nil } -func BlobAccessForWget(url string, opts ...Option) (_ bpi.BlobAccess, rerr error) { +func BlobAccess(url string, opts ...Option) (_ bpi.BlobAccess, rerr error) { eff := optionutils.EvalOptions(opts...) log := eff.Logger("URL", url) @@ -167,15 +167,15 @@ func BlobAccessForWget(url string, opts ...Option) (_ bpi.BlobAccess, rerr error if err != nil { return nil, err } - blob = standard.ForData(eff.MimeType, buf) + blob = blobaccess.ForData(eff.MimeType, buf) } return blob, nil } -func BlobAccessProviderForWget(url string, opts ...Option) bpi.BlobAccessProvider { +func Provider(url string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - b, err := BlobAccessForWget(url, opts...) + b, err := BlobAccess(url, opts...) return b, err }) } diff --git a/pkg/blobaccess/wget/deprecated.go b/pkg/blobaccess/wget/deprecated.go new file mode 100644 index 0000000000..793eb85ef8 --- /dev/null +++ b/pkg/blobaccess/wget/deprecated.go @@ -0,0 +1,23 @@ +package wget + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" +) + +// DataAccessForWget returns a DataAccess for the given URL. +// Deprecated: use DataAccess. +func DataAccessForWget(url string, opts ...Option) (bpi.DataAccess, error) { + return DataAccess(url, opts...) +} + +// BlobAccessForWget returns a BlobAccess for the given URL. +// Deprecated: use BlobAccess. +func BlobAccessForWget(url string, opts ...Option) (_ bpi.BlobAccess, rerr error) { + return BlobAccess(url, opts...) +} + +// BlobAccessProviderForWget returns a BlobAccessProvider for the given URL. +// Deprecated: use Provider. +func BlobAccessProviderForWget(url string, opts ...Option) bpi.BlobAccessProvider { + return Provider(url, opts...) +} diff --git a/pkg/common/accessio/access.go b/pkg/common/accessio/access.go index 9b9aeaf619..e4245cf2c2 100644 --- a/pkg/common/accessio/access.go +++ b/pkg/common/accessio/access.go @@ -1,15 +1,11 @@ package accessio import ( - "io" "math/rand" "time" "github.com/mandelsoft/goutils/errors" - "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/refmgmt" ) @@ -19,139 +15,12 @@ var ( ErrReadOnly = errors.ErrReadOnly() ) -const ( - // Deprecated: use blobaccess.KIND_BLOB. - KIND_BLOB = blobaccess.KIND_BLOB - // Deprecated: use blobaccess.KIND_MEDIATYPE. - KIND_MEDIATYPE = blobaccess.KIND_MEDIATYPE -) - -// Deprecated: use blobaccess.ErrBlobNotFound. -func ErrBlobNotFound(digest digest.Digest) error { - return errors.ErrNotFound(blobaccess.KIND_BLOB, digest.String()) -} - -// Deprecated: use blobaccess.IsErrBlobNotFound. -func IsErrBlobNotFound(err error) bool { - return errors.IsErrNotFoundKind(err, blobaccess.KIND_BLOB) -} - -//////////////////////////////////////////////////////////////////////////////// - -// DataSource describes some data plus its origin. -// Deprecated: use blobaccess.DataSource. -type DataSource = blobaccess.DataSource - -//////////////////////////////////////////////////////////////////////////////// - -// DataAccess describes the access to sequence of bytes. -// Deprecated: use blobaccess.DataAccess. -type DataAccess = blobaccess.DataAccess - -// BlobAccess describes the access to a blob. -// Deprecated: use blobaccess.BlobAccess. -type BlobAccess = blobaccess.BlobAccess - //////////////////////////////////////////////////////////////////////////////// type NopCloser = iotools.NopCloser //////////////////////////////////////////////////////////////////////////////// -// Deprecated: use blobaccess.DataAccessForReaderFunction. -func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) blobaccess.DataAccess { - return blobaccess.DataAccessForReaderFunction(reader, origin) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Deprecated: use blobaccess.DataAccessForFile. -func DataAccessForFile(fs vfs.FileSystem, path string) blobaccess.DataAccess { - return blobaccess.DataAccessForFile(fs, path) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Deprecated: use blobaccess.DataAccessForBytes. -func DataAccessForBytes(data []byte, origin ...string) blobaccess.DataSource { - return blobaccess.DataAccessForBytes(data, origin...) -} - -// Deprecated: use blobaccess.DataAccessForString. -func DataAccessForString(data string, origin ...string) blobaccess.DataSource { - return blobaccess.DataAccessForBytes([]byte(data), origin...) -} - -//////////////////////////////////////////////////////////////////////////////// - -// AnnotatedBlobAccess provides access to the original underlying data source. -// Deprecated: use blobaccess.AnnotatedBlobAccess. -type AnnotatedBlobAccess[T blobaccess.DataAccess] interface { - blobaccess.BlobAccess - Source() T -} - -// BlobAccessForDataAccess wraps the general access object into a blob access. -// It closes the wrapped access, if closed. -// Deprecated: use blobaccess.ForDataAccess. -func BlobAccessForDataAccess[T blobaccess.DataAccess](digest digest.Digest, size int64, mimeType string, access T) blobaccess.AnnotatedBlobAccess[T] { - return blobaccess.ForDataAccess[T](digest, size, mimeType, access) -} - -// Deprecated: use blobaccess.ForString. -func BlobAccessForString(mimeType string, data string) blobaccess.BlobAccess { - return blobaccess.ForData(mimeType, []byte(data)) -} - -// Deprecated: use blobaccess.ForData. -func BlobAccessForData(mimeType string, data []byte) blobaccess.BlobAccess { - return blobaccess.ForData(mimeType, data) -} - -//////////////////////////////////////////////////////////////////////////////// - -// BlobWithMimeType changes the mime type for a blob access -// by wrapping the given blob access. It does NOT provide -// a new view for the given blob access, so closing the resulting -// blob access will directly close the backing blob access. -// Deprecated: use blobaccess.WithMimeType. -func BlobWithMimeType(mimeType string, blob blobaccess.BlobAccess) blobaccess.BlobAccess { - return blobaccess.WithMimeType(mimeType, blob) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Deprecated: use blobaccess.ForFile. -func BlobAccessForFile(mimeType string, path string, fss ...vfs.FileSystem) blobaccess.BlobAccess { - return blobaccess.ForFile(mimeType, path, fss...) -} - -// Deprecated: use blobaccess.ForFileWithCloser. -func BlobAccessForFileWithCloser(closer io.Closer, mimeType string, path string, fss ...vfs.FileSystem) blobaccess.BlobAccess { - return blobaccess.ForFileWithCloser(closer, mimeType, path, fss...) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Deprecated: use blobaccess.ForTemporaryFile. -func BlobAccessForTemporaryFile(mime string, temp vfs.File, fss ...vfs.FileSystem) blobaccess.BlobAccess { - return blobaccess.ForTemporaryFile(mime, temp, fss...) -} - -// Deprecated: use blobaccess.ForTemporaryFilePath. -func BlobAccessForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) blobaccess.BlobAccess { - return blobaccess.ForTemporaryFilePath(mime, temp, fss...) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Deprecated: use blobaccess.NewTempFile. -func NewTempFile(fs vfs.FileSystem, dir string, pattern string) (*blobaccess.TempFile, error) { - return blobaccess.NewTempFile(dir, pattern, fs) -} - -//////////////////////////////////////////////////////////////////////////////// - type retriableError struct { wrapped error } diff --git a/pkg/common/accessio/cache.go b/pkg/common/accessio/cache.go index 720d4135df..7cbb62b7f4 100644 --- a/pkg/common/accessio/cache.go +++ b/pkg/common/accessio/cache.go @@ -15,17 +15,13 @@ import ( "github.com/marstr/guid" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/refmgmt" ) -const ( - BLOB_UNKNOWN_SIZE = blobaccess.BLOB_UNKNOWN_SIZE - BLOB_UNKNOWN_DIGEST = blobaccess.BLOB_UNKNOWN_DIGEST -) - type StaticAllocatable struct{} func (_ StaticAllocatable) Ref() error { return nil } @@ -190,19 +186,19 @@ func (c *blobCache) GetBlobData(digest digest.Digest) (int64, blobaccess.DataAcc vfs.WriteFile(c.cache, path+ACCESS_SUFFIX, []byte{}, 0o600) // now := time.Now() // c.cache.Chtimes(path+ACCESS_SUFFIX, now, now) - return fi.Size(), blobaccess.DataAccessForFile(c.cache, path), nil + return fi.Size(), file.DataAccess(c.cache, path), nil } if os.IsNotExist(err) { return -1, nil, blobaccess.ErrBlobNotFound(digest) } } - return BLOB_UNKNOWN_SIZE, nil, err + return blobaccess.BLOB_UNKNOWN_SIZE, nil, err } func (c *blobCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest, error) { err := c.Ref() if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } defer c.Unref() @@ -222,7 +218,7 @@ func (c *blobCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest, e br, err := blob.Reader() if err != nil { - return BLOB_UNKNOWN_SIZE, "", errors.Wrapf(err, "cannot get blob content") + return blobaccess.BLOB_UNKNOWN_SIZE, "", errors.Wrapf(err, "cannot get blob content") } defer br.Close() @@ -234,13 +230,13 @@ func (c *blobCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest, e writer, err := c.cache.Create(tmp) if err != nil { - return BLOB_UNKNOWN_SIZE, "", errors.Wrapf(err, "cannot create blob file in cache") + return blobaccess.BLOB_UNKNOWN_SIZE, "", errors.Wrapf(err, "cannot create blob file in cache") } defer writer.Close() size, err := io.Copy(writer, reader) if err != nil { c.cache.Remove(tmp) - return BLOB_UNKNOWN_SIZE, "", err + return blobaccess.BLOB_UNKNOWN_SIZE, "", err } var digest digest.Digest @@ -263,7 +259,7 @@ func (c *blobCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest, e } func (c *blobCache) AddData(data blobaccess.DataAccess) (int64, digest.Digest, error) { - return c.AddBlob(blobaccess.ForDataAccess(BLOB_UNKNOWN_DIGEST, BLOB_UNKNOWN_SIZE, "", data)) + return c.AddBlob(blobaccess.ForDataAccess(blobaccess.BLOB_UNKNOWN_DIGEST, blobaccess.BLOB_UNKNOWN_SIZE, "", data)) } //////////////////////////////////////////////////////////////////////////////// @@ -349,7 +345,7 @@ func (c *cascadedCache) cleanup() error { func (c *cascadedCache) GetBlobData(digest digest.Digest) (int64, blobaccess.DataAccess, error) { err := c.Ref() if err != nil { - return BLOB_UNKNOWN_SIZE, nil, err + return blobaccess.BLOB_UNKNOWN_SIZE, nil, err } defer c.Unref() @@ -362,17 +358,17 @@ func (c *cascadedCache) GetBlobData(digest digest.Digest) (int64, blobaccess.Dat return size, acc, err } if !blobaccess.IsErrBlobNotFound(err) { - return BLOB_UNKNOWN_SIZE, nil, err + return blobaccess.BLOB_UNKNOWN_SIZE, nil, err } } if c.parent != nil { return c.parent.GetBlobData(digest) } - return BLOB_UNKNOWN_SIZE, nil, blobaccess.ErrBlobNotFound(digest) + return blobaccess.BLOB_UNKNOWN_SIZE, nil, blobaccess.ErrBlobNotFound(digest) } func (c *cascadedCache) AddData(data blobaccess.DataAccess) (int64, digest.Digest, error) { - return c.AddBlob(blobaccess.ForDataAccess(BLOB_UNKNOWN_DIGEST, BLOB_UNKNOWN_SIZE, "", data)) + return c.AddBlob(blobaccess.ForDataAccess(blobaccess.BLOB_UNKNOWN_DIGEST, blobaccess.BLOB_UNKNOWN_SIZE, "", data)) } func (c *cascadedCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest, error) { @@ -385,7 +381,7 @@ func (c *cascadedCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Diges if c.source == nil { cache, err := NewDefaultBlobCache() if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } c.source = cache c.sink = cache @@ -399,7 +395,7 @@ func (c *cascadedCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Diges } } } - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } //////////////////////////////////////////////////////////////////////////////// @@ -429,14 +425,14 @@ func (c *cached) cleanup() error { func (a *cached) GetBlobData(digest digest.Digest) (int64, blobaccess.DataAccess, error) { err := a.Ref() if err != nil { - return BLOB_UNKNOWN_SIZE, nil, err + return blobaccess.BLOB_UNKNOWN_SIZE, nil, err } defer a.Unref() size, acc, err := a.cache.GetBlobData(digest) if err != nil { if !blobaccess.IsErrBlobNotFound(err) { - return BLOB_UNKNOWN_SIZE, nil, err + return blobaccess.BLOB_UNKNOWN_SIZE, nil, err } size, acc, err = a.source.GetBlobData(digest) if err == nil { @@ -449,30 +445,30 @@ func (a *cached) GetBlobData(digest digest.Digest) (int64, blobaccess.DataAccess func (a *cached) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest, error) { err := a.Ref() if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } defer a.Unref() if a.sink == nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, fmt.Errorf("no blob sink") + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, fmt.Errorf("no blob sink") } size, digest, err := a.cache.AddBlob(blob) if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } _, acc, err := a.cache.GetBlobData(digest) if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } size, digest, err = a.sink.AddBlob(blobaccess.ForDataAccess(digest, size, blob.MimeType(), acc)) if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } return size, digest, err } func (c *cached) AddData(data blobaccess.DataAccess) (int64, digest.Digest, error) { - return c.AddBlob(blobaccess.ForDataAccess(blobaccess.BLOB_UNKNOWN_DIGEST, BLOB_UNKNOWN_SIZE, "", data)) + return c.AddBlob(blobaccess.ForDataAccess(blobaccess.BLOB_UNKNOWN_DIGEST, blobaccess.BLOB_UNKNOWN_SIZE, "", data)) } ///////////////////////////////////////// @@ -550,7 +546,7 @@ func (c *cachedAccess) Get() ([]byte, error) { if err != nil { return nil, err } - c.size, c.digest, err = c.cache.cache.AddData(blobaccess.DataAccessForBytes(data)) + c.size, c.digest, err = c.cache.cache.AddData(blobaccess.DataAccessForData(data)) if err == nil { c.orig.Close() c.orig = nil diff --git a/pkg/common/accessio/cache_test.go b/pkg/common/accessio/cache_test.go index 9d14bb58d1..e11c58e5a4 100644 --- a/pkg/common/accessio/cache_test.go +++ b/pkg/common/accessio/cache_test.go @@ -1,14 +1,13 @@ package accessio_test import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" ) @@ -31,7 +30,7 @@ var _ = Describe("cache management", func() { source, err = accessio.NewDefaultBlobCache() Expect(err).To(Succeed()) - td1_size, td1_digest, err = source.AddData(blobaccess.DataAccessForBytes([]byte("testdata"))) + td1_size, td1_digest, err = source.AddData(blobaccess.DataAccessForData([]byte("testdata"))) Expect(err).To(Succeed()) cache, err = accessio.CachedAccess(source, nil, local) diff --git a/pkg/common/accessio/deprecated.go b/pkg/common/accessio/deprecated.go new file mode 100644 index 0000000000..6513bcb2fd --- /dev/null +++ b/pkg/common/accessio/deprecated.go @@ -0,0 +1,233 @@ +package accessio + +import ( + "crypto" + "io" + + "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/goutils/sliceutils" + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/opencontainers/go-digest" + + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" + "github.com/open-component-model/ocm/pkg/iotools" + "github.com/open-component-model/ocm/pkg/utils" +) + +const ( + // Deprecated: use blobaccess.BLOB_UNKNOWN_SIZE. + BLOB_UNKNOWN_SIZE = blobaccess.BLOB_UNKNOWN_SIZE + // Deprecated: use blobaccess.BLOB_UNKNOWN_DIGEST. + BLOB_UNKNOWN_DIGEST = blobaccess.BLOB_UNKNOWN_DIGEST +) + +const ( + // Deprecated: use blobaccess.KIND_BLOB. + KIND_BLOB = blobaccess.KIND_BLOB + // Deprecated: use blobaccess.KIND_MEDIATYPE. + KIND_MEDIATYPE = blobaccess.KIND_MEDIATYPE +) + +// Deprecated: use blobaccess.ErrBlobNotFound. +func ErrBlobNotFound(digest digest.Digest) error { + return errors.ErrNotFound(blobaccess.KIND_BLOB, digest.String()) +} + +// Deprecated: use blobaccess.IsErrBlobNotFound. +func IsErrBlobNotFound(err error) bool { + return errors.IsErrNotFoundKind(err, blobaccess.KIND_BLOB) +} + +//////////////////////////////////////////////////////////////////////////////// + +// DataSource describes some data plus its origin. +// Deprecated: use blobaccess.DataSource. +type DataSource = blobaccess.DataSource + +//////////////////////////////////////////////////////////////////////////////// + +// DataAccess describes the access to sequence of bytes. +// Deprecated: use blobaccess.DataAccess. +type DataAccess = blobaccess.DataAccess + +// BlobAccess describes the access to a blob. +// Deprecated: use blobaccess.BlobAccess. +type BlobAccess = blobaccess.BlobAccess + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.DataAccessForReaderFunction. +func DataAccessForReaderFunction(reader func() (io.ReadCloser, error), origin string) blobaccess.DataAccess { + return blobaccess.DataAccessForReaderFunction(reader, origin) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.DataAccessForFile. +func DataAccessForFile(fs vfs.FileSystem, path string) blobaccess.DataAccess { + return file.DataAccess(fs, path) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.DataAccessForBytes. +func DataAccessForBytes(data []byte, origin ...string) blobaccess.DataSource { + return blobaccess.DataAccessForData(data, origin...) +} + +// Deprecated: use blobaccess.DataAccessForString. +func DataAccessForString(data string, origin ...string) blobaccess.DataSource { + return blobaccess.DataAccessForData([]byte(data), origin...) +} + +//////////////////////////////////////////////////////////////////////////////// + +// BlobWithMimeType changes the mime type for a blob access +// by wrapping the given blob access. It does NOT provide +// a new view for the given blob access, so closing the resulting +// blob access will directly close the backing blob access. +// Deprecated: use blobaccess.WithMimeType. +func BlobWithMimeType(mimeType string, blob blobaccess.BlobAccess) blobaccess.BlobAccess { + return blobaccess.WithMimeType(mimeType, blob) +} + +//////////////////////////////////////////////////////////////////////////////// + +// AnnotatedBlobAccess provides access to the original underlying data source. +// Deprecated: use blobaccess.AnnotatedBlobAccess. +type AnnotatedBlobAccess[T blobaccess.DataAccess] interface { + blobaccess.BlobAccess + Source() T +} + +// BlobAccessForDataAccess wraps the general access object into a blob access. +// It closes the wrapped access, if closed. +// Deprecated: use blobaccess.ForDataAccess. +func BlobAccessForDataAccess[T blobaccess.DataAccess](digest digest.Digest, size int64, mimeType string, access T) blobaccess.AnnotatedBlobAccess[T] { + return blobaccess.ForDataAccess[T](digest, size, mimeType, access) +} + +// Deprecated: use blobaccess.ForString. +func BlobAccessForString(mimeType string, data string) blobaccess.BlobAccess { + return blobaccess.ForData(mimeType, []byte(data)) +} + +// Deprecated: use blobaccess.ForData. +func BlobAccessForData(mimeType string, data []byte) blobaccess.BlobAccess { + return blobaccess.ForData(mimeType, data) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.ForFile. +func BlobAccessForFile(mimeType string, path string, fss ...vfs.FileSystem) blobaccess.BlobAccess { + return file.BlobAccess(mimeType, path, fss...) +} + +// Deprecated: use blobaccess.ForFileWithCloser. +func BlobAccessForFileWithCloser(closer io.Closer, mimeType string, path string, fss ...vfs.FileSystem) blobaccess.BlobAccess { + return file.BlobAccessWithCloser(closer, mimeType, path, fss...) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.ForTemporaryFile. +func BlobAccessForTemporaryFile(mime string, temp vfs.File, fss ...vfs.FileSystem) blobaccess.BlobAccess { + return file.BlobAccessForTemporaryFile(mime, temp, file.WithFileSystem(fss...)) +} + +// Deprecated: use blobaccess.ForTemporaryFilePath. +func BlobAccessForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) blobaccess.BlobAccess { + return file.BlobAccessForTemporaryFilePath(mime, temp, file.WithFileSystem(fss...)) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.NewTempFile. +func NewTempFile(fs vfs.FileSystem, dir string, pattern string) (*file.TempFile, error) { + return file.NewTempFile(dir, pattern, fs) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use iotools.DigestReader. +type DigestReader = iotools.DigestReader + +// Deprecated: use iotools.NewDefaultDigestReader. +func NewDefaultDigestReader(r io.Reader) *iotools.DigestReader { + return iotools.NewDigestReaderWith(digest.Canonical, r) +} + +// Deprecated: use iotools.NewDigestReaderWith. +func NewDigestReaderWith(algorithm digest.Algorithm, r io.Reader) *iotools.DigestReader { + return iotools.NewDigestReaderWith(algorithm, r) +} + +// Deprecated: use iotools.NewDigestReaderWithHash. +func NewDigestReaderWithHash(hash crypto.Hash, r io.Reader) *iotools.DigestReader { + return iotools.NewDigestReaderWithHash(hash, r) +} + +// Deprecated: use iotools.VerifyingReader. +func VerifyingReader(r io.ReadCloser, digest digest.Digest) io.ReadCloser { + return iotools.VerifyingReader(r, digest) +} + +// Deprecated: use iotools.VerifyingReaderWithHash. +func VerifyingReaderWithHash(r io.ReadCloser, hash crypto.Hash, digest string) io.ReadCloser { + return iotools.VerifyingReaderWithHash(r, hash, digest) +} + +// Deprecated: use blobaccess.Digest. +func Digest(access blobaccess.DataAccess) (digest.Digest, error) { + return blobaccess.Digest(access) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use iotools.DigestWriter. +type DigestWriter = iotools.DigestWriter + +// Deprecated: use iotools.NewDefaultDigestWriter. +func NewDefaultDigestWriter(w io.WriteCloser) *iotools.DigestWriter { + return iotools.NewDefaultDigestWriter(w) +} + +// Deprecated: use iotools.NewDigestWriterWith. +func NewDigestWriterWith(algorithm digest.Algorithm, w io.WriteCloser) *iotools.DigestWriter { + return iotools.NewDigestWriterWith(algorithm, w) +} + +//////////////////////////////////////////////////////////////////////////////// + +// Deprecated: use blobaccess.BlobData. +func BlobData(blob blobaccess.DataGetter, err error) ([]byte, error) { + if err != nil { + return nil, err + } + return blob.Get() +} + +// Deprecated: use blobaccess.BlobReader. +func BlobReader(blob blobaccess.DataReader, err error) (io.ReadCloser, error) { + if err != nil { + return nil, err + } + return blob.Reader() +} + +// Deprecated: use utils.FileSystem. +func FileSystem(fss ...vfs.FileSystem) vfs.FileSystem { + return utils.FileSystem(fss...) +} + +// Deprecated: use utils.DefaultedFileSystem. +func DefaultedFileSystem(def vfs.FileSystem, fss ...vfs.FileSystem) vfs.FileSystem { + return utils.DefaultedFileSystem(def, fss...) +} + +// Deprecated: use iotools.AddReaderCloser. +func AddCloser(reader io.ReadCloser, closer io.Closer, msg ...string) io.ReadCloser { + return iotools.AddReaderCloser(reader, closer, sliceutils.AsAny(msg)...) +} diff --git a/pkg/common/accessio/digestreader.go b/pkg/common/accessio/digestreader.go deleted file mode 100644 index e4df566ac4..0000000000 --- a/pkg/common/accessio/digestreader.go +++ /dev/null @@ -1,44 +0,0 @@ -package accessio - -import ( - "crypto" - "io" - - "github.com/opencontainers/go-digest" - - "github.com/open-component-model/ocm/pkg/blobaccess" - "github.com/open-component-model/ocm/pkg/iotools" -) - -// Deprecated: use iotools.DigestReader. -type DigestReader = iotools.DigestReader - -// Deprecated: use iotools.NewDefaultDigestReader. -func NewDefaultDigestReader(r io.Reader) *iotools.DigestReader { - return iotools.NewDigestReaderWith(digest.Canonical, r) -} - -// Deprecated: use iotools.NewDigestReaderWith. -func NewDigestReaderWith(algorithm digest.Algorithm, r io.Reader) *iotools.DigestReader { - return iotools.NewDigestReaderWith(algorithm, r) -} - -// Deprecated: use iotools.NewDigestReaderWithHash. -func NewDigestReaderWithHash(hash crypto.Hash, r io.Reader) *iotools.DigestReader { - return iotools.NewDigestReaderWithHash(hash, r) -} - -// Deprecated: use iotools.VerifyingReader. -func VerifyingReader(r io.ReadCloser, digest digest.Digest) io.ReadCloser { - return iotools.VerifyingReader(r, digest) -} - -// Deprecated: use iotools.VerifyingReaderWithHash. -func VerifyingReaderWithHash(r io.ReadCloser, hash crypto.Hash, digest string) io.ReadCloser { - return iotools.VerifyingReaderWithHash(r, hash, digest) -} - -// Deprecated: use blobaccess.Digest. -func Digest(access blobaccess.DataAccess) (digest.Digest, error) { - return blobaccess.Digest(access) -} diff --git a/pkg/common/accessio/digestwriter.go b/pkg/common/accessio/digestwriter.go deleted file mode 100644 index d2454be130..0000000000 --- a/pkg/common/accessio/digestwriter.go +++ /dev/null @@ -1,22 +0,0 @@ -package accessio - -import ( - "io" - - "github.com/opencontainers/go-digest" - - "github.com/open-component-model/ocm/pkg/iotools" -) - -// Deprecated: use iotools.DigestWriter. -type DigestWriter = iotools.DigestWriter - -// Deprecated: use iotools.NewDefaultDigestWriter. -func NewDefaultDigestWriter(w io.WriteCloser) *iotools.DigestWriter { - return iotools.NewDefaultDigestWriter(w) -} - -// Deprecated: use iotools.NewDigestWriterWith. -func NewDigestWriterWith(algorithm digest.Algorithm, w io.WriteCloser) *iotools.DigestWriter { - return iotools.NewDigestWriterWith(algorithm, w) -} diff --git a/pkg/common/accessio/utils.go b/pkg/common/accessio/utils.go index 954de1125e..bc9a1c62ac 100644 --- a/pkg/common/accessio/utils.go +++ b/pkg/common/accessio/utils.go @@ -5,13 +5,8 @@ import ( "io" "github.com/mandelsoft/goutils/errors" - "github.com/mandelsoft/goutils/sliceutils" - "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/compression" - "github.com/open-component-model/ocm/pkg/iotools" - "github.com/open-component-model/ocm/pkg/utils" ) type closableReader struct { @@ -38,39 +33,6 @@ func NopWriteCloser(w io.Writer) io.WriteCloser { //////////////////////////////////////////////////////////////////////////////// -// Deprecated: use iotools.BlobData. -func AddCloser(reader io.ReadCloser, closer io.Closer, msg ...string) io.ReadCloser { - return iotools.AddReaderCloser(reader, closer, sliceutils.AsAny(msg)...) -} - -//////////////////////////////////////////////////////////////////////////////// - -// Deprecated: use blobaccess.BlobData. -func BlobData(blob blobaccess.DataGetter, err error) ([]byte, error) { - if err != nil { - return nil, err - } - return blob.Get() -} - -// Deprecated: use blobaccess.BlobReader. -func BlobReader(blob blobaccess.DataReader, err error) (io.ReadCloser, error) { - if err != nil { - return nil, err - } - return blob.Reader() -} - -// Deprecated: use utils.FileSystem. -func FileSystem(fss ...vfs.FileSystem) vfs.FileSystem { - return utils.FileSystem(fss...) -} - -// Deprecated: use utils.DefaultedFileSystem. -func DefaultedFileSystem(def vfs.FileSystem, fss ...vfs.FileSystem) vfs.FileSystem { - return utils.DefaultedFileSystem(def, fss...) -} - type once struct { callbacks []CloserCallback closer io.Closer diff --git a/pkg/common/accessio/wrapper.go b/pkg/common/accessio/wrapper.go index 7d477f46b2..c768e6efac 100644 --- a/pkg/common/accessio/wrapper.go +++ b/pkg/common/accessio/wrapper.go @@ -6,7 +6,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/iotools" ) @@ -34,7 +34,7 @@ func (d *readerWriter) WriteTo(w Writer) (size int64, dig digest.Digest, err err dr := iotools.NewDefaultDigestReader(d.reader) _, err = io.Copy(w, dr) if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } return dr.Size(), dr.Digest(), err } @@ -50,7 +50,7 @@ func NewDataAccessWriter(acc blobaccess.DataAccess) DataWriter { func (d *dataAccessWriter) WriteTo(w Writer) (int64, digest.Digest, error) { r, err := d.access.Reader() if err != nil { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } return (&readerWriter{r}).WriteTo(w) } @@ -64,5 +64,5 @@ func NewWriteAtWriter(at func(w io.WriterAt) error) DataWriter { } func (d *writerAtWrapper) WriteTo(w Writer) (int64, digest.Digest, error) { - return BLOB_UNKNOWN_SIZE, BLOB_UNKNOWN_DIGEST, d.writer(w) + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, d.writer(w) } diff --git a/pkg/common/accessobj/accessstate.go b/pkg/common/accessobj/accessstate.go index 871d54de4f..b7abad9024 100644 --- a/pkg/common/accessobj/accessstate.go +++ b/pkg/common/accessobj/accessstate.go @@ -9,7 +9,8 @@ import ( "github.com/modern-go/reflect2" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/common/accessio" ) @@ -315,7 +316,7 @@ func (f *fileBasedAccess) Get() (blobaccess.BlobAccess, error) { if !ok { return nil, errors.ErrNotFoundWrap(vfs.ErrNotExist, "file", f.path, f.filesystem.Name()) } - return blobaccess.ForFile(f.mimeType, f.path, f.filesystem), nil + return file.BlobAccess(f.mimeType, f.path, f.filesystem), nil } func (f *fileBasedAccess) Put(data []byte) error { diff --git a/pkg/common/accessobj/cachedblob.go b/pkg/common/accessobj/cachedblob.go index 4e08c175ef..cc2281a8ac 100644 --- a/pkg/common/accessobj/cachedblob.go +++ b/pkg/common/accessobj/cachedblob.go @@ -7,8 +7,9 @@ import ( "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/datacontext" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/tmpcache" @@ -52,21 +53,21 @@ func (c *CachedBlobAccess) setup() error { return nil } - file, err := c.cache.CreateTempFile("blob*") + f, err := c.cache.CreateTempFile("blob*") if err != nil { return fmt.Errorf("unable to create temporary file: %w", err) } - defer file.Close() + defer f.Close() - c.path = file.Name() + c.path = f.Name() - c.size, c.digest, err = c.source.WriteTo(file) + c.size, c.digest, err = c.source.WriteTo(f) if err != nil { - defer c.cache.Filesystem.Remove(file.Name()) - return fmt.Errorf("unable to write source to file '%s': %w", file.Name(), err) + defer c.cache.Filesystem.Remove(f.Name()) + return fmt.Errorf("unable to write source to file '%s': %w", f.Name(), err) } - c.effective = blobaccess.ForFile(c.mime, c.path, c.cache.Filesystem) + c.effective = file.BlobAccess(c.mime, c.path, c.cache.Filesystem) return nil } @@ -111,9 +112,9 @@ func (c *CachedBlobAccess) Close() error { func (c *CachedBlobAccess) Digest() digest.Digest { err := c.setup() if err != nil { - return accessio.BLOB_UNKNOWN_DIGEST + return bpi.BLOB_UNKNOWN_DIGEST } - if c.digest == accessio.BLOB_UNKNOWN_DIGEST { + if c.digest == bpi.BLOB_UNKNOWN_DIGEST { return c.effective.Digest() } return c.digest @@ -130,9 +131,9 @@ func (c *CachedBlobAccess) DigestKnown() bool { func (c *CachedBlobAccess) Size() int64 { err := c.setup() if err != nil { - return accessio.BLOB_UNKNOWN_SIZE + return blobaccess.BLOB_UNKNOWN_SIZE } - if c.size == accessio.BLOB_UNKNOWN_SIZE { + if c.size == blobaccess.BLOB_UNKNOWN_SIZE { return c.effective.Size() } return c.size diff --git a/pkg/common/accessobj/filesystemaccess.go b/pkg/common/accessobj/filesystemaccess.go index 26b43e1bea..bdf667c7e5 100644 --- a/pkg/common/accessobj/filesystemaccess.go +++ b/pkg/common/accessobj/filesystemaccess.go @@ -9,7 +9,8 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/mime" @@ -75,7 +76,7 @@ func (a *FileSystemBlobAccess) GetBlobData(digest digest.Digest) (int64, blobacc } path := a.DigestPath(digest) if ok, err := vfs.FileExists(a.base.GetFileSystem(), path); ok { - return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.DataAccessForFile(a.base.GetFileSystem(), path), nil + return blobaccess.BLOB_UNKNOWN_SIZE, file.DataAccess(a.base.GetFileSystem(), path), nil } else { if err != nil { return blobaccess.BLOB_UNKNOWN_SIZE, nil, err @@ -91,7 +92,7 @@ func (a *FileSystemBlobAccess) GetBlobDataByName(name string) (blobaccess.DataAc path := a.BlobPath(name) if ok, err := vfs.IsDir(a.base.GetFileSystem(), path); ok { - tempfile, err := blobaccess.NewTempFile(os.TempDir(), "COMPARCH") + tempfile, err := file.NewTempFile(os.TempDir(), "COMPARCH") if err != nil { return nil, err } @@ -106,7 +107,7 @@ func (a *FileSystemBlobAccess) GetBlobDataByName(name string) (blobaccess.DataAc } if ok, err := vfs.FileExists(a.base.GetFileSystem(), path); ok { - return blobaccess.DataAccessForFile(a.base.GetFileSystem(), path), nil + return file.DataAccess(a.base.GetFileSystem(), path), nil } else { if err != nil { return nil, err diff --git a/pkg/contexts/config/cpi/content.go b/pkg/contexts/config/cpi/content.go index c0ad9b6cad..a1e864089d 100644 --- a/pkg/contexts/config/cpi/content.go +++ b/pkg/contexts/config/cpi/content.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/utils" ) diff --git a/pkg/contexts/oci/annotations/annotations.go b/pkg/contexts/oci/annotations/annotations.go index ed2fc1d6fe..59f782c5bb 100644 --- a/pkg/contexts/oci/annotations/annotations.go +++ b/pkg/contexts/oci/annotations/annotations.go @@ -1,21 +1,19 @@ package annotations -import ( - "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset" -) - // MAINARTIFACT_ANNOTATION is the name of the OCI manifest annotation used to describe -// the main artifact identity in an artifact set.. -const MAINARTIFACT_ANNOTATION = artifactset.MAINARTIFACT_ANNOTATION +// the main artifact identity in an artifact set. +const MAINARTIFACT_ANNOTATION = "software.ocm/main" // TAGS_ANNOTATION is the name of the OCI manifest annotation used to describe a set of // tags assigned to a manifest in an artifact set. -const TAGS_ANNOTATION = artifactset.TAGS_ANNOTATION +const TAGS_ANNOTATION = "software.ocm/tags" -const TYPE_ANNOTATION = artifactset.TYPE_ANNOTATION +// TYPE_ANNOTATION is the name of the OCI manifest annotation used to describe the type +// (not yet used). +const TYPE_ANNOTATION = "software.ocm/type" // OCITAG_ANNOTATION is the name of the OCI manifest annotation used to describe a tag. -const OCITAG_ANNOTATION = artifactset.OCITAG_ANNOTATION +const OCITAG_ANNOTATION = "org.opencontainers.image.ref.name" // COMPVERS_ANNOTATION is the name of the OCI manifest annotation used to describe // the OCM identity of the origin of an OCI artifact. This is the identity of a diff --git a/pkg/contexts/oci/artdesc/artifact.go b/pkg/contexts/oci/artdesc/artifact.go index 857c61b7e7..ad66c12534 100644 --- a/pkg/contexts/oci/artdesc/artifact.go +++ b/pkg/contexts/oci/artdesc/artifact.go @@ -9,7 +9,7 @@ import ( "github.com/opencontainers/go-digest" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc/helper" ) diff --git a/pkg/contexts/oci/artdesc/config.go b/pkg/contexts/oci/artdesc/config.go index 03cdd68422..b0e990ee05 100644 --- a/pkg/contexts/oci/artdesc/config.go +++ b/pkg/contexts/oci/artdesc/config.go @@ -5,7 +5,7 @@ import ( ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" ) type ImageConfig = ociv1.Image diff --git a/pkg/contexts/oci/artdesc/index.go b/pkg/contexts/oci/artdesc/index.go index fd18b7fbd9..05b209ae06 100644 --- a/pkg/contexts/oci/artdesc/index.go +++ b/pkg/contexts/oci/artdesc/index.go @@ -8,7 +8,7 @@ import ( "github.com/opencontainers/image-spec/specs-go" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" ) type Index ociv1.Index diff --git a/pkg/contexts/oci/artdesc/manifest.go b/pkg/contexts/oci/artdesc/manifest.go index 67f136cbc3..ed8ae22472 100644 --- a/pkg/contexts/oci/artdesc/manifest.go +++ b/pkg/contexts/oci/artdesc/manifest.go @@ -8,7 +8,7 @@ import ( "github.com/opencontainers/image-spec/specs-go" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" ) type Manifest ociv1.Manifest diff --git a/pkg/contexts/oci/artdesc/utils.go b/pkg/contexts/oci/artdesc/utils.go index cfaa25c7a6..8c0ea74b90 100644 --- a/pkg/contexts/oci/artdesc/utils.go +++ b/pkg/contexts/oci/artdesc/utils.go @@ -5,7 +5,7 @@ import ( "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" ) func DefaultBlobDescriptor(blob blobaccess.BlobAccess) *Descriptor { diff --git a/pkg/contexts/oci/cpi/interface.go b/pkg/contexts/oci/cpi/interface.go index f57e92c66f..8d372f2bf4 100644 --- a/pkg/contexts/oci/cpi/interface.go +++ b/pkg/contexts/oci/cpi/interface.go @@ -6,7 +6,7 @@ import ( "github.com/opencontainers/go-digest" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/datacontext" "github.com/open-component-model/ocm/pkg/contexts/oci/internal" ) @@ -46,7 +46,9 @@ type ( type Descriptor = ociv1.Descriptor -var DefaultContext = internal.DefaultContext +func DefaultContext() Context { + return internal.DefaultContext +} func New(m ...datacontext.BuilderMode) Context { return internal.Builder{}.New(m...) diff --git a/pkg/contexts/oci/cpi/support/artifact.go b/pkg/contexts/oci/cpi/support/artifact.go index 50aeecea09..a2ed0493f1 100644 --- a/pkg/contexts/oci/cpi/support/artifact.go +++ b/pkg/contexts/oci/cpi/support/artifact.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/contexts/oci/cpi/support/artifactsetblobaccess.go b/pkg/contexts/oci/cpi/support/artifactsetblobaccess.go index 55a3132b70..425c2d8ccd 100644 --- a/pkg/contexts/oci/cpi/support/artifactsetblobaccess.go +++ b/pkg/contexts/oci/cpi/support/artifactsetblobaccess.go @@ -5,7 +5,7 @@ import ( "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" ) diff --git a/pkg/contexts/oci/cpi/support/base.go b/pkg/contexts/oci/cpi/support/base.go index 407f4ce84d..c4a32c6302 100644 --- a/pkg/contexts/oci/cpi/support/base.go +++ b/pkg/contexts/oci/cpi/support/base.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" diff --git a/pkg/contexts/oci/cpi/support/flavor_index.go b/pkg/contexts/oci/cpi/support/flavor_index.go index 535422bb49..450fce7cab 100644 --- a/pkg/contexts/oci/cpi/support/flavor_index.go +++ b/pkg/contexts/oci/cpi/support/flavor_index.go @@ -4,7 +4,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" diff --git a/pkg/contexts/oci/cpi/support/namespace.go b/pkg/contexts/oci/cpi/support/namespace.go index 0055903b52..99a78d743e 100644 --- a/pkg/contexts/oci/cpi/support/namespace.go +++ b/pkg/contexts/oci/cpi/support/namespace.go @@ -4,7 +4,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" "github.com/open-component-model/ocm/pkg/refmgmt" diff --git a/pkg/contexts/oci/identity/creds.go b/pkg/contexts/oci/identity/deprecated.go similarity index 100% rename from pkg/contexts/oci/identity/creds.go rename to pkg/contexts/oci/identity/deprecated.go diff --git a/pkg/contexts/oci/interface.go b/pkg/contexts/oci/interface.go index 86e2ecc859..dac0af7259 100644 --- a/pkg/contexts/oci/interface.go +++ b/pkg/contexts/oci/interface.go @@ -3,7 +3,7 @@ package oci import ( "context" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/oci/internal" ) diff --git a/pkg/contexts/oci/internal/errors.go b/pkg/contexts/oci/internal/errors.go index 3b790e669c..8b537522b6 100644 --- a/pkg/contexts/oci/internal/errors.go +++ b/pkg/contexts/oci/internal/errors.go @@ -5,7 +5,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" ) const ( diff --git a/pkg/contexts/oci/internal/repository.go b/pkg/contexts/oci/internal/repository.go index 27bad551bd..20335719e8 100644 --- a/pkg/contexts/oci/internal/repository.go +++ b/pkg/contexts/oci/internal/repository.go @@ -5,7 +5,7 @@ import ( "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/refmgmt/resource" diff --git a/pkg/contexts/oci/ociutils/helm/art_test.go b/pkg/contexts/oci/ociutils/helm/art_test.go index 7f080ef174..2d497254dd 100644 --- a/pkg/contexts/oci/ociutils/helm/art_test.go +++ b/pkg/contexts/oci/ociutils/helm/art_test.go @@ -15,7 +15,7 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chartutil" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/ociutils/helm" "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset" diff --git a/pkg/contexts/oci/ociutils/helm/artifact.go b/pkg/contexts/oci/ociutils/helm/artifact.go index e0aa054cbc..d012c0162c 100644 --- a/pkg/contexts/oci/ociutils/helm/artifact.go +++ b/pkg/contexts/oci/ociutils/helm/artifact.go @@ -11,7 +11,8 @@ import ( "helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/registry" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset" @@ -68,7 +69,7 @@ func TransferAsArtifact(loader loader.Loader, ns oci.NamespaceAccess) (*chart.Ch if err != nil { return chart, nil, err } - blob = blobaccess.ForFile(registry.ChartLayerMediaType, path, osfs.New()) + blob = file.BlobAccess(registry.ChartLayerMediaType, path, osfs.New()) } else { defer blob.Close() } diff --git a/pkg/contexts/oci/ociutils/info.go b/pkg/contexts/oci/ociutils/info.go index 47fef72065..f8dfdb1757 100644 --- a/pkg/contexts/oci/ociutils/info.go +++ b/pkg/contexts/oci/ociutils/info.go @@ -10,7 +10,7 @@ import ( "github.com/opencontainers/go-digest" "sigs.k8s.io/yaml" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/compression" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/contexts/oci/ociutils/print.go b/pkg/contexts/oci/ociutils/print.go index cea469d98e..0637020d08 100644 --- a/pkg/contexts/oci/ociutils/print.go +++ b/pkg/contexts/oci/ociutils/print.go @@ -8,7 +8,7 @@ import ( "io" "strings" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/compression" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/contexts/oci/repositories/artifactset/artifactset.go b/pkg/contexts/oci/repositories/artifactset/artifactset.go index 612b21c5a3..b708bc2a45 100644 --- a/pkg/contexts/oci/repositories/artifactset/artifactset.go +++ b/pkg/contexts/oci/repositories/artifactset/artifactset.go @@ -7,20 +7,22 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" + "github.com/open-component-model/ocm/pkg/contexts/oci/annotations" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi/support" ) const ( - MAINARTIFACT_ANNOTATION = "software.ocm/main" - TAGS_ANNOTATION = "software.ocm/tags" - TYPE_ANNOTATION = "software.ocm/type" + MAINARTIFACT_ANNOTATION = annotations.MAINARTIFACT_ANNOTATION - OCITAG_ANNOTATION = "org.opencontainers.image.ref.name" + TAGS_ANNOTATION = annotations.TAGS_ANNOTATION + TYPE_ANNOTATION = annotations.TYPE_ANNOTATION + + OCITAG_ANNOTATION = annotations.OCITAG_ANNOTATION ) func RetrieveMainArtifactFromIndex(index *artdesc.Index) string { diff --git a/pkg/contexts/oci/repositories/artifactset/filesystemaccess.go b/pkg/contexts/oci/repositories/artifactset/filesystemaccess.go index c0a2ea0230..baaac052fd 100644 --- a/pkg/contexts/oci/repositories/artifactset/filesystemaccess.go +++ b/pkg/contexts/oci/repositories/artifactset/filesystemaccess.go @@ -3,7 +3,7 @@ package artifactset import ( "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi/support" diff --git a/pkg/contexts/oci/repositories/artifactset/format.go b/pkg/contexts/oci/repositories/artifactset/format.go index ae4c67aec7..61c207f860 100644 --- a/pkg/contexts/oci/repositories/artifactset/format.go +++ b/pkg/contexts/oci/repositories/artifactset/format.go @@ -6,7 +6,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" mime2 "github.com/open-component-model/ocm/pkg/mime" diff --git a/pkg/contexts/oci/repositories/artifactset/repo_test.go b/pkg/contexts/oci/repositories/artifactset/repo_test.go index 27f46db651..0d7f374002 100644 --- a/pkg/contexts/oci/repositories/artifactset/repo_test.go +++ b/pkg/contexts/oci/repositories/artifactset/repo_test.go @@ -40,7 +40,7 @@ var _ = Describe("", func() { spec, err := artifactset.NewRepositorySpec(accessobj.ACC_READONLY, "/tmp/set", accessio.PathFileSystem(env)) Expect(err).To(Succeed()) - r, err := cpi.DefaultContext.RepositoryForSpec(spec) + r, err := cpi.DefaultContext().RepositoryForSpec(spec) Expect(err).To(Succeed()) defer Close(r) ns, err := r.LookupNamespace("") diff --git a/pkg/contexts/oci/repositories/artifactset/utils_synthesis.go b/pkg/contexts/oci/repositories/artifactset/utils_synthesis.go index 52df2f528a..17db6a7217 100644 --- a/pkg/contexts/oci/repositories/artifactset/utils_synthesis.go +++ b/pkg/contexts/oci/repositories/artifactset/utils_synthesis.go @@ -9,7 +9,8 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" @@ -27,7 +28,7 @@ type ArtifactBlob interface { type Producer func(set *ArtifactSet) (string, error) func SythesizeArtifactSet(producer Producer) (ArtifactBlob, error) { - temp, err := blobaccess.NewTempFile("", "artifactblob*.tgz") + temp, err := file.NewTempFile("", "artifactblob*.tgz") if err != nil { return nil, err } diff --git a/pkg/contexts/oci/repositories/ctf/ctf_test.go b/pkg/contexts/oci/repositories/ctf/ctf_test.go index 7f4d111705..8243f01f5c 100644 --- a/pkg/contexts/oci/repositories/ctf/ctf_test.go +++ b/pkg/contexts/oci/repositories/ctf/ctf_test.go @@ -8,6 +8,7 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf/testhelper" "github.com/mandelsoft/goutils/errors" @@ -17,7 +18,6 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci" diff --git a/pkg/contexts/oci/repositories/ctf/format.go b/pkg/contexts/oci/repositories/ctf/format.go index f77d0da8fd..64167460ff 100644 --- a/pkg/contexts/oci/repositories/ctf/format.go +++ b/pkg/contexts/oci/repositories/ctf/format.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" diff --git a/pkg/contexts/oci/repositories/ctf/namespace.go b/pkg/contexts/oci/repositories/ctf/namespace.go index e8ec28dfb4..beefb173f5 100644 --- a/pkg/contexts/oci/repositories/ctf/namespace.go +++ b/pkg/contexts/oci/repositories/ctf/namespace.go @@ -4,7 +4,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi/support" diff --git a/pkg/contexts/oci/repositories/ctf/synthesis_test.go b/pkg/contexts/oci/repositories/ctf/synthesis_test.go index db478ceb80..dbd290a98b 100644 --- a/pkg/contexts/oci/repositories/ctf/synthesis_test.go +++ b/pkg/contexts/oci/repositories/ctf/synthesis_test.go @@ -4,6 +4,7 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf/testhelper" "github.com/mandelsoft/filepath/pkg/filepath" @@ -12,7 +13,6 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci" diff --git a/pkg/contexts/oci/repositories/docker/artifact.go b/pkg/contexts/oci/repositories/docker/artifact.go index 2b35b1a963..5a01ffb0ba 100644 --- a/pkg/contexts/oci/repositories/docker/artifact.go +++ b/pkg/contexts/oci/repositories/docker/artifact.go @@ -6,7 +6,7 @@ import ( "github.com/containers/image/v5/types" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" ) @@ -55,7 +55,7 @@ func (d *dockerSource) GetBlobData(digest digest.Digest) (int64, blobaccess.Data if err != nil { return -1, nil, err } - return info.Size, blobaccess.DataAccessForBytes(data), nil + return info.Size, blobaccess.DataAccessForData(data), nil } info.Digest = "" for _, l := range d.img.LayerInfos() { diff --git a/pkg/contexts/oci/repositories/docker/convert.go b/pkg/contexts/oci/repositories/docker/convert.go index 24d5acfb1f..54247e271d 100644 --- a/pkg/contexts/oci/repositories/docker/convert.go +++ b/pkg/contexts/oci/repositories/docker/convert.go @@ -12,7 +12,7 @@ import ( "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" ) @@ -39,7 +39,7 @@ func (f *fakeSource) GetManifest(ctx context.Context, instanceDigest *digest.Dig func (f *fakeSource) GetBlob(ctx context.Context, bi types.BlobInfo, bc types.BlobInfoCache) (io.ReadCloser, int64, error) { _, blob, err := f.blobs.GetBlobData(bi.Digest) if err != nil { - return nil, accessio.BLOB_UNKNOWN_SIZE, err + return nil, blobaccess.BLOB_UNKNOWN_SIZE, err } r, err := blob.Reader() @@ -87,7 +87,7 @@ func (a *artBlobCache) AddBlob(blob blobaccess.BlobAccess) (int64, digest.Digest } func (c *artBlobCache) AddData(data blobaccess.DataAccess) (int64, digest.Digest, error) { - return c.AddBlob(blobaccess.ForDataAccess(accessio.BLOB_UNKNOWN_DIGEST, accessio.BLOB_UNKNOWN_SIZE, "", data)) + return c.AddBlob(blobaccess.ForDataAccess(blobaccess.BLOB_UNKNOWN_DIGEST, blobaccess.BLOB_UNKNOWN_SIZE, "", data)) } //////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/contexts/oci/repositories/docker/namespace.go b/pkg/contexts/oci/repositories/docker/namespace.go index f5367f01ad..0f6739babc 100644 --- a/pkg/contexts/oci/repositories/docker/namespace.go +++ b/pkg/contexts/oci/repositories/docker/namespace.go @@ -12,7 +12,7 @@ import ( "github.com/mandelsoft/logging" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" diff --git a/pkg/contexts/oci/repositories/ocireg/blobs.go b/pkg/contexts/oci/repositories/ocireg/blobs.go index 40f773576c..9c503f1295 100644 --- a/pkg/contexts/oci/repositories/ocireg/blobs.go +++ b/pkg/contexts/oci/repositories/ocireg/blobs.go @@ -8,6 +8,7 @@ import ( "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/attrs/cacheattr" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" @@ -96,13 +97,13 @@ func NewBlobContainer(cache accessio.BlobCache, mime string, fetcher resolve.Fet func (n *blobContainer) GetBlobData(digest digest.Digest) (int64, cpi.DataAccess, error) { logrus.Debugf("orig get %s %s\n", n.mime, digest) acc, err := NewDataAccess(n.fetcher, digest, n.mime, false) - return accessio.BLOB_UNKNOWN_SIZE, acc, err + return blobaccess.BLOB_UNKNOWN_SIZE, acc, err } func (n *blobContainer) AddBlob(blob cpi.BlobAccess) (int64, digest.Digest, error) { err := push(dummyContext, n.pusher, blob) if err != nil { - return accessio.BLOB_UNKNOWN_SIZE, accessio.BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } return blob.Size(), blob.Digest(), err } diff --git a/pkg/contexts/oci/repositories/ocireg/namespace.go b/pkg/contexts/oci/repositories/ocireg/namespace.go index cab9245d2f..80e5b194af 100644 --- a/pkg/contexts/oci/repositories/ocireg/namespace.go +++ b/pkg/contexts/oci/repositories/ocireg/namespace.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/actions/oci-repository-prepare" diff --git a/pkg/contexts/oci/repositories/ocireg/utils.go b/pkg/contexts/oci/repositories/ocireg/utils.go index e11b2806d0..6eec2288bc 100644 --- a/pkg/contexts/oci/repositories/ocireg/utils.go +++ b/pkg/contexts/oci/repositories/ocireg/utils.go @@ -12,7 +12,7 @@ import ( "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" @@ -38,7 +38,7 @@ func NewDataAccess(fetcher remotes.Fetcher, digest digest.Digest, mimeType strin desc := artdesc.Descriptor{ MediaType: mimeType, Digest: digest, - Size: accessio.BLOB_UNKNOWN_SIZE, + Size: blobaccess.BLOB_UNKNOWN_SIZE, } if !delayed { reader, err = fetcher.Fetch(dummyContext, desc) diff --git a/pkg/contexts/oci/types/interface.go b/pkg/contexts/oci/types/interface.go new file mode 100644 index 0000000000..8df345f0d8 --- /dev/null +++ b/pkg/contexts/oci/types/interface.go @@ -0,0 +1,87 @@ +package cpi + +// This is the Context Provider Interface for credential providers + +import ( + "github.com/opencontainers/go-digest" + ociv1 "github.com/opencontainers/image-spec/specs-go/v1" + + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/contexts/datacontext" + "github.com/open-component-model/ocm/pkg/contexts/oci/internal" +) + +const CONTEXT_TYPE = internal.CONTEXT_TYPE + +const CommonTransportFormat = internal.CommonTransportFormat + +type ( + Context = internal.Context + ContextProvider = internal.ContextProvider + Repository = internal.Repository + RepositorySpecHandlers = internal.RepositorySpecHandlers + RepositorySpecHandler = internal.RepositorySpecHandler + UniformRepositorySpec = internal.UniformRepositorySpec + RepositoryType = internal.RepositoryType + RepositoryTypeProvider = internal.RepositoryTypeProvider + RepositoryTypeScheme = internal.RepositoryTypeScheme + RepositorySpec = internal.RepositorySpec + IntermediateRepositorySpecAspect = internal.IntermediateRepositorySpecAspect + GenericRepositorySpec = internal.GenericRepositorySpec + ArtifactAccess = internal.ArtifactAccess + Artifact = internal.Artifact + ArtifactSource = internal.ArtifactSource + ArtifactSink = internal.ArtifactSink + BlobSource = internal.BlobSource + BlobSink = internal.BlobSink + NamespaceLister = internal.NamespaceLister + NamespaceAccess = internal.NamespaceAccess + ManifestAccess = internal.ManifestAccess + IndexAccess = internal.IndexAccess + RepositorySource = internal.RepositorySource + ConsumerIdentityProvider = internal.ConsumerIdentityProvider +) + +type Descriptor = ociv1.Descriptor + +func DefaultContext() Context { + return internal.DefaultContext +} + +func New(m ...datacontext.BuilderMode) Context { + return internal.Builder{}.New(m...) +} + +func FromProvider(p ContextProvider) Context { + return internal.FromProvider(p) +} + +func RegisterRepositorySpecHandler(handler RepositorySpecHandler, types ...string) { + internal.RegisterRepositorySpecHandler(handler, types...) +} + +func ToGenericRepositorySpec(spec RepositorySpec) (*GenericRepositorySpec, error) { + return internal.ToGenericRepositorySpec(spec) +} + +func UniformRepositorySpecForHostURL(typ string, host string) *UniformRepositorySpec { + return internal.UniformRepositorySpecForHostURL(typ, host) +} + +const ( + KIND_OCIARTIFACT = internal.KIND_OCIARTIFACT + KIND_MEDIATYPE = blobaccess.KIND_MEDIATYPE + KIND_BLOB = blobaccess.KIND_BLOB +) + +func ErrUnknownArtifact(name, version string) error { + return internal.ErrUnknownArtifact(name, version) +} + +func ErrBlobNotFound(digest digest.Digest) error { + return blobaccess.ErrBlobNotFound(digest) +} + +func IsErrBlobNotFound(err error) bool { + return blobaccess.IsErrBlobNotFound(err) +} diff --git a/pkg/contexts/ocm/accessmethods/compose/method.go b/pkg/contexts/ocm/accessmethods/compose/method.go index 3811654745..6301043f7d 100644 --- a/pkg/contexts/ocm/accessmethods/compose/method.go +++ b/pkg/contexts/ocm/accessmethods/compose/method.go @@ -5,7 +5,7 @@ import ( "io" "sync/atomic" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" "github.com/open-component-model/ocm/pkg/runtime" ) diff --git a/pkg/contexts/ocm/accessmethods/github/method.go b/pkg/contexts/ocm/accessmethods/github/method.go index 08fc0cbc6e..d682437afd 100644 --- a/pkg/contexts/ocm/accessmethods/github/method.go +++ b/pkg/contexts/ocm/accessmethods/github/method.go @@ -14,7 +14,7 @@ import ( "github.com/mandelsoft/goutils/errors" "golang.org/x/oauth2" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessio/downloader" hd "github.com/open-component-model/ocm/pkg/common/accessio/downloader/http" diff --git a/pkg/contexts/ocm/accessmethods/helm/method.go b/pkg/contexts/ocm/accessmethods/helm/method.go index a1cc57e7ac..afa28f74fb 100644 --- a/pkg/contexts/ocm/accessmethods/helm/method.go +++ b/pkg/contexts/ocm/accessmethods/helm/method.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/helm/identity" diff --git a/pkg/contexts/ocm/accessmethods/maven/method.go b/pkg/contexts/ocm/accessmethods/maven/method.go index 71514c2b71..1eb4b56cb6 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method.go +++ b/pkg/contexts/ocm/accessmethods/maven/method.go @@ -5,7 +5,7 @@ import ( "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" @@ -108,7 +108,7 @@ func (a *AccessSpec) AccessMethod(cv accspeccpi.ComponentVersionAccess) (accspec } factory := func() (blobaccess.BlobAccess, error) { - return mavenblob.BlobAccessForMavenCoords(repo, &a.Coordinates, + return mavenblob.BlobAccessForCoords(repo, &a.Coordinates, mavenblob.WithCredentialContext(octx), mavenblob.WithLoggingContext(octx), mavenblob.WithCachingFileSystem(vfsattr.Get(octx))) diff --git a/pkg/contexts/ocm/accessmethods/npm/method.go b/pkg/contexts/ocm/accessmethods/npm/method.go index 7d70ecb217..fde12de9d8 100644 --- a/pkg/contexts/ocm/accessmethods/npm/method.go +++ b/pkg/contexts/ocm/accessmethods/npm/method.go @@ -14,7 +14,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/credentials/cpi" diff --git a/pkg/contexts/ocm/accessmethods/ociartifact/method.go b/pkg/contexts/ocm/accessmethods/ociartifact/method.go index 16e6c90991..fcd113c9bc 100644 --- a/pkg/contexts/ocm/accessmethods/ociartifact/method.go +++ b/pkg/contexts/ocm/accessmethods/ociartifact/method.go @@ -12,7 +12,7 @@ import ( "github.com/mandelsoft/goutils/general" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/credentials" ociidentity "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/oci/identity" "github.com/open-component-model/ocm/pkg/contexts/oci" diff --git a/pkg/contexts/ocm/accessmethods/ociartifact/method_test.go b/pkg/contexts/ocm/accessmethods/ociartifact/method_test.go index e1a97ccd5a..fce7b5a706 100644 --- a/pkg/contexts/ocm/accessmethods/ociartifact/method_test.go +++ b/pkg/contexts/ocm/accessmethods/ociartifact/method_test.go @@ -3,10 +3,10 @@ package ociartifact_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/oci/testhelper" . "github.com/open-component-model/ocm/pkg/env/builder" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/oci" diff --git a/pkg/contexts/ocm/accessmethods/ociblob/method.go b/pkg/contexts/ocm/accessmethods/ociblob/method.go index 81fa19c623..9b68fb8caf 100644 --- a/pkg/contexts/ocm/accessmethods/ociblob/method.go +++ b/pkg/contexts/ocm/accessmethods/ociblob/method.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/credentials" ociidentity "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/oci/identity" "github.com/open-component-model/ocm/pkg/contexts/oci" diff --git a/pkg/contexts/ocm/accessmethods/plugin/method.go b/pkg/contexts/ocm/accessmethods/plugin/method.go index 0958040bc2..876743b29e 100644 --- a/pkg/contexts/ocm/accessmethods/plugin/method.go +++ b/pkg/contexts/ocm/accessmethods/plugin/method.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/credentials/identity/hostpath" diff --git a/pkg/contexts/ocm/accessmethods/relativeociref/method_test.go b/pkg/contexts/ocm/accessmethods/relativeociref/method_test.go index 8937b86526..8c54dfdb8c 100644 --- a/pkg/contexts/ocm/accessmethods/relativeociref/method_test.go +++ b/pkg/contexts/ocm/accessmethods/relativeociref/method_test.go @@ -4,12 +4,12 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/oci/testhelper" . "github.com/open-component-model/ocm/pkg/env/builder" "github.com/mandelsoft/goutils/finalizer" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/relativeociref" diff --git a/pkg/contexts/ocm/accessmethods/s3/method.go b/pkg/contexts/ocm/accessmethods/s3/method.go index 91cb1db275..706679e6fd 100644 --- a/pkg/contexts/ocm/accessmethods/s3/method.go +++ b/pkg/contexts/ocm/accessmethods/s3/method.go @@ -5,7 +5,7 @@ import ( . "github.com/mandelsoft/goutils/exception" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessio/downloader" "github.com/open-component-model/ocm/pkg/common/accessio/downloader/s3" diff --git a/pkg/contexts/ocm/accessmethods/wget/method.go b/pkg/contexts/ocm/accessmethods/wget/method.go index 168c1baace..595324dc2e 100644 --- a/pkg/contexts/ocm/accessmethods/wget/method.go +++ b/pkg/contexts/ocm/accessmethods/wget/method.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/wget" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/wget/identity" @@ -146,7 +146,7 @@ func (m *accessMethod) getBlob() (blobaccess.BlobAccess, error) { return m.blob, nil } - blob, err := wget.BlobAccessForWget(m.spec.URL, + blob, err := wget.BlobAccess(m.spec.URL, wget.WithMimeType(m.spec.MediaType), wget.WithCredentialContext(m.comp.GetContext()), wget.WithLoggingContext(m.comp.GetContext()), diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go index 5c6a8fd2d7..36990c2dc2 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go @@ -2,7 +2,6 @@ package maven_test import ( "encoding/json" - "github.com/open-component-model/ocm/pkg/maven/maventest" "os" . "github.com/mandelsoft/goutils/testutils" @@ -19,6 +18,7 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/composition" "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/maven/maventest" ) const MAVEN_PATH = "/testdata/.m2/repository" @@ -64,7 +64,7 @@ var _ = Describe("blobhandler generic maven tests", func() { It("Upload artifact to file system", func() { env.OCMContext().BlobHandlers().Register(me.NewArtifactHandler(me.NewFileConfig("target", env.FileSystem()))) coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - bacc := Must(mavenblob.BlobAccessForMavenCoords(repo, coords, mavenblob.WithCachingFileSystem(env.FileSystem()))) + bacc := Must(mavenblob.BlobAccessForCoords(repo, coords, mavenblob.WithCachingFileSystem(env.FileSystem()))) defer Close(bacc) ocmrepo := composition.NewRepository(env) defer Close(ocmrepo) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/blobhandler.go index 56555c5f5b..d4ba687bef 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/blobhandler.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/sliceutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/contexts/ocm/blobhandler/handlers/oci/ocirepo/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/oci/ocirepo/blobhandler.go index f9da21dd45..3f81c334dd 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/oci/ocirepo/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/oci/ocirepo/blobhandler.go @@ -11,7 +11,7 @@ import ( "github.com/mandelsoft/goutils/sliceutils" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/contexts/ocm/blobhandler/handlers/ocm/ctx.go b/pkg/contexts/ocm/blobhandler/handlers/ocm/ctx.go index b51d3eb63a..8bad848bfc 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/ocm/ctx.go +++ b/pkg/contexts/ocm/blobhandler/handlers/ocm/ctx.go @@ -1,7 +1,7 @@ package ocm import ( - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/utils" ) diff --git a/pkg/contexts/ocm/consts/extra_identities.go b/pkg/contexts/ocm/consts/deprecated.go similarity index 100% rename from pkg/contexts/ocm/consts/extra_identities.go rename to pkg/contexts/ocm/consts/deprecated.go diff --git a/pkg/contexts/ocm/cpi/accspeccpi/method.go b/pkg/contexts/ocm/cpi/accspeccpi/method.go index ed4de33991..2063b41468 100644 --- a/pkg/contexts/ocm/cpi/accspeccpi/method.go +++ b/pkg/contexts/ocm/cpi/accspeccpi/method.go @@ -6,7 +6,7 @@ import ( "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/utils" ) diff --git a/pkg/contexts/ocm/cpi/accspeccpi/methodview.go b/pkg/contexts/ocm/cpi/accspeccpi/methodview.go index 27d5ce9488..61e93bc8b4 100644 --- a/pkg/contexts/ocm/cpi/accspeccpi/methodview.go +++ b/pkg/contexts/ocm/cpi/accspeccpi/methodview.go @@ -6,7 +6,7 @@ import ( "github.com/modern-go/reflect2" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/refmgmt" "github.com/open-component-model/ocm/pkg/utils" diff --git a/pkg/contexts/ocm/cpi/compose_test.go b/pkg/contexts/ocm/cpi/compose_test.go index 6a10f7b51a..c8d5c371f6 100644 --- a/pkg/contexts/ocm/cpi/compose_test.go +++ b/pkg/contexts/ocm/cpi/compose_test.go @@ -5,12 +5,12 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/ocm/testhelper" "github.com/mandelsoft/vfs/pkg/memoryfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/datacontext" diff --git a/pkg/contexts/ocm/cpi/repocpi/blobcache.go b/pkg/contexts/ocm/cpi/repocpi/blobcache.go index 63bc8b9513..83edc2876f 100644 --- a/pkg/contexts/ocm/cpi/repocpi/blobcache.go +++ b/pkg/contexts/ocm/cpi/repocpi/blobcache.go @@ -5,7 +5,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" ) type ( diff --git a/pkg/contexts/ocm/cpi/repocpi/bridge_c.go b/pkg/contexts/ocm/cpi/repocpi/bridge_c.go index c4734c439c..eeac749dc4 100644 --- a/pkg/contexts/ocm/cpi/repocpi/bridge_c.go +++ b/pkg/contexts/ocm/cpi/repocpi/bridge_c.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/attrs/compositionmodeattr" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" diff --git a/pkg/contexts/ocm/cpi/repocpi/bridge_cv.go b/pkg/contexts/ocm/cpi/repocpi/bridge_cv.go index 4de83f7d4c..edc79f6c86 100644 --- a/pkg/contexts/ocm/cpi/repocpi/bridge_cv.go +++ b/pkg/contexts/ocm/cpi/repocpi/bridge_cv.go @@ -10,7 +10,7 @@ import ( "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/compose" diff --git a/pkg/contexts/ocm/cpi/repocpi/view_cv.go b/pkg/contexts/ocm/cpi/repocpi/view_cv.go index 7b5aa395c7..6d2b45e329 100644 --- a/pkg/contexts/ocm/cpi/repocpi/view_cv.go +++ b/pkg/contexts/ocm/cpi/repocpi/view_cv.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/compose" diff --git a/pkg/contexts/ocm/cpi/utils.go b/pkg/contexts/ocm/cpi/utils.go index 62a71fcfdc..4ce7faef19 100644 --- a/pkg/contexts/ocm/cpi/utils.go +++ b/pkg/contexts/ocm/cpi/utils.go @@ -3,7 +3,7 @@ package cpi import ( "io" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/internal" "github.com/open-component-model/ocm/pkg/iotools" ) diff --git a/pkg/contexts/ocm/cpi/view_rsc.go b/pkg/contexts/ocm/cpi/view_rsc.go index c4e83044a4..6baca3c0aa 100644 --- a/pkg/contexts/ocm/cpi/view_rsc.go +++ b/pkg/contexts/ocm/cpi/view_rsc.go @@ -5,7 +5,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" ocm "github.com/open-component-model/ocm/pkg/contexts/ocm/context" diff --git a/pkg/contexts/ocm/digester/digesters/artifact/digester.go b/pkg/contexts/ocm/digester/digesters/artifact/digester.go index 40c67dc4d8..0fcc3508ab 100644 --- a/pkg/contexts/ocm/digester/digesters/artifact/digester.go +++ b/pkg/contexts/ocm/digester/digesters/artifact/digester.go @@ -9,7 +9,7 @@ import ( "github.com/mandelsoft/goutils/general" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/compression" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/artifactset" diff --git a/pkg/contexts/ocm/download/handlers/blueprint/extractor.go b/pkg/contexts/ocm/download/handlers/blueprint/extractor.go index f31a355469..9a90af8b7b 100644 --- a/pkg/contexts/ocm/download/handlers/blueprint/extractor.go +++ b/pkg/contexts/ocm/download/handlers/blueprint/extractor.go @@ -5,7 +5,7 @@ import ( "github.com/mandelsoft/vfs/pkg/projectionfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" diff --git a/pkg/contexts/ocm/download/handlers/blueprint/handler.go b/pkg/contexts/ocm/download/handlers/blueprint/handler.go index afe36ffe04..6dc13f7875 100644 --- a/pkg/contexts/ocm/download/handlers/blueprint/handler.go +++ b/pkg/contexts/ocm/download/handlers/blueprint/handler.go @@ -5,7 +5,7 @@ import ( "github.com/mandelsoft/goutils/set" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" diff --git a/pkg/contexts/ocm/download/handlers/helm/handler.go b/pkg/contexts/ocm/download/handlers/helm/handler.go index cc6a83ca50..b17aba902f 100644 --- a/pkg/contexts/ocm/download/handlers/helm/handler.go +++ b/pkg/contexts/ocm/download/handlers/helm/handler.go @@ -9,7 +9,7 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" helmregistry "helm.sh/helm/v3/pkg/registry" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" diff --git a/pkg/contexts/ocm/elements/artifactblob/datablob/resource.go b/pkg/contexts/ocm/elements/artifactblob/datablob/resource.go index 4b0e64b2f3..120ab34ada 100644 --- a/pkg/contexts/ocm/elements/artifactblob/datablob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/datablob/resource.go @@ -4,7 +4,7 @@ import ( "github.com/mandelsoft/goutils/generics" "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" diff --git a/pkg/contexts/ocm/elements/artifactblob/dirtreeblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/dirtreeblob/resource.go index 62304ff052..a377a7a613 100644 --- a/pkg/contexts/ocm/elements/artifactblob/dirtreeblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/dirtreeblob/resource.go @@ -18,7 +18,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, p if meta.GetType() == "" { meta.SetType(TYPE) } - blobprov := dirtree.BlobAccessProviderForDirTree(path, &eff.Blob) + blobprov := dirtree.Provider(path, &eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, eff.Hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/elements/artifactblob/dockerdaemonblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/dockerdaemonblob/resource.go index f18ae7c4b2..7ee1ae185d 100644 --- a/pkg/contexts/ocm/elements/artifactblob/dockerdaemonblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/dockerdaemonblob/resource.go @@ -25,7 +25,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, n version = eff.Blob.Version } hint := ociartifact.Hint(optionutils.AsValue(eff.Blob.Origin), locator, eff.Hint, version) - blobprov := dockerdaemon.BlobAccessProviderForImageFromDockerDaemon(name, &eff.Blob) + blobprov := dockerdaemon.Provider(name, &eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/elements/artifactblob/dockermultiblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/dockermultiblob/resource.go index b8c2b5726b..32993f9eae 100644 --- a/pkg/contexts/ocm/elements/artifactblob/dockermultiblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/dockermultiblob/resource.go @@ -20,7 +20,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, o } eff.Blob.Context = ctx.OCIContext() - blobprov := dockermulti.BlobAccessProviderForMultiImageFromDockerDaemon(&eff.Blob) + blobprov := dockermulti.Provider(&eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, eff.Hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/elements/artifactblob/fileblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/fileblob/resource.go index 7c779e1578..6415b69198 100644 --- a/pkg/contexts/ocm/elements/artifactblob/fileblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/fileblob/resource.go @@ -4,7 +4,8 @@ import ( "github.com/mandelsoft/goutils/generics" "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" @@ -26,14 +27,14 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, media str var blobprov blobaccess.BlobAccessProvider switch eff.Compression { case NONE: - blobprov = blobaccess.ProviderForFile(media, path, eff.FileSystem) + blobprov = file.Provider(media, path, eff.FileSystem) case COMPRESSION: - blob := blobaccess.ForFile(media, path, eff.FileSystem) + blob := file.BlobAccess(media, path, eff.FileSystem) defer blob.Close() blob, _ = blobaccess.WithCompression(blob) blobprov = blobaccess.ProviderForBlobAccess(blob) case DECOMPRESSION: - blob := blobaccess.ForFile(media, path, eff.FileSystem) + blob := file.BlobAccess(media, path, eff.FileSystem) defer blob.Close() blob, _ = blobaccess.WithDecompression(blob) blobprov = blobaccess.ProviderForBlobAccess(blob) diff --git a/pkg/contexts/ocm/elements/artifactblob/genericblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/genericblob/resource.go index 8c6f8fbcde..6e511ae64b 100644 --- a/pkg/contexts/ocm/elements/artifactblob/genericblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/genericblob/resource.go @@ -4,7 +4,7 @@ import ( "github.com/mandelsoft/goutils/generics" "github.com/mandelsoft/goutils/optionutils" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" ) diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/helmblob/resource.go index 22b0be16d5..88d48b2a58 100644 --- a/pkg/contexts/ocm/elements/artifactblob/helmblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/resource.go @@ -19,7 +19,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, p meta.SetType(TYPE) } hint := eff.Hint - blobprov := helm.BlobAccessProviderForHelmChart(path, &eff.Blob) + blobprov := helm.Provider(path, &eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go index 9a6e736e6f..63aa8c70f8 100644 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go @@ -23,7 +23,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, r meta.SetType(TYPE) } - blobprov := maven.BlobAccessProviderForMaven(repo, groupId, artifactId, version, &eff.Blob) + blobprov := maven.Provider(repo, groupId, artifactId, version, &eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, eff.Hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/elements/artifactblob/ociartifactblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/ociartifactblob/resource.go index 3cb30ee21e..d93d016f72 100644 --- a/pkg/contexts/ocm/elements/artifactblob/ociartifactblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/ociartifactblob/resource.go @@ -28,7 +28,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, r } } - blobprov := blob.BlobAccessProviderForOCIArtifact(refname, &eff.Blob) + blobprov := blob.Provider(refname, &eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go index ef9273b23a..535fb8e93c 100644 --- a/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go @@ -20,7 +20,7 @@ func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, u meta.SetType(TYPE) } - blobprov := wget.BlobAccessProviderForWget(url, &eff.Blob) + blobprov := wget.Provider(url, &eff.Blob) accprov := cpi.NewAccessProviderForBlobAccessProvider(ctx, blobprov, eff.Hint, eff.Global) // strange type cast is required by Go compiler, meta has the correct type. return cpi.NewArtifactAccessForProvider(generics.Cast[*M](meta), accprov) diff --git a/pkg/contexts/ocm/interface.go b/pkg/contexts/ocm/interface.go index e9f32736bc..5ea237b644 100644 --- a/pkg/contexts/ocm/interface.go +++ b/pkg/contexts/ocm/interface.go @@ -3,7 +3,7 @@ package ocm import ( "context" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" diff --git a/pkg/contexts/ocm/internal/repository.go b/pkg/contexts/ocm/internal/repository.go index 9fa462dcea..b8cda58fbc 100644 --- a/pkg/contexts/ocm/internal/repository.go +++ b/pkg/contexts/ocm/internal/repository.go @@ -3,7 +3,7 @@ package internal import ( "io" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" diff --git a/pkg/contexts/ocm/plugin/utils.go b/pkg/contexts/ocm/plugin/utils.go index 4573a2ad80..c890613275 100644 --- a/pkg/contexts/ocm/plugin/utils.go +++ b/pkg/contexts/ocm/plugin/utils.go @@ -5,6 +5,7 @@ import ( "github.com/opencontainers/go-digest" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/iotools" ) @@ -23,7 +24,7 @@ func (d *AccessDataWriter) WriteTo(w accessio.Writer) (int64, digest.Digest, err dw := iotools.NewDefaultDigestWriter(accessio.NopWriteCloser(w)) err := d.plugin.Get(dw, d.creds, d.accspec) if err != nil { - return accessio.BLOB_UNKNOWN_SIZE, accessio.BLOB_UNKNOWN_DIGEST, err + return blobaccess.BLOB_UNKNOWN_SIZE, blobaccess.BLOB_UNKNOWN_DIGEST, err } return dw.Size(), dw.Digest(), nil } diff --git a/pkg/contexts/ocm/repositories/comparch/accessmethod_localfs.go b/pkg/contexts/ocm/repositories/comparch/accessmethod_localfs.go index 57eca72ee0..2ec284ca06 100644 --- a/pkg/contexts/ocm/repositories/comparch/accessmethod_localfs.go +++ b/pkg/contexts/ocm/repositories/comparch/accessmethod_localfs.go @@ -4,7 +4,7 @@ import ( "io" "sync" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" diff --git a/pkg/contexts/ocm/repositories/comparch/comparch_test.go b/pkg/contexts/ocm/repositories/comparch/comparch_test.go index 58852f4b6c..e8e73b293f 100644 --- a/pkg/contexts/ocm/repositories/comparch/comparch_test.go +++ b/pkg/contexts/ocm/repositories/comparch/comparch_test.go @@ -6,6 +6,7 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/ocm/testhelper" "github.com/mandelsoft/filepath/pkg/filepath" @@ -14,7 +15,6 @@ import ( "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/ocm" diff --git a/pkg/contexts/ocm/repositories/comparch/componentarchive.go b/pkg/contexts/ocm/repositories/comparch/componentarchive.go index e3c48085e4..3cc2a90b88 100644 --- a/pkg/contexts/ocm/repositories/comparch/componentarchive.go +++ b/pkg/contexts/ocm/repositories/comparch/componentarchive.go @@ -4,7 +4,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessobj" ocicpi "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" diff --git a/pkg/contexts/ocm/repositories/comparch/repository.go b/pkg/contexts/ocm/repositories/comparch/repository.go index 1433505a9b..64a8365833 100644 --- a/pkg/contexts/ocm/repositories/comparch/repository.go +++ b/pkg/contexts/ocm/repositories/comparch/repository.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/datacontext" diff --git a/pkg/contexts/ocm/repositories/composition/repository.go b/pkg/contexts/ocm/repositories/composition/repository.go index 64c3aaf293..fa1aa08c15 100644 --- a/pkg/contexts/ocm/repositories/composition/repository.go +++ b/pkg/contexts/ocm/repositories/composition/repository.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/general" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/datacontext" diff --git a/pkg/contexts/ocm/repositories/composition/repository_test.go b/pkg/contexts/ocm/repositories/composition/repository_test.go index 88b4cdcf60..f5bc0d7c71 100644 --- a/pkg/contexts/ocm/repositories/composition/repository_test.go +++ b/pkg/contexts/ocm/repositories/composition/repository_test.go @@ -8,7 +8,7 @@ import ( "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/vfs/pkg/memoryfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" diff --git a/pkg/contexts/ocm/repositories/ctf/repo_test.go b/pkg/contexts/ocm/repositories/ctf/repo_test.go index db72130f6c..113cf8b880 100644 --- a/pkg/contexts/ocm/repositories/ctf/repo_test.go +++ b/pkg/contexts/ocm/repositories/ctf/repo_test.go @@ -7,6 +7,7 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/ocm/testhelper" "github.com/mandelsoft/logging" @@ -14,7 +15,6 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/tonglil/buflogr" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/ocm" diff --git a/pkg/contexts/ocm/repositories/genericocireg/accessmethod_localblob.go b/pkg/contexts/ocm/repositories/genericocireg/accessmethod_localblob.go index 3bf2dd6202..bd3a94b1f0 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/accessmethod_localblob.go +++ b/pkg/contexts/ocm/repositories/genericocireg/accessmethod_localblob.go @@ -7,7 +7,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/opencontainers/go-digest" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" diff --git a/pkg/contexts/ocm/repositories/genericocireg/info.go b/pkg/contexts/ocm/repositories/genericocireg/info.go index b642014705..d36361d914 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/info.go +++ b/pkg/contexts/ocm/repositories/genericocireg/info.go @@ -3,7 +3,7 @@ package genericocireg import ( "encoding/json" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/oci/cpi" "github.com/open-component-model/ocm/pkg/contexts/oci/ociutils" diff --git a/pkg/contexts/ocm/repositories/genericocireg/state.go b/pkg/contexts/ocm/repositories/genericocireg/state.go index eabc479bdc..39d4f20ab5 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/state.go +++ b/pkg/contexts/ocm/repositories/genericocireg/state.go @@ -15,7 +15,7 @@ import ( "github.com/opencontainers/go-digest" ociv1 "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessobj" "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/contexts/ocm/repositories/virtual/accessmethod_localblob.go b/pkg/contexts/ocm/repositories/virtual/accessmethod_localblob.go index 0ed379c0c1..f7fd081b1f 100644 --- a/pkg/contexts/ocm/repositories/virtual/accessmethod_localblob.go +++ b/pkg/contexts/ocm/repositories/virtual/accessmethod_localblob.go @@ -6,7 +6,7 @@ import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" ) diff --git a/pkg/contexts/ocm/repositories/virtual/example/example.go b/pkg/contexts/ocm/repositories/virtual/example/example.go index 11262932e0..bcf3d60bb8 100644 --- a/pkg/contexts/ocm/repositories/virtual/example/example.go +++ b/pkg/contexts/ocm/repositories/virtual/example/example.go @@ -13,7 +13,8 @@ import ( "github.com/mandelsoft/vfs/pkg/projectionfs" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" @@ -167,7 +168,7 @@ func (v *VersionAccess) GetBlob(name string) (cpi.DataAccess, error) { if ok, err := vfs.FileExists(v.access.fs, p); !ok || err != nil { return nil, vfs.ErrNotExist } - return blobaccess.DataAccessForFile(v.access.fs, p), nil + return file.DataAccess(v.access.fs, p), nil } func (v *VersionAccess) AddBlob(blob cpi.BlobAccess) (string, error) { diff --git a/pkg/contexts/ocm/repositories/virtual/repo_test.go b/pkg/contexts/ocm/repositories/virtual/repo_test.go index f2bf3db768..2ed51f6fe3 100644 --- a/pkg/contexts/ocm/repositories/virtual/repo_test.go +++ b/pkg/contexts/ocm/repositories/virtual/repo_test.go @@ -4,6 +4,7 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess" . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" @@ -12,7 +13,6 @@ import ( "github.com/mandelsoft/vfs/pkg/memoryfs" "github.com/mandelsoft/vfs/pkg/projectionfs" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/compose" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" diff --git a/pkg/contexts/ocm/signing/deprecated.go b/pkg/contexts/ocm/signing/deprecated.go new file mode 100644 index 0000000000..b2b4a55d0b --- /dev/null +++ b/pkg/contexts/ocm/signing/deprecated.go @@ -0,0 +1,8 @@ +package signing + +// SignerByName set a signer by algorithm name. +// +// Deprecated: use SignerByAlgo. +func SignerByName(algo string) Option { + return SignerByAlgo(algo) +} diff --git a/pkg/contexts/ocm/signing/options.go b/pkg/contexts/ocm/signing/options.go index 0384d9afa9..3dce220449 100644 --- a/pkg/contexts/ocm/signing/options.go +++ b/pkg/contexts/ocm/signing/options.go @@ -145,13 +145,6 @@ func SignerByAlgo(algo string) Option { return &signer{algo, nil, ""} } -// SignerByName set a signer by algorithm name. -// -// Deprecated: use SignerByAlgo. -func SignerByName(algo string) Option { - return SignerByAlgo(algo) -} - func (o *signer) ApplySigningOption(opts *Options) { n := strings.TrimSpace(o.name) if n != "" { diff --git a/pkg/contexts/ocm/transfer/transferhandler/standard/handler_test.go b/pkg/contexts/ocm/transfer/transferhandler/standard/handler_test.go index fa2cb4731a..52c7bb1937 100644 --- a/pkg/contexts/ocm/transfer/transferhandler/standard/handler_test.go +++ b/pkg/contexts/ocm/transfer/transferhandler/standard/handler_test.go @@ -7,13 +7,13 @@ import ( . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/blobaccess" . "github.com/open-component-model/ocm/pkg/contexts/oci/testhelper" . "github.com/open-component-model/ocm/pkg/contexts/ocm/testhelper" . "github.com/open-component-model/ocm/pkg/env/builder" "github.com/mandelsoft/goutils/finalizer" - "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/common/accessobj" diff --git a/pkg/contexts/ocm/utils/resource.go b/pkg/contexts/ocm/utils/resource.go index 3fbb771d46..f7e6ccf2ce 100644 --- a/pkg/contexts/ocm/utils/resource.go +++ b/pkg/contexts/ocm/utils/resource.go @@ -3,7 +3,7 @@ package utils import ( "io" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm" metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" "github.com/open-component-model/ocm/pkg/iotools" diff --git a/pkg/env/builder/blob.go b/pkg/env/builder/blob.go index 17aa690e22..894e7c8a2a 100644 --- a/pkg/env/builder/blob.go +++ b/pkg/env/builder/blob.go @@ -39,6 +39,6 @@ func (b *Builder) BlobFromDirTree(path string, opts ...dirtree.Option) { b.fail("access already set") } var err error - *(b.blob), err = dirtree.BlobAccessForDirTree(path, append([]dirtree.Option{dirtree.WithFileSystem(b.FileSystem())}, opts...)...) + *(b.blob), err = dirtree.BlobAccess(path, append([]dirtree.Option{dirtree.WithFileSystem(b.FileSystem())}, opts...)...) b.failOn(err) } diff --git a/pkg/env/builder/builder.go b/pkg/env/builder/builder.go index 9e1a8d14fa..daa6e49239 100644 --- a/pkg/env/builder/builder.go +++ b/pkg/env/builder/builder.go @@ -6,7 +6,7 @@ import ( "github.com/modern-go/reflect2" "github.com/onsi/ginkgo/v2" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/oci" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" diff --git a/pkg/env/builder/oci_config.go b/pkg/env/builder/oci_config.go index 71c9cfd742..875787d28c 100644 --- a/pkg/env/builder/oci_config.go +++ b/pkg/env/builder/oci_config.go @@ -3,7 +3,7 @@ package builder import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" ) diff --git a/pkg/env/builder/oci_layer.go b/pkg/env/builder/oci_layer.go index 2fa1ebef81..694bd7247b 100644 --- a/pkg/env/builder/oci_layer.go +++ b/pkg/env/builder/oci_layer.go @@ -3,7 +3,7 @@ package builder import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" ) diff --git a/pkg/env/builder/ocm_resource.go b/pkg/env/builder/ocm_resource.go index 97807b86b6..44d352857e 100644 --- a/pkg/env/builder/ocm_resource.go +++ b/pkg/env/builder/ocm_resource.go @@ -3,7 +3,7 @@ package builder import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" diff --git a/pkg/env/builder/ocm_source.go b/pkg/env/builder/ocm_source.go index 62b3f8bb5d..d23f41f286 100644 --- a/pkg/env/builder/ocm_source.go +++ b/pkg/env/builder/ocm_source.go @@ -3,7 +3,7 @@ package builder import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" ) diff --git a/pkg/helm/chartaccess.go b/pkg/helm/chartaccess.go index ca62fa1068..60200d8f90 100644 --- a/pkg/helm/chartaccess.go +++ b/pkg/helm/chartaccess.go @@ -9,7 +9,8 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "helm.sh/helm/v3/pkg/registry" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/contexts/oci/artdesc" "github.com/open-component-model/ocm/pkg/refmgmt" "github.com/open-component-model/ocm/pkg/utils" @@ -29,7 +30,7 @@ type ChartAccess interface { func newFileAccess(c *chartAccess, path string, mime string) blobaccess.BlobAccess { c.refcnt++ - return blobaccess.ForFileWithCloser(refmgmt.CloserFunc(c.unref), mime, path, c.fs) + return file.BlobAccessWithCloser(refmgmt.CloserFunc(c.unref), mime, path, c.fs) } type chartAccess struct { diff --git a/pkg/helm/loader/access.go b/pkg/helm/loader/access.go index 28c96f6693..71d00b9b8b 100644 --- a/pkg/helm/loader/access.go +++ b/pkg/helm/loader/access.go @@ -4,7 +4,7 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/helm" ) diff --git a/pkg/helm/loader/loader.go b/pkg/helm/loader/loader.go index 8658e0ffb6..c6304e4ddb 100644 --- a/pkg/helm/loader/loader.go +++ b/pkg/helm/loader/loader.go @@ -6,7 +6,8 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/file" "github.com/open-component-model/ocm/pkg/helm" "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/utils" @@ -40,7 +41,7 @@ func (l *vfsLoader) ChartArchive() (blobaccess.BlobAccess, error) { if ok, err := vfs.IsFile(l.fs, l.path); !ok || err != nil { return nil, err } - return blobaccess.ForFile(helm.ChartMediaType, l.path, l.fs), nil + return file.BlobAccess(helm.ChartMediaType, l.path, l.fs), nil } func (l *vfsLoader) ChartArtefactSet() (blobaccess.BlobAccess, error) { diff --git a/pkg/iotools/deprecated.go b/pkg/iotools/deprecated.go new file mode 100644 index 0000000000..0983d96460 --- /dev/null +++ b/pkg/iotools/deprecated.go @@ -0,0 +1,12 @@ +package iotools + +import ( + "io" + + "github.com/mandelsoft/goutils/sliceutils" +) + +// Deprecated: use AddReaderCloser . +func AddCloser(reader io.ReadCloser, closer io.Closer, msg ...string) io.ReadCloser { + return AddReaderCloser(reader, closer, sliceutils.Convert[any](msg)...) +} diff --git a/pkg/iotools/readerwriter.go b/pkg/iotools/readerwriter.go index 893fb4e0e6..1718ae5722 100644 --- a/pkg/iotools/readerwriter.go +++ b/pkg/iotools/readerwriter.go @@ -5,7 +5,6 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/generics" - "github.com/mandelsoft/goutils/sliceutils" ) //////////////////////////////////////////////////////////////////////////////// @@ -52,11 +51,6 @@ type readCloser struct { var _ io.ReadCloser = (*readCloser)(nil) -// Deprecated: use AddReaderCloser . -func AddCloser(reader io.ReadCloser, closer io.Closer, msg ...string) io.ReadCloser { - return AddReaderCloser(reader, closer, sliceutils.Convert[any](msg)...) -} - func ReadCloser(r io.Reader) io.ReadCloser { return AddReaderCloser(r, nil) } diff --git a/pkg/signing/cert.go b/pkg/signing/cert.go index c85920b2b5..ae82b474db 100644 --- a/pkg/signing/cert.go +++ b/pkg/signing/cert.go @@ -3,7 +3,6 @@ package signing import ( "crypto/x509" "crypto/x509/pkix" - "time" "github.com/mandelsoft/goutils/errors" @@ -48,24 +47,3 @@ func VerifyCertDN(intermediate signutils.GenericCertificateChain, root signutils } return errors.ErrNotSupported("codesign", "", "certificate") } - -// Deprecated: use signutils.CreateCertificate. -func CreateCertificate(subject pkix.Name, validFrom *time.Time, - validity time.Duration, pub interface{}, - ca *x509.Certificate, priv interface{}, isCA bool, names ...string, -) ([]byte, error) { - spec := &signutils.Specification{ - RootCAs: ca, - IsCA: isCA, - PublicKey: pub, - CAPrivateKey: priv, - CAChain: ca, - Subject: subject, - Usages: signutils.Usages{x509.ExtKeyUsageCodeSigning}, - Validity: validity, - NotBefore: validFrom, - Hosts: names, - } - _, data, err := signutils.CreateCertificate(spec) - return data, err -} diff --git a/pkg/signing/deprecated.go b/pkg/signing/deprecated.go index 8bbe888156..5972ebb8ae 100644 --- a/pkg/signing/deprecated.go +++ b/pkg/signing/deprecated.go @@ -2,6 +2,8 @@ package signing import ( "crypto/x509" + "crypto/x509/pkix" + "time" parse "github.com/mandelsoft/spiff/dynaml/x509" @@ -28,3 +30,24 @@ func ParsePrivateKey(data []byte) (interface{}, error) { func BaseRootPool() (*x509.CertPool, error) { return signutils.SystemCertPool() } + +// Deprecated: use signutils.CreateCertificate. +func CreateCertificate(subject pkix.Name, validFrom *time.Time, + validity time.Duration, pub interface{}, + ca *x509.Certificate, priv interface{}, isCA bool, names ...string, +) ([]byte, error) { + spec := &signutils.Specification{ + RootCAs: ca, + IsCA: isCA, + PublicKey: pub, + CAPrivateKey: priv, + CAChain: ca, + Subject: subject, + Usages: signutils.Usages{x509.ExtKeyUsageCodeSigning}, + Validity: validity, + NotBefore: validFrom, + Hosts: names, + } + _, data, err := signutils.CreateCertificate(spec) + return data, err +} diff --git a/pkg/signing/signutils/certs_test.go b/pkg/signing/signutils/certs_test.go index 6802f7ee81..a6d831ba02 100644 --- a/pkg/signing/signutils/certs_test.go +++ b/pkg/signing/signutils/certs_test.go @@ -57,7 +57,7 @@ var _ = Describe("normalization", func() { Province: []string{"BW"}, }, interBytes, ca, interpriv, 1*time.Hour)) - acc := blobaccess.DataAccessForBytes(pemBytes) + acc := blobaccess.DataAccessForData(pemBytes) certs := Must(signutils.GetCertificateChain(acc, false)) Expect(len(certs)).To(Equal(3)) diff --git a/pkg/signing/signutils/utils.go b/pkg/signing/signutils/utils.go index 6f2f02a0e7..e3b2c8509e 100644 --- a/pkg/signing/signutils/utils.go +++ b/pkg/signing/signutils/utils.go @@ -19,7 +19,7 @@ import ( "github.com/modern-go/reflect2" "golang.org/x/exp/slices" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/utils" ) diff --git a/pkg/toi/drivers/docker/driver.go b/pkg/toi/drivers/docker/driver.go index d35d71f380..935f42560f 100644 --- a/pkg/toi/drivers/docker/driver.go +++ b/pkg/toi/drivers/docker/driver.go @@ -25,7 +25,7 @@ import ( "github.com/mandelsoft/goutils/set" "github.com/mitchellh/copystructure" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/toi" "github.com/open-component-model/ocm/pkg/toi/install" ) diff --git a/pkg/toi/install/execute.go b/pkg/toi/install/execute.go index 8fecf1bc9b..108ed0d003 100644 --- a/pkg/toi/install/execute.go +++ b/pkg/toi/install/execute.go @@ -3,7 +3,7 @@ package install import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/ocm" metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" diff --git a/pkg/toi/install/interface.go b/pkg/toi/install/interface.go index 53fce0dba3..24ebf9bf58 100644 --- a/pkg/toi/install/interface.go +++ b/pkg/toi/install/interface.go @@ -3,7 +3,7 @@ package install import ( "io" - "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/blobaccess" "github.com/open-component-model/ocm/pkg/toi" )