From 18fc03aea9a39b93974ab504c548aadc06e59e3e Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Wed, 22 May 2024 18:50:43 +0200 Subject: [PATCH 01/13] wip --- pkg/blobaccess/maven/access.go | 31 +++ pkg/blobaccess/maven/access_test.go | 68 ++++++ pkg/blobaccess/maven/options.go | 179 +++++++++++++++ pkg/blobaccess/maven/suite_test.go | 13 ++ .../fail/test/repository/42/repository-42.pom | 14 ++ .../test/repository/42/repository-42.pom.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.json | 1 + ...modules-bom-5.7.0-random-content.json.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.txt | 1 + ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 0 -> 595 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ++++++++++++++++++ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 + pkg/blobaccess/maven/utils.go | 146 ++++++++++++ pkg/blobaccess/standard.go | 17 ++ pkg/blobaccess/wget/options.go | 3 + pkg/common/accessobj/cachedblob.go | 6 +- .../{mvn => maven}/identity/identity.go | 0 .../datacontext/attrs/tmpcache/attr.go | 18 +- pkg/contexts/ocm/accessmethods/mvn/method.go | 17 +- .../ocm/accessmethods/wget/options.go | 15 -- .../handlers/generic/mvn/blobhandler.go | 7 +- pkg/maven/access.go | 182 +++++++++++++++ pkg/maven/access_test.go | 87 ++++++++ .../mvn => maven}/coordinates.go | 38 +++- .../mvn => maven}/coordinates_test.go | 18 +- pkg/maven/logging.go | 11 + pkg/maven/suite_test.go | 13 ++ .../fail/test/repository/42/repository-42.pom | 14 ++ .../test/repository/42/repository-42.pom.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ++++++++++++++++++ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 + pkg/maven/utils.go | 50 +++++ 34 files changed, 1331 insertions(+), 45 deletions(-) create mode 100644 pkg/blobaccess/maven/access.go create mode 100644 pkg/blobaccess/maven/access_test.go create mode 100644 pkg/blobaccess/maven/options.go create mode 100644 pkg/blobaccess/maven/suite_test.go create mode 100644 pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom create mode 100644 pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 create mode 100644 pkg/blobaccess/maven/utils.go rename pkg/contexts/credentials/builtin/{mvn => maven}/identity/identity.go (100%) create mode 100644 pkg/maven/access.go create mode 100644 pkg/maven/access_test.go rename pkg/{contexts/ocm/accessmethods/mvn => maven}/coordinates.go (82%) rename pkg/{contexts/ocm/accessmethods/mvn => maven}/coordinates_test.go (79%) create mode 100644 pkg/maven/logging.go create mode 100644 pkg/maven/suite_test.go create mode 100644 pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom create mode 100644 pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 create mode 100644 pkg/maven/utils.go diff --git a/pkg/blobaccess/maven/access.go b/pkg/blobaccess/maven/access.go new file mode 100644 index 0000000000..eaa5cb59df --- /dev/null +++ b/pkg/blobaccess/maven/access.go @@ -0,0 +1,31 @@ +package maven + +import ( + "github.com/open-component-model/ocm/pkg/blobaccess" + "github.com/open-component-model/ocm/pkg/blobaccess/bpi" + "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/optionutils" +) + +type BlobMeta = maven.FileMeta + +func DataAccessForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) (blobaccess.DataAccess, error) { + return BlobAccessForMaven(repoUrl, groupId, artifactId, version, opts...) +} + +func BlobAccessForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) (blobaccess.BlobAccess, error) { + eff := optionutils.EvalOptions(opts...) + s := &spec{ + coords: maven.NewCoordinates(groupId, artifactId, version, eff.Classifier, eff.Extension), + repoUrl: repoUrl, + options: eff, + } + return s.getBlobAccess() +} + +func BlobAccessProviderForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { + return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { + b, err := BlobAccessForMaven(repoUrl, groupId, artifactId, version, opts...) + return b, err + }) +} diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go new file mode 100644 index 0000000000..3e2e75ec66 --- /dev/null +++ b/pkg/blobaccess/maven/access_test.go @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + "github.com/open-component-model/ocm/pkg/maven" + . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/open-component-model/ocm/pkg/utils/tarutils" + + me "github.com/open-component-model/ocm/pkg/blobaccess/maven" +) + +const ( + mvnPATH = "/testdata/.m2/repository" + FAILPATH = "/testdata/.m2/fail" +) + +var _ = Describe("blobaccess for maven", func() { + var env *Builder + + BeforeEach(func() { + env = NewBuilder(TestData()) + }) + + AfterEach(func() { + MustBeSuccessful(env.Cleanup()) + }) + + It("blobaccess for artifact", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + + b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithFileSystem(env.FileSystem()))) + defer Close(b, "blobaccess") + files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) + Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0.pom", "sdk-modules-bom-5.7.0-random-content.txt", + "sdk-modules-bom-5.7.0-random-content.json")) + }) + + It("blobaccess for files with the same classifier", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + "random-content") + + b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithClassifier(coords.Classifier), + me.WithFileSystem(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", + "sdk-modules-bom-5.7.0-random-content.json")) + }) + It("blobaccess for a single file with classifier and extension", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + "random-content", "json") + + b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithClassifier(coords.Classifier), + me.WithExtension(coords.Extension), me.WithFileSystem(env.FileSystem()))) + defer Close(b, "blobaccess") + Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) + }) +}) diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go new file mode 100644 index 0000000000..714efb41f1 --- /dev/null +++ b/pkg/blobaccess/maven/options.go @@ -0,0 +1,179 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven + +import ( + "github.com/mandelsoft/logging" + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" + "github.com/open-component-model/ocm/pkg/contexts/datacontext" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/tmpcache" + ocmlog "github.com/open-component-model/ocm/pkg/logging" + "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/optionutils" +) + +type Option = optionutils.Option[*Options] + +type Options struct { + CredentialContext credentials.Context + LoggingContext logging.Context + CachingContext datacontext.Context + FileSystem vfs.FileSystem + CachingPath string + // Credentials allows to pass credentials and certificates for the http communication + Credentials credentials.Credentials + // Classifier defines the classifier of the maven file coordinates + Classifier string + // Extension defines the extension of the maven file coordinates + Extension string +} + +func (o *Options) Logger(keyValuePairs ...interface{}) logging.Logger { + return ocmlog.LogContext(o.LoggingContext, o.CredentialContext).Logger(maven.REALM).WithValues(keyValuePairs...) +} + +func (o *Options) Cache() *tmpcache.Attribute { + if o.CachingPath != "" { + return tmpcache.New(o.CachingPath, o.FileSystem) + } + return tmpcache.Get(o.CachingContext) +} + +func mapCredentials(creds credentials.Credentials) maven.Credentials { + if creds == nil || (!creds.ExistsProperty(identity.ATTR_USERNAME) && !creds.ExistsProperty(identity.ATTR_PASSWORD)) { + return nil + } + return &maven.BasicAuthCredentials{ + Username: creds.GetProperty(identity.ATTR_USERNAME), + Password: creds.GetProperty(identity.ATTR_PASSWORD), + } +} + +func (o *Options) GetCredentials(repoUrl, groupId string) (maven.Credentials, error) { + switch { + case o.Credentials != nil: + return mapCredentials(o.Credentials), nil + case o.CredentialContext != nil: + consumerid, err := identity.GetConsumerId(repoUrl, groupId) + if err != nil { + return nil, err + } + creds, err := credentials.CredentialsForConsumer(o.CredentialContext, consumerid, identity.IdentityMatcher) + if err != nil { + return nil, err + } + return mapCredentials(creds), nil + default: + return nil, nil + } +} + +func (o *Options) ApplyTo(opts *Options) { + if opts == nil { + return + } + if o.CredentialContext != nil { + opts.CredentialContext = o.CredentialContext + } + if o.LoggingContext != nil { + opts.LoggingContext = o.LoggingContext + } + if o.FileSystem != nil { + opts.FileSystem = o.FileSystem + } + if o.Credentials != nil { + opts.Credentials = o.Credentials + } + if o.Classifier != "" { + opts.Classifier = o.Classifier + } + if o.Extension != "" { + opts.Extension = o.Extension + } +} + +//////////////////////////////////////////////////////////////////////////////// + +type context struct { + credentials.Context +} + +func (o context) ApplyTo(opts *Options) { + opts.CredentialContext = o +} + +func WithCredentialContext(ctx credentials.ContextProvider) Option { + return context{ctx.CredentialsContext()} +} + +//////////////////////////////////////////////////////////////////////////////// + +type loggingContext struct { + logging.Context +} + +func (o loggingContext) ApplyTo(opts *Options) { + opts.LoggingContext = o +} + +func WithLoggingContext(ctx logging.ContextProvider) Option { + return loggingContext{ctx.LoggingContext()} +} + +//////////////////////////////////////////////////////////////////////////////// + +type fileSystem struct { + fs vfs.FileSystem +} + +func (o *fileSystem) ApplyTo(opts *Options) { + opts.FileSystem = o.fs +} + +func WithFileSystem(fs vfs.FileSystem) Option { + return &fileSystem{fs: fs} +} + +//////////////////////////////////////////////////////////////////////////////// + +type creds struct { + credentials.Credentials +} + +func (o creds) ApplyTo(opts *Options) { + opts.Credentials = o.Credentials +} + +func WithCredentials(c credentials.Credentials) Option { + return creds{c} +} + +//////////////////////////////////////////////////////////////////////////////// + +type classifier string + +func (o classifier) ApplyTo(opts *Options) { + opts.Classifier = string(o) +} + +func WithClassifier(c string) Option { + return classifier(c) +} + +//////////////////////////////////////////////////////////////////////////////// + +type extension string + +func (o extension) ApplyTo(opts *Options) { + opts.Extension = string(o) +} + +func WithExtension(e string) Option { + return extension(e) +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/blobaccess/maven/suite_test.go b/pkg/blobaccess/maven/suite_test.go new file mode 100644 index 0000000000..b69187676e --- /dev/null +++ b/pkg/blobaccess/maven/suite_test.go @@ -0,0 +1,13 @@ +package maven_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestConfig(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Maven Blob Access Test Suite") +} diff --git a/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom b/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom new file mode 100644 index 0000000000..218894d775 --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom @@ -0,0 +1,14 @@ + + + 4.0.0 + fail + repository + 42 + pom + ocm + test + + SAP SE + https://www.sap.com + + diff --git a/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 b/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 new file mode 100644 index 0000000000..3d6c52fe9e --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 @@ -0,0 +1 @@ +44a77645201d1a8fc5213ace787c220eabbd0967 \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json new file mode 100644 index 0000000000..2f1fc35fdc --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json @@ -0,0 +1 @@ +{"some": "test content"} \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 new file mode 100644 index 0000000000..d6836aeaa0 --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 @@ -0,0 +1 @@ +f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt new file mode 100644 index 0000000000..b4af84697f --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt @@ -0,0 +1 @@ +some test content \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 new file mode 100644 index 0000000000..55eceeb992 --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 @@ -0,0 +1 @@ +dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..8564f0addae8de5525417df8294d13c0c2a3a7c0 GIT binary patch literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo + + 4.0.0 + com.sap.cloud.sdk + sdk-modules-bom + 5.7.0 + pom + SAP Cloud SDK - Modules BOM + Bill of Materials (BOM) of the SAP Cloud SDK modules. + https://sap.github.io/cloud-sdk/docs/java/getting-started + + SAP SE + https://www.sap.com + + + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + SAP + cloudsdk@sap.com + SAP SE + https://www.sap.com + + + + + + + + UTF-8 + Public + Stable + + 5.7.0 + + + + + com.sap.cloud.sdk + sdk-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + dwc-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + caching + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient4 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient5 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity-scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-destination-service + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-oauth + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-dwc + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-ztis + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience-api + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience4j + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + security + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + servlet-jakarta + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + tenant + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-core + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + rfc + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + datamodel-metadata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator-utility + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-client + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + fluent-result + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + + soap + ${sdk.version} + + + + diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 new file mode 100644 index 0000000000..35f63a2e1f --- /dev/null +++ b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 @@ -0,0 +1 @@ +34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go new file mode 100644 index 0000000000..bcc45df6ff --- /dev/null +++ b/pkg/blobaccess/maven/utils.go @@ -0,0 +1,146 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven + +import ( + "github.com/mandelsoft/goutils/errors" + "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/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" + "github.com/open-component-model/ocm/pkg/iotools" + "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/mime" + "github.com/open-component-model/ocm/pkg/utils" + "github.com/open-component-model/ocm/pkg/utils/tarutils" + "github.com/opencontainers/go-digest" + "io" +) + +type coords = *maven.Coordinates + +type spec struct { + coords + repoUrl string + options *Options +} + +func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { + var finalize finalizer.Finalizer + defer finalize.FinalizeWithErrorPropagation(&rerr) + + log := s.options.Logger("BaseUrl", s.repoUrl) + creds, err := s.options.GetCredentials(s.repoUrl, s.GroupId) + if err != nil { + return nil, err + } + fileMap, err := maven.GavFiles(s.repoUrl, s.coords, creds, s.options.FileSystem) + if err != nil { + return nil, err + } + + if s.Classifier != "" || s.Extension != "" { + fileMap = maven.FilterByCoordinates(fileMap, s.coords) + } + + switch l := len(fileMap); { + case l <= 0: + return nil, errors.New("no maven artifact files found") + case l == 1 && s.Extension != "": + for file, hash := range fileMap { + metadata, err := maven.GetFileMeta(s.repoUrl, s.coords, file, hash, creds, s.options.FileSystem) + if err != nil { + return nil, err + } + return blobAccessForRepositoryAccess(metadata, creds, s.options, s.options.FileSystem) + } + // default: continue below with: create tmpfs where all files can be downloaded to and packed together as tar.gz + } + + tmpfs, err := osfs.NewTempFileSystem() + if err != nil { + return nil, err + } + finalize.With(func() error { + return vfs.Cleanup(tmpfs) + }) + + for file, hash := range fileMap { + loop := finalize.Nested() + metadata, err := maven.GetFileMeta(s.repoUrl, s.coords, file, hash, creds, s.options.FileSystem) + if err != nil { + return nil, err + } + + // download the artifact into the temporary file system + out, err := tmpfs.Create(file) + if err != nil { + return nil, err + } + loop.Close(out) + + reader, err := maven.GetReader(metadata.Url, creds, s.options.FileSystem) + if err != nil { + return nil, err + } + loop.Close(reader) + if hash > 0 { + dreader := iotools.NewDigestReaderWithHash(hash, reader) + _, err = io.Copy(out, dreader) + if err != nil { + return nil, err + } + sum := dreader.Digest().Encoded() + if metadata.Hash != sum { + return nil, errors.Newf("%s digest mismatch: expected %s, found %s", metadata.HashType, metadata.Hash, sum) + } + } else { + _, err = io.Copy(out, reader) + return nil, err + } + err = loop.Finalize() + if err != nil { + return nil, err + } + } + + // pack all downloaded files into a tar.gz file + fs := utils.FileSystem(s.options.FileSystem) + tgz, err := vfs.TempFile(fs, "", "maven-"+s.coords.FileNamePrefix()+"-*.tar.gz") + if err != nil { + return nil, err + } + + dw := iotools.NewDigestWriterWith(digest.SHA256, tgz) + finalize.Close(dw) + + err = tarutils.TgzFs(tmpfs, dw) + if err != nil { + return nil, err + } + log.Debug("created", "file", tgz.Name()) + return blobaccess.ForTemporaryFilePathWithMeta(mime.MIME_TGZ, dw.Digest(), dw.Size(), tgz.Name(), fs), nil +} + +func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts *Options, fss ...vfs.FileSystem) (bpi.BlobAccess, error) { + reader := func() (io.ReadCloser, error) { + return maven.GetReader(meta.Url, creds, fss...) + } + if meta.Hash != "" { + getreader := reader + reader = func() (io.ReadCloser, error) { + readCloser, err := getreader() + if err != nil { + return nil, err + } + return iotools.VerifyingReaderWithHash(readCloser, meta.HashType, meta.Hash), nil + } + } + acc := blobaccess.DataAccessForReaderFunction(reader, meta.Url) + return accessobj.CachedBlobAccessForWriterWithCache(opts.Cache(), meta.MimeType, accessio.NewDataAccessWriter(acc)), nil +} diff --git a/pkg/blobaccess/standard.go b/pkg/blobaccess/standard.go index ea8379cdf6..7555ac3114 100644 --- a/pkg/blobaccess/standard.go +++ b/pkg/blobaccess/standard.go @@ -321,6 +321,15 @@ func ForTemporaryFile(mime string, temp vfs.File, fss ...vfs.FileSystem) BlobAcc }) } +func ForTemporaryFileWithMeta(mime string, digest digest.Digest, size int64, temp vfs.File, fss ...vfs.FileSystem) BlobAccess { + return bpi.NewBlobAccessForBase(bpi.BaseAccessForDataAccessAndMeta(mime, &temporaryFileBlob{ + _blobAccess: ForFile(mime, temp.Name(), fss...), + filesystem: utils.FileSystem(fss...), + path: temp.Name(), + file: temp, + }, digest, size)) +} + func ForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) BlobAccess { return bpi.NewBlobAccessForBase(&temporaryFileBlob{ _blobAccess: ForFile(mime, temp, fss...), @@ -329,6 +338,14 @@ func ForTemporaryFilePath(mime string, temp string, fss ...vfs.FileSystem) BlobA }) } +func ForTemporaryFilePathWithMeta(mime string, digest digest.Digest, size int64, temp string, fss ...vfs.FileSystem) BlobAccess { + return bpi.NewBlobAccessForBase(bpi.BaseAccessForDataAccessAndMeta(mime, &temporaryFileBlob{ + _blobAccess: ForFile(mime, temp, fss...), + filesystem: utils.FileSystem(fss...), + path: temp, + }, digest, size)) +} + //////////////////////////////////////////////////////////////////////////////// type mimeBlob struct { diff --git a/pkg/blobaccess/wget/options.go b/pkg/blobaccess/wget/options.go index a14fb5614f..a808e4545c 100644 --- a/pkg/blobaccess/wget/options.go +++ b/pkg/blobaccess/wget/options.go @@ -64,6 +64,9 @@ func (o *Options) ApplyTo(opts *Options) { if o.LoggingContext != nil { opts.LoggingContext = o.LoggingContext } + if o.Credentials != nil { + opts.Credentials = o.Credentials + } if o.Header != nil { opts.Header = o.Header } diff --git a/pkg/common/accessobj/cachedblob.go b/pkg/common/accessobj/cachedblob.go index 5ca6cfbab8..4e08c175ef 100644 --- a/pkg/common/accessobj/cachedblob.go +++ b/pkg/common/accessobj/cachedblob.go @@ -29,10 +29,14 @@ type CachedBlobAccess struct { var _ bpi.BlobAccessBase = (*CachedBlobAccess)(nil) func CachedBlobAccessForWriter(ctx datacontext.Context, mime string, src accessio.DataWriter) blobaccess.BlobAccess { + return CachedBlobAccessForWriterWithCache(tmpcache.Get(ctx), mime, src) +} + +func CachedBlobAccessForWriterWithCache(cache *tmpcache.Attribute, mime string, src accessio.DataWriter) blobaccess.BlobAccess { return bpi.NewBlobAccessForBase(&CachedBlobAccess{ source: src, mime: mime, - cache: tmpcache.Get(ctx), + cache: cache, }) } diff --git a/pkg/contexts/credentials/builtin/mvn/identity/identity.go b/pkg/contexts/credentials/builtin/maven/identity/identity.go similarity index 100% rename from pkg/contexts/credentials/builtin/mvn/identity/identity.go rename to pkg/contexts/credentials/builtin/maven/identity/identity.go diff --git a/pkg/contexts/datacontext/attrs/tmpcache/attr.go b/pkg/contexts/datacontext/attrs/tmpcache/attr.go index b71abfe230..bbe00a818f 100644 --- a/pkg/contexts/datacontext/attrs/tmpcache/attr.go +++ b/pkg/contexts/datacontext/attrs/tmpcache/attr.go @@ -62,6 +62,13 @@ type Attribute struct { Filesystem vfs.FileSystem } +func New(path string, fss ...vfs.FileSystem) *Attribute { + return &Attribute{ + Path: path, + Filesystem: utils.FileSystem(fss...), + } +} + func (a *Attribute) CreateTempFile(pat string) (vfs.File, error) { err := a.Filesystem.MkdirAll(a.Path, 0o777) if err != nil { @@ -73,8 +80,15 @@ func (a *Attribute) CreateTempFile(pat string) (vfs.File, error) { //////////////////////////////////////////////////////////////////////////////// func Get(ctx datacontext.Context) *Attribute { - v := ctx.GetAttributes().GetAttribute(ATTR_KEY) - fs := utils.FileSystem(vfsattr.Get(ctx)) + var v interface{} + var fs vfs.FileSystem + + if ctx != nil { + v = ctx.GetAttributes().GetAttribute(ATTR_KEY) + fs = utils.FileSystem(vfsattr.Get(ctx)) + } + fs = utils.FileSystem(fs) + if v != nil { a := v.(*Attribute) if a.Filesystem == nil { diff --git a/pkg/contexts/ocm/accessmethods/mvn/method.go b/pkg/contexts/ocm/accessmethods/mvn/method.go index d430b774c2..ab483eef65 100644 --- a/pkg/contexts/ocm/accessmethods/mvn/method.go +++ b/pkg/contexts/ocm/accessmethods/mvn/method.go @@ -5,6 +5,7 @@ import ( "context" "crypto" "fmt" + "github.com/open-component-model/ocm/pkg/maven" "io" "net/http" "path" @@ -22,7 +23,7 @@ import ( "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/credentials/builtin/mvn/identity" + "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" "github.com/open-component-model/ocm/pkg/iotools" @@ -51,7 +52,7 @@ type AccessSpec struct { // Repository is the base URL of the Maven (mvn) repository. Repository string `json:"repository"` - Coordinates `json:",inline"` + maven.Coordinates `json:",inline"` } // Option defines the interface function "ApplyTo()". @@ -66,7 +67,7 @@ func New(repository, groupId, artifactId, version string, options ...Option) *Ac accessSpec := &AccessSpec{ ObjectVersionedType: runtime.NewVersionedTypedObject(Type), Repository: repository, - Coordinates: Coordinates{ + Coordinates: maven.Coordinates{ GroupId: groupId, ArtifactId: artifactId, Version: version, @@ -143,7 +144,7 @@ func (a *AccessSpec) ArtifactUrl() string { return a.Url(a.Repository) } -func (a *AccessSpec) NewArtifact() *Coordinates { +func (a *AccessSpec) GetCoordinates() *maven.Coordinates { return a.Coordinates.Copy() } @@ -155,7 +156,7 @@ type meta struct { } func update(a *AccessSpec, file string, hash crypto.Hash, metadata *meta, ctx accspeccpi.Context, fs vfs.FileSystem) error { - artifact := a.NewArtifact() + artifact := a.GetCoordinates() err := artifact.SetClassifierExtensionBy(file) if err != nil { return err @@ -248,7 +249,7 @@ func (a *AccessSpec) GetPackageMeta(ctx accspeccpi.Context) (*meta, error) { } // pack all downloaded files into a tar.gz file - tgz, err := vfs.TempFile(fs, "", Type+"-"+a.NewArtifact().FileNamePrefix()+"-*.tar.gz") + tgz, err := vfs.TempFile(fs, "", Type+"-"+a.GetCoordinates().FileNamePrefix()+"-*.tar.gz") if err != nil { return nil, err } @@ -343,7 +344,7 @@ func filesAndHashes(fileList []string) map[string]crypto.Hash { // Which hash files are available? result := make(map[string]crypto.Hash, len(fileList)/2) for _, file := range fileList { - if IsResource(file) { + if maven.IsResource(file) { result[file] = bestAvailableHash(fileList, file) log.Debug("found", "file", file) } @@ -365,8 +366,8 @@ func bestAvailableHash(list []string, filename string) crypto.Hash { //////////////////////////////////////////////////////////////////////////////// -// getStringData reads all data from the given URL and returns it as a string. func getStringData(ctx accspeccpi.Context, url string, fs vfs.FileSystem) (string, error) { + // getStringData reads all data from the given URL and returns it as a string. r, err := getReader(ctx, url, fs) if err != nil { return "", err diff --git a/pkg/contexts/ocm/accessmethods/wget/options.go b/pkg/contexts/ocm/accessmethods/wget/options.go index 4693d6c697..fcf667661f 100644 --- a/pkg/contexts/ocm/accessmethods/wget/options.go +++ b/pkg/contexts/ocm/accessmethods/wget/options.go @@ -4,10 +4,7 @@ import ( "io" "net/http" - "github.com/mandelsoft/logging" - "github.com/open-component-model/ocm/pkg/blobaccess/wget" - "github.com/open-component-model/ocm/pkg/contexts/credentials" ) type ( @@ -15,22 +12,10 @@ type ( Option = wget.Option ) -func WithCredentialContext(ctx credentials.ContextProvider) Option { - return wget.WithCredentialContext(ctx) -} - -func WithLoggingContext(ctx logging.ContextProvider) Option { - return wget.WithLoggingContext(ctx) -} - func WithMimeType(mime string) Option { return wget.WithMimeType(mime) } -func WithCredentials(c credentials.Credentials) Option { - return wget.WithCredentials(c) -} - func WithHeader(h http.Header) Option { return wget.WithHeader(h) } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go index 0a11fcc96f..0167b4c7a6 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go @@ -5,6 +5,7 @@ import ( "crypto" "encoding/json" "fmt" + "github.com/open-component-model/ocm/pkg/maven" "io" "net/http" "strings" @@ -12,7 +13,7 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/mvn/identity" + "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/mvn" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" @@ -56,7 +57,7 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi // setup logger log := log.WithValues("repository", b.spec.Url) // identify artifact - artifact, err := mvn.Parse(hint) + artifact, err := maven.Parse(hint) if err != nil { return nil, err } @@ -113,7 +114,7 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi } // deploy an artifact to the specified destination. See https://jfrog.com/help/r/jfrog-rest-apis/deploy-artifact -func deploy(artifact *mvn.Coordinates, url string, reader io.ReadCloser, ctx accspeccpi.Context, hashes *iotools.HashReader) (err error) { +func deploy(artifact *maven.Coordinates, url string, reader io.ReadCloser, ctx accspeccpi.Context, hashes *iotools.HashReader) (err error) { req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, artifact.Url(url), reader) if err != nil { return diff --git a/pkg/maven/access.go b/pkg/maven/access.go new file mode 100644 index 0000000000..54448d6c8c --- /dev/null +++ b/pkg/maven/access.go @@ -0,0 +1,182 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven + +import ( + "bytes" + "context" + "crypto" + "github.com/cloudflare/cfssl/log" + "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/utils" + "github.com/open-component-model/ocm/pkg/utils/tarutils" + "golang.org/x/net/html" + "io" + "net/http" + "path" + "strings" +) + +type FileMeta struct { + MimeType string + HashType crypto.Hash + Hash string + Url string +} + +type Credentials interface { + SetForRequest(req *http.Request) error +} +type BasicAuthCredentials struct { + Username string + Password string +} + +func (b *BasicAuthCredentials) SetForRequest(req *http.Request) error { + req.SetBasicAuth(b.Username, b.Password) + return nil +} + +func GetHash(url string, creds Credentials, hash crypto.Hash, fss ...vfs.FileSystem) (string, error) { + // getStringData reads all data from the given URL and returns it as a string. + r, err := GetReader(url+HashUrlExt(hash), creds, fss...) + if err != nil { + return "", err + } + defer r.Close() + b, err := io.ReadAll(r) + if err != nil { + return "", err + } + return string(b), nil +} + +func GetReader(url string, creds Credentials, fss ...vfs.FileSystem) (io.ReadCloser, error) { + if strings.HasPrefix(url, "file://") { + fs := utils.FileSystem(fss...) + path := url[7:] + return fs.OpenFile(path, vfs.O_RDONLY, 0o600) + } + + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) + if err != nil { + return nil, err + } + if creds != nil { + err = creds.SetForRequest(req) + if err != nil { + return nil, err + } + } + httpClient := &http.Client{} + resp, err := httpClient.Do(req) + if err != nil { + return nil, err + } + if resp.StatusCode != http.StatusOK { + defer resp.Body.Close() + buf := &bytes.Buffer{} + _, err = io.Copy(buf, io.LimitReader(resp.Body, 2000)) + if err == nil { + Log.Error("http", "code", resp.Status, "url", url, "body", buf.String()) + } + return nil, errors.Newf("http %s error - %s", resp.Status, url) + } + return resp.Body, nil +} + +func GetFileMeta(repoUrl string, c *Coordinates, file string, hash crypto.Hash, creds Credentials, fss ...vfs.FileSystem) (*FileMeta, error) { + coords := c.Copy() + err := coords.SetClassifierExtensionBy(file) + if err != nil { + return nil, err + } + metadata := &FileMeta{ + Url: coords.Url(repoUrl), + MimeType: coords.MimeType(), + } + log := Log.WithValues("file", metadata.Url) + log.Debug("processing") + if hash > 0 { + metadata.HashType = hash + metadata.Hash, err = GetHash(metadata.Url, creds, hash, fss...) + if err != nil { + return nil, errors.Wrapf(err, "cannot read %s digest of: %s", hash, metadata.Url) + } + } else { + log.Warn("no digest available") + } + return metadata, nil +} + +func GavFiles(repoUrl string, coords *Coordinates, creds Credentials, fss ...vfs.FileSystem) (map[string]crypto.Hash, error) { + if strings.HasPrefix(repoUrl, "file://") { + dir := path.Join(repoUrl[7:], coords.GavPath()) + return gavFilesFromDisk(utils.FileSystem(fss...), dir) + } + return gavOnlineFiles(repoUrl, coords, creds) +} + +func gavFilesFromDisk(fs vfs.FileSystem, dir string) (map[string]crypto.Hash, error) { + files, err := tarutils.ListSortedFilesInDir(fs, dir, true) + if err != nil { + return nil, err + } + return filesAndHashes(files), nil +} + +// gavOnlineFiles returns the files of the Maven (mvn) artifact in the repository and their available digests. +func gavOnlineFiles(repoUrl string, coords *Coordinates, creds Credentials) (map[string]crypto.Hash, error) { + log := Log.WithValues("BaseUrl", repoUrl) + log.Debug("gavOnlineFiles") + + reader, err := GetReader(coords.GavUrl(repoUrl), creds, nil) + if err != nil { + return nil, err + } + defer reader.Close() + + // Which files are listed in the repository? + log.Debug("parse-html") + htmlDoc, err := html.Parse(reader) + if err != nil { + return nil, err + } + var fileList []string + var process func(*html.Node) + prefix := coords.FileNamePrefix() + process = func(node *html.Node) { + // check if the node is an element node and the tag is "" + if node.Type == html.ElementNode && node.Data == "a" { + for _, attribute := range node.Attr { + if attribute.Key == "href" { + // check if the href starts with artifactId-version + if strings.HasPrefix(attribute.Val, prefix) { + fileList = append(fileList, attribute.Val) + } + } + } + } + for nextChild := node.FirstChild; nextChild != nil; nextChild = nextChild.NextSibling { + process(nextChild) // recursive call! + } + } + process(htmlDoc) + + return filesAndHashes(fileList), nil +} + +func filesAndHashes(fileList []string) map[string]crypto.Hash { + // Which hash files are available? + result := make(map[string]crypto.Hash, len(fileList)/2) + for _, file := range fileList { + if IsResource(file) { + result[file] = bestAvailableHash(fileList, file) + log.Debug("found", "file", file) + } + } + return result +} diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go new file mode 100644 index 0000000000..628ef280fd --- /dev/null +++ b/pkg/maven/access_test.go @@ -0,0 +1,87 @@ +package maven_test + +import ( + "crypto" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + . "github.com/open-component-model/ocm/pkg/testutils" + + me "github.com/open-component-model/ocm/pkg/maven" +) + +const ( + mvnPATH = "/testdata/.m2/repository" + FAILPATH = "/testdata/.m2/fail" +) + +var _ = Describe("local accessmethods.me.AccessSpec tests", func() { + var env *Builder + + BeforeEach(func() { + env = NewBuilder(TestData()) + }) + + AfterEach(func() { + env.Cleanup() + }) + + It("accesses local artifact file", func() { + repoUrl := "file://" + mvnPATH + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + files := Must(me.GavFiles(repoUrl, coords, nil, env.FileSystem())) + Expect(files).To(YAMLEqual("sdk-modules-bom-5.7.0.pom: 3")) + }) + + It("accesses local artifact file with extension", func() { + repoUrl := "file://" + mvnPATH + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", "", "pom") + hash := Must(me.GetHash(coords.Url(repoUrl), nil, crypto.SHA1, env.FileSystem())) + Expect(hash).To(Equal("34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) + }) + + FIt("", func() { + repoUrl := "file://" + mvnPATH + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", "", "pom") + meta := Must(me.GetFileMeta(repoUrl, coords, "sdk-modules-bom-5.7.0.pom", crypto.SHA1, nil, env.FileSystem())) + Expect(meta).To(YAMLEqual(` + Hash: 34ccdeb9c008f8aaef90873fc636b09d3ae5c709 + HashType: 3 + MimeType: application/xml + Url: file:///testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom +`)) + }) + + //It("accesses local artifact with extension", func() { + // acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) + // m := Must(acc.AccessMethod(cv)) + // defer m.Close() + // Expect(m.MimeType()).To(Equal(mime.MIME_XML)) + // r := Must(m.Reader()) + // defer r.Close() + // dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) + // for { + // var buf [8096]byte + // _, err := dr.Read(buf[:]) + // if err != nil { + // break + // } + // } + // Expect(dr.Size()).To(Equal(int64(7153))) + // Expect(dr.Digest().String()).To(Equal("SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) + //}) + // + //It("Describe", func() { + // acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) + // Expect(acc.Describe(nil)).To(Equal("Maven (me) package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) + //}) + // + //It("detects digests mismatch", func() { + // acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) + // m := Must(acc.AccessMethod(cv)) + // defer m.Close() + // _, err := m.Reader() + // Expect(err).To(MatchError(ContainSubstring("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7"))) + //}) +}) diff --git a/pkg/contexts/ocm/accessmethods/mvn/coordinates.go b/pkg/maven/coordinates.go similarity index 82% rename from pkg/contexts/ocm/accessmethods/mvn/coordinates.go rename to pkg/maven/coordinates.go index d39e09c2e5..7b436432b6 100644 --- a/pkg/contexts/ocm/accessmethods/mvn/coordinates.go +++ b/pkg/maven/coordinates.go @@ -1,7 +1,12 @@ -package mvn +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven import ( "fmt" + "github.com/mandelsoft/goutils/generics" "mime" "path" "path/filepath" @@ -20,11 +25,26 @@ type Coordinates struct { // Version of the Maven (mvn) artifact. Version string `json:"version"` // Classifier of the Maven (mvn) artifact. - Classifier string `json:"classifier"` + Classifier string `json:"classifier"` //TODO: make it a pointer to differentiate between empty and none // Extension of the Maven (mvn) artifact. Extension string `json:"extension"` } +func NewCoordinates(groupId, artifactId, version string, other ...string) *Coordinates { + c := &Coordinates{ + GroupId: groupId, + ArtifactId: artifactId, + Version: version, + } + if len(other) > 0 { + c.Classifier = other[0] + } + if len(other) > 1 { + c.Extension = other[1] + } + return c +} + // GAV returns the GAV coordinates of the Maven Coordinates. func (c *Coordinates) GAV() string { return c.GroupId + ":" + c.ArtifactId + ":" + c.Version @@ -40,6 +60,10 @@ func (c *Coordinates) GavPath() string { return c.GroupPath() + "/" + c.ArtifactId + "/" + c.Version } +func (c *Coordinates) GavUrl(repoUrl string) string { + return repoUrl + "/" + c.GavPath() +} + // FilePath returns the Maven Coordinates's GAV-name with classifier and extension. // Which is equal to the URL-path of the artifact in the repository. // Default extension is jar. @@ -104,16 +128,10 @@ func (c *Coordinates) MimeType() string { // Copy creates a new Coordinates with the same values. func (c *Coordinates) Copy() *Coordinates { - return &Coordinates{ - GroupId: c.GroupId, - ArtifactId: c.ArtifactId, - Version: c.Version, - Classifier: c.Classifier, - Extension: c.Extension, - } + return generics.Pointer(*c) } -// Parse creates an Coordinates from it's serialized form (see Coordinates.String). +// Parse creates a Coordinates from it's serialized form (see Coordinates.String). func Parse(serializedArtifact string) (*Coordinates, error) { parts := strings.Split(serializedArtifact, ":") if len(parts) < 3 { diff --git a/pkg/contexts/ocm/accessmethods/mvn/coordinates_test.go b/pkg/maven/coordinates_test.go similarity index 79% rename from pkg/contexts/ocm/accessmethods/mvn/coordinates_test.go rename to pkg/maven/coordinates_test.go index 63df1268ae..32f78db66f 100644 --- a/pkg/contexts/ocm/accessmethods/mvn/coordinates_test.go +++ b/pkg/maven/coordinates_test.go @@ -1,14 +1,20 @@ -package mvn +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + + me "github.com/open-component-model/ocm/pkg/maven" ) var _ = Describe("Maven Test Environment", func() { It("GAV, GroupPath, FilePath", func() { - artifact := &Coordinates{ + artifact := &me.Coordinates{ GroupId: "ocm.software", ArtifactId: "hello-ocm", Version: "0.0.1", @@ -20,7 +26,7 @@ var _ = Describe("Maven Test Environment", func() { }) It("SetClassifierExtensionBy", func() { - artifact := &Coordinates{ + artifact := &me.Coordinates{ GroupId: "ocm.software", ArtifactId: "hello-ocm", Version: "0.0.1", @@ -33,16 +39,16 @@ var _ = Describe("Maven Test Environment", func() { Expect(artifact.Classifier).To(Equal("tests")) Expect(artifact.Extension).To(Equal("jar")) - artifact.ArtifactId = "apache-maven" + artifact.ArtifactId = "apache-me" artifact.Version = "3.9.6" - artifact.SetClassifierExtensionBy("apache-maven-3.9.6-bin.tar.gz") + artifact.SetClassifierExtensionBy("apache-me-3.9.6-bin.tar.gz") Expect(artifact.Classifier).To(Equal("bin")) Expect(artifact.Extension).To(Equal("tar.gz")) }) It("parse GAV", func() { gav := "org.apache.commons:commons-compress:1.26.1:cyclonedx:xml" - artifact, err := Parse(gav) + artifact, err := me.Parse(gav) Expect(err).To(BeNil()) Expect(artifact.String()).To(Equal(gav)) Expect(artifact.GroupId).To(Equal("org.apache.commons")) diff --git a/pkg/maven/logging.go b/pkg/maven/logging.go new file mode 100644 index 0000000000..beea3c7d0c --- /dev/null +++ b/pkg/maven/logging.go @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven + +import "github.com/open-component-model/ocm/pkg/logging" + +var REALM = logging.DefineSubRealm("Maven repository", "mvn") + +var Log = logging.DynamicLogger(REALM) diff --git a/pkg/maven/suite_test.go b/pkg/maven/suite_test.go new file mode 100644 index 0000000000..0892bc9a7f --- /dev/null +++ b/pkg/maven/suite_test.go @@ -0,0 +1,13 @@ +package maven_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestConfig(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Maven (mvn) Test Suite") +} diff --git a/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom b/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom new file mode 100644 index 0000000000..218894d775 --- /dev/null +++ b/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom @@ -0,0 +1,14 @@ + + + 4.0.0 + fail + repository + 42 + pom + ocm + test + + SAP SE + https://www.sap.com + + diff --git a/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 b/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 new file mode 100644 index 0000000000..3d6c52fe9e --- /dev/null +++ b/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 @@ -0,0 +1 @@ +44a77645201d1a8fc5213ace787c220eabbd0967 \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom new file mode 100644 index 0000000000..b3baaee32f --- /dev/null +++ b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom @@ -0,0 +1,210 @@ + + + 4.0.0 + com.sap.cloud.sdk + sdk-modules-bom + 5.7.0 + pom + SAP Cloud SDK - Modules BOM + Bill of Materials (BOM) of the SAP Cloud SDK modules. + https://sap.github.io/cloud-sdk/docs/java/getting-started + + SAP SE + https://www.sap.com + + + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + SAP + cloudsdk@sap.com + SAP SE + https://www.sap.com + + + + + + + + UTF-8 + Public + Stable + + 5.7.0 + + + + + com.sap.cloud.sdk + sdk-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + dwc-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + caching + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient4 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient5 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity-scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-destination-service + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-oauth + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-dwc + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-ztis + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience-api + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience4j + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + security + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + servlet-jakarta + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + tenant + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-core + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + rfc + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + datamodel-metadata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator-utility + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-client + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + fluent-result + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + + soap + ${sdk.version} + + + + diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 new file mode 100644 index 0000000000..35f63a2e1f --- /dev/null +++ b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 @@ -0,0 +1 @@ +34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/maven/utils.go b/pkg/maven/utils.go new file mode 100644 index 0000000000..0d7b9d4265 --- /dev/null +++ b/pkg/maven/utils.go @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven + +import ( + "crypto" + . "github.com/mandelsoft/goutils/regexutils" + "slices" + "strings" +) + +// HashUrlExt returns the 'maven' hash extension for the given hash. +// Maven usually uses sha1, sha256, sha512, md5 instead of SHA-1, SHA-256, SHA-512, MD5. +func HashUrlExt(h crypto.Hash) string { + return "." + strings.ReplaceAll(strings.ToLower(h.String()), "-", "") +} + +func FilterByCoordinates(fileMap map[string]crypto.Hash, coords *Coordinates) map[string]crypto.Hash { + exp := Literal(coords.ArtifactId + "-" + coords.Version) + if coords.Classifier != "" { + exp = Sequence(exp, Literal("-"+coords.Classifier)) + } + if coords.Extension != "" { + exp = Sequence(exp, Literal("."+coords.Extension)) + } else { + exp = Sequence(exp, Literal("."), Match(".*")) + } + exp = Anchored(exp) + for file := range fileMap { + if !exp.MatchString(file) { + delete(fileMap, file) + } + } + return fileMap +} + +var hashes = [5]crypto.Hash{crypto.SHA512, crypto.SHA256, crypto.SHA1, crypto.MD5} + +// bestAvailableHash returns the best available hash for the given file. +// It first checks for SHA-512, then SHA-256, SHA-1, and finally MD5. If nothing is found, it returns 0. +func bestAvailableHash(list []string, filename string) crypto.Hash { + for _, hash := range hashes { + if slices.Contains(list, filename+HashUrlExt(hash)) { + return hash + } + } + return 0 +} From 8d7d2aa5abe73315fef07ff4915bd8d36b4c3312 Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Thu, 23 May 2024 17:15:57 +0200 Subject: [PATCH 02/13] wip --- pkg/blobaccess/maven/access.go | 10 +- pkg/blobaccess/maven/access_test.go | 138 +++++++++++++----- pkg/blobaccess/maven/options.go | 26 +++- .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 0 -> 595 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 + pkg/blobaccess/maven/utils.go | 7 +- .../repositories/vault/repo_int_test.go | 24 +-- pkg/contexts/ocm/accessmethods/mvn/method.go | 14 +- .../handlers/generic/mvn/blobhandler.go | 3 +- .../artifactblob/helmblob/helmblob_test.go | 42 ++++++ .../artifactblob/helmblob/suite_test.go | 13 ++ .../helmblob/testdata/testchart1/.helmignore | 23 +++ .../testdata/testchart1/.idea/somefile | 0 .../helmblob/testdata/testchart1/Chart.yaml | 24 +++ .../testdata/testchart1/templates/NOTES.txt | 22 +++ .../testchart1/templates/_helpers.tpl | 62 ++++++++ .../testchart1/templates/deployment.yaml | 61 ++++++++ .../testdata/testchart1/templates/hpa.yaml | 28 ++++ .../testchart1/templates/ingress.yaml | 61 ++++++++ .../testchart1/templates/service.yaml | 15 ++ .../testchart1/templates/serviceaccount.yaml | 12 ++ .../templates/tests/test-connection.yaml | 15 ++ .../helmblob/testdata/testchart1/values.yaml | 81 ++++++++++ .../helmblob/testdata/testchart2/.helmignore | 23 +++ .../testdata/testchart2/.idea/somefile | 0 .../helmblob/testdata/testchart2/Chart.yaml | 24 +++ .../testdata/testchart2/templates/NOTES.txt | 22 +++ .../testchart2/templates/_helpers.tpl | 62 ++++++++ .../testchart2/templates/deployment.yaml | 61 ++++++++ .../testdata/testchart2/templates/hpa.yaml | 28 ++++ .../testchart2/templates/ingress.yaml | 61 ++++++++ .../testchart2/templates/service.yaml | 15 ++ .../testchart2/templates/serviceaccount.yaml | 12 ++ .../templates/tests/test-connection.yaml | 15 ++ .../helmblob/testdata/testchart2/values.yaml | 81 ++++++++++ pkg/maven/access_test.go | 98 ++++++++----- pkg/maven/coordinates.go | 108 ++++++++++---- pkg/maven/coordinates_test.go | 64 ++++---- .../sdk-modules-bom-5.7.0-random-content.json | 1 + ...modules-bom-5.7.0-random-content.json.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.txt | 1 + ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 0 -> 595 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 0 -> 595 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 + pkg/maven/utils.go | 20 --- pkg/testutils/tcp.go | 33 +++++ 48 files changed, 1218 insertions(+), 197 deletions(-) create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar create mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/suite_test.go create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/.helmignore create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/.idea/somefile create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/Chart.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/NOTES.txt create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/_helpers.tpl create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/deployment.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/hpa.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/ingress.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/service.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/serviceaccount.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/tests/test-connection.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/values.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.helmignore create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.idea/somefile create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/Chart.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/NOTES.txt create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/_helpers.tpl create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/deployment.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/hpa.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/ingress.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/service.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/serviceaccount.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/tests/test-connection.yaml create mode 100644 pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/values.yaml create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar create mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 create mode 100644 pkg/testutils/tcp.go diff --git a/pkg/blobaccess/maven/access.go b/pkg/blobaccess/maven/access.go index eaa5cb59df..940be2565a 100644 --- a/pkg/blobaccess/maven/access.go +++ b/pkg/blobaccess/maven/access.go @@ -16,16 +16,24 @@ func DataAccessForMaven(repoUrl, groupId, artifactId, version string, opts ...Op func BlobAccessForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) (blobaccess.BlobAccess, error) { eff := optionutils.EvalOptions(opts...) s := &spec{ - coords: maven.NewCoordinates(groupId, artifactId, version, eff.Classifier, eff.Extension), + coords: maven.NewCoordinates(groupId, artifactId, version, maven.WithOptionalClassifier(eff.Classifier), maven.WithOptionalExtension(eff.Extension)), repoUrl: repoUrl, options: eff, } return s.getBlobAccess() } +func BlobAccessForMavenCoords(repoUrl string, coords *maven.Coordinates, opts ...Option) (blobaccess.BlobAccess, error) { + return BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) +} + func BlobAccessProviderForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { b, err := BlobAccessForMaven(repoUrl, groupId, artifactId, version, opts...) return b, err }) } + +func BlobAccessProviderForMavenCoords(repoUrl string, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { + return BlobAccessProviderForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) +} diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index 3e2e75ec66..869162a5ca 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -7,62 +7,124 @@ package maven_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + me "github.com/open-component-model/ocm/pkg/blobaccess/maven" . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" "github.com/open-component-model/ocm/pkg/maven" . "github.com/open-component-model/ocm/pkg/testutils" "github.com/open-component-model/ocm/pkg/utils/tarutils" - - me "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "time" ) const ( mvnPATH = "/testdata/.m2/repository" FAILPATH = "/testdata/.m2/fail" + + MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" + MAVEN_GROUP_ID = "maven" + MAVEN_ARTIFACT_ID = "maven" + MAVEN_VERSION = "1.1" ) var _ = Describe("blobaccess for maven", func() { - var env *Builder - BeforeEach(func() { - env = NewBuilder(TestData()) - }) + Context("maven filesystem repository", func() { + var env *Builder - AfterEach(func() { - MustBeSuccessful(env.Cleanup()) - }) + BeforeEach(func() { + env = NewBuilder(TestData()) + }) - It("blobaccess for artifact", func() { - repoUrl := "file://" + mvnPATH - coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + AfterEach(func() { + MustBeSuccessful(env.Cleanup()) + }) - b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithFileSystem(env.FileSystem()))) - defer Close(b, "blobaccess") - files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) - Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0.pom", "sdk-modules-bom-5.7.0-random-content.txt", - "sdk-modules-bom-5.7.0-random-content.json")) - }) + It("blobaccess for gav", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + + b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithFileSystem(env.FileSystem()))) + defer Close(b, "blobaccess") + files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) + Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0.pom", "sdk-modules-bom-5.7.0.jar", "sdk-modules-bom-5.7.0-random-content.txt", + "sdk-modules-bom-5.7.0-random-content.json", "sdk-modules-bom-5.7.0-sources.jar")) + }) + + It("blobaccess for files with the same classifier", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + maven.WithClassifier("random-content")) - It("blobaccess for files with the same classifier", func() { - repoUrl := "file://" + mvnPATH - coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", - "random-content") - - b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithClassifier(coords.Classifier), - me.WithFileSystem(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", - "sdk-modules-bom-5.7.0-random-content.json")) + b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(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", + "sdk-modules-bom-5.7.0-random-content.json")) + }) + + It("blobaccess for files with empty classifier", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + maven.WithClassifier("")) + + b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + defer Close(b, "blobaccess") + files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) + Expect(files).To(ConsistOf("sdk-modules-bom-5.7.0.pom", + "sdk-modules-bom-5.7.0.jar")) + }) + + It("blobaccess for files with extension", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + maven.WithExtension("jar")) + + b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(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", + "sdk-modules-bom-5.7.0.jar")) + }) + + It("blobaccess for files with extension", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + maven.WithExtension("txt")) + + b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(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")) + }) + + It("blobaccess for a single file with classifier and extension", func() { + repoUrl := "file://" + mvnPATH + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + maven.WithClassifier("random-content"), maven.WithExtension("json")) + + b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + defer Close(b, "blobaccess") + Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) + }) }) - It("blobaccess for a single file with classifier and extension", func() { - repoUrl := "file://" + mvnPATH - coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", - "random-content", "json") - - b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithClassifier(coords.Classifier), - me.WithExtension(coords.Extension), me.WithFileSystem(env.FileSystem()))) - defer Close(b, "blobaccess") - Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) + + Context("maven http repository", func() { + if PingTCPServer("repo.maven.apache.org:443", time.Second) == nil { + var coords *maven.Coordinates + BeforeEach(func() { + coords = maven.NewCoordinates(MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID, MAVEN_VERSION) + }) + It("blobaccess for gav", func() { + b := Must(me.BlobAccessForMavenCoords(MAVEN_CENTRAL, coords)) + defer Close(b, "blobaccess") + files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) + Expect(files).To(ConsistOf( + "maven-1.1-RC1.javadoc.javadoc.jar", + "maven-1.1-sources.jar", + "maven-1.1.jar", + "maven-1.1.pom", + )) + }) + } }) }) diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index 714efb41f1..206ef08bf4 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -27,9 +27,9 @@ type Options struct { // Credentials allows to pass credentials and certificates for the http communication Credentials credentials.Credentials // Classifier defines the classifier of the maven file coordinates - Classifier string + Classifier *string // Extension defines the extension of the maven file coordinates - Extension string + Extension *string } func (o *Options) Logger(keyValuePairs ...interface{}) logging.Logger { @@ -88,10 +88,10 @@ func (o *Options) ApplyTo(opts *Options) { if o.Credentials != nil { opts.Credentials = o.Credentials } - if o.Classifier != "" { + if o.Classifier != nil { opts.Classifier = o.Classifier } - if o.Extension != "" { + if o.Extension != nil { opts.Extension = o.Extension } } @@ -157,23 +157,37 @@ func WithCredentials(c credentials.Credentials) Option { type classifier string func (o classifier) ApplyTo(opts *Options) { - opts.Classifier = string(o) + opts.Classifier = optionutils.PointerTo(string(o)) } func WithClassifier(c string) Option { return classifier(c) } +func WithOptionalClassifier(c *string) Option { + if c != nil { + return WithClassifier(*c) + } + return nil +} + //////////////////////////////////////////////////////////////////////////////// type extension string func (o extension) ApplyTo(opts *Options) { - opts.Extension = string(o) + opts.Extension = optionutils.PointerTo(string(o)) } func WithExtension(e string) Option { return extension(e) } +func WithOptionalExtension(e *string) Option { + if e != nil { + return WithExtension(*e) + } + return nil +} + //////////////////////////////////////////////////////////////////////////////// diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..8564f0addae8de5525417df8294d13c0c2a3a7c0 GIT binary patch literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "testchart.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/service.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/service.yaml new file mode 100644 index 0000000000..86baf14821 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "testchart.selectorLabels" . | nindent 4 }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/serviceaccount.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/serviceaccount.yaml new file mode 100644 index 0000000000..f728deb2a6 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "testchart.serviceAccountName" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/tests/test-connection.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/tests/test-connection.yaml new file mode 100644 index 0000000000..a391ef1c46 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "testchart.fullname" . }}-test-connection" + labels: + {{- include "testchart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "testchart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/values.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/values.yaml new file mode 100644 index 0000000000..b598adba92 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart1/values.yaml @@ -0,0 +1,81 @@ +# Default values for testchart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: gcr.io/google_containers/echoserver + pullPolicy: IfNotPresent + tag: "1.0" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.helmignore b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.helmignore new file mode 100644 index 0000000000..0e8a0eb36f --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.idea/somefile b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/.idea/somefile new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/Chart.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/Chart.yaml new file mode 100644 index 0000000000..8f4b7146ce --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: testchart2 +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/NOTES.txt b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/NOTES.txt new file mode 100644 index 0000000000..45e51670a8 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "testchart.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "testchart.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "testchart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "testchart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/_helpers.tpl b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/_helpers.tpl new file mode 100644 index 0000000000..4b0db05bf5 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "testchart.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "testchart.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "testchart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "testchart.labels" -}} +helm.sh/chart: {{ include "testchart.chart" . }} +{{ include "testchart.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "testchart.selectorLabels" -}} +app.kubernetes.io/name: {{ include "testchart.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "testchart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "testchart.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/deployment.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/deployment.yaml new file mode 100644 index 0000000000..69b8e08feb --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "testchart.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "testchart.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "testchart.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/hpa.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/hpa.yaml new file mode 100644 index 0000000000..51734471d4 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "testchart.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/ingress.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/ingress.yaml new file mode 100644 index 0000000000..9732d2a24a --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "testchart.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "testchart.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/service.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/service.yaml new file mode 100644 index 0000000000..86baf14821 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "testchart.fullname" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "testchart.selectorLabels" . | nindent 4 }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/serviceaccount.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/serviceaccount.yaml new file mode 100644 index 0000000000..f728deb2a6 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "testchart.serviceAccountName" . }} + labels: + {{- include "testchart.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/tests/test-connection.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/tests/test-connection.yaml new file mode 100644 index 0000000000..a391ef1c46 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "testchart.fullname" . }}-test-connection" + labels: + {{- include "testchart.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "testchart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/values.yaml b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/values.yaml new file mode 100644 index 0000000000..b598adba92 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/testdata/testchart2/values.yaml @@ -0,0 +1,81 @@ +# Default values for testchart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: gcr.io/google_containers/echoserver + pullPolicy: IfNotPresent + tag: "1.0" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go index 628ef280fd..795ff35581 100644 --- a/pkg/maven/access_test.go +++ b/pkg/maven/access_test.go @@ -6,6 +6,7 @@ import ( . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" + "github.com/open-component-model/ocm/pkg/optionutils" . "github.com/open-component-model/ocm/pkg/testutils" me "github.com/open-component-model/ocm/pkg/maven" @@ -31,19 +32,25 @@ var _ = Describe("local accessmethods.me.AccessSpec tests", func() { repoUrl := "file://" + mvnPATH coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") files := Must(me.GavFiles(repoUrl, coords, nil, env.FileSystem())) - Expect(files).To(YAMLEqual("sdk-modules-bom-5.7.0.pom: 3")) + Expect(files).To(YAMLEqual(` +sdk-modules-bom-5.7.0-random-content.json: 3 +sdk-modules-bom-5.7.0-random-content.txt: 3 +sdk-modules-bom-5.7.0-sources.jar: 3 +sdk-modules-bom-5.7.0.jar: 3 +sdk-modules-bom-5.7.0.pom: 3 +`)) }) It("accesses local artifact file with extension", func() { repoUrl := "file://" + mvnPATH - coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", "", "pom") + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) hash := Must(me.GetHash(coords.Url(repoUrl), nil, crypto.SHA1, env.FileSystem())) Expect(hash).To(Equal("34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) }) - FIt("", func() { + It("", func() { repoUrl := "file://" + mvnPATH - coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", "", "pom") + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) meta := Must(me.GetFileMeta(repoUrl, coords, "sdk-modules-bom-5.7.0.pom", crypto.SHA1, nil, env.FileSystem())) Expect(meta).To(YAMLEqual(` Hash: 34ccdeb9c008f8aaef90873fc636b09d3ae5c709 @@ -53,35 +60,56 @@ var _ = Describe("local accessmethods.me.AccessSpec tests", func() { `)) }) - //It("accesses local artifact with extension", func() { - // acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) - // m := Must(acc.AccessMethod(cv)) - // defer m.Close() - // Expect(m.MimeType()).To(Equal(mime.MIME_XML)) - // r := Must(m.Reader()) - // defer r.Close() - // dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) - // for { - // var buf [8096]byte - // _, err := dr.Read(buf[:]) - // if err != nil { - // break - // } - // } - // Expect(dr.Size()).To(Equal(int64(7153))) - // Expect(dr.Digest().String()).To(Equal("SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) - //}) - // - //It("Describe", func() { - // acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) - // Expect(acc.Describe(nil)).To(Equal("Maven (me) package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) - //}) - // - //It("detects digests mismatch", func() { - // acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) - // m := Must(acc.AccessMethod(cv)) - // defer m.Close() - // _, err := m.Reader() - // Expect(err).To(MatchError(ContainSubstring("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7"))) - //}) + Context("filtering", func() { + var ( + files map[string]crypto.Hash + coords *me.Coordinates + ) + BeforeEach(func() { + repoUrl := "file://" + mvnPATH + coords = me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + files = Must(me.GavFiles(repoUrl, coords, nil, env.FileSystem())) + }) + + It("filters nothing", func() { + Expect(coords.FilterFileMap(files)).To(Equal(files)) + }) + It("filter by empty classifier", func() { + coords.Classifier = optionutils.PointerTo("") + Expect(coords.FilterFileMap(files)).To(YAMLEqual(` +sdk-modules-bom-5.7.0.jar: 3 +sdk-modules-bom-5.7.0.pom: 3 +`)) + }) + It("filter by non-empty classifier", func() { + coords.Classifier = optionutils.PointerTo("random-content") + Expect(coords.FilterFileMap(files)).To(YAMLEqual(` +sdk-modules-bom-5.7.0-random-content.json: 3 +sdk-modules-bom-5.7.0-random-content.txt: 3 +`)) + }) + It("filter by extension", func() { + coords.Extension = optionutils.PointerTo("jar") + Expect(coords.FilterFileMap(files)).To(YAMLEqual(` +sdk-modules-bom-5.7.0-sources.jar: 3 +sdk-modules-bom-5.7.0.jar: 3 +`)) + }) + + It("filter by empty classifier and extension", func() { + coords.Classifier = optionutils.PointerTo("") + coords.Extension = optionutils.PointerTo("jar") + Expect(coords.FilterFileMap(files)).To(YAMLEqual(` +sdk-modules-bom-5.7.0.jar: 3 +`)) + }) + + It("filter by non-empty classifier and extension", func() { + coords.Classifier = optionutils.PointerTo("sources") + coords.Extension = optionutils.PointerTo("jar") + Expect(coords.FilterFileMap(files)).To(YAMLEqual(` +sdk-modules-bom-5.7.0-sources.jar: 3 +`)) + }) + }) }) diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index 7b436432b6..d03ff4c40d 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -5,8 +5,11 @@ package maven import ( + "crypto" "fmt" "github.com/mandelsoft/goutils/generics" + . "github.com/mandelsoft/goutils/regexutils" + "github.com/open-component-model/ocm/pkg/optionutils" "mime" "path" "path/filepath" @@ -15,6 +18,34 @@ import ( ocmmime "github.com/open-component-model/ocm/pkg/mime" ) +type CoordinateOption = optionutils.Option[*Coordinates] + +type WithClassifier string + +func WithOptionalClassifier(c *string) CoordinateOption { + if c != nil { + return WithClassifier(*c) + } + return nil +} + +func (o WithClassifier) ApplyTo(c *Coordinates) { + c.Classifier = optionutils.PointerTo(string(o)) +} + +type WithExtension string + +func WithOptionalExtension(e *string) CoordinateOption { + if e != nil { + return WithExtension(*e) + } + return nil +} + +func (o WithExtension) ApplyTo(c *Coordinates) { + c.Extension = optionutils.PointerTo(string(o)) +} + // Coordinates holds the typical Maven coordinates groupId, artifactId, version. Optional also classifier and extension. // https://maven.apache.org/ref/3.9.6/maven-core/artifact-handlers.html type Coordinates struct { @@ -25,34 +56,30 @@ type Coordinates struct { // Version of the Maven (mvn) artifact. Version string `json:"version"` // Classifier of the Maven (mvn) artifact. - Classifier string `json:"classifier"` //TODO: make it a pointer to differentiate between empty and none + Classifier *string `json:"classifier,omitempty"` //TODO: make it a pointer to differentiate between empty and none // Extension of the Maven (mvn) artifact. - Extension string `json:"extension"` + Extension *string `json:"extension,omitempty"` } -func NewCoordinates(groupId, artifactId, version string, other ...string) *Coordinates { +func NewCoordinates(groupId, artifactId, version string, opts ...CoordinateOption) *Coordinates { c := &Coordinates{ GroupId: groupId, ArtifactId: artifactId, Version: version, } - if len(other) > 0 { - c.Classifier = other[0] - } - if len(other) > 1 { - c.Extension = other[1] - } + optionutils.ApplyOptions(c, opts...) return c } // GAV returns the GAV coordinates of the Maven Coordinates. func (c *Coordinates) GAV() string { + NewCoordinates("a", "b", "c", WithClassifier("a"), WithExtension("c")) return c.GroupId + ":" + c.ArtifactId + ":" + c.Version } -// String returns the Coordinates as a string (GroupId:ArtifactId:Version:Classifier:Extension). +// String returns the Coordinates as a string (GroupId:ArtifactId:Version:WithClassifier:WithExtension). func (c *Coordinates) String() string { - return c.GroupId + ":" + c.ArtifactId + ":" + c.Version + ":" + c.Classifier + ":" + c.Extension + return c.GroupId + ":" + c.ArtifactId + ":" + c.Version + ":" + optionutils.AsValue(c.Classifier) + ":" + optionutils.AsValue(c.Extension) } // GavPath returns the Maven repository path. @@ -61,6 +88,9 @@ func (c *Coordinates) GavPath() string { } func (c *Coordinates) GavUrl(repoUrl string) string { + if strings.HasSuffix(repoUrl, "/") { + return repoUrl + c.GavPath() + } return repoUrl + "/" + c.GavPath() } @@ -69,11 +99,11 @@ func (c *Coordinates) GavUrl(repoUrl string) string { // Default extension is jar. func (c *Coordinates) FilePath() string { path := c.GavPath() + "/" + c.FileNamePrefix() - if c.Classifier != "" { - path += "-" + c.Classifier + if optionutils.AsValue(c.Classifier) != "" { + path += "-" + *c.Classifier } - if c.Extension != "" { - path += "." + c.Extension + if optionutils.AsValue(c.Extension) != "" { + path += "." + *c.Extension } else { path += ".jar" } @@ -81,6 +111,9 @@ func (c *Coordinates) FilePath() string { } func (c *Coordinates) Url(baseUrl string) string { + if strings.HasSuffix(baseUrl, "/") { + return baseUrl + c.FilePath() + } return baseUrl + "/" + c.FilePath() } @@ -107,19 +140,19 @@ func (c *Coordinates) SetClassifierExtensionBy(filename string) error { if i < 0 { return fmt.Errorf("no extension after classifier found in filename: %s", filename) } - c.Classifier = s[:i] - s = strings.TrimPrefix(s, c.Classifier) + c.Classifier = optionutils.PointerTo(s[:i]) + s = strings.TrimPrefix(s, optionutils.AsValue(c.Classifier)) } else { - c.Classifier = "" + c.Classifier = nil } - c.Extension = strings.TrimPrefix(s, ".") + c.Extension = optionutils.PointerTo(strings.TrimPrefix(s, ".")) return nil } // MimeType returns the MIME type of the Maven Coordinates based on the file extension. // Default is application/x-tgz. func (c *Coordinates) MimeType() string { - m := mime.TypeByExtension("." + c.Extension) + m := mime.TypeByExtension("." + optionutils.AsValue(c.Extension)) if m != "" { return m } @@ -131,24 +164,49 @@ func (c *Coordinates) Copy() *Coordinates { return generics.Pointer(*c) } +func (c *Coordinates) FilterFileMap(fileMap map[string]crypto.Hash) map[string]crypto.Hash { + if c.Classifier == nil && c.Extension == nil { + return fileMap + } + exp := Literal(c.ArtifactId + "-" + c.Version) + if optionutils.AsValue(c.Classifier) != "" { + exp = Sequence(exp, Literal("-"+*c.Classifier)) + } + if optionutils.AsValue(c.Extension) != "" { + if c.Classifier == nil { + exp = Sequence(exp, Optional(Literal("-"), Match(".+"))) + } + exp = Sequence(exp, Literal("."+*c.Extension)) + } else { + exp = Sequence(exp, Literal("."), Match(".*")) + } + exp = Anchored(exp) + for file := range fileMap { + if !exp.MatchString(file) { + delete(fileMap, file) + } + } + return fileMap +} + // Parse creates a Coordinates from it's serialized form (see Coordinates.String). func Parse(serializedArtifact string) (*Coordinates, error) { parts := strings.Split(serializedArtifact, ":") if len(parts) < 3 { - return nil, fmt.Errorf("invalid artifact string: %s", serializedArtifact) + return nil, fmt.Errorf("invalid coordination string: %s", serializedArtifact) } - artifact := &Coordinates{ + coords := &Coordinates{ GroupId: parts[0], ArtifactId: parts[1], Version: parts[2], } if len(parts) >= 4 { - artifact.Classifier = parts[3] + coords.Classifier = optionutils.PointerTo(parts[3]) } if len(parts) >= 5 { - artifact.Extension = parts[4] + coords.Extension = optionutils.PointerTo(parts[4]) } - return artifact, nil + return coords, nil } // IsResource returns true if the filename is not a checksum or signature file. diff --git a/pkg/maven/coordinates_test.go b/pkg/maven/coordinates_test.go index 32f78db66f..fab400b5c2 100644 --- a/pkg/maven/coordinates_test.go +++ b/pkg/maven/coordinates_test.go @@ -7,55 +7,47 @@ package maven_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - me "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/optionutils" + . "github.com/open-component-model/ocm/pkg/testutils" ) var _ = Describe("Maven Test Environment", func() { It("GAV, GroupPath, FilePath", func() { - artifact := &me.Coordinates{ - GroupId: "ocm.software", - ArtifactId: "hello-ocm", - Version: "0.0.1", - Extension: "jar", - } - Expect(artifact.GAV()).To(Equal("ocm.software:hello-ocm:0.0.1")) - Expect(artifact.GroupPath()).To(Equal("ocm/software")) - Expect(artifact.FilePath()).To(Equal("ocm/software/hello-ocm/0.0.1/hello-ocm-0.0.1.jar")) + coords := me.NewCoordinates("ocm.software", "hello-ocm", "0.0.1", me.WithExtension("jar")) + Expect(coords.GAV()).To(Equal("ocm.software:hello-ocm:0.0.1")) + Expect(coords.GroupPath()).To(Equal("ocm/software")) + Expect(coords.FilePath()).To(Equal("ocm/software/hello-ocm/0.0.1/hello-ocm-0.0.1.jar")) }) It("SetClassifierExtensionBy", func() { - artifact := &me.Coordinates{ - GroupId: "ocm.software", - ArtifactId: "hello-ocm", - Version: "0.0.1", - } - artifact.SetClassifierExtensionBy("hello-ocm-0.0.1.pom") - Expect(artifact.Classifier).To(Equal("")) - Expect(artifact.Extension).To(Equal("pom")) - - artifact.SetClassifierExtensionBy("hello-ocm-0.0.1-tests.jar") - Expect(artifact.Classifier).To(Equal("tests")) - Expect(artifact.Extension).To(Equal("jar")) - - artifact.ArtifactId = "apache-me" - artifact.Version = "3.9.6" - artifact.SetClassifierExtensionBy("apache-me-3.9.6-bin.tar.gz") - Expect(artifact.Classifier).To(Equal("bin")) - Expect(artifact.Extension).To(Equal("tar.gz")) + coords := me.NewCoordinates("ocm.software", "hello-ocm", "0.0.1") + MustBeSuccessful(coords.SetClassifierExtensionBy("hello-ocm-0.0.1.pom")) + Expect(coords.Classifier).To(BeNil()) + Expect(optionutils.AsValue(coords.Extension)).To(Equal("pom")) + + MustBeSuccessful(coords.SetClassifierExtensionBy("hello-ocm-0.0.1-tests.jar")) + Expect(optionutils.AsValue(coords.Classifier)).To(Equal("tests")) + Expect(optionutils.AsValue(coords.Extension)).To(Equal("jar")) + + coords.ArtifactId = "apache-me" + coords.Version = "3.9.6" + MustBeSuccessful(coords.SetClassifierExtensionBy("apache-me-3.9.6-bin.tar.gz")) + Expect(optionutils.AsValue(coords.Classifier)).To(Equal("bin")) + Expect(optionutils.AsValue(coords.Extension)).To(Equal("tar.gz")) }) It("parse GAV", func() { gav := "org.apache.commons:commons-compress:1.26.1:cyclonedx:xml" - artifact, err := me.Parse(gav) + coords, err := me.Parse(gav) Expect(err).To(BeNil()) - Expect(artifact.String()).To(Equal(gav)) - Expect(artifact.GroupId).To(Equal("org.apache.commons")) - Expect(artifact.ArtifactId).To(Equal("commons-compress")) - Expect(artifact.Version).To(Equal("1.26.1")) - Expect(artifact.Classifier).To(Equal("cyclonedx")) - Expect(artifact.Extension).To(Equal("xml")) - Expect(artifact.FilePath()).To(Equal("org/apache/commons/commons-compress/1.26.1/commons-compress-1.26.1-cyclonedx.xml")) + Expect(coords.String()).To(Equal(gav)) + Expect(coords.GroupId).To(Equal("org.apache.commons")) + Expect(coords.ArtifactId).To(Equal("commons-compress")) + Expect(coords.Version).To(Equal("1.26.1")) + Expect(optionutils.AsValue(coords.Classifier)).To(Equal("cyclonedx")) + Expect(optionutils.AsValue(coords.Extension)).To(Equal("xml")) + Expect(coords.FilePath()).To(Equal("org/apache/commons/commons-compress/1.26.1/commons-compress-1.26.1-cyclonedx.xml")) }) }) diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json new file mode 100644 index 0000000000..2f1fc35fdc --- /dev/null +++ b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json @@ -0,0 +1 @@ +{"some": "test content"} \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 new file mode 100644 index 0000000000..d6836aeaa0 --- /dev/null +++ b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 @@ -0,0 +1 @@ +f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt new file mode 100644 index 0000000000..b4af84697f --- /dev/null +++ b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt @@ -0,0 +1 @@ +some test content \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 new file mode 100644 index 0000000000..55eceeb992 --- /dev/null +++ b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 @@ -0,0 +1 @@ +dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..8564f0addae8de5525417df8294d13c0c2a3a7c0 GIT binary patch literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo Date: Thu, 23 May 2024 19:02:28 +0200 Subject: [PATCH 03/13] access method --- pkg/blobaccess/maven/access_test.go | 16 +- pkg/blobaccess/maven/options.go | 14 +- pkg/blobaccess/maven/utils.go | 12 + pkg/contexts/ocm/accessmethods/init.go | 2 +- .../accessmethods/{mvn => maven}/README.md | 0 .../ocm/accessmethods/{mvn => maven}/cli.go | 2 +- .../ocm/accessmethods/maven/method.go | 134 ++++++ .../ocm/accessmethods/maven/method_test.go | 132 ++++++ .../{mvn => maven}/suite_test.go | 2 +- .../5.7.0/sdk-modules-bom-5.7.0.pom | 0 .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 0 .../fail/test/repository/42/repository-42.pom | 0 .../test/repository/42/repository-42.pom.sha1 | 0 .../ocm/accessmethods/mvn/integration_test.go | 98 ---- pkg/contexts/ocm/accessmethods/mvn/method.go | 443 ------------------ .../ocm/accessmethods/mvn/method_test.go | 87 ---- .../handlers/generic/mvn/blobhandler.go | 4 +- pkg/maven/coordinates.go | 9 +- 18 files changed, 299 insertions(+), 656 deletions(-) rename pkg/contexts/ocm/accessmethods/{mvn => maven}/README.md (100%) rename pkg/contexts/ocm/accessmethods/{mvn => maven}/cli.go (99%) create mode 100644 pkg/contexts/ocm/accessmethods/maven/method.go create mode 100644 pkg/contexts/ocm/accessmethods/maven/method_test.go rename pkg/contexts/ocm/accessmethods/{mvn => maven}/suite_test.go (90%) rename pkg/contexts/ocm/accessmethods/{mvn => maven}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom (100%) rename pkg/contexts/ocm/accessmethods/{mvn => maven}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 (100%) rename pkg/contexts/ocm/accessmethods/{mvn => maven}/testdata/fail/test/repository/42/repository-42.pom (100%) rename pkg/contexts/ocm/accessmethods/{mvn => maven}/testdata/fail/test/repository/42/repository-42.pom.sha1 (100%) delete mode 100644 pkg/contexts/ocm/accessmethods/mvn/integration_test.go delete mode 100644 pkg/contexts/ocm/accessmethods/mvn/method.go delete mode 100644 pkg/contexts/ocm/accessmethods/mvn/method_test.go diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index 869162a5ca..679f197c1b 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -17,13 +17,13 @@ import ( ) const ( - mvnPATH = "/testdata/.m2/repository" - FAILPATH = "/testdata/.m2/fail" - - MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" - MAVEN_GROUP_ID = "maven" - MAVEN_ARTIFACT_ID = "maven" - MAVEN_VERSION = "1.1" + mvnPATH = "/testdata/.m2/repository" + FAILPATH = "/testdata/.m2/fail" + MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" + MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" + MAVEN_GROUP_ID = "maven" + MAVEN_ARTIFACT_ID = "maven" + MAVEN_VERSION = "1.1" ) var _ = Describe("blobaccess for maven", func() { @@ -109,7 +109,7 @@ var _ = Describe("blobaccess for maven", func() { }) Context("maven http repository", func() { - if PingTCPServer("repo.maven.apache.org:443", time.Second) == nil { + if PingTCPServer(MAVEN_CENTRAL_ADDRESS, time.Second) == nil { var coords *maven.Coordinates BeforeEach(func() { coords = maven.NewCoordinates(MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID, MAVEN_VERSION) diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index 206ef08bf4..a12f4a24b8 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -43,20 +43,10 @@ func (o *Options) Cache() *tmpcache.Attribute { return tmpcache.Get(o.CachingContext) } -func mapCredentials(creds credentials.Credentials) maven.Credentials { - if creds == nil || (!creds.ExistsProperty(identity.ATTR_USERNAME) && !creds.ExistsProperty(identity.ATTR_PASSWORD)) { - return nil - } - return &maven.BasicAuthCredentials{ - Username: creds.GetProperty(identity.ATTR_USERNAME), - Password: creds.GetProperty(identity.ATTR_PASSWORD), - } -} - func (o *Options) GetCredentials(repoUrl, groupId string) (maven.Credentials, error) { switch { case o.Credentials != nil: - return mapCredentials(o.Credentials), nil + return MapCredentials(o.Credentials), nil case o.CredentialContext != nil: consumerid, err := identity.GetConsumerId(repoUrl, groupId) if err != nil { @@ -66,7 +56,7 @@ func (o *Options) GetCredentials(repoUrl, groupId string) (maven.Credentials, er if err != nil { return nil, err } - return mapCredentials(creds), nil + return MapCredentials(creds), nil default: return nil, nil } diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index c2d5f8b709..735706f783 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -13,6 +13,8 @@ import ( "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" + "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/maven" "github.com/open-component-model/ocm/pkg/mime" @@ -143,3 +145,13 @@ func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts acc := blobaccess.DataAccessForReaderFunction(reader, meta.Url) return accessobj.CachedBlobAccessForWriterWithCache(opts.Cache(), meta.MimeType, accessio.NewDataAccessWriter(acc)), nil } + +func MapCredentials(creds credentials.Credentials) maven.Credentials { + if creds == nil || (!creds.ExistsProperty(identity.ATTR_USERNAME) && !creds.ExistsProperty(identity.ATTR_PASSWORD)) { + return nil + } + return &maven.BasicAuthCredentials{ + Username: creds.GetProperty(identity.ATTR_USERNAME), + Password: creds.GetProperty(identity.ATTR_PASSWORD), + } +} diff --git a/pkg/contexts/ocm/accessmethods/init.go b/pkg/contexts/ocm/accessmethods/init.go index f0a70ce7dd..55ffe41be8 100644 --- a/pkg/contexts/ocm/accessmethods/init.go +++ b/pkg/contexts/ocm/accessmethods/init.go @@ -6,7 +6,7 @@ import ( _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localfsblob" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localociblob" - _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/mvn" + _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/none" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/npm" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact" diff --git a/pkg/contexts/ocm/accessmethods/mvn/README.md b/pkg/contexts/ocm/accessmethods/maven/README.md similarity index 100% rename from pkg/contexts/ocm/accessmethods/mvn/README.md rename to pkg/contexts/ocm/accessmethods/maven/README.md diff --git a/pkg/contexts/ocm/accessmethods/mvn/cli.go b/pkg/contexts/ocm/accessmethods/maven/cli.go similarity index 99% rename from pkg/contexts/ocm/accessmethods/mvn/cli.go rename to pkg/contexts/ocm/accessmethods/maven/cli.go index dd81479a6b..a6211bebbd 100644 --- a/pkg/contexts/ocm/accessmethods/mvn/cli.go +++ b/pkg/contexts/ocm/accessmethods/maven/cli.go @@ -1,4 +1,4 @@ -package mvn +package maven import ( "github.com/open-component-model/ocm/pkg/cobrautils/flagsets" diff --git a/pkg/contexts/ocm/accessmethods/maven/method.go b/pkg/contexts/ocm/accessmethods/maven/method.go new file mode 100644 index 0000000000..cc1feaf4f5 --- /dev/null +++ b/pkg/contexts/ocm/accessmethods/maven/method.go @@ -0,0 +1,134 @@ +package maven + +import ( + "fmt" + + "github.com/mandelsoft/goutils/optionutils" + + "github.com/open-component-model/ocm/pkg/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" + "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" + "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/runtime" +) + +// Type is the access type of Maven (mvn) repository. +const ( + Type = "maven" + TypeV1 = Type + runtime.VersionSeparator + "v1" +) + +func init() { + accspeccpi.RegisterAccessType(accspeccpi.NewAccessSpecType[*AccessSpec](Type, accspeccpi.WithDescription(usage))) + accspeccpi.RegisterAccessType(accspeccpi.NewAccessSpecType[*AccessSpec](TypeV1, accspeccpi.WithFormatSpec(formatV1), accspeccpi.WithConfigHandler(ConfigHandler()))) +} + +// AccessSpec describes the access for a Maven (mvn) artifact. +type AccessSpec struct { + runtime.ObjectVersionedType `json:",inline"` + + // Repository is the base URL of the Maven (mvn) repository. + Repository string `json:"repository"` + + maven.Coordinates `json:",inline"` +} + +// Option defines the interface function "ApplyTo()". +type Option = maven.CoordinateOption + +type WithClassifier = maven.WithClassifier + +func WithOptionalClassifier(c *string) Option { + return maven.WithOptionalClassifier(c) +} + +type WithExtension = maven.WithExtension + +func WithOptionalExtension(e *string) Option { + return maven.WithOptionalExtension(e) +} + +/////////////////////////////////////////////////////////////////////////////// + +var _ accspeccpi.AccessSpec = (*AccessSpec)(nil) + +// New creates a new Maven (mvn) repository access spec version v1. +func New(repository, groupId, artifactId, version string, opts ...Option) *AccessSpec { + accessSpec := &AccessSpec{ + ObjectVersionedType: runtime.NewVersionedTypedObject(Type), + Repository: repository, + Coordinates: *maven.NewCoordinates(groupId, artifactId, version, opts...), + } + return accessSpec +} + +func (a *AccessSpec) Describe(_ accspeccpi.Context) string { + return fmt.Sprintf("Maven (mvn) package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.Repository, a.Coordinates.FilePath()) +} + +func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool { + return false +} + +func (a *AccessSpec) GlobalAccessSpec(_ accspeccpi.Context) accspeccpi.AccessSpec { + return a +} + +// GetReferenceHint returns the reference hint for the Maven (mvn) artifact. +func (a *AccessSpec) GetReferenceHint(_ accspeccpi.ComponentVersionAccess) string { + return a.String() +} + +func (_ *AccessSpec) GetType() string { + return Type +} + +func (a *AccessSpec) AccessMethod(cv accspeccpi.ComponentVersionAccess) (accspeccpi.AccessMethod, error) { + octx := cv.GetContext() + factory := func() (blobaccess.BlobAccess, error) { + return mavenblob.BlobAccessForMavenCoords(a.Repository, &a.Coordinates, + mavenblob.WithCredentialContext(octx), + mavenblob.WithLoggingContext(octx), + mavenblob.WithFileSystem(vfsattr.Get(octx))) + } + return accspeccpi.AccessMethodForImplementation(accspeccpi.NewDefaultMethodImpl(cv, a, "", a.MimeType(), factory), nil) +} + +func (a *AccessSpec) GetInexpensiveContentVersionIdentity(cv accspeccpi.ComponentVersionAccess) string { + creds, err := identity.GetCredentials(cv.GetContext(), a.Repository, a.GroupId) + if err != nil { + return "" + } + mvncreds := mavenblob.MapCredentials(creds) + fs := vfsattr.Get(cv.GetContext()) + files, err := maven.GavFiles(a.Repository, &a.Coordinates, mvncreds, fs) + if err != nil { + return "" + } + files = a.Coordinates.FilterFileMap(files) + if len(files) != 1 { + return "" + } + if optionutils.AsValue(a.Extension) == "" { + return "" + } + for _, h := range files { + id, _ := maven.GetHash(a.Url(a.Repository), mvncreds, h, fs) + return id + } + return "" +} + +func (a *AccessSpec) BaseUrl() string { + return a.Repository + "/" + a.GavPath() +} + +func (a *AccessSpec) ArtifactUrl() string { + return a.Url(a.Repository) +} + +func (a *AccessSpec) GetCoordinates() *maven.Coordinates { + return a.Coordinates.Copy() +} diff --git a/pkg/contexts/ocm/accessmethods/maven/method_test.go b/pkg/contexts/ocm/accessmethods/maven/method_test.go new file mode 100644 index 0000000000..3372a80200 --- /dev/null +++ b/pkg/contexts/ocm/accessmethods/maven/method_test.go @@ -0,0 +1,132 @@ +package maven_test + +import ( + "crypto" + me "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" + "github.com/open-component-model/ocm/pkg/utils/tarutils" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/open-component-model/ocm/pkg/contexts/ocm" + "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + "github.com/open-component-model/ocm/pkg/iotools" + "github.com/open-component-model/ocm/pkg/mime" + . "github.com/open-component-model/ocm/pkg/testutils" +) + +const ( + mvnPATH = "/testdata/.m2/repository" + FAILPATH = "/testdata/fail" + MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" + MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" + MAVEN_GROUP_ID = "maven" + MAVEN_ARTIFACT_ID = "maven" + MAVEN_VERSION = "1.1" +) + +var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { + var env *Builder + var cv ocm.ComponentVersionAccess + + BeforeEach(func() { + env = NewBuilder(TestData()) + cv = &cpi.DummyComponentVersionAccess{env.OCMContext()} + }) + + AfterEach(func() { + env.Cleanup() + }) + + It("accesses local artifact", func() { + acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + m := Must(acc.AccessMethod(cv)) + defer m.Close() + Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) + r := Must(m.Reader()) + defer r.Close() + dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) + for { + var buf [8096]byte + _, err := dr.Read(buf[:]) + if err != nil { + break + } + } + Expect(dr.Size()).To(Equal(int64(1109))) + Expect(dr.Digest().String()).To(Equal("SHA-1:4ee125ffe4f7690588833f1217a13cc741e4df5f")) + }) + + It("accesses local artifact with empty classifier and with extension", func() { + acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) + m := Must(acc.AccessMethod(cv)) + defer Close(m) + Expect(m.MimeType()).To(Equal(mime.MIME_XML)) + r := Must(m.Reader()) + defer Close(r) + + dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) + for { + var buf [8096]byte + _, err := dr.Read(buf[:]) + if err != nil { + break + } + } + + Expect(dr.Size()).To(Equal(int64(7153))) + Expect(dr.Digest().String()).To(Equal("SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) + }) + + It("accesses local artifact with extension", func() { + acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) + m := Must(acc.AccessMethod(cv)) + defer m.Close() + Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) + r := Must(m.Reader()) + defer r.Close() + dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) + list := Must(tarutils.ListArchiveContentFromReader(dr)) + Expect(list).To(HaveLen(1)) + Expect(dr.Size()).To(Equal(int64(1109))) + Expect(dr.Digest().String()).To(Equal("SHA-1:4ee125ffe4f7690588833f1217a13cc741e4df5f")) + }) + + It("Describe", func() { + acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) + Expect(acc.Describe(nil)).To(Equal("Maven (mvn) package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) + }) + + It("detects digests mismatch", func() { + acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) + m := Must(acc.AccessMethod(cv)) + defer m.Close() + _, err := m.Reader() + Expect(err).To(MatchError(ContainSubstring("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7"))) + }) + + Context("me http repository", func() { + if PingTCPServer(MAVEN_CENTRAL_ADDRESS, time.Second) == nil { + It("blobaccess for gav", func() { + acc := me.New(MAVEN_CENTRAL, MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID, MAVEN_VERSION) + m := Must(acc.AccessMethod(cv)) + defer Close(m) + files := Must(tarutils.ListArchiveContentFromReader(Must(m.Reader()))) + Expect(files).To(ConsistOf( + "maven-1.1-RC1.javadoc.javadoc.jar", + "maven-1.1-sources.jar", + "maven-1.1.jar", + "maven-1.1.pom", + )) + }) + + It("inexpensive id", func() { + acc := me.New(MAVEN_CENTRAL, MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID, MAVEN_VERSION, me.WithClassifier(""), me.WithExtension("pom")) + Expect(acc.GetInexpensiveContentVersionIdentity(cv)).To(Equal("4fb753e1a4ab7acebc39557f1aa292052775b0d8")) + }) + } + }) +}) diff --git a/pkg/contexts/ocm/accessmethods/mvn/suite_test.go b/pkg/contexts/ocm/accessmethods/maven/suite_test.go similarity index 90% rename from pkg/contexts/ocm/accessmethods/mvn/suite_test.go rename to pkg/contexts/ocm/accessmethods/maven/suite_test.go index c62cadc7b0..0892bc9a7f 100644 --- a/pkg/contexts/ocm/accessmethods/mvn/suite_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/suite_test.go @@ -1,4 +1,4 @@ -package mvn_test +package maven_test import ( "testing" diff --git a/pkg/contexts/ocm/accessmethods/mvn/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom b/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom similarity index 100% rename from pkg/contexts/ocm/accessmethods/mvn/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom rename to pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom diff --git a/pkg/contexts/ocm/accessmethods/mvn/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 similarity index 100% rename from pkg/contexts/ocm/accessmethods/mvn/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 rename to pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 diff --git a/pkg/contexts/ocm/accessmethods/mvn/testdata/fail/test/repository/42/repository-42.pom b/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom similarity index 100% rename from pkg/contexts/ocm/accessmethods/mvn/testdata/fail/test/repository/42/repository-42.pom rename to pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom diff --git a/pkg/contexts/ocm/accessmethods/mvn/testdata/fail/test/repository/42/repository-42.pom.sha1 b/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom.sha1 similarity index 100% rename from pkg/contexts/ocm/accessmethods/mvn/testdata/fail/test/repository/42/repository-42.pom.sha1 rename to pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom.sha1 diff --git a/pkg/contexts/ocm/accessmethods/mvn/integration_test.go b/pkg/contexts/ocm/accessmethods/mvn/integration_test.go deleted file mode 100644 index b2eca2b1d0..0000000000 --- a/pkg/contexts/ocm/accessmethods/mvn/integration_test.go +++ /dev/null @@ -1,98 +0,0 @@ -//go:build integration - -package mvn_test - -import ( - "crypto" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/open-component-model/ocm/pkg/contexts/ocm" - "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/mvn" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" - . "github.com/open-component-model/ocm/pkg/env" - . "github.com/open-component-model/ocm/pkg/env/builder" - "github.com/open-component-model/ocm/pkg/mime" - . "github.com/open-component-model/ocm/pkg/testutils" - "github.com/open-component-model/ocm/pkg/utils/tarutils" -) - -var _ = Describe("online accessmethods.mvn.AccessSpec integration tests", func() { - var env *Builder - var cv ocm.ComponentVersionAccess - - BeforeEach(func() { - env = NewBuilder(TestData()) - cv = &cpi.DummyComponentVersionAccess{env.OCMContext()} - }) - - AfterEach(func() { - env.Cleanup() - }) - - // https://repo1.maven.org/maven2/com/sap/cloud/sdk/sdk-modules-bom/5.7.0 - It("one single pom only", func() { - acc := mvn.New("https://repo1.maven.org/maven2", "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - files, err := acc.GavFiles(cv.GetContext()) - Expect(err).ToNot(HaveOccurred()) - Expect(files).To(HaveLen(1)) - Expect(files["sdk-modules-bom-5.7.0.pom"]).To(Equal(crypto.SHA1)) - }) - It("GetPackageMeta - com.sap.cloud.sdk", func() { - acc := mvn.New("https://repo1.maven.org/maven2", "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - meta, err := acc.GetPackageMeta(ocm.DefaultContext()) - Expect(err).ToNot(HaveOccurred()) - Expect(meta.Bin).To(HavePrefix("file://")) - Expect(meta.Bin).To(ContainSubstring("mvn-sdk-modules-bom-5.7.0-")) - Expect(meta.Bin).To(HaveSuffix(".tar.gz")) - Expect(meta.Hash).To(Equal("345fe2e640663c3cd6ac87b7afb92e1c934f665f75ddcb9555bc33e1813ef00b")) - Expect(meta.HashType).To(Equal(crypto.SHA256)) - }) - - // https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.6 - It("apache-maven, with bin + tar.gz etc.", func() { - acc := mvn.New("https://repo1.maven.org/maven2", "org.apache.maven", "apache-maven", "3.9.6") - Expect(acc).ToNot(BeNil()) - Expect(acc.BaseUrl()).To(Equal("https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.6")) - files, err := acc.GavFiles(cv.GetContext()) - Expect(err).ToNot(HaveOccurred()) - Expect(files).To(HaveLen(8)) - Expect(files["apache-maven-3.9.6-src.zip"]).To(Equal(crypto.SHA512)) - Expect(files["apache-maven-3.9.6.pom"]).To(Equal(crypto.SHA1)) - }) - - // https://repo1.maven.org/maven2/com/sap/cloud/environment/servicebinding/java-sap-vcap-services/0.10.4 - It("accesses local artifact", func() { - acc := mvn.New("https://repo1.maven.org/maven2", "com.sap.cloud.environment.servicebinding", "java-sap-vcap-services", "0.10.4") - meta, err := acc.GetPackageMeta(ocm.DefaultContext()) - Expect(err).ToNot(HaveOccurred()) - Expect(meta.Bin).To(HavePrefix("file://")) - m := Must(acc.AccessMethod(cv)) - defer m.Close() - Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) - /* manually also tested with repos: - - https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.26.1/ // cyclonedx - - https://repo1.maven.org/maven2/cn/afternode/commons/commons/1.6/ // gradle module! - */ - }) - - // https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.6 - It("apache-maven, 'bin' zip + tar.gz only!", func() { - acc := mvn.New("https://repo1.maven.org/maven2", "org.apache.maven", "apache-maven", "3.9.6", mvn.WithClassifier("bin")) - Expect(acc).ToNot(BeNil()) - Expect(acc.BaseUrl()).To(Equal("https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.9.6")) - files, err := acc.GavFiles(cv.GetContext()) - Expect(err).ToNot(HaveOccurred()) - Expect(files).To(HaveLen(8)) // the repo contains 8 files... - m := Must(acc.AccessMethod(cv)) - defer m.Close() - Expect(err).ToNot(HaveOccurred()) - Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) - r := Must(m.Reader()) - defer r.Close() - list, err := tarutils.ListArchiveContentFromReader(r) - Expect(err).ToNot(HaveOccurred()) - Expect(list).To(HaveLen(2)) // ...but with the classifier set, we're interested only in two! - }) -}) diff --git a/pkg/contexts/ocm/accessmethods/mvn/method.go b/pkg/contexts/ocm/accessmethods/mvn/method.go deleted file mode 100644 index a8a15e7162..0000000000 --- a/pkg/contexts/ocm/accessmethods/mvn/method.go +++ /dev/null @@ -1,443 +0,0 @@ -package mvn - -import ( - "bytes" - "context" - "crypto" - "fmt" - "github.com/open-component-model/ocm/pkg/maven" - "io" - "net/http" - "path" - "sort" - "strings" - - "github.com/mandelsoft/goutils/errors" - "github.com/mandelsoft/goutils/optionutils" - "github.com/mandelsoft/vfs/pkg/osfs" - "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/opencontainers/go-digest" - "golang.org/x/exp/slices" - "golang.org/x/net/html" - - "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/credentials/builtin/maven/identity" - "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" - "github.com/open-component-model/ocm/pkg/iotools" - "github.com/open-component-model/ocm/pkg/logging" - "github.com/open-component-model/ocm/pkg/mime" - "github.com/open-component-model/ocm/pkg/runtime" - "github.com/open-component-model/ocm/pkg/utils" - "github.com/open-component-model/ocm/pkg/utils/tarutils" -) - -// Type is the access type of Maven (mvn) repository. -const ( - Type = "mvn" - TypeV1 = Type + runtime.VersionSeparator + "v1" -) - -func init() { - accspeccpi.RegisterAccessType(accspeccpi.NewAccessSpecType[*AccessSpec](Type, accspeccpi.WithDescription(usage))) - accspeccpi.RegisterAccessType(accspeccpi.NewAccessSpecType[*AccessSpec](TypeV1, accspeccpi.WithFormatSpec(formatV1), accspeccpi.WithConfigHandler(ConfigHandler()))) -} - -// AccessSpec describes the access for a Maven (mvn) artifact. -type AccessSpec struct { - runtime.ObjectVersionedType `json:",inline"` - - // Repository is the base URL of the Maven (mvn) repository. - Repository string `json:"repository"` - - maven.Coordinates `json:",inline"` -} - -// Option defines the interface function "ApplyTo()". -type Option = optionutils.Option[*AccessSpec] - -var _ accspeccpi.AccessSpec = (*AccessSpec)(nil) - -var log = logging.DynamicLogger(identity.REALM) - -// New creates a new Maven (mvn) repository access spec version v1. -func New(repository, groupId, artifactId, version string, options ...Option) *AccessSpec { - accessSpec := &AccessSpec{ - ObjectVersionedType: runtime.NewVersionedTypedObject(Type), - Repository: repository, - Coordinates: maven.Coordinates{ - GroupId: groupId, - ArtifactId: artifactId, - Version: version, - }, - } - optionutils.ApplyOptions(accessSpec, options...) - return accessSpec -} - -// classifier Option for Maven (mvn) Coordinates. -type classifier string - -func (c classifier) ApplyTo(a *AccessSpec) { - a.Classifier = optionutils.PointerTo(string(c)) -} - -// WithClassifier sets the classifier of the Maven (mvn) artifact. -func WithClassifier(c string) Option { - return classifier(c) -} - -// extension Option for Maven (mvn) Coordinates. -type extension string - -func (e extension) ApplyTo(a *AccessSpec) { - a.Extension = optionutils.PointerTo(string(e)) -} - -// WithExtension sets the extension of the Maven (mvn) artifact. -func WithExtension(e string) Option { - return extension(e) -} - -func (a *AccessSpec) Describe(_ accspeccpi.Context) string { - return fmt.Sprintf("Maven (mvn) package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.Repository, a.Coordinates.FilePath()) -} - -func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool { - return false -} - -func (a *AccessSpec) GlobalAccessSpec(_ accspeccpi.Context) accspeccpi.AccessSpec { - return a -} - -// GetReferenceHint returns the reference hint for the Maven (mvn) artifact. -func (a *AccessSpec) GetReferenceHint(_ accspeccpi.ComponentVersionAccess) string { - return a.String() -} - -func (_ *AccessSpec) GetType() string { - return Type -} - -func (a *AccessSpec) AccessMethod(c accspeccpi.ComponentVersionAccess) (accspeccpi.AccessMethod, error) { - return accspeccpi.AccessMethodForImplementation(newMethod(c, a)) -} - -func (a *AccessSpec) GetInexpensiveContentVersionIdentity(access accspeccpi.ComponentVersionAccess) string { - meta, _ := a.GetPackageMeta(access.GetContext()) - if meta != nil { - return meta.Hash - } - return "" -} - -func (a *AccessSpec) BaseUrl() string { - return a.Repository + "/" + a.GavPath() -} - -func (a *AccessSpec) ArtifactUrl() string { - return a.Url(a.Repository) -} - -func (a *AccessSpec) GetCoordinates() *maven.Coordinates { - return a.Coordinates.Copy() -} - -type meta struct { - MimeType string `json:"packaging"` - HashType crypto.Hash `json:"hashType"` - Hash string `json:"hash"` - Bin string `json:"bin"` -} - -func update(a *AccessSpec, file string, hash crypto.Hash, metadata *meta, ctx accspeccpi.Context, fs vfs.FileSystem) error { - artifact := a.GetCoordinates() - err := artifact.SetClassifierExtensionBy(file) - if err != nil { - return err - } - metadata.Bin = artifact.Url(a.Repository) - log := log.WithValues("file", metadata.Bin) - log.Debug("processing") - metadata.MimeType = artifact.MimeType() - if hash > 0 { - metadata.HashType = hash - metadata.Hash, err = getStringData(ctx, metadata.Bin+hashUrlExt(hash), fs) - if err != nil { - return errors.Wrapf(err, "cannot read %s digest of: %s", hash, metadata.Bin) - } - } else { - log.Warn("no digest available") - } - return nil -} - -func (a *AccessSpec) GetPackageMeta(ctx accspeccpi.Context) (*meta, error) { - fs := vfsattr.Get(ctx) - - log := log.WithValues("BaseUrl", a.BaseUrl()) - fileMap, err := a.GavFiles(ctx, fs) - if err != nil { - return nil, err - } - - if optionutils.AsValue(a.Classifier) != "" { - fileMap = filterByClassifier(fileMap, *a.Classifier) - } - - switch l := len(fileMap); { - case l <= 0: - return nil, errors.New("no maven artifact files found") - case l == 1 && (optionutils.AsValue(a.Extension) != "" || optionutils.AsValue(a.Classifier) != ""): - metadata := meta{} - for file, hash := range fileMap { - update(a, file, hash, &metadata, ctx, fs) - } - return &metadata, nil - // default: continue below with: create tempFs where all files can be downloaded to and packed together as tar.gz - } - - if (optionutils.AsValue(a.Extension) == "") != (optionutils.AsValue(a.Classifier) == "") { // XOR - log.Warn("Either classifier or extension have been specified, which results in an incomplete GAV!") - } - tempFs, err := osfs.NewTempFileSystem() - if err != nil { - return nil, err - } - defer vfs.Cleanup(tempFs) - - metadata := meta{} - for file, hash := range fileMap { - update(a, file, hash, &metadata, ctx, fs) - - // download the artifact into the temporary file system - e := func() error { - out, err := tempFs.Create(file) - if err != nil { - return err - } - defer out.Close() - reader, err := getReader(ctx, metadata.Bin, fs) - if err != nil { - return err - } - defer reader.Close() - if hash > 0 { - dreader := iotools.NewDigestReaderWithHash(hash, reader) - _, err = io.Copy(out, dreader) - if err != nil { - return err - } - sum := dreader.Digest().Encoded() - if metadata.Hash != sum { - return errors.Newf("%s digest mismatch: expected %s, found %s", metadata.HashType, metadata.Hash, sum) - } - } else { - _, err = io.Copy(out, reader) - return err - } - return err - }() - if e != nil { - return nil, e - } - } - - // pack all downloaded files into a tar.gz file - tgz, err := vfs.TempFile(fs, "", Type+"-"+a.GetCoordinates().FileNamePrefix()+"-*.tar.gz") - if err != nil { - return nil, err - } - defer tgz.Close() - - dw := iotools.NewDigestWriterWith(digest.SHA256, tgz) - defer dw.Close() - err = tarutils.TgzFs(tempFs, dw) - if err != nil { - return nil, err - } - - metadata.Bin = "file://" + tgz.Name() - metadata.MimeType = mime.MIME_TGZ - metadata.Hash = dw.Digest().Encoded() - metadata.HashType = crypto.SHA256 - log.Debug("created", "file", metadata.Bin) - - return &metadata, nil -} - -func filterByClassifier(fileMap map[string]crypto.Hash, classifier string) map[string]crypto.Hash { - for file := range fileMap { - if !strings.Contains(file, "-"+classifier+".") { - delete(fileMap, file) - } - } - return fileMap -} - -func (a *AccessSpec) GavFiles(ctx accspeccpi.Context, fs ...vfs.FileSystem) (map[string]crypto.Hash, error) { - if strings.HasPrefix(a.Repository, "file://") { - dir := path.Join(a.Repository[7:], a.GavPath()) - return gavFilesFromDisk(utils.FileSystem(fs...), dir) - } - return a.gavOnlineFiles(ctx) -} - -func gavFilesFromDisk(fs vfs.FileSystem, dir string) (map[string]crypto.Hash, error) { - files, err := tarutils.ListSortedFilesInDir(fs, dir, true) - if err != nil { - return nil, err - } - return filesAndHashes(files), nil -} - -// gavOnlineFiles returns the files of the Maven (mvn) artifact in the repository and their available digests. -func (a *AccessSpec) gavOnlineFiles(ctx accspeccpi.Context) (map[string]crypto.Hash, error) { - log := log.WithValues("BaseUrl", a.BaseUrl()) - log.Debug("gavOnlineFiles") - - reader, err := getReader(ctx, a.BaseUrl(), nil) - if err != nil { - return nil, err - } - defer reader.Close() - - // Which files are listed in the repository? - log.Debug("parse-html") - htmlDoc, err := html.Parse(reader) - if err != nil { - return nil, err - } - var fileList []string - var process func(*html.Node) - prefix := a.FileNamePrefix() - process = func(node *html.Node) { - // check if the node is an element node and the tag is "" - if node.Type == html.ElementNode && node.Data == "a" { - for _, attribute := range node.Attr { - if attribute.Key == "href" { - // check if the href starts with artifactId-version - if strings.HasPrefix(attribute.Val, prefix) { - fileList = append(fileList, attribute.Val) - } - } - } - } - for nextChild := node.FirstChild; nextChild != nil; nextChild = nextChild.NextSibling { - process(nextChild) // recursive call! - } - } - process(htmlDoc) - - return filesAndHashes(fileList), nil -} - -func filesAndHashes(fileList []string) map[string]crypto.Hash { - // Sort the list of files, to ensure always the same results for e.g. identical tar.gz files. - sort.Strings(fileList) - - // Which hash files are available? - result := make(map[string]crypto.Hash, len(fileList)/2) - for _, file := range fileList { - if maven.IsResource(file) { - result[file] = bestAvailableHash(fileList, file) - log.Debug("found", "file", file) - } - } - return result -} - -// bestAvailableHash returns the best available hash for the given file. -// It first checks for SHA-512, then SHA-256, SHA-1, and finally MD5. If nothing is found, it returns 0. -func bestAvailableHash(list []string, filename string) crypto.Hash { - hashes := [5]crypto.Hash{crypto.SHA512, crypto.SHA256, crypto.SHA1, crypto.MD5} - for _, hash := range hashes { - if slices.Contains(list, filename+hashUrlExt(hash)) { - return hash - } - } - return 0 -} - -//////////////////////////////////////////////////////////////////////////////// - -func getStringData(ctx accspeccpi.Context, url string, fs vfs.FileSystem) (string, error) { - // getStringData reads all data from the given URL and returns it as a string. - r, err := getReader(ctx, url, fs) - if err != nil { - return "", err - } - defer r.Close() - b, err := io.ReadAll(r) - if err != nil { - return "", err - } - return string(b), nil -} - -// hashUrlExt returns the 'maven' hash extension for the given hash. -// Maven usually uses sha1, sha256, sha512, md5 instead of SHA-1, SHA-256, SHA-512, MD5. -func hashUrlExt(h crypto.Hash) string { - return "." + strings.ReplaceAll(strings.ToLower(h.String()), "-", "") -} - -func newMethod(c accspeccpi.ComponentVersionAccess, a *AccessSpec) (accspeccpi.AccessMethodImpl, error) { - factory := func() (blobaccess.BlobAccess, error) { - meta, err := a.GetPackageMeta(c.GetContext()) - if err != nil { - return nil, err - } - - reader := func() (io.ReadCloser, error) { - return getReader(c.GetContext(), meta.Bin, vfsattr.Get(c.GetContext())) - } - if meta.Hash != "" { - getreader := reader - reader = func() (io.ReadCloser, error) { - readCloser, err := getreader() - if err != nil { - return nil, err - } - return iotools.VerifyingReaderWithHash(readCloser, meta.HashType, meta.Hash), nil - } - } - acc := blobaccess.DataAccessForReaderFunction(reader, meta.Bin) - return accessobj.CachedBlobAccessForWriter(c.GetContext(), a.MimeType(), accessio.NewDataAccessWriter(acc)), nil - } - // FIXME add Digest! - return accspeccpi.NewDefaultMethodImpl(c, a, "", a.MimeType(), factory), nil -} - -func getReader(ctx accspeccpi.Context, url string, fs vfs.FileSystem) (io.ReadCloser, error) { - if strings.HasPrefix(url, "file://") { - path := url[7:] - return fs.OpenFile(path, vfs.O_RDONLY, 0o600) - } - - req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) - if err != nil { - return nil, err - } - err = identity.BasicAuth(req, ctx, url, "") - if err != nil { - return nil, err - } - httpClient := &http.Client{} - resp, err := httpClient.Do(req) - if err != nil { - return nil, err - } - if resp.StatusCode != http.StatusOK { - defer resp.Body.Close() - buf := &bytes.Buffer{} - _, err = io.Copy(buf, io.LimitReader(resp.Body, 2000)) - if err == nil { - log.Error("http", "code", resp.Status, "url", url, "body", buf.String()) - } - return nil, errors.Newf("http %s error - %s", resp.Status, url) - } - return resp.Body, nil -} diff --git a/pkg/contexts/ocm/accessmethods/mvn/method_test.go b/pkg/contexts/ocm/accessmethods/mvn/method_test.go deleted file mode 100644 index 7b4ca85a80..0000000000 --- a/pkg/contexts/ocm/accessmethods/mvn/method_test.go +++ /dev/null @@ -1,87 +0,0 @@ -package mvn_test - -import ( - "crypto" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/open-component-model/ocm/pkg/contexts/ocm" - "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/mvn" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" - . "github.com/open-component-model/ocm/pkg/env" - . "github.com/open-component-model/ocm/pkg/env/builder" - "github.com/open-component-model/ocm/pkg/iotools" - "github.com/open-component-model/ocm/pkg/mime" - . "github.com/open-component-model/ocm/pkg/testutils" -) - -const ( - mvnPATH = "/testdata/.m2/repository" - FAILPATH = "/testdata/fail" -) - -var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { - var env *Builder - var cv ocm.ComponentVersionAccess - - BeforeEach(func() { - env = NewBuilder(TestData()) - cv = &cpi.DummyComponentVersionAccess{env.OCMContext()} - }) - - AfterEach(func() { - env.Cleanup() - }) - - It("accesses local artifact", func() { - acc := mvn.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - m := Must(acc.AccessMethod(cv)) - defer m.Close() - Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) - r := Must(m.Reader()) - defer r.Close() - dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) - for { - var buf [8096]byte - _, err := dr.Read(buf[:]) - if err != nil { - break - } - } - Expect(dr.Size()).To(Equal(int64(1109))) - Expect(dr.Digest().String()).To(Equal("SHA-1:4ee125ffe4f7690588833f1217a13cc741e4df5f")) - }) - - It("accesses local artifact with extension", func() { - acc := mvn.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", mvn.WithExtension("pom")) - m := Must(acc.AccessMethod(cv)) - defer m.Close() - Expect(m.MimeType()).To(Equal(mime.MIME_XML)) - r := Must(m.Reader()) - defer r.Close() - dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) - for { - var buf [8096]byte - _, err := dr.Read(buf[:]) - if err != nil { - break - } - } - Expect(dr.Size()).To(Equal(int64(7153))) - Expect(dr.Digest().String()).To(Equal("SHA-1:34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) - }) - - It("Describe", func() { - acc := mvn.New("file://"+FAILPATH, "test", "repository", "42", mvn.WithExtension("pom")) - Expect(acc.Describe(nil)).To(Equal("Maven (mvn) package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) - }) - - It("detects digests mismatch", func() { - acc := mvn.New("file://"+FAILPATH, "test", "repository", "42", mvn.WithExtension("pom")) - m := Must(acc.AccessMethod(cv)) - defer m.Close() - _, err := m.Reader() - Expect(err).To(MatchError(ContainSubstring("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7"))) - }) -}) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go index 558994be08..a253a8bd8d 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go @@ -5,6 +5,7 @@ import ( "crypto" "encoding/json" "fmt" + access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" "github.com/open-component-model/ocm/pkg/maven" "github.com/open-component-model/ocm/pkg/optionutils" "io" @@ -15,7 +16,6 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" - "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/mvn" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" @@ -111,7 +111,7 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi } log.Debug("done", "artifact", artifact) - return mvn.New(b.spec.Url, artifact.GroupId, artifact.ArtifactId, artifact.Version, mvn.WithClassifier(optionutils.AsValue(artifact.Classifier)), mvn.WithExtension(optionutils.AsValue(artifact.Extension))), nil + return access.New(b.spec.Url, artifact.GroupId, artifact.ArtifactId, artifact.Version, maven.WithClassifier(optionutils.AsValue(artifact.Classifier)), maven.WithExtension(optionutils.AsValue(artifact.Extension))), nil } // deploy an artifact to the specified destination. See https://jfrog.com/help/r/jfrog-rest-apis/deploy-artifact diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index d03ff4c40d..8642ac5851 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -152,9 +152,12 @@ func (c *Coordinates) SetClassifierExtensionBy(filename string) error { // MimeType returns the MIME type of the Maven Coordinates based on the file extension. // Default is application/x-tgz. func (c *Coordinates) MimeType() string { - m := mime.TypeByExtension("." + optionutils.AsValue(c.Extension)) - if m != "" { - return m + if c.Extension != nil && c.Classifier != nil { + m := mime.TypeByExtension("." + optionutils.AsValue(c.Extension)) + if m != "" { + return m + } + return ocmmime.MIME_OCTET } return ocmmime.MIME_TGZ } From 1c68ce27a149d6c73c01aa28e72bf2d1ff66072b Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Fri, 24 May 2024 17:55:43 +0200 Subject: [PATCH 04/13] introduce repo/location object and input type --- .../ocmcmds/common/inputs/options/standard.go | 11 +- .../common/inputs/types/directory/spec.go | 2 +- .../ocmcmds/common/inputs/types/init.go | 1 + .../ocmcmds/common/inputs/types/maven/cli.go | 36 +++ .../common/inputs/types/maven/input_test.go | 93 ++++++++ .../ocmcmds/common/inputs/types/maven/spec.go | 99 +++++++++ .../common/inputs/types/maven/suite_test.go | 13 ++ .../sdk-modules-bom-5.7.0-random-content.json | 1 + ...modules-bom-5.7.0-random-content.json.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.txt | 1 + ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 0 -> 595 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 0 -> 595 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ++++++++++++++++++ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 + .../types/maven/testdata/resources1.yaml | 8 + .../ocmcmds/common/inputs/types/maven/type.go | 43 ++++ .../common/options/repooption/option.go | 2 +- .../ocmcmds/plugins/describe/cmd_test.go | 4 +- .../ocmcmds/plugins/describe/describe.go | 4 +- examples/lib/transfer1/example.go | 2 +- pkg/blobaccess/maven/access.go | 20 +- pkg/blobaccess/maven/access_test.go | 23 +- pkg/blobaccess/maven/options.go | 20 +- pkg/blobaccess/maven/utils.go | 24 +- .../credentials/config/config_test.go | 2 +- .../repositories/aliases/repo_test.go | 2 +- .../repositories/directcreds/repo_test.go | 2 +- .../repositories/dockerconfig/repo_test.go | 4 +- .../repositories/gardenerconfig/repo_test.go | 2 +- .../repositories/memory/config/type.go | 2 +- .../repositories/memory/repo_test.go | 2 +- .../repositories/npm/repository_test.go | 2 +- .../repositories/npm/suite_test.go | 2 +- .../datacontext/attrs/vfsattr/attr.go | 2 +- .../oci/repositories/ctf/repository.go | 2 +- pkg/contexts/ocm/accessmethods/github/cli.go | 2 +- .../ocm/accessmethods/localblob/cli.go | 2 +- pkg/contexts/ocm/accessmethods/maven/cli.go | 6 +- .../ocm/accessmethods/maven/method.go | 47 +++- .../ocm/accessmethods/maven/method_test.go | 10 +- .../ocm/accessmethods/options/standard.go | 9 +- .../ocm/attrs/ociuploadattr/suite_test.go | 2 +- .../handlers/generic/mvn/blobhandler.go | 34 +-- .../handlers/generic/mvn/registration_test.go | 2 +- .../handlers/generic/npm/registration_test.go | 2 +- .../handlers/generic/npm/suite_test.go | 2 +- .../handlers/generic/ocirepo/suite_test.go | 2 +- .../artifactblob/helmblob/helmblob_test.go | 2 +- pkg/contexts/ocm/plugin/common/describe.go | 2 +- .../ocm/plugin/descriptor/descriptor.go | 2 +- pkg/contexts/ocm/plugin/descriptor/keys.go | 2 +- .../repositories/comparch/comparch_test.go | 2 +- .../repositories/composition/suite_test.go | 2 +- .../repositories/genericocireg/suite_test.go | 2 +- .../ocm/repositories/ocireg/suite_test.go | 2 +- .../ocm/repositories/virtual/suite_test.go | 2 +- pkg/contexts/ocm/resolver_test.go | 2 +- pkg/contexts/ocm/resourcetypes/const.go | 2 +- pkg/contexts/ocm/session.go | 2 +- pkg/contexts/ocm/utils/localize/format.go | 6 +- pkg/maven/access.go | 123 +++++++--- pkg/maven/access_test.go | 18 +- pkg/maven/coordinates.go | 16 +- pkg/maven/coordinates_test.go | 3 +- pkg/maven/utils.go | 8 +- pkg/toi/drivers/docker/driver.go | 2 +- pkg/utils/tarutils/pack.go | 2 +- 70 files changed, 792 insertions(+), 176 deletions(-) create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/suite_test.go create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml create mode 100644 cmds/ocm/commands/ocmcmds/common/inputs/types/maven/type.go diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go b/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go index c43f18f318..74a22ddc28 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/options/standard.go @@ -6,13 +6,20 @@ import ( ) var ( - HintOption = options.HintOption - MediaTypeOption = options.MediatypeOption + HintOption = options.HintOption + MediaTypeOption = options.MediatypeOption + URLOption = options.URLOption HTTPHeaderOption = options.HTTPHeaderOption HTTPVerbOption = options.HTTPVerbOption HTTPBodyOption = options.HTTPBodyOption HTTPRedirectOption = options.HTTPRedirectOption + + RepositoryOption = options.RepositoryOption + GroupOption = options.GroupOption + ArtifactOption = options.ArtifactOption + ClassifierOption = options.ClassifierOption + ExtensionOption = options.ExtensionOption ) // string options 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..04efcddeb5 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go @@ -14,7 +14,7 @@ import ( type Spec struct { cpi.MediaFileSpec `json:",inline"` - // PreserveDir defines that the directory specified in the Path field should be included in the blob. + // PreserveDir defines that the directory specified in the BasePath field should be included in the blob. // Only supported for Type dir. PreserveDir *bool `json:"preserveDir,omitempty"` // IncludeFiles is a list of shell file name patterns that describe the files that should be included. diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/init.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/init.go index ccf3c66649..8c42a5781a 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/init.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/init.go @@ -7,6 +7,7 @@ import ( _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/dockermulti" _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/file" _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/helm" + _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/maven" _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/ociartifact" _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/spiff" _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types/utf8" diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go new file mode 100644 index 0000000000..5c417805b5 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maven + +import ( + "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/options" + "github.com/open-component-model/ocm/pkg/cobrautils/flagsets" +) + +func ConfigHandler() flagsets.ConfigOptionTypeSetHandler { + return flagsets.NewConfigOptionTypeSetHandler( + TYPE, AddConfig, + options.URLOption, + options.PathOption, + options.GroupOption, + options.ArtifactOption, + options.VersionOption, + // optional + options.ClassifierOption, + options.ExtensionOption, + ) +} + +func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error { + flagsets.AddFieldByOptionP(opts, options.URLOption, config, "repoUrl") + flagsets.AddFieldByOptionP(opts, options.PathOption, config, "path") + flagsets.AddFieldByOptionP(opts, options.GroupOption, config, "groupId") + flagsets.AddFieldByOptionP(opts, options.ArtifactOption, config, "artifactId") + flagsets.AddFieldByOptionP(opts, options.VersionOption, config, "version") + // optional + flagsets.AddFieldByOptionP(opts, options.ClassifierOption, config, "classifier") + flagsets.AddFieldByOptionP(opts, options.ExtensionOption, config, "extension") + return nil +} diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go new file mode 100644 index 0000000000..95663b6166 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go @@ -0,0 +1,93 @@ +package maven_test + +import ( + "crypto" + . "github.com/mandelsoft/goutils/testutils" + . "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/contexts/ocm/accessmethods/localblob" + "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" + "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/comparch" + "github.com/open-component-model/ocm/pkg/mime" + "github.com/open-component-model/ocm/pkg/utils/tarutils" +) + +const ( + ARCH = "test.ca" + VERSION = "v1" +) + +var _ = Describe("Test Environment", func() { + var env *TestEnv + + BeforeEach(func() { + env = NewTestEnv(TestData()) + + Expect(env.Execute("create", "ca", "-ft", "directory", "test.de/x", VERSION, "--provider", "mandelsoft", "--file", ARCH)).To(Succeed()) + }) + + AfterEach(func() { + env.Cleanup() + }) + + It("add maven from file system described by resources.yaml", func() { + Expect(env.Execute("add", "resources", "--file", ARCH, "/testdata/resources1.yaml")).To(Succeed()) + data, err := env.ReadFile(env.Join(ARCH, comparch.ComponentDescriptorFileName)) + Expect(err).To(Succeed()) + cd, err := compdesc.Decode(data) + Expect(err).To(Succeed()) + Expect(len(cd.Resources)).To(Equal(1)) + access := Must(env.Context.OCMContext().AccessSpecForSpec(cd.Resources[0].Access)).(*localblob.AccessSpec) + Expect(access.MediaType).To(Equal(mime.MIME_TGZ)) + fi := Must(env.FileSystem().Stat(env.Join(ARCH, "blobs", access.LocalReference))) + Expect(fi.Size()).To(Equal(int64(1570))) + li := Must(tarutils.ListArchiveContent(env.Join(ARCH, "blobs", access.LocalReference), env.FileSystem())) + Expect(li).To(ConsistOf( + "sdk-modules-bom-5.7.0-random-content.json", + "sdk-modules-bom-5.7.0-random-content.txt", + "sdk-modules-bom-5.7.0-sources.jar", + "sdk-modules-bom-5.7.0.jar", + "sdk-modules-bom-5.7.0.pom")) + Expect(cd.Resources[0].Digest.HashAlgorithm).To(Equal(crypto.SHA256.String())) + Expect(cd.Resources[0].Digest.Value).To(Equal("16cfb5ced0ea7688dba14aeb0d3aa76ad46e4661bfcc556ffd7287de3b2f7152")) + }) + + It("add maven from file system described by cli options", func() { + meta := ` +name: testdata +type: mavenArtifact +` + Expect(env.Execute("add", "resources", "--file", ARCH, "--resource", meta, "--inputType", "maven", + "--inputPath", "testdata/.m2/repository", "--groupId", "com.sap.cloud.sdk", "--artifactId", "sdk-modules-bom", + "--inputVersion", "5.7.0", "--classifier", "", "--extension", "pom")).To(Succeed()) + data, err := env.ReadFile(env.Join(ARCH, comparch.ComponentDescriptorFileName)) + Expect(err).To(Succeed()) + cd, err := compdesc.Decode(data) + Expect(err).To(Succeed()) + Expect(len(cd.Resources)).To(Equal(1)) + access := Must(env.Context.OCMContext().AccessSpecForSpec(cd.Resources[0].Access)).(*localblob.AccessSpec) + Expect(access.MediaType).To(Equal(mime.MIME_XML)) + fi := Must(env.FileSystem().Stat(env.Join(ARCH, "blobs", access.LocalReference))) + Expect(fi.Size()).To(Equal(int64(7153))) + }) + + It("add maven file from file system described by cli options", func() { + meta := ` +name: testdata +type: mavenArtifact +` + Expect(env.Execute("add", "resources", "--file", ARCH, "--resource", meta, "--inputType", "maven", + "--inputPath", "testdata/.m2/repository", "--groupId", "com.sap.cloud.sdk", "--artifactId", "sdk-modules-bom", + "--inputVersion", "5.7.0", "--extension", "pom")).To(Succeed()) + data, err := env.ReadFile(env.Join(ARCH, comparch.ComponentDescriptorFileName)) + Expect(err).To(Succeed()) + cd, err := compdesc.Decode(data) + Expect(err).To(Succeed()) + Expect(len(cd.Resources)).To(Equal(1)) + access := Must(env.Context.OCMContext().AccessSpecForSpec(cd.Resources[0].Access)).(*localblob.AccessSpec) + Expect(access.MediaType).To(Equal(mime.MIME_TGZ)) + fi := Must(env.FileSystem().Stat(env.Join(ARCH, "blobs", access.LocalReference))) + Expect(fi.Size()).To(Equal(int64(1109))) + }) +}) diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go new file mode 100644 index 0000000000..e6581d2f29 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go @@ -0,0 +1,99 @@ +package maven + +import ( + "fmt" + "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/cpi" + mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" + "github.com/open-component-model/ocm/pkg/maven" + "k8s.io/apimachinery/pkg/util/validation/field" + + "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs" + "github.com/open-component-model/ocm/pkg/blobaccess" +) + +type Spec struct { + cpi.PathSpec `json:",inline"` + // RepoUrl defines the url from which the artifact is downloaded. + // RepoUrl is the base URL of the Maven (mvn) repository. + RepoUrl string `json:"repoUrl,omitempty"` + + maven.Coordinates `json:",inline"` +} + +var _ inputs.InputSpec = (*Spec)(nil) + +func New(repoUrl, groupId, artifactId, version string, classifier, extension *string) *Spec { + return &Spec{ + PathSpec: cpi.NewPathSpec(TYPE, ""), + RepoUrl: repoUrl, + Coordinates: *maven.NewCoordinates(groupId, artifactId, version, + maven.WithOptionalClassifier(classifier), + maven.WithOptionalExtension(extension)), + } +} + +func NewForFilePath(filePath, groupId, artifactId, version string, classifier, extension *string) *Spec { + return &Spec{ + PathSpec: cpi.NewPathSpec(TYPE, filePath), + RepoUrl: "", + Coordinates: *maven.NewCoordinates(groupId, artifactId, version, + maven.WithOptionalClassifier(classifier), + maven.WithOptionalExtension(extension)), + } +} + +func (s *Spec) Validate(fldPath *field.Path, ctx inputs.Context, inputFilePath string) field.ErrorList { + var allErrs field.ErrorList + if s.RepoUrl == "" { + allErrs = s.PathSpec.Validate(fldPath, ctx, inputFilePath) + } else { + if s.Path != "" { + pathField := fldPath.Child("path") + allErrs = append(allErrs, field.Forbidden(pathField, "only path or repoUrl can be specified, not both")) + } + } + if s.ArtifactId == "" { + pathField := fldPath.Child("artifactId") + allErrs = append(allErrs, field.Invalid(pathField, s.ArtifactId, "no artifact id")) + } + if s.GroupId == "" { + pathField := fldPath.Child("groupId") + allErrs = append(allErrs, field.Invalid(pathField, s.GroupId, "no group id")) + } + if s.Version == "" { + pathField := fldPath.Child("version") + allErrs = append(allErrs, field.Invalid(pathField, s.GroupId, "no group id")) + } + + return allErrs +} + +func (s *Spec) GetBlob(ctx inputs.Context, info inputs.InputResourceInfo) (blobaccess.BlobAccess, string, error) { + var repo *maven.Repository + var err error + + fs := ctx.FileSystem() + if s.Path != "" { + inputInfo, inputPath, err := inputs.FileInfo(ctx, s.Path, info.InputFilePath) + if err != nil { + return nil, "", err + } + if !inputInfo.IsDir() { + return nil, "", fmt.Errorf("maven file repository must be a directory") + } + repo = maven.NewFileRepository(inputPath, fs) + } else { + repo, err = maven.NewUrlRepository(s.RepoUrl, fs) + if err != nil { + return nil, "", err + } + } + access, err := mavenblob.BlobAccessForMavenCoords(repo, &s.Coordinates, + mavenblob.WithCredentialContext(ctx), + mavenblob.WithLoggingContext(ctx), + mavenblob.WithCachingFileSystem(vfsattr.Get(ctx)), + ) + + return access, "", err +} diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/suite_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/suite_test.go new file mode 100644 index 0000000000..c3662b31b0 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/suite_test.go @@ -0,0 +1,13 @@ +package maven_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestConfig(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Input Type maven") +} diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json new file mode 100644 index 0000000000..2f1fc35fdc --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json @@ -0,0 +1 @@ +{"some": "test content"} \ No newline at end of file diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 new file mode 100644 index 0000000000..d6836aeaa0 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 @@ -0,0 +1 @@ +f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt new file mode 100644 index 0000000000..b4af84697f --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt @@ -0,0 +1 @@ +some test content \ No newline at end of file diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 new file mode 100644 index 0000000000..55eceeb992 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 @@ -0,0 +1 @@ +dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..8564f0addae8de5525417df8294d13c0c2a3a7c0 GIT binary patch literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo + + 4.0.0 + com.sap.cloud.sdk + sdk-modules-bom + 5.7.0 + pom + SAP Cloud SDK - Modules BOM + Bill of Materials (BOM) of the SAP Cloud SDK modules. + https://sap.github.io/cloud-sdk/docs/java/getting-started + + SAP SE + https://www.sap.com + + + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + SAP + cloudsdk@sap.com + SAP SE + https://www.sap.com + + + + + + + + UTF-8 + Public + Stable + + 5.7.0 + + + + + com.sap.cloud.sdk + sdk-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + dwc-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + caching + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient4 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient5 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity-scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-destination-service + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-oauth + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-dwc + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-ztis + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience-api + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience4j + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + security + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + servlet-jakarta + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + tenant + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-core + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + rfc + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + datamodel-metadata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator-utility + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-client + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + fluent-result + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + + soap + ${sdk.version} + + + + diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 new file mode 100644 index 0000000000..35f63a2e1f --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 @@ -0,0 +1 @@ +34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml new file mode 100644 index 0000000000..952a1ecb7a --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml @@ -0,0 +1,8 @@ +name: myblob +type: mavenArtifact +input: + type: maven + path: .m2/repository + groupId: com.sap.cloud.sdk + artifactId: sdk-modules-bom + version: 5.7.0 \ No newline at end of file diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/type.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/type.go new file mode 100644 index 0000000000..7c80db8e33 --- /dev/null +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/type.go @@ -0,0 +1,43 @@ +package maven + +import ( + "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs" +) + +const TYPE = "maven" + +func init() { + inputs.DefaultInputTypeScheme.Register(inputs.NewInputType(TYPE, &Spec{}, usage, ConfigHandler())) +} + +const usage = ` +The repoUrl is the url pointing either to the http endpoint of a maven +repository (e.g. https://repo.maven.apache.org/maven2/) or to a file system based +maven repository (e.g. file://local/directory). + +This blob type specification supports the following fields: +- **repoUrl** *string* + + This REQUIRED property describes the url from which the resource is to be + accessed. + +- **groupId** *string* + + This REQUIRED property describes the groupId of a maven artifact. + +- **artifactId** *string* + + This REQUIRED property describes artifactId of a maven artifact. + +- **version** *string* + + This REQUIRED property describes the version of a maven artifact. + +- **classifier** *string* + + This OPTIONAL property describes the classifier of a maven artifact. + +- **extension** *string* + + This OPTIONAL property describes the extension of a maven artifact. +` diff --git a/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go b/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go index f922398789..53ab5e8b6f 100644 --- a/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go +++ b/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go @@ -94,7 +94,7 @@ Dedicated OCM repository types: s += listformat.FormatMapElements("", runtime.KindToVersionList(ocm.DefaultContext().RepositoryTypes().KnownTypeNames())) s += ` -OCI Repository types (using standard component repository to OCI mapping): +OCI RepoUrl types (using standard component repository to OCI mapping): ` s += listformat.FormatMapElements("", runtime.KindToVersionList(oci.DefaultContext().RepositoryTypes().KnownTypeNames(), genericocireg.Excludes...)) return s diff --git a/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go b/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go index 2dc4707514..04cbdd97d9 100644 --- a/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go @@ -39,7 +39,7 @@ var _ = Describe("Test Environment", func() { ` Plugin Name: action Plugin Version: v1 -Path: ` + path + `/action +BasePath: ` + path + `/action Status: valid Source: manually installed Capabilities: Actions @@ -64,7 +64,7 @@ Actions: ---------------------- Plugin Name: test Plugin Version: v1 -Path: ` + path + `/test +BasePath: ` + path + `/test Status: valid Source: manually installed Capabilities: Access Methods diff --git a/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go b/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go index 67da8d3f48..bbbd369590 100644 --- a/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go +++ b/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go @@ -11,7 +11,7 @@ import ( func DescribePlugin(p plugin.Plugin, out common.Printer) { out.Printf("Plugin Name: %s\n", p.Name()) out.Printf("Plugin Version: %s\n", p.Version()) - out.Printf("Path: %s\n", p.Path()) + out.Printf("BasePath: %s\n", p.Path()) if !p.IsValid() { out.Printf("Status: %s\n", p.Error()) @@ -32,7 +32,7 @@ func DescribePlugin(p plugin.Plugin, out common.Printer) { return } - out.Printf(" Repository: %s\n", u.String()) + out.Printf(" RepoUrl: %s\n", u.String()) out.Printf(" Specification: %s\n", string(data)) } else { out.Printf("Source: manually installed\n") diff --git a/examples/lib/transfer1/example.go b/examples/lib/transfer1/example.go index ff534fc62b..9a08f5a728 100644 --- a/examples/lib/transfer1/example.go +++ b/examples/lib/transfer1/example.go @@ -117,7 +117,7 @@ func TransferApplication() (rerr error) { } // if you know you have an OCI registry based OCM repository - // repoSpec := ocireg.NewRepositorySpec(cfg.Repository) + // repoSpec := ocireg.NewRepositorySpec(cfg.RepoUrl) // if you want to provide specific credentials.... // target, err := octx.RepositoryForSpec(repoSpec, cfg.GetCredentials()) diff --git a/pkg/blobaccess/maven/access.go b/pkg/blobaccess/maven/access.go index 940be2565a..4a65fe1a2d 100644 --- a/pkg/blobaccess/maven/access.go +++ b/pkg/blobaccess/maven/access.go @@ -9,31 +9,31 @@ import ( type BlobMeta = maven.FileMeta -func DataAccessForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) (blobaccess.DataAccess, error) { - return BlobAccessForMaven(repoUrl, groupId, artifactId, version, opts...) +func DataAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (blobaccess.DataAccess, error) { + return BlobAccessForMaven(repo, groupId, artifactId, version, opts...) } -func BlobAccessForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) (blobaccess.BlobAccess, error) { +func BlobAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (blobaccess.BlobAccess, error) { eff := optionutils.EvalOptions(opts...) s := &spec{ coords: maven.NewCoordinates(groupId, artifactId, version, maven.WithOptionalClassifier(eff.Classifier), maven.WithOptionalExtension(eff.Extension)), - repoUrl: repoUrl, + repo: repo, options: eff, } return s.getBlobAccess() } -func BlobAccessForMavenCoords(repoUrl string, coords *maven.Coordinates, opts ...Option) (blobaccess.BlobAccess, error) { - return BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) +func BlobAccessForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) (blobaccess.BlobAccess, error) { + return BlobAccessForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) } -func BlobAccessProviderForMaven(repoUrl, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { +func BlobAccessProviderForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) bpi.BlobAccessProvider { return bpi.BlobAccessProviderFunction(func() (bpi.BlobAccess, error) { - b, err := BlobAccessForMaven(repoUrl, groupId, artifactId, version, opts...) + b, err := BlobAccessForMaven(repo, groupId, artifactId, version, opts...) return b, err }) } -func BlobAccessProviderForMavenCoords(repoUrl string, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { - return BlobAccessProviderForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) +func BlobAccessProviderForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { + return BlobAccessProviderForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) } diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index 679f197c1b..f900e7c717 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -30,9 +30,11 @@ var _ = Describe("blobaccess for maven", func() { Context("maven filesystem repository", func() { var env *Builder + var repo *maven.Repository BeforeEach(func() { env = NewBuilder(TestData()) + repo = maven.NewFileRepository(mvnPATH, env.FileSystem()) }) AfterEach(func() { @@ -40,10 +42,9 @@ var _ = Describe("blobaccess for maven", func() { }) It("blobaccess for gav", func() { - repoUrl := "file://" + mvnPATH coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - b := Must(me.BlobAccessForMaven(repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, me.WithFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForMaven(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("sdk-modules-bom-5.7.0.pom", "sdk-modules-bom-5.7.0.jar", "sdk-modules-bom-5.7.0-random-content.txt", @@ -51,11 +52,10 @@ var _ = Describe("blobaccess for maven", func() { }) It("blobaccess for files with the same classifier", func() { - repoUrl := "file://" + mvnPATH coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithClassifier("random-content")) - b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForMavenCoords(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", @@ -63,11 +63,10 @@ var _ = Describe("blobaccess for maven", func() { }) It("blobaccess for files with empty classifier", func() { - repoUrl := "file://" + mvnPATH coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithClassifier("")) - b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForMavenCoords(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", @@ -75,11 +74,10 @@ var _ = Describe("blobaccess for maven", func() { }) It("blobaccess for files with extension", func() { - repoUrl := "file://" + mvnPATH coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithExtension("jar")) - b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForMavenCoords(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", @@ -87,22 +85,20 @@ var _ = Describe("blobaccess for maven", func() { }) It("blobaccess for files with extension", func() { - repoUrl := "file://" + mvnPATH coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithExtension("txt")) - b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForMavenCoords(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")) }) It("blobaccess for a single file with classifier and extension", func() { - repoUrl := "file://" + mvnPATH coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", maven.WithClassifier("random-content"), maven.WithExtension("json")) - b := Must(me.BlobAccessForMavenCoords(repoUrl, coords, me.WithFileSystem(env.FileSystem()))) + b := Must(me.BlobAccessForMavenCoords(repo, coords, me.WithCachingFileSystem(env.FileSystem()))) defer Close(b, "blobaccess") Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) }) @@ -115,7 +111,8 @@ var _ = Describe("blobaccess for maven", func() { coords = maven.NewCoordinates(MAVEN_GROUP_ID, MAVEN_ARTIFACT_ID, MAVEN_VERSION) }) It("blobaccess for gav", func() { - b := Must(me.BlobAccessForMavenCoords(MAVEN_CENTRAL, coords)) + repo := Must(maven.NewUrlRepository(MAVEN_CENTRAL)) + b := Must(me.BlobAccessForMavenCoords(repo, coords)) defer Close(b, "blobaccess") files := Must(tarutils.ListArchiveContentFromReader(Must(b.Reader()))) Expect(files).To(ConsistOf( diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index a12f4a24b8..9f4a38b47a 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -22,7 +22,7 @@ type Options struct { CredentialContext credentials.Context LoggingContext logging.Context CachingContext datacontext.Context - FileSystem vfs.FileSystem + CachingFileSystem vfs.FileSystem CachingPath string // Credentials allows to pass credentials and certificates for the http communication Credentials credentials.Credentials @@ -38,17 +38,21 @@ func (o *Options) Logger(keyValuePairs ...interface{}) logging.Logger { func (o *Options) Cache() *tmpcache.Attribute { if o.CachingPath != "" { - return tmpcache.New(o.CachingPath, o.FileSystem) + return tmpcache.New(o.CachingPath, o.CachingFileSystem) } return tmpcache.Get(o.CachingContext) } -func (o *Options) GetCredentials(repoUrl, groupId string) (maven.Credentials, error) { +func (o *Options) GetCredentials(repo *maven.Repository, groupId string) (maven.Credentials, error) { + if repo.IsFileSystem() { + return nil, nil + } + switch { case o.Credentials != nil: return MapCredentials(o.Credentials), nil case o.CredentialContext != nil: - consumerid, err := identity.GetConsumerId(repoUrl, groupId) + consumerid, err := identity.GetConsumerId(repo.String(), groupId) if err != nil { return nil, err } @@ -72,8 +76,8 @@ func (o *Options) ApplyTo(opts *Options) { if o.LoggingContext != nil { opts.LoggingContext = o.LoggingContext } - if o.FileSystem != nil { - opts.FileSystem = o.FileSystem + if o.CachingFileSystem != nil { + opts.CachingFileSystem = o.CachingFileSystem } if o.Credentials != nil { opts.Credentials = o.Credentials @@ -121,10 +125,10 @@ type fileSystem struct { } func (o *fileSystem) ApplyTo(opts *Options) { - opts.FileSystem = o.fs + opts.CachingFileSystem = o.fs } -func WithFileSystem(fs vfs.FileSystem) Option { +func WithCachingFileSystem(fs vfs.FileSystem) Option { return &fileSystem{fs: fs} } diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index 735706f783..e454e2f4f9 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -29,7 +29,7 @@ type coords = *maven.Coordinates type spec struct { coords - repoUrl string + repo *maven.Repository options *Options } @@ -37,12 +37,12 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { var finalize finalizer.Finalizer defer finalize.FinalizeWithErrorPropagation(&rerr) - log := s.options.Logger("BaseUrl", s.repoUrl) - creds, err := s.options.GetCredentials(s.repoUrl, s.GroupId) + log := s.options.Logger("RepoUrl", s.repo.String()) + creds, err := s.options.GetCredentials(s.repo, s.GroupId) if err != nil { return nil, err } - fileMap, err := maven.GavFiles(s.repoUrl, s.coords, creds, s.options.FileSystem) + fileMap, err := s.repo.GavFiles(s.coords, creds) if err != nil { return nil, err } @@ -54,11 +54,11 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { return nil, errors.New("no maven artifact files found") case l == 1 && optionutils.AsValue(s.Extension) != "" && s.Classifier != nil: for file, hash := range fileMap { - metadata, err := maven.GetFileMeta(s.repoUrl, s.coords, file, hash, creds, s.options.FileSystem) + metadata, err := s.repo.GetFileMeta(s.coords, file, hash, creds) if err != nil { return nil, err } - return blobAccessForRepositoryAccess(metadata, creds, s.options, s.options.FileSystem) + return blobAccessForRepositoryAccess(metadata, creds, s.options) } // default: continue below with: create tmpfs where all files can be downloaded to and packed together as tar.gz } @@ -73,7 +73,7 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { for file, hash := range fileMap { loop := finalize.Nested() - metadata, err := maven.GetFileMeta(s.repoUrl, s.coords, file, hash, creds, s.options.FileSystem) + metadata, err := s.repo.GetFileMeta(s.coords, file, hash, creds) if err != nil { return nil, err } @@ -85,7 +85,7 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { } loop.Close(out) - reader, err := maven.GetReader(metadata.Url, creds, s.options.FileSystem) + reader, err := metadata.Location.GetReader(creds) if err != nil { return nil, err } @@ -111,7 +111,7 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { } // pack all downloaded files into a tar.gz file - fs := utils.FileSystem(s.options.FileSystem) + fs := utils.FileSystem(s.options.CachingFileSystem) tgz, err := vfs.TempFile(fs, "", "maven-"+s.coords.FileNamePrefix()+"-*.tar.gz") if err != nil { return nil, err @@ -128,9 +128,9 @@ func (s *spec) getBlobAccess() (_ bpi.BlobAccess, rerr error) { return blobaccess.ForTemporaryFilePathWithMeta(mime.MIME_TGZ, dw.Digest(), dw.Size(), tgz.Name(), fs), nil } -func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts *Options, fss ...vfs.FileSystem) (bpi.BlobAccess, error) { +func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts *Options) (bpi.BlobAccess, error) { reader := func() (io.ReadCloser, error) { - return maven.GetReader(meta.Url, creds, fss...) + return meta.Location.GetReader(creds) } if meta.Hash != "" { getreader := reader @@ -142,7 +142,7 @@ func blobAccessForRepositoryAccess(meta *BlobMeta, creds maven.Credentials, opts return iotools.VerifyingReaderWithHash(readCloser, meta.HashType, meta.Hash), nil } } - acc := blobaccess.DataAccessForReaderFunction(reader, meta.Url) + acc := blobaccess.DataAccessForReaderFunction(reader, meta.Location.String()) return accessobj.CachedBlobAccessForWriterWithCache(opts.Cache(), meta.MimeType, accessio.NewDataAccessWriter(acc)), nil } diff --git a/pkg/contexts/credentials/config/config_test.go b/pkg/contexts/credentials/config/config_test.go index 6871066ebf..21a59e4d6d 100644 --- a/pkg/contexts/credentials/config/config_test.go +++ b/pkg/contexts/credentials/config/config_test.go @@ -146,7 +146,7 @@ var _ = Describe("generic credentials", func() { repo, err := ctx.RepositoryForSpec(spec) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.RepoUrl")) }) It("applies a config for consumers", func() { diff --git a/pkg/contexts/credentials/repositories/aliases/repo_test.go b/pkg/contexts/credentials/repositories/aliases/repo_test.go index 326d38dd56..11db237c83 100644 --- a/pkg/contexts/credentials/repositories/aliases/repo_test.go +++ b/pkg/contexts/credentials/repositories/aliases/repo_test.go @@ -46,7 +46,7 @@ var _ = Describe("alias credentials", func() { repo, err := DefaultContext.RepositoryForConfig([]byte(specdata), nil) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.RepoUrl")) }) It("sets and retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/directcreds/repo_test.go b/pkg/contexts/credentials/repositories/directcreds/repo_test.go index 3694363e89..6bc1f3d552 100644 --- a/pkg/contexts/credentials/repositories/directcreds/repo_test.go +++ b/pkg/contexts/credentials/repositories/directcreds/repo_test.go @@ -30,7 +30,7 @@ var _ = Describe("direct credentials", func() { It("deserializes credentials spec", func() { spec, err := DefaultContext.RepositoryForConfig([]byte(propsdata), nil) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(spec).String()).To(Equal("*directcreds.Repository")) + Expect(reflect.TypeOf(spec).String()).To(Equal("*directcreds.RepoUrl")) }) It("resolved direct credentials", func() { diff --git a/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go b/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go index 6945a809ae..69c665b0f5 100644 --- a/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go +++ b/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go @@ -62,7 +62,7 @@ var _ = Describe("docker config", func() { It("resolves repository", func() { repo := Must(DefaultContext.RepositoryForConfig([]byte(specdata), nil)) - Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.RepoUrl")) }) It("retrieves credentials", func() { @@ -122,7 +122,7 @@ var _ = Describe("docker config", func() { It("resolves repository", func() { repo := Must(DefaultContext.RepositoryForConfig([]byte(specdata), nil)) - Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.RepoUrl")) }) It("retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go b/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go index 5c51f5ed28..728e83afc6 100644 --- a/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go +++ b/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go @@ -91,7 +91,7 @@ var _ = Describe("gardener config", func() { repo, err := defaultContext.RepositoryForConfig([]byte(specdata), nil) Expect(err).ToNot(HaveOccurred()) Expect(repo).ToNot(BeNil()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*gardenerconfig.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*gardenerconfig.RepoUrl")) }) It("retrieves credentials from unencrypted server", func() { diff --git a/pkg/contexts/credentials/repositories/memory/config/type.go b/pkg/contexts/credentials/repositories/memory/config/type.go index 3e1b5aecd3..be6d144191 100644 --- a/pkg/contexts/credentials/repositories/memory/config/type.go +++ b/pkg/contexts/credentials/repositories/memory/config/type.go @@ -82,7 +82,7 @@ func (a *Config) ApplyTo(ctx cfgcpi.Context, target interface{}) error { mem, ok := repo.(*memory.Repository) if !ok { - return fmt.Errorf("invalid type assertion of type %T to memory.Repository", repo) + return fmt.Errorf("invalid type assertion of type %T to memory.RepoUrl", repo) } for i, e := range a.Credentials { diff --git a/pkg/contexts/credentials/repositories/memory/repo_test.go b/pkg/contexts/credentials/repositories/memory/repo_test.go index 58af3b1828..09e847bda4 100644 --- a/pkg/contexts/credentials/repositories/memory/repo_test.go +++ b/pkg/contexts/credentials/repositories/memory/repo_test.go @@ -45,7 +45,7 @@ var _ = Describe("direct credentials", func() { It("resolves repository", func() { repo, err := DefaultContext.RepositoryForConfig([]byte(specdata), nil) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.RepoUrl")) }) It("sets and retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/npm/repository_test.go b/pkg/contexts/credentials/repositories/npm/repository_test.go index e7fd29cfa6..6ff9514d37 100644 --- a/pkg/contexts/credentials/repositories/npm/repository_test.go +++ b/pkg/contexts/credentials/repositories/npm/repository_test.go @@ -48,7 +48,7 @@ var _ = Describe("NPM config - .npmrc", func() { It("resolves repository", func() { repo := Must(DefaultContext.RepositoryForConfig([]byte(specdata), nil)) - Expect(reflect.TypeOf(repo).String()).To(Equal("*npm.Repository")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*npm.RepoUrl")) }) It("retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/npm/suite_test.go b/pkg/contexts/credentials/repositories/npm/suite_test.go index e4947738d0..f3a1370c15 100644 --- a/pkg/contexts/credentials/repositories/npm/suite_test.go +++ b/pkg/contexts/credentials/repositories/npm/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "NPM Repository tests") + RunSpecs(t, "NPM RepoUrl tests") } diff --git a/pkg/contexts/datacontext/attrs/vfsattr/attr.go b/pkg/contexts/datacontext/attrs/vfsattr/attr.go index c0b8858d23..5ba3ef9645 100644 --- a/pkg/contexts/datacontext/attrs/vfsattr/attr.go +++ b/pkg/contexts/datacontext/attrs/vfsattr/attr.go @@ -35,7 +35,7 @@ Virtual filesystem to use for command line context. func (a AttributeType) Encode(v interface{}, marshaller runtime.Marshaler) ([]byte, error) { if _, ok := v.(vfs.FileSystem); !ok { - return nil, fmt.Errorf("vfs.FileSystem required") + return nil, fmt.Errorf("vfs.CachingFileSystem required") } return nil, nil } diff --git a/pkg/contexts/oci/repositories/ctf/repository.go b/pkg/contexts/oci/repositories/ctf/repository.go index d65dfe3e83..747ea3def7 100644 --- a/pkg/contexts/oci/repositories/ctf/repository.go +++ b/pkg/contexts/oci/repositories/ctf/repository.go @@ -117,7 +117,7 @@ func (a *RepositoryImpl) getIndex() *index.RepositoryIndex { } //////////////////////////////////////////////////////////////////////////////// -// cpi.Repository methods +// cpi.RepoUrl methods func (r *RepositoryImpl) ExistsArtifact(name string, tag string) (bool, error) { return r.getIndex().HasArtifact(name, tag), nil diff --git a/pkg/contexts/ocm/accessmethods/github/cli.go b/pkg/contexts/ocm/accessmethods/github/cli.go index 22e9f538e8..82cf2e43a8 100644 --- a/pkg/contexts/ocm/accessmethods/github/cli.go +++ b/pkg/contexts/ocm/accessmethods/github/cli.go @@ -31,7 +31,7 @@ The type specific specification fields are: - **repoUrl** *string* - Repository URL with or without scheme. + RepoUrl URL with or without scheme. - **ref** (optional) *string* diff --git a/pkg/contexts/ocm/accessmethods/localblob/cli.go b/pkg/contexts/ocm/accessmethods/localblob/cli.go index 9a1d5a0902..5f8edabe9c 100644 --- a/pkg/contexts/ocm/accessmethods/localblob/cli.go +++ b/pkg/contexts/ocm/accessmethods/localblob/cli.go @@ -41,7 +41,7 @@ The type specific specification fields are: - **localReference** *string* - Repository type specific location information as string. The value + RepoUrl type specific location information as string. The value may encode any deep structure, but typically just an access path is sufficient. - **mediaType** *string* diff --git a/pkg/contexts/ocm/accessmethods/maven/cli.go b/pkg/contexts/ocm/accessmethods/maven/cli.go index a6211bebbd..15554e4472 100644 --- a/pkg/contexts/ocm/accessmethods/maven/cli.go +++ b/pkg/contexts/ocm/accessmethods/maven/cli.go @@ -10,7 +10,7 @@ func ConfigHandler() flagsets.ConfigOptionTypeSetHandler { Type, AddConfig, options.RepositoryOption, options.GroupOption, - options.PackageOption, + options.ArtifactOption, options.VersionOption, // optional options.ClassifierOption, @@ -19,7 +19,7 @@ func ConfigHandler() flagsets.ConfigOptionTypeSetHandler { } func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error { - flagsets.AddFieldByOptionP(opts, options.RepositoryOption, config, "repository") + flagsets.AddFieldByOptionP(opts, options.RepositoryOption, config, "repoUrl") flagsets.AddFieldByOptionP(opts, options.GroupOption, config, "groupId") flagsets.AddFieldByOptionP(opts, options.PackageOption, config, "artifactId") flagsets.AddFieldByOptionP(opts, options.VersionOption, config, "version") @@ -36,7 +36,7 @@ This method implements the access of a Maven (mvn) artifact in a Maven repositor var formatV1 = ` The type specific specification fields are: -- **repository** *string* +- **repoUrl** *string* Base URL of the Maven (mvn) repository diff --git a/pkg/contexts/ocm/accessmethods/maven/method.go b/pkg/contexts/ocm/accessmethods/maven/method.go index cc1feaf4f5..2a31a3fc69 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method.go +++ b/pkg/contexts/ocm/accessmethods/maven/method.go @@ -29,8 +29,8 @@ func init() { type AccessSpec struct { runtime.ObjectVersionedType `json:",inline"` - // Repository is the base URL of the Maven (mvn) repository. - Repository string `json:"repository"` + // RepoUrl is the base URL of the Maven (mvn) repository. + RepoUrl string `json:"repoUrl"` maven.Coordinates `json:",inline"` } @@ -58,14 +58,25 @@ var _ accspeccpi.AccessSpec = (*AccessSpec)(nil) func New(repository, groupId, artifactId, version string, opts ...Option) *AccessSpec { accessSpec := &AccessSpec{ ObjectVersionedType: runtime.NewVersionedTypedObject(Type), - Repository: repository, + RepoUrl: repository, Coordinates: *maven.NewCoordinates(groupId, artifactId, version, opts...), } return accessSpec } +// NewForCoordinates creates a new Maven (mvn) repository access spec version v1. +func NewForCoordinates(repository string, coords *maven.Coordinates, opts ...Option) *AccessSpec { + optionutils.ApplyOptions(coords, opts...) + accessSpec := &AccessSpec{ + ObjectVersionedType: runtime.NewVersionedTypedObject(Type), + RepoUrl: repository, + Coordinates: *coords, + } + return accessSpec +} + func (a *AccessSpec) Describe(_ accspeccpi.Context) string { - return fmt.Sprintf("Maven (mvn) package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.Repository, a.Coordinates.FilePath()) + return fmt.Sprintf("Maven (mvn) package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.RepoUrl, a.Coordinates.FilePath()) } func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool { @@ -87,23 +98,33 @@ func (_ *AccessSpec) GetType() string { func (a *AccessSpec) AccessMethod(cv accspeccpi.ComponentVersionAccess) (accspeccpi.AccessMethod, error) { octx := cv.GetContext() + + repo, err := maven.NewUrlRepository(a.RepoUrl, vfsattr.Get(cv.GetContext())) + if err != nil { + return nil, err + } + factory := func() (blobaccess.BlobAccess, error) { - return mavenblob.BlobAccessForMavenCoords(a.Repository, &a.Coordinates, + return mavenblob.BlobAccessForMavenCoords(repo, &a.Coordinates, mavenblob.WithCredentialContext(octx), mavenblob.WithLoggingContext(octx), - mavenblob.WithFileSystem(vfsattr.Get(octx))) + mavenblob.WithCachingFileSystem(vfsattr.Get(octx))) } return accspeccpi.AccessMethodForImplementation(accspeccpi.NewDefaultMethodImpl(cv, a, "", a.MimeType(), factory), nil) } func (a *AccessSpec) GetInexpensiveContentVersionIdentity(cv accspeccpi.ComponentVersionAccess) string { - creds, err := identity.GetCredentials(cv.GetContext(), a.Repository, a.GroupId) + creds, err := identity.GetCredentials(cv.GetContext(), a.RepoUrl, a.GroupId) if err != nil { return "" } mvncreds := mavenblob.MapCredentials(creds) fs := vfsattr.Get(cv.GetContext()) - files, err := maven.GavFiles(a.Repository, &a.Coordinates, mvncreds, fs) + repo, err := maven.NewUrlRepository(a.RepoUrl, fs) + if err != nil { + return "" + } + files, err := repo.GavFiles(&a.Coordinates, mvncreds) if err != nil { return "" } @@ -115,18 +136,22 @@ func (a *AccessSpec) GetInexpensiveContentVersionIdentity(cv accspeccpi.Componen return "" } for _, h := range files { - id, _ := maven.GetHash(a.Url(a.Repository), mvncreds, h, fs) + id, _ := a.Location(repo).GetHash(mvncreds, h) return id } return "" } func (a *AccessSpec) BaseUrl() string { - return a.Repository + "/" + a.GavPath() + return a.RepoUrl + "/" + a.GavPath() } func (a *AccessSpec) ArtifactUrl() string { - return a.Url(a.Repository) + repo, err := maven.NewUrlRepository(a.RepoUrl) + if err != nil { + return "" + } + return a.Location(repo).String() } func (a *AccessSpec) GetCoordinates() *maven.Coordinates { diff --git a/pkg/contexts/ocm/accessmethods/maven/method_test.go b/pkg/contexts/ocm/accessmethods/maven/method_test.go index 3372a80200..34d9efd5f6 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/method_test.go @@ -44,10 +44,10 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { It("accesses local artifact", func() { acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") m := Must(acc.AccessMethod(cv)) - defer m.Close() + defer Close(m) Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) r := Must(m.Reader()) - defer r.Close() + defer Close(r) dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) for { var buf [8096]byte @@ -84,10 +84,10 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { It("accesses local artifact with extension", func() { acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) m := Must(acc.AccessMethod(cv)) - defer m.Close() + defer Close(m) Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) r := Must(m.Reader()) - defer r.Close() + defer Close(r) dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) list := Must(tarutils.ListArchiveContentFromReader(dr)) Expect(list).To(HaveLen(1)) @@ -103,7 +103,7 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { It("detects digests mismatch", func() { acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) m := Must(acc.AccessMethod(cv)) - defer m.Close() + defer Close(m) _, err := m.Reader() Expect(err).To(MatchError(ContainSubstring("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7"))) }) diff --git a/pkg/contexts/ocm/accessmethods/options/standard.go b/pkg/contexts/ocm/accessmethods/options/standard.go index 7e8680f12b..2b399ae853 100644 --- a/pkg/contexts/ocm/accessmethods/options/standard.go +++ b/pkg/contexts/ocm/accessmethods/options/standard.go @@ -18,8 +18,11 @@ var ReferenceOption = RegisterOption(NewStringOptionType("reference", "reference // PackageOption. var PackageOption = RegisterOption(NewStringOptionType("accessPackage", "package or object name")) +// ArtifactOption. +var ArtifactOption = RegisterOption(NewStringOptionType("artifactId", "artifact id")) + // GroupOption. -var GroupOption = RegisterOption(NewStringOptionType("accessGroup", "GroupID or namespace")) +var GroupOption = RegisterOption(NewStringOptionType("groupId", "group id or namespace")) // RepositoryOption. var RepositoryOption = RegisterOption(NewStringOptionType("accessRepository", "repository URL")) @@ -60,7 +63,7 @@ var HTTPRedirectOption = RegisterOption(NewBoolOptionType("noredirect", "http re var CommentOption = RegisterOption(NewStringOptionType("comment", "comment field value")) // ClassifierOption the optional classifier of a maven resource. -var ClassifierOption = RegisterOption(NewStringOptionType("accessClassifier", "mvn classifier")) +var ClassifierOption = RegisterOption(NewStringOptionType("classifier", "mvn classifier")) // ExtensionOption the optional extension of a maven resource. -var ExtensionOption = RegisterOption(NewStringOptionType("accessExtension", "mvn extension name")) +var ExtensionOption = RegisterOption(NewStringOptionType("extension", "mvn extension name")) diff --git a/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go b/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go index b6e55ed373..8267b39b70 100644 --- a/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go +++ b/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCI Upload Repository Attribute") + RunSpecs(t, "OCI Upload RepoUrl Attribute") } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go index a253a8bd8d..781788d7bf 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go @@ -5,6 +5,7 @@ import ( "crypto" "encoding/json" "fmt" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" "github.com/open-component-model/ocm/pkg/maven" "github.com/open-component-model/ocm/pkg/optionutils" @@ -80,30 +81,33 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi return nil, err } for _, file := range files { - e := func() (err error) { + e := func() error { log.Debug("uploading", "file", file) - err = artifact.SetClassifierExtensionBy(file) + err := artifact.SetClassifierExtensionBy(file) if err != nil { - return + return err } readHash, err := tempFs.Open(file) if err != nil { - return + return err } defer readHash.Close() // MD5 + SHA1 are still the most used ones in the mvn context hr := iotools.NewHashReader(readHash, crypto.SHA256, crypto.SHA1, crypto.MD5) _, err = hr.CalcHashes() if err != nil { - return + return err } reader, err := tempFs.Open(file) if err != nil { - return + return err } defer reader.Close() - err = deploy(artifact, b.spec.Url, reader, ctx.GetContext(), hr) - return + repo, err := maven.NewUrlRepository(b.spec.Url, vfsattr.Get(ctx.GetContext())) + if err != nil { + return err + } + return deploy(artifact, repo, reader, ctx.GetContext(), hr) }() if e != nil { return nil, e @@ -115,12 +119,12 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi } // deploy an artifact to the specified destination. See https://jfrog.com/help/r/jfrog-rest-apis/deploy-artifact -func deploy(artifact *maven.Coordinates, url string, reader io.ReadCloser, ctx accspeccpi.Context, hashes *iotools.HashReader) (err error) { - req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, artifact.Url(url), reader) +func deploy(coords *maven.Coordinates, repo *maven.Repository, reader io.ReadCloser, ctx accspeccpi.Context, hashes *iotools.HashReader) (err error) { + req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, coords.Location(repo).String(), reader) if err != nil { return } - err = identity.BasicAuth(req, ctx, url, artifact.GroupPath()) + err = identity.BasicAuth(req, ctx, repo.String(), coords.GroupPath()) if err != nil { return } @@ -143,9 +147,9 @@ func deploy(artifact *maven.Coordinates, url string, reader io.ReadCloser, ctx a if e != nil { return e } - return fmt.Errorf("http (%d) - failed to upload artifact: %s", resp.StatusCode, string(all)) + return fmt.Errorf("http (%d) - failed to upload coords: %s", resp.StatusCode, string(all)) } - log.Debug("uploaded", "artifact", artifact, "extension", artifact.Extension, "classifier", artifact.Classifier) + log.Debug("uploaded", "coords", coords, "extension", coords.Extension, "classifier", coords.Classifier) // Validate the response - especially the hash values with the ones we've tried to send respBody, err := io.ReadAll(resp.Body) @@ -162,9 +166,9 @@ func deploy(artifact *maven.Coordinates, url string, reader io.ReadCloser, ctx a digest := hashes.GetString(crypto.SHA256) remoteDigest := artifactBody.Checksums[strings.ReplaceAll(strings.ToLower(crypto.SHA256.String()), "-", "")] if remoteDigest == "" { - log.Warn("no checksum found for algorithm, we can't guarantee that the artifact has been uploaded correctly", "algorithm", crypto.SHA256) + log.Warn("no checksum found for algorithm, we can't guarantee that the coords has been uploaded correctly", "algorithm", crypto.SHA256) } else if remoteDigest != digest { - return errors.New("failed to upload artifact: checksums do not match") + return errors.New("failed to upload coords: checksums do not match") } log.Debug("digests are ok", "remoteDigest", remoteDigest, "digest", digest) return diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go index c64b3e13bb..82ff6d887e 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go @@ -17,7 +17,7 @@ var _ = Describe("Config deserialization Test Environment", func() { }) It("deserializes struct", func() { - cfg := Must(registrations.DecodeConfig[mvn.Config](`{"Url":"test"}`)) + cfg := Must(registrations.DecodeConfig[mvn.Config](`{"RepoUrl":"test"}`)) Expect(cfg).To(Equal(&mvn.Config{Url: "test"})) }) }) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go index 89aae1d6e9..027c394622 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go @@ -17,7 +17,7 @@ var _ = Describe("Config deserialization Test Environment", func() { }) It("deserializes struct", func() { - cfg := Must(registrations.DecodeConfig[npm.Config](`{"Url":"test"}`)) + cfg := Must(registrations.DecodeConfig[npm.Config](`{"RepoUrl":"test"}`)) Expect(cfg).To(Equal(&npm.Config{Url: "test"})) }) }) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go index e4947738d0..f3a1370c15 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "NPM Repository tests") + RunSpecs(t, "NPM RepoUrl tests") } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go index 5473371796..a49481cb0f 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCI Upload Repository Attribute") + RunSpecs(t, "OCI Upload RepoUrl Attribute") } diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go b/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go index 3e2ab3178a..f3d247d474 100644 --- a/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go @@ -37,6 +37,6 @@ var _ = Describe("", func() { defer Close(cv) MustBeSuccessful(cv.SetResourceAccess(me.ResourceAccess(e.OCMContext(), cpi.NewResourceMeta("helm1", "blob", metav1.LocalRelation), "/testdata/testchart1", me.WithFileSystem(e.FileSystem())))) MustBeSuccessful(cv.SetResourceAccess(me.ResourceAccess(e.OCMContext(), cpi.NewResourceMeta("helm2", "blob", metav1.LocalRelation), "/testdata/testchart2", me.WithFileSystem(e.FileSystem())))) - MustBeSuccessful(ctf.AddComponentVersion(cv)) + MustBeSuccessful(ctf.AddComponentVersion(cv, true)) }) }) diff --git a/pkg/contexts/ocm/plugin/common/describe.go b/pkg/contexts/ocm/plugin/common/describe.go index 2352d7ed6e..0960854c50 100644 --- a/pkg/contexts/ocm/plugin/common/describe.go +++ b/pkg/contexts/ocm/plugin/common/describe.go @@ -43,7 +43,7 @@ func DescribePluginDescriptorCapabilities(reg api.ActionTypeRegistry, d *descrip if len(d.Uploaders) > 0 { out.Printf("\n") // a working type inference would be really great - ListElements[descriptor.UploaderDescriptor, descriptor.UploaderKey]("Repository Uploaders", d.Uploaders, out) + ListElements[descriptor.UploaderDescriptor, descriptor.UploaderKey]("RepoUrl Uploaders", d.Uploaders, out) } if len(d.Downloaders) > 0 { out.Printf("\n") diff --git a/pkg/contexts/ocm/plugin/descriptor/descriptor.go b/pkg/contexts/ocm/plugin/descriptor/descriptor.go index a0c9d01bcf..2a342bb4f5 100644 --- a/pkg/contexts/ocm/plugin/descriptor/descriptor.go +++ b/pkg/contexts/ocm/plugin/descriptor/descriptor.go @@ -32,7 +32,7 @@ func (d *Descriptor) Capabilities() []string { caps = append(caps, "Access Methods") } if len(d.Uploaders) > 0 { - caps = append(caps, "Repository Uploaders") + caps = append(caps, "RepoUrl Uploaders") } if len(d.Downloaders) > 0 { caps = append(caps, "Resource Downloaders") diff --git a/pkg/contexts/ocm/plugin/descriptor/keys.go b/pkg/contexts/ocm/plugin/descriptor/keys.go index e4288213ca..c6f7b4ec9d 100644 --- a/pkg/contexts/ocm/plugin/descriptor/keys.go +++ b/pkg/contexts/ocm/plugin/descriptor/keys.go @@ -28,7 +28,7 @@ func (k RepositoryContext) String() string { func (k RepositoryContext) Describe() string { if k.HasRepo() { - return fmt.Sprintf("Default Repository Upload:\n Context Type: %s\n RepositoryType: %s", k.ContextType, k.RepositoryType) + return fmt.Sprintf("Default RepoUrl Upload:\n Context Type: %s\n RepositoryType: %s", k.ContextType, k.RepositoryType) } return "" } diff --git a/pkg/contexts/ocm/repositories/comparch/comparch_test.go b/pkg/contexts/ocm/repositories/comparch/comparch_test.go index b3f77b9794..9ecc1fed8c 100644 --- a/pkg/contexts/ocm/repositories/comparch/comparch_test.go +++ b/pkg/contexts/ocm/repositories/comparch/comparch_test.go @@ -39,7 +39,7 @@ const ( COMPONENT_VERSION = "1.0.0" ) -var _ = Describe("Repository", func() { +var _ = Describe("RepoUrl", func() { It("marshal/unmarshal simple", func() { octx := ocm.DefaultContext() diff --git a/pkg/contexts/ocm/repositories/composition/suite_test.go b/pkg/contexts/ocm/repositories/composition/suite_test.go index 64a032a7df..4b81c81bbc 100644 --- a/pkg/contexts/ocm/repositories/composition/suite_test.go +++ b/pkg/contexts/ocm/repositories/composition/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCM Composition Repository Test Suite") + RunSpecs(t, "OCM Composition RepoUrl Test Suite") } diff --git a/pkg/contexts/ocm/repositories/genericocireg/suite_test.go b/pkg/contexts/ocm/repositories/genericocireg/suite_test.go index 3daa4931bc..d8a82dcb02 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/suite_test.go +++ b/pkg/contexts/ocm/repositories/genericocireg/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Generic OCI OCM Repository Test Suite") + RunSpecs(t, "Generic OCI OCM RepoUrl Test Suite") } diff --git a/pkg/contexts/ocm/repositories/ocireg/suite_test.go b/pkg/contexts/ocm/repositories/ocireg/suite_test.go index 95a1566969..94bcbb31c0 100644 --- a/pkg/contexts/ocm/repositories/ocireg/suite_test.go +++ b/pkg/contexts/ocm/repositories/ocireg/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCI Registry OCM Repository Test Suite") + RunSpecs(t, "OCI Registry OCM RepoUrl Test Suite") } diff --git a/pkg/contexts/ocm/repositories/virtual/suite_test.go b/pkg/contexts/ocm/repositories/virtual/suite_test.go index d1241c2c4c..bc17d60b05 100644 --- a/pkg/contexts/ocm/repositories/virtual/suite_test.go +++ b/pkg/contexts/ocm/repositories/virtual/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCM Virtual Repository Suite") + RunSpecs(t, "OCM Virtual RepoUrl Suite") } diff --git a/pkg/contexts/ocm/resolver_test.go b/pkg/contexts/ocm/resolver_test.go index 4289b85987..d338956051 100644 --- a/pkg/contexts/ocm/resolver_test.go +++ b/pkg/contexts/ocm/resolver_test.go @@ -51,7 +51,7 @@ var _ = Describe("resolver", func() { cv := Must(ctx.GetResolver().LookupComponentVersion(COMPONENT, VERSION)) /* - err := cv.Repository().Close() + err := cv.RepoUrl().Close() if err != nil { defer cv.Close() Expect(err).To(Succeed()) diff --git a/pkg/contexts/ocm/resourcetypes/const.go b/pkg/contexts/ocm/resourcetypes/const.go index 6c0dc78650..8e29ae25bd 100644 --- a/pkg/contexts/ocm/resourcetypes/const.go +++ b/pkg/contexts/ocm/resourcetypes/const.go @@ -17,7 +17,7 @@ const ( // NPM_PACKAGE describes a Node.js (npm) package. NPM_PACKAGE = "npmPackage" // MVN_ARTIFACT describes a Maven artifact (jar). - MVN_ARTIFACT = "mvnArtifact" + MVN_ARTIFACT = "mavenArtifact" // BLUEPRINT describes a Gardener Landscaper blueprint which is an artifact used in its installations describing // how to deploy a software component. BLUEPRINT = "landscaper.gardener.cloud/blueprint" diff --git a/pkg/contexts/ocm/session.go b/pkg/contexts/ocm/session.go index d9a1cd8d77..52d2dc4c95 100644 --- a/pkg/contexts/ocm/session.go +++ b/pkg/contexts/ocm/session.go @@ -102,7 +102,7 @@ func (s *session) LookupRepository(ctx Context, spec RepositorySpec) (Repository // The repo's closer function should only be added once with add closer. Otherwise, it would be attempted to close // an already closed object. Thus, we only want to add the repo's closer function, if it was not already cached // (and thus, consequently already added to the sessions close). - // Session has to take over responsibility for open repositories for the Repository Cache because the objects + // Session has to take over responsibility for open repositories for the RepoUrl Cache because the objects // opened during a session have to be closed in the reverse order they were opened (e.g. components opened based // on a previously opened repository have to be closed first). if !cached { diff --git a/pkg/contexts/ocm/utils/localize/format.go b/pkg/contexts/ocm/utils/localize/format.go index 5f2a487d13..39a91bc6e0 100644 --- a/pkg/contexts/ocm/utils/localize/format.go +++ b/pkg/contexts/ocm/utils/localize/format.go @@ -34,11 +34,11 @@ type ImageMapping struct { // The optional variants for the value determination - // Path in target to substitute by the image tag/digest + // BasePath in target to substitute by the image tag/digest Tag string `json:"tag,omitempty"` - // Path in target to substitute the image repository + // BasePath in target to substitute the image repository Repository string `json:"repository,omitempty"` - // Path in target to substitute the complete image + // BasePath in target to substitute the complete image Image string `json:"image,omitempty"` } diff --git a/pkg/maven/access.go b/pkg/maven/access.go index 54448d6c8c..e471be0013 100644 --- a/pkg/maven/access.go +++ b/pkg/maven/access.go @@ -8,23 +8,99 @@ import ( "bytes" "context" "crypto" + "encoding/json" "github.com/cloudflare/cfssl/log" "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/goutils/general" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/open-component-model/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/utils/tarutils" "golang.org/x/net/html" "io" "net/http" - "path" + "net/url" "strings" ) +type Repository struct { + Location +} + +type Location struct { + url string + path string + fs vfs.FileSystem +} + +func (l *Location) MarshalJSON() ([]byte, error) { + return json.Marshal(l.String()) +} + +func (l *Location) IsFileSystem() bool { + return l.path != "" +} + +func (l *Location) AddPath(path string) *Location { + result := *l + var p *string + if result.url != "" { + p = &result.url + } else { + p = &result.path + } + + if !strings.HasSuffix(*p, "/") { + *p += "/" + } + *p += path + return &result +} + +func (l *Location) AddExtension(ext string) *Location { + result := *l + var p *string + if result.url != "" { + p = &result.url + } else { + p = &result.path + } + + *p += "." + ext + return &result +} + +func (l *Location) String() string { + return general.Conditional(l.path != "", l.path, l.url) +} + +func NewFileRepository(path string, fss ...vfs.FileSystem) *Repository { + return &Repository{Location{ + path: path, + fs: utils.FileSystem(fss...), + }} +} + +func NewUrlRepository(repoUrl string, fss ...vfs.FileSystem) (*Repository, error) { + u, err := url.Parse(repoUrl) + if err != nil { + return nil, err + } + if u.Scheme == "file" { + if u.Host != "" && u.Host != "localhost" { + return nil, errors.Newf("named host not supported for url file scheme: %q", repoUrl) + } + return NewFileRepository(u.Path, fss...), nil + } + return &Repository{Location{ + url: repoUrl, + }}, nil +} + type FileMeta struct { MimeType string HashType crypto.Hash Hash string - Url string + Location *Location } type Credentials interface { @@ -40,9 +116,9 @@ func (b *BasicAuthCredentials) SetForRequest(req *http.Request) error { return nil } -func GetHash(url string, creds Credentials, hash crypto.Hash, fss ...vfs.FileSystem) (string, error) { +func (l *Location) GetHash(creds Credentials, hash crypto.Hash) (string, error) { // getStringData reads all data from the given URL and returns it as a string. - r, err := GetReader(url+HashUrlExt(hash), creds, fss...) + r, err := l.AddExtension(HashExt(hash)).GetReader(creds) if err != nil { return "", err } @@ -54,14 +130,12 @@ func GetHash(url string, creds Credentials, hash crypto.Hash, fss ...vfs.FileSys return string(b), nil } -func GetReader(url string, creds Credentials, fss ...vfs.FileSystem) (io.ReadCloser, error) { - if strings.HasPrefix(url, "file://") { - fs := utils.FileSystem(fss...) - path := url[7:] - return fs.OpenFile(path, vfs.O_RDONLY, 0o600) +func (l *Location) GetReader(creds Credentials) (io.ReadCloser, error) { + if l.path != "" { + return l.fs.OpenFile(l.path, vfs.O_RDONLY, 0o600) } - req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, l.url, nil) if err != nil { return nil, err } @@ -81,30 +155,30 @@ func GetReader(url string, creds Credentials, fss ...vfs.FileSystem) (io.ReadClo buf := &bytes.Buffer{} _, err = io.Copy(buf, io.LimitReader(resp.Body, 2000)) if err == nil { - Log.Error("http", "code", resp.Status, "url", url, "body", buf.String()) + Log.Error("http", "code", resp.Status, "repo", l.url, "body", buf.String()) } - return nil, errors.Newf("http %s error - %s", resp.Status, url) + return nil, errors.Newf("http %s error - %s", resp.Status, l.url) } return resp.Body, nil } -func GetFileMeta(repoUrl string, c *Coordinates, file string, hash crypto.Hash, creds Credentials, fss ...vfs.FileSystem) (*FileMeta, error) { +func (r *Repository) GetFileMeta(c *Coordinates, file string, hash crypto.Hash, creds Credentials) (*FileMeta, error) { coords := c.Copy() err := coords.SetClassifierExtensionBy(file) if err != nil { return nil, err } metadata := &FileMeta{ - Url: coords.Url(repoUrl), + Location: coords.Location(r), MimeType: coords.MimeType(), } - log := Log.WithValues("file", metadata.Url) + log := Log.WithValues("file", metadata.Location.String()) log.Debug("processing") if hash > 0 { metadata.HashType = hash - metadata.Hash, err = GetHash(metadata.Url, creds, hash, fss...) + metadata.Hash, err = metadata.Location.GetHash(creds, hash) if err != nil { - return nil, errors.Wrapf(err, "cannot read %s digest of: %s", hash, metadata.Url) + return nil, errors.Wrapf(err, "cannot read %s digest of: %s", hash, metadata.Location) } } else { log.Warn("no digest available") @@ -112,12 +186,11 @@ func GetFileMeta(repoUrl string, c *Coordinates, file string, hash crypto.Hash, return metadata, nil } -func GavFiles(repoUrl string, coords *Coordinates, creds Credentials, fss ...vfs.FileSystem) (map[string]crypto.Hash, error) { - if strings.HasPrefix(repoUrl, "file://") { - dir := path.Join(repoUrl[7:], coords.GavPath()) - return gavFilesFromDisk(utils.FileSystem(fss...), dir) +func (r *Repository) GavFiles(coords *Coordinates, creds Credentials) (map[string]crypto.Hash, error) { + if r.path != "" { + return gavFilesFromDisk(r.fs, coords.GavLocation(r).path) } - return gavOnlineFiles(repoUrl, coords, creds) + return gavOnlineFiles(r, coords, creds) } func gavFilesFromDisk(fs vfs.FileSystem, dir string) (map[string]crypto.Hash, error) { @@ -129,11 +202,11 @@ func gavFilesFromDisk(fs vfs.FileSystem, dir string) (map[string]crypto.Hash, er } // gavOnlineFiles returns the files of the Maven (mvn) artifact in the repository and their available digests. -func gavOnlineFiles(repoUrl string, coords *Coordinates, creds Credentials) (map[string]crypto.Hash, error) { - log := Log.WithValues("BaseUrl", repoUrl) +func gavOnlineFiles(repo *Repository, coords *Coordinates, creds Credentials) (map[string]crypto.Hash, error) { + log := Log.WithValues("RepoUrl", repo.String(), "GAV", coords.GavPath()) log.Debug("gavOnlineFiles") - reader, err := GetReader(coords.GavUrl(repoUrl), creds, nil) + reader, err := coords.GavLocation(repo).GetReader(creds) if err != nil { return nil, err } diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go index 795ff35581..5ba6e6ebe2 100644 --- a/pkg/maven/access_test.go +++ b/pkg/maven/access_test.go @@ -19,9 +19,11 @@ const ( var _ = Describe("local accessmethods.me.AccessSpec tests", func() { var env *Builder + var repo *me.Repository BeforeEach(func() { env = NewBuilder(TestData()) + repo = me.NewFileRepository(mvnPATH, env.FileSystem()) }) AfterEach(func() { @@ -29,9 +31,8 @@ var _ = Describe("local accessmethods.me.AccessSpec tests", func() { }) It("accesses local artifact file", func() { - repoUrl := "file://" + mvnPATH coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - files := Must(me.GavFiles(repoUrl, coords, nil, env.FileSystem())) + files := Must(repo.GavFiles(coords, nil)) Expect(files).To(YAMLEqual(` sdk-modules-bom-5.7.0-random-content.json: 3 sdk-modules-bom-5.7.0-random-content.txt: 3 @@ -42,21 +43,19 @@ sdk-modules-bom-5.7.0.pom: 3 }) It("accesses local artifact file with extension", func() { - repoUrl := "file://" + mvnPATH coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) - hash := Must(me.GetHash(coords.Url(repoUrl), nil, crypto.SHA1, env.FileSystem())) + hash := Must(coords.Location(repo).GetHash(nil, crypto.SHA1)) Expect(hash).To(Equal("34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) }) It("", func() { - repoUrl := "file://" + mvnPATH - coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) - meta := Must(me.GetFileMeta(repoUrl, coords, "sdk-modules-bom-5.7.0.pom", crypto.SHA1, nil, env.FileSystem())) + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) + meta := Must(repo.GetFileMeta(coords, "sdk-modules-bom-5.7.0.pom", crypto.SHA1, nil)) Expect(meta).To(YAMLEqual(` Hash: 34ccdeb9c008f8aaef90873fc636b09d3ae5c709 HashType: 3 MimeType: application/xml - Url: file:///testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom + Location: /testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom `)) }) @@ -66,9 +65,8 @@ sdk-modules-bom-5.7.0.pom: 3 coords *me.Coordinates ) BeforeEach(func() { - repoUrl := "file://" + mvnPATH coords = me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") - files = Must(me.GavFiles(repoUrl, coords, nil, env.FileSystem())) + files = Must(repo.GavFiles(coords, nil)) }) It("filters nothing", func() { diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index 8642ac5851..1499c99025 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -87,11 +87,8 @@ func (c *Coordinates) GavPath() string { return c.GroupPath() + "/" + c.ArtifactId + "/" + c.Version } -func (c *Coordinates) GavUrl(repoUrl string) string { - if strings.HasSuffix(repoUrl, "/") { - return repoUrl + c.GavPath() - } - return repoUrl + "/" + c.GavPath() +func (c *Coordinates) GavLocation(repo *Repository) *Location { + return repo.AddPath(c.GavPath()) } // FilePath returns the Maven Coordinates's GAV-name with classifier and extension. @@ -110,11 +107,8 @@ func (c *Coordinates) FilePath() string { return path } -func (c *Coordinates) Url(baseUrl string) string { - if strings.HasSuffix(baseUrl, "/") { - return baseUrl + c.FilePath() - } - return baseUrl + "/" + c.FilePath() +func (c *Coordinates) Location(repo *Repository) *Location { + return repo.AddPath(c.FilePath()) } // GroupPath returns GroupId with `/` instead of `.`. @@ -143,7 +137,7 @@ func (c *Coordinates) SetClassifierExtensionBy(filename string) error { c.Classifier = optionutils.PointerTo(s[:i]) s = strings.TrimPrefix(s, optionutils.AsValue(c.Classifier)) } else { - c.Classifier = nil + c.Classifier = optionutils.PointerTo("") } c.Extension = optionutils.PointerTo(strings.TrimPrefix(s, ".")) return nil diff --git a/pkg/maven/coordinates_test.go b/pkg/maven/coordinates_test.go index fab400b5c2..87d3acb92d 100644 --- a/pkg/maven/coordinates_test.go +++ b/pkg/maven/coordinates_test.go @@ -24,7 +24,8 @@ var _ = Describe("Maven Test Environment", func() { It("SetClassifierExtensionBy", func() { coords := me.NewCoordinates("ocm.software", "hello-ocm", "0.0.1") MustBeSuccessful(coords.SetClassifierExtensionBy("hello-ocm-0.0.1.pom")) - Expect(coords.Classifier).To(BeNil()) + Expect(coords.Classifier).ToNot(BeNil()) + Expect(optionutils.AsValue(coords.Classifier)).To(Equal("")) Expect(optionutils.AsValue(coords.Extension)).To(Equal("pom")) MustBeSuccessful(coords.SetClassifierExtensionBy("hello-ocm-0.0.1-tests.jar")) diff --git a/pkg/maven/utils.go b/pkg/maven/utils.go index c3a2517e07..3d3cd747f0 100644 --- a/pkg/maven/utils.go +++ b/pkg/maven/utils.go @@ -10,10 +10,10 @@ import ( "strings" ) -// HashUrlExt returns the 'maven' hash extension for the given hash. +// HashExt returns the 'maven' hash extension for the given hash. // Maven usually uses sha1, sha256, sha512, md5 instead of SHA-1, SHA-256, SHA-512, MD5. -func HashUrlExt(h crypto.Hash) string { - return "." + strings.ReplaceAll(strings.ToLower(h.String()), "-", "") +func HashExt(h crypto.Hash) string { + return strings.ReplaceAll(strings.ToLower(h.String()), "-", "") } var hashes = [5]crypto.Hash{crypto.SHA512, crypto.SHA256, crypto.SHA1, crypto.MD5} @@ -22,7 +22,7 @@ var hashes = [5]crypto.Hash{crypto.SHA512, crypto.SHA256, crypto.SHA1, crypto.MD // It first checks for SHA-512, then SHA-256, SHA-1, and finally MD5. If nothing is found, it returns 0. func bestAvailableHash(list []string, filename string) crypto.Hash { for _, hash := range hashes { - if slices.Contains(list, filename+HashUrlExt(hash)) { + if slices.Contains(list, filename+"."+HashExt(hash)) { return hash } } diff --git a/pkg/toi/drivers/docker/driver.go b/pkg/toi/drivers/docker/driver.go index d35d71f380..58549980df 100644 --- a/pkg/toi/drivers/docker/driver.go +++ b/pkg/toi/drivers/docker/driver.go @@ -159,7 +159,7 @@ func pullImage(ctx context.Context, cli command.Cli, imageName string) error { return fmt.Errorf("unable to parse normalized name: %w", err) } - // Resolve the Repository name from fqn to RepositoryInfo + // Resolve the RepoUrl name from fqn to RepositoryInfo repoInfo, err := registry.ParseRepositoryInfo(ref) if err != nil { return fmt.Errorf("unable to parse repository info: %w", err) diff --git a/pkg/utils/tarutils/pack.go b/pkg/utils/tarutils/pack.go index c65ce25a78..c5158283e1 100644 --- a/pkg/utils/tarutils/pack.go +++ b/pkg/utils/tarutils/pack.go @@ -44,7 +44,7 @@ func CreateTarFromFs(fs vfs.FileSystem, path string, compress func(w io.Writer) type TarFileSystemOptions struct { IncludeFiles []string ExcludeFiles []string - // PreserveDir defines that the directory specified in the Path field should be included in the blob. + // PreserveDir defines that the directory specified in the BasePath field should be included in the blob. // Only supported for Type dir. PreserveDir bool FollowSymlinks bool From 979f45b3a6cb939ead34662f69262718c09f1673 Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Mon, 27 May 2024 11:08:58 +0200 Subject: [PATCH 05/13] access helper functions --- .../01-basic-componentversion-creation.go | 2 +- .../03-working-with-credentials/common.go | 2 +- .../common.go | 2 +- .../06-signing-component-versions/common.go | 2 +- pkg/blobaccess/maven/access.go | 2 - pkg/blobaccess/maven/maven.go | 35 +++++++ pkg/blobaccess/maven/options.go | 35 ++++++- .../handlers/generic/mvn/blobhandler.go | 4 +- .../handlers/generic/mvn/registration.go | 4 +- .../artifactaccess/mavenaccess/options.go | 20 ++++ .../artifactaccess/mavenaccess/resource.go | 39 ++++++++ .../artifactaccess/mvnaccess/resource.go | 30 ------ .../artifactblob/mavenblob/options.go | 95 +++++++++++++++++++ .../artifactblob/mavenblob/resource.go | 42 ++++++++ .../elements/artifactblob/textblob/options.go | 2 +- .../artifactblob/wgetblob/resource.go | 2 +- pkg/contexts/ocm/resourcetypes/const.go | 4 +- pkg/optionutils/utils.go | 7 ++ 18 files changed, 282 insertions(+), 47 deletions(-) create mode 100644 pkg/blobaccess/maven/maven.go create mode 100644 pkg/contexts/ocm/elements/artifactaccess/mavenaccess/options.go create mode 100644 pkg/contexts/ocm/elements/artifactaccess/mavenaccess/resource.go delete mode 100644 pkg/contexts/ocm/elements/artifactaccess/mvnaccess/resource.go create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go create mode 100644 pkg/optionutils/utils.go 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 7284bcc274..da13cdc0bb 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 @@ -173,7 +173,7 @@ data: some very important data required to understand this component // The above case could also be written as follows: // --- begin setup by access --- res := textblob.ResourceAccess(cv.GetContext(), meta, yamldata, - textblob.WithimeType(mime.MIME_YAML)) + textblob.WithMimeType(mime.MIME_YAML)) err = cv.SetResourceAccess(res) if err != nil { return errors.Wrapf(err, "cannot add yaml document") diff --git a/examples/lib/tour/03-working-with-credentials/common.go b/examples/lib/tour/03-working-with-credentials/common.go index 27aa3149db..86151feab0 100644 --- a/examples/lib/tour/03-working-with-credentials/common.go +++ b/examples/lib/tour/03-working-with-credentials/common.go @@ -136,7 +136,7 @@ data: some very important data required to understand this component // component version. // The above case could be written as follows, also: res := textblob.ResourceAccess(cv.GetContext(), meta, yamldata, - textblob.WithimeType(mime.MIME_YAML)) + textblob.WithMimeType(mime.MIME_YAML)) err = cv.SetResourceAccess(res) if err != nil { return errors.Wrapf(err, "cannot add yaml document") diff --git a/examples/lib/tour/05-transporting-component-versions/common.go b/examples/lib/tour/05-transporting-component-versions/common.go index e170b62eec..81fdab6c30 100644 --- a/examples/lib/tour/05-transporting-component-versions/common.go +++ b/examples/lib/tour/05-transporting-component-versions/common.go @@ -135,7 +135,7 @@ data: some very important data required to understand this component // component version. // The above case could be written as follows, also: res := textblob.ResourceAccess(cv.GetContext(), meta, yamldata, - textblob.WithimeType(mime.MIME_YAML)) + textblob.WithMimeType(mime.MIME_YAML)) err = cv.SetResourceAccess(res) if err != nil { return errors.Wrapf(err, "cannot add yaml document") diff --git a/examples/lib/tour/06-signing-component-versions/common.go b/examples/lib/tour/06-signing-component-versions/common.go index 094ae6c094..f0d013f572 100644 --- a/examples/lib/tour/06-signing-component-versions/common.go +++ b/examples/lib/tour/06-signing-component-versions/common.go @@ -141,7 +141,7 @@ data: some very important data required to understand this component // component version. // The above case could be written as follows, also: res := textblob.ResourceAccess(cv.GetContext(), meta, yamldata, - textblob.WithimeType(mime.MIME_YAML)) + textblob.WithMimeType(mime.MIME_YAML)) err = cv.SetResourceAccess(res) if err != nil { return errors.Wrapf(err, "cannot add yaml document") diff --git a/pkg/blobaccess/maven/access.go b/pkg/blobaccess/maven/access.go index 4a65fe1a2d..6255f8e0c9 100644 --- a/pkg/blobaccess/maven/access.go +++ b/pkg/blobaccess/maven/access.go @@ -7,8 +7,6 @@ import ( "github.com/open-component-model/ocm/pkg/optionutils" ) -type BlobMeta = maven.FileMeta - func DataAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (blobaccess.DataAccess, error) { return BlobAccessForMaven(repo, groupId, artifactId, version, opts...) } diff --git a/pkg/blobaccess/maven/maven.go b/pkg/blobaccess/maven/maven.go new file mode 100644 index 0000000000..41cbed5726 --- /dev/null +++ b/pkg/blobaccess/maven/maven.go @@ -0,0 +1,35 @@ +package maven + +import ( + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/optionutils" +) + +type ( + BlobMeta = maven.FileMeta + Repository = maven.Repository + Coordinates = maven.Coordinates +) + +func NewFileRepository(path string, fss ...vfs.FileSystem) *Repository { + return maven.NewFileRepository(path, fss...) +} + +func NewUrlRepository(repoUrl string, fss ...vfs.FileSystem) (*Repository, error) { + return maven.NewUrlRepository(repoUrl, fss...) +} + +type optionwrapper struct { + options *Options +} + +func (o *optionwrapper) ApplyTo(opts *Coordinates) { + maven.WithOptionalExtension(o.options.Extension).ApplyTo(opts) + maven.WithOptionalClassifier(o.options.Classifier).ApplyTo(opts) +} + +func NewCoordinates(groupId, artifactId, version string, opts ...Option) *Coordinates { + eff := optionutils.EvalOptions(opts...) + return maven.NewCoordinates(groupId, artifactId, version, &optionwrapper{eff}) +} diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index 9f4a38b47a..86161f8476 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -40,6 +40,9 @@ func (o *Options) Cache() *tmpcache.Attribute { if o.CachingPath != "" { return tmpcache.New(o.CachingPath, o.CachingFileSystem) } + if o.CachingContext == nil { + return tmpcache.Get(o.CredentialContext) + } return tmpcache.Get(o.CachingContext) } @@ -120,20 +123,46 @@ func WithLoggingContext(ctx logging.ContextProvider) Option { //////////////////////////////////////////////////////////////////////////////// -type fileSystem struct { +type cachingContext struct { + datacontext.Context +} + +func (o cachingContext) ApplyTo(opts *Options) { + opts.CachingContext = o +} + +func WithCachingContext(ctx datacontext.Context) Option { + return cachingContext{ctx} +} + +//////////////////////////////////////////////////////////////////////////////// + +type cachingFileSystem struct { fs vfs.FileSystem } -func (o *fileSystem) ApplyTo(opts *Options) { +func (o *cachingFileSystem) ApplyTo(opts *Options) { opts.CachingFileSystem = o.fs } func WithCachingFileSystem(fs vfs.FileSystem) Option { - return &fileSystem{fs: fs} + return &cachingFileSystem{fs: fs} } //////////////////////////////////////////////////////////////////////////////// +type cachingPath string + +func (o cachingPath) ApplyTo(opts *Options) { + opts.CachingPath = string(o) +} + +func WithCachingPath(p string) Option { + return cachingPath(p) +} + +/////////////////////////////////////////////////////////////////////////////// + type creds struct { credentials.Credentials } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go index 781788d7bf..43c1814bb6 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go @@ -26,7 +26,7 @@ import ( "github.com/open-component-model/ocm/pkg/utils/tarutils" ) -const BlobHandlerName = "ocm/" + resourcetypes.MVN_ARTIFACT +const BlobHandlerName = "ocm/" + resourcetypes.MAVEN_ARTIFACT type artifactHandler struct { spec *Config @@ -44,7 +44,7 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi return nil, nil } mimeType := blob.MimeType() - if resourcetypes.MVN_ARTIFACT != resourceType { + if resourcetypes.MAVEN_ARTIFACT != resourceType { log.Debug("not a MVN artifact", "resourceType", resourceType) return nil, nil } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go index be1436b455..1ab2a37bb9 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go @@ -43,7 +43,7 @@ var _ cpi.BlobHandlerRegistrationHandler = (*RegistrationHandler)(nil) func (r *RegistrationHandler) RegisterByName(handler string, ctx cpi.Context, config cpi.BlobHandlerConfig, olist ...cpi.BlobHandlerOption) (bool, error) { if handler != "" { - return true, fmt.Errorf("invalid %s handler %q", resourcetypes.MVN_ARTIFACT, handler) + return true, fmt.Errorf("invalid %s handler %q", resourcetypes.MAVEN_ARTIFACT, handler) } if config == nil { return true, fmt.Errorf("mvn target specification required") @@ -54,7 +54,7 @@ func (r *RegistrationHandler) RegisterByName(handler string, ctx cpi.Context, co } ctx.BlobHandlers().Register(NewArtifactHandler(cfg), - cpi.ForArtifactType(resourcetypes.MVN_ARTIFACT), + cpi.ForArtifactType(resourcetypes.MAVEN_ARTIFACT), cpi.ForMimeType(mime.MIME_TGZ), cpi.NewBlobHandlerOptions(olist...), ) diff --git a/pkg/contexts/ocm/elements/artifactaccess/mavenaccess/options.go b/pkg/contexts/ocm/elements/artifactaccess/mavenaccess/options.go new file mode 100644 index 0000000000..8a965b6958 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactaccess/mavenaccess/options.go @@ -0,0 +1,20 @@ +package mavenaccess + +import "github.com/open-component-model/ocm/pkg/maven" + +type ( + Options = maven.Coordinates + Option = maven.CoordinateOption +) + +type WithClassifier = maven.WithClassifier + +func WithOptionalClassifier(c *string) Option { + return maven.WithOptionalClassifier(c) +} + +type WithExtension = maven.WithExtension + +func WithOptionalExtension(e *string) Option { + return maven.WithOptionalExtension(e) +} diff --git a/pkg/contexts/ocm/elements/artifactaccess/mavenaccess/resource.go b/pkg/contexts/ocm/elements/artifactaccess/mavenaccess/resource.go new file mode 100644 index 0000000000..d2a1d2b21e --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactaccess/mavenaccess/resource.go @@ -0,0 +1,39 @@ +package mavenaccess + +import ( + "github.com/open-component-model/ocm/pkg/contexts/ocm" + access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" + "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" + "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" + "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactaccess/genericaccess" + "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" + "github.com/open-component-model/ocm/pkg/maven" +) + +const TYPE = resourcetypes.MAVEN_ARTIFACT + +func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, repoUrl, groupId, artifactId, version string, opts ...Option) cpi.ArtifactAccess[M] { + if meta.GetType() == "" { + meta.SetType(TYPE) + } + + spec := access.New(repoUrl, groupId, artifactId, version, opts...) + // is global access, must work, otherwise there is an error in the lib. + return genericaccess.MustAccess(ctx, meta, spec) +} + +func ResourceAccess(ctx ocm.Context, meta *cpi.ResourceMeta, repoUrl, groupId, artifactId, version string, opts ...Option) cpi.ResourceAccess { + return Access(ctx, meta, repoUrl, groupId, artifactId, version, opts...) +} + +func ResourceAccessForMavenCoords(ctx ocm.Context, meta *cpi.ResourceMeta, repoUrl string, coords *maven.Coordinates) cpi.ResourceAccess { + return Access(ctx, meta, repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)) +} + +func SourceAccess(ctx ocm.Context, meta *cpi.SourceMeta, repoUrl, groupId, artifactId, version string, opts ...Option) cpi.SourceAccess { + return Access(ctx, meta, repoUrl, groupId, artifactId, version, opts...) +} + +func SourceAccessForMavenCoords(ctx ocm.Context, meta *cpi.SourceMeta, repoUrl string, coords *maven.Coordinates) cpi.SourceAccess { + return Access(ctx, meta, repoUrl, coords.GroupId, coords.ArtifactId, coords.Version, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)) +} diff --git a/pkg/contexts/ocm/elements/artifactaccess/mvnaccess/resource.go b/pkg/contexts/ocm/elements/artifactaccess/mvnaccess/resource.go deleted file mode 100644 index 6c90b396a9..0000000000 --- a/pkg/contexts/ocm/elements/artifactaccess/mvnaccess/resource.go +++ /dev/null @@ -1,30 +0,0 @@ -package mvnaccess - -import ( - "github.com/open-component-model/ocm/pkg/contexts/ocm" - access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/mvn" - "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" - "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactaccess/genericaccess" - "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" -) - -const TYPE = resourcetypes.MVN_ARTIFACT - -func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, repository, groupId, artifactId, version string) cpi.ArtifactAccess[M] { - if meta.GetType() == "" { - meta.SetType(TYPE) - } - - spec := access.New(repository, groupId, artifactId, version) - // is global access, must work, otherwise there is an error in the lib. - return genericaccess.MustAccess(ctx, meta, spec) -} - -func ResourceAccess(ctx ocm.Context, meta *cpi.ResourceMeta, repository, groupId, artifactId, version string) cpi.ResourceAccess { - return Access(ctx, meta, repository, groupId, artifactId, version) -} - -func SourceAccess(ctx ocm.Context, meta *cpi.SourceMeta, repository, groupId, artifactId, version string) cpi.SourceAccess { - return Access(ctx, meta, repository, groupId, artifactId, version) -} diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go new file mode 100644 index 0000000000..10bf96d028 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go @@ -0,0 +1,95 @@ +package mavenblob + +import ( + "github.com/mandelsoft/logging" + "github.com/mandelsoft/vfs/pkg/vfs" + base "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/contexts/datacontext" + "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" + "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactblob/api" + "github.com/open-component-model/ocm/pkg/optionutils" +) + +type Option = optionutils.Option[*Options] + +type Options struct { + api.Options + Blob base.Options +} + +var ( + _ api.GeneralOptionsProvider = (*Options)(nil) + _ Option = (*Options)(nil) +) + +func (o *Options) ApplyTo(opts *Options) { + o.Options.ApplyTo(&opts.Options) + o.Blob.ApplyTo(&opts.Blob) +} + +func (o *Options) Apply(opts ...Option) { + optionutils.ApplyOptions(o, opts...) +} + +//////////////////////////////////////////////////////////////////////////////// +// General Options + +func WithHint(h string) Option { + return api.WrapHint[Options](h) +} + +func WithGlobalAccess(a cpi.AccessSpec) Option { + return api.WrapGlobalAccess[Options](a) +} + +//////////////////////////////////////////////////////////////////////////////// +// Local Options + +func mapBaseOption(opts *Options) *base.Options { + return &opts.Blob +} + +func wrapBase(o base.Option) Option { + return optionutils.OptionWrapperFunc[*base.Options, *Options](o, mapBaseOption) +} + +func WithCredentialContext(credctx credentials.ContextProvider) Option { + return wrapBase(base.WithCredentialContext(credctx)) +} + +func WithLoggingContext(logctx logging.ContextProvider) Option { + return wrapBase(base.WithLoggingContext(logctx)) +} + +func WithCachingContext(cachectx datacontext.Context) Option { + return wrapBase(base.WithCachingContext(cachectx)) +} + +func WithCachingFileSystem(fs vfs.FileSystem) Option { + return wrapBase(base.WithCachingFileSystem(fs)) +} + +func WithCachingPath(p string) Option { + return wrapBase(base.WithCachingPath(p)) +} + +func WithCredentials(c credentials.Credentials) Option { + return wrapBase(base.WithCredentials(c)) +} + +func WithClassifier(c string) Option { + return wrapBase(base.WithClassifier(c)) +} + +func WithOptionalClassifier(c *string) Option { + return wrapBase(base.WithOptionalClassifier(c)) +} + +func WithExtension(e string) Option { + return wrapBase(base.WithExtension(e)) +} + +func WithOptionalExtension(e *string) Option { + return wrapBase(base.WithOptionalExtension(e)) +} diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go new file mode 100644 index 0000000000..9ebe571aa6 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go @@ -0,0 +1,42 @@ +package mavenblob + +import ( + "github.com/mandelsoft/goutils/generics" + "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "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" + "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" + "github.com/open-component-model/ocm/pkg/optionutils" +) + +const TYPE = resourcetypes.MAVEN_ARTIFACT + +func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, repo *maven.Repository, groupId, artifactId, version string, opts ...Option) cpi.ArtifactAccess[M] { + eff := optionutils.EvalOptions(optionutils.WithDefaults(opts, WithCredentialContext(ctx))...) + + if meta.GetType() == "" { + meta.SetType(TYPE) + } + + blobprov := maven.BlobAccessProviderForMaven(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) +} + +func ResourceAccess(ctx ocm.Context, meta *ocm.ResourceMeta, repo *maven.Repository, groupId, artifactId, version string, opts ...Option) cpi.ResourceAccess { + return Access(ctx, meta, repo, groupId, artifactId, version, opts...) +} + +func ResourceAccessForMavenCoords(ctx ocm.Context, meta *ocm.ResourceMeta, repo *maven.Repository, coords *maven.Coordinates, opts ...Option) cpi.ResourceAccess { + return Access(ctx, meta, repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) +} + +func SourceAccess(ctx ocm.Context, meta *ocm.SourceMeta, repo *maven.Repository, groupId, artifactId, version string, opts ...Option) cpi.SourceAccess { + return Access(ctx, meta, repo, groupId, artifactId, version, opts...) +} + +func SourceAccessForMavenCoords(ctx ocm.Context, meta *ocm.SourceMeta, repo *maven.Repository, coords *maven.Coordinates, opts ...Option) cpi.SourceAccess { + return Access(ctx, meta, repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) +} diff --git a/pkg/contexts/ocm/elements/artifactblob/textblob/options.go b/pkg/contexts/ocm/elements/artifactblob/textblob/options.go index 46e99a0035..ab1d01c966 100644 --- a/pkg/contexts/ocm/elements/artifactblob/textblob/options.go +++ b/pkg/contexts/ocm/elements/artifactblob/textblob/options.go @@ -30,7 +30,7 @@ func WithGlobalAccess(a cpi.AccessSpec) Option { //////////////////////////////////////////////////////////////////////////////// // Local Options -func WithimeType(mime string) Option { +func WithMimeType(mime string) Option { return datablob.WithMimeType(mime) } diff --git a/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go index 3045c59bef..ef9273b23a 100644 --- a/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/wgetblob/resource.go @@ -14,7 +14,7 @@ import ( const TYPE = resourcetypes.BLOB func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, url string, opts ...Option) cpi.ArtifactAccess[M] { - eff := optionutils.EvalOptions(append([]Option{WithCredentialContext(ctx), WithLoggingContext(ctx)}, opts...)...) + eff := optionutils.EvalOptions(optionutils.WithDefaults(opts, WithCredentialContext(ctx))...) if meta.GetType() == "" { meta.SetType(TYPE) diff --git a/pkg/contexts/ocm/resourcetypes/const.go b/pkg/contexts/ocm/resourcetypes/const.go index 8e29ae25bd..40ee9453e8 100644 --- a/pkg/contexts/ocm/resourcetypes/const.go +++ b/pkg/contexts/ocm/resourcetypes/const.go @@ -16,8 +16,8 @@ const ( HELM_CHART = "helmChart" // NPM_PACKAGE describes a Node.js (npm) package. NPM_PACKAGE = "npmPackage" - // MVN_ARTIFACT describes a Maven artifact (jar). - MVN_ARTIFACT = "mavenArtifact" + // MAVEN_ARTIFACT describes a Maven artifact (jar). + MAVEN_ARTIFACT = "mavenArtifact" // BLUEPRINT describes a Gardener Landscaper blueprint which is an artifact used in its installations describing // how to deploy a software component. BLUEPRINT = "landscaper.gardener.cloud/blueprint" diff --git a/pkg/optionutils/utils.go b/pkg/optionutils/utils.go new file mode 100644 index 0000000000..52479a708c --- /dev/null +++ b/pkg/optionutils/utils.go @@ -0,0 +1,7 @@ +package optionutils + +import "github.com/mandelsoft/goutils/sliceutils" + +func WithDefaults[O any](opts []O, defaults ...O) []O { + return sliceutils.CopyAppend(defaults, opts...) +} From 74ccf31c4880f9d614b89e546c838d7cbd248a6f Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Mon, 27 May 2024 11:33:59 +0200 Subject: [PATCH 06/13] change optionutils package to mandelsoft --- go.mod | 2 +- go.sum | 2 ++ pkg/blobaccess/maven/access.go | 7 ++++--- pkg/blobaccess/maven/maven.go | 3 ++- pkg/blobaccess/maven/options.go | 3 ++- pkg/blobaccess/maven/utils.go | 3 ++- .../ocm/blobhandler/handlers/generic/mvn/blobhandler.go | 8 ++++---- .../ocm/elements/artifactblob/mavenblob/options.go | 3 ++- .../ocm/elements/artifactblob/mavenblob/resource.go | 3 ++- pkg/maven/access_test.go | 4 +++- pkg/maven/coordinates.go | 8 +++++--- pkg/maven/coordinates_test.go | 6 ++++-- 12 files changed, 33 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index df7787db42..95628b7e78 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/klauspost/compress v1.17.8 github.com/klauspost/pgzip v1.2.6 github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 - github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460 + github.com/mandelsoft/goutils v0.0.0-20240527090454-525d51156f92 github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf github.com/mandelsoft/spiff v1.7.0-beta-5 github.com/mandelsoft/vfs v0.4.3 diff --git a/go.sum b/go.sum index 8708b4b5d7..71e543ac8d 100644 --- a/go.sum +++ b/go.sum @@ -683,6 +683,8 @@ github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 h1:oo9nIgnyiBg github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3/go.mod h1:LxhqC7khDoRENwooP6f/vWvia9ivj6TqLYrR39zqkN0= github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460 h1:q44fRqo/PC3eTexd8Q3pO2BTHTABVXsW6DBXRUhC97E= github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460/go.mod h1:EbNqk9JceSMq7MJuALB/vlOpoD4MAGE0TenM9TR+C0o= +github.com/mandelsoft/goutils v0.0.0-20240527090454-525d51156f92 h1:JKHpPtPpkCA7AVRv5trXmqAcncjbfkjiv4x7wGSJnEc= +github.com/mandelsoft/goutils v0.0.0-20240527090454-525d51156f92/go.mod h1:EbNqk9JceSMq7MJuALB/vlOpoD4MAGE0TenM9TR+C0o= github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf h1:WEmgzeArDbp6Aw34jmziMIE5ygo2zpl/atXRq3D7lSw= github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf/go.mod h1:uO460C1lIB3IOOgrbXhAlz3AKsOv4T2K6ALBn3PwuSg= github.com/mandelsoft/spiff v1.7.0-beta-5 h1:3kC10nTviDQhL8diSxp7i4IC2iSiDg6KPbH1CAq7Lfw= diff --git a/pkg/blobaccess/maven/access.go b/pkg/blobaccess/maven/access.go index 6255f8e0c9..b9b963f5d9 100644 --- a/pkg/blobaccess/maven/access.go +++ b/pkg/blobaccess/maven/access.go @@ -1,10 +1,11 @@ package maven import ( + "github.com/mandelsoft/goutils/optionutils" + "github.com/open-component-model/ocm/pkg/blobaccess" "github.com/open-component-model/ocm/pkg/blobaccess/bpi" "github.com/open-component-model/ocm/pkg/maven" - "github.com/open-component-model/ocm/pkg/optionutils" ) func DataAccessForMaven(repo *maven.Repository, groupId, artifactId, version string, opts ...Option) (blobaccess.DataAccess, error) { @@ -22,7 +23,7 @@ func BlobAccessForMaven(repo *maven.Repository, groupId, artifactId, version str } func BlobAccessForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) (blobaccess.BlobAccess, error) { - return BlobAccessForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) + return BlobAccessForMaven(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 { @@ -33,5 +34,5 @@ func BlobAccessProviderForMaven(repo *maven.Repository, groupId, artifactId, ver } func BlobAccessProviderForMavenCoords(repo *maven.Repository, coords *maven.Coordinates, opts ...Option) bpi.BlobAccessProvider { - return BlobAccessProviderForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, append([]Option{WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension)}, opts...)...) + return BlobAccessProviderForMaven(repo, coords.GroupId, coords.ArtifactId, coords.Version, optionutils.WithDefaults(opts, WithOptionalClassifier(coords.Classifier), WithOptionalExtension(coords.Extension))...) } diff --git a/pkg/blobaccess/maven/maven.go b/pkg/blobaccess/maven/maven.go index 41cbed5726..5d334937bb 100644 --- a/pkg/blobaccess/maven/maven.go +++ b/pkg/blobaccess/maven/maven.go @@ -1,9 +1,10 @@ package maven import ( + "github.com/mandelsoft/goutils/optionutils" "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/maven" - "github.com/open-component-model/ocm/pkg/optionutils" ) type ( diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index 86161f8476..2ea8939a13 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -5,15 +5,16 @@ package maven import ( + "github.com/mandelsoft/goutils/optionutils" "github.com/mandelsoft/logging" "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" "github.com/open-component-model/ocm/pkg/contexts/datacontext" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/tmpcache" ocmlog "github.com/open-component-model/ocm/pkg/logging" "github.com/open-component-model/ocm/pkg/maven" - "github.com/open-component-model/ocm/pkg/optionutils" ) type Option = optionutils.Option[*Options] diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index e454e2f4f9..87781cc63e 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -7,8 +7,10 @@ package maven import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" + "github.com/mandelsoft/goutils/optionutils" "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/bpi" "github.com/open-component-model/ocm/pkg/common/accessio" @@ -18,7 +20,6 @@ import ( "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/maven" "github.com/open-component-model/ocm/pkg/mime" - "github.com/open-component-model/ocm/pkg/optionutils" "github.com/open-component-model/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/utils/tarutils" "github.com/opencontainers/go-digest" diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go index 43c1814bb6..7e787ed32d 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go @@ -5,23 +5,23 @@ import ( "crypto" "encoding/json" "fmt" - "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" - access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" - "github.com/open-component-model/ocm/pkg/maven" - "github.com/open-component-model/ocm/pkg/optionutils" "io" "net/http" "strings" "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/goutils/optionutils" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" + access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/logging" + "github.com/open-component-model/ocm/pkg/maven" "github.com/open-component-model/ocm/pkg/mime" "github.com/open-component-model/ocm/pkg/utils/tarutils" ) diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go index 10bf96d028..6bc448da74 100644 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/options.go @@ -1,14 +1,15 @@ package mavenblob import ( + "github.com/mandelsoft/goutils/optionutils" "github.com/mandelsoft/logging" "github.com/mandelsoft/vfs/pkg/vfs" + base "github.com/open-component-model/ocm/pkg/blobaccess/maven" "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/datacontext" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactblob/api" - "github.com/open-component-model/ocm/pkg/optionutils" ) type Option = optionutils.Option[*Options] diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go index 9ebe571aa6..c977c55ad0 100644 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/resource.go @@ -2,12 +2,13 @@ package mavenblob import ( "github.com/mandelsoft/goutils/generics" + "github.com/mandelsoft/goutils/optionutils" + "github.com/open-component-model/ocm/pkg/blobaccess/maven" "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" "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" - "github.com/open-component-model/ocm/pkg/optionutils" ) const TYPE = resourcetypes.MAVEN_ARTIFACT diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go index 5ba6e6ebe2..f4d395067c 100644 --- a/pkg/maven/access_test.go +++ b/pkg/maven/access_test.go @@ -2,13 +2,15 @@ package maven_test import ( "crypto" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" - "github.com/open-component-model/ocm/pkg/optionutils" . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/mandelsoft/goutils/optionutils" + me "github.com/open-component-model/ocm/pkg/maven" ) diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index 1499c99025..3e8db32718 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -7,14 +7,16 @@ package maven import ( "crypto" "fmt" - "github.com/mandelsoft/goutils/generics" - . "github.com/mandelsoft/goutils/regexutils" - "github.com/open-component-model/ocm/pkg/optionutils" "mime" "path" "path/filepath" "strings" + . "github.com/mandelsoft/goutils/regexutils" + + "github.com/mandelsoft/goutils/generics" + "github.com/mandelsoft/goutils/optionutils" + ocmmime "github.com/open-component-model/ocm/pkg/mime" ) diff --git a/pkg/maven/coordinates_test.go b/pkg/maven/coordinates_test.go index 87d3acb92d..24dbcf4a0a 100644 --- a/pkg/maven/coordinates_test.go +++ b/pkg/maven/coordinates_test.go @@ -7,9 +7,11 @@ package maven_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - me "github.com/open-component-model/ocm/pkg/maven" - "github.com/open-component-model/ocm/pkg/optionutils" . "github.com/open-component-model/ocm/pkg/testutils" + + "github.com/mandelsoft/goutils/optionutils" + + me "github.com/open-component-model/ocm/pkg/maven" ) var _ = Describe("Maven Test Environment", func() { From 810b7c6825a2ef45a1a735f604828365af5d7db5 Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Mon, 27 May 2024 12:18:53 +0200 Subject: [PATCH 07/13] artifact blob access test --- .../ocmcmds/common/inputs/types/maven/spec.go | 1 - .../common/options/repooption/option.go | 2 +- .../ocmcmds/plugins/describe/describe.go | 2 +- examples/lib/transfer1/example.go | 2 +- go.mod | 1 + go.sum | 2 - .../credentials/config/config_test.go | 2 +- .../repositories/aliases/repo_test.go | 2 +- .../repositories/directcreds/repo_test.go | 2 +- .../repositories/dockerconfig/repo_test.go | 4 +- .../repositories/gardenerconfig/repo_test.go | 2 +- .../repositories/memory/config/type.go | 2 +- .../repositories/memory/repo_test.go | 2 +- .../repositories/npm/repository_test.go | 2 +- .../repositories/npm/suite_test.go | 2 +- .../oci/repositories/ctf/repository.go | 2 +- .../ocm/accessmethods/localblob/cli.go | 2 +- .../ocm/attrs/ociuploadattr/suite_test.go | 2 +- .../handlers/generic/mvn/registration_test.go | 2 +- .../handlers/generic/npm/registration_test.go | 2 +- .../handlers/generic/npm/suite_test.go | 2 +- .../handlers/generic/ocirepo/suite_test.go | 2 +- .../artifactblob/mavenblob/access_test.go | 64 ++++++ .../artifactblob/mavenblob/suite_test.go | 13 ++ .../fail/test/repository/42/repository-42.pom | 14 ++ .../test/repository/42/repository-42.pom.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.json | 1 + ...modules-bom-5.7.0-random-content.json.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.txt | 1 + ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 0 -> 595 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 0 -> 595 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ++++++++++++++++++ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 + pkg/contexts/ocm/plugin/common/describe.go | 2 +- .../ocm/plugin/descriptor/descriptor.go | 2 +- pkg/contexts/ocm/plugin/descriptor/keys.go | 2 +- .../repositories/comparch/comparch_test.go | 2 +- .../repositories/composition/suite_test.go | 2 +- .../repositories/genericocireg/suite_test.go | 2 +- .../ocm/repositories/ocireg/suite_test.go | 2 +- .../ocm/repositories/virtual/suite_test.go | 2 +- pkg/contexts/ocm/resolver_test.go | 2 +- 45 files changed, 339 insertions(+), 32 deletions(-) create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/suite_test.go create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom create mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 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 e6581d2f29..2e5a39abf7 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go @@ -15,7 +15,6 @@ import ( type Spec struct { cpi.PathSpec `json:",inline"` // RepoUrl defines the url from which the artifact is downloaded. - // RepoUrl is the base URL of the Maven (mvn) repository. RepoUrl string `json:"repoUrl,omitempty"` maven.Coordinates `json:",inline"` diff --git a/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go b/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go index 53ab5e8b6f..f922398789 100644 --- a/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go +++ b/cmds/ocm/commands/ocmcmds/common/options/repooption/option.go @@ -94,7 +94,7 @@ Dedicated OCM repository types: s += listformat.FormatMapElements("", runtime.KindToVersionList(ocm.DefaultContext().RepositoryTypes().KnownTypeNames())) s += ` -OCI RepoUrl types (using standard component repository to OCI mapping): +OCI Repository types (using standard component repository to OCI mapping): ` s += listformat.FormatMapElements("", runtime.KindToVersionList(oci.DefaultContext().RepositoryTypes().KnownTypeNames(), genericocireg.Excludes...)) return s diff --git a/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go b/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go index bbbd369590..8df5cfd5b8 100644 --- a/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go +++ b/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go @@ -32,7 +32,7 @@ func DescribePlugin(p plugin.Plugin, out common.Printer) { return } - out.Printf(" RepoUrl: %s\n", u.String()) + out.Printf(" Repository: %s\n", u.String()) out.Printf(" Specification: %s\n", string(data)) } else { out.Printf("Source: manually installed\n") diff --git a/examples/lib/transfer1/example.go b/examples/lib/transfer1/example.go index 9a08f5a728..ff534fc62b 100644 --- a/examples/lib/transfer1/example.go +++ b/examples/lib/transfer1/example.go @@ -117,7 +117,7 @@ func TransferApplication() (rerr error) { } // if you know you have an OCI registry based OCM repository - // repoSpec := ocireg.NewRepositorySpec(cfg.RepoUrl) + // repoSpec := ocireg.NewRepositorySpec(cfg.Repository) // if you want to provide specific credentials.... // target, err := octx.RepositoryForSpec(repoSpec, cfg.GetCredentials()) diff --git a/go.mod b/go.mod index 95628b7e78..84a8c9eeed 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.21 github.com/aws/aws-sdk-go-v2/service/ecr v1.28.3 github.com/aws/aws-sdk-go-v2/service/s3 v1.54.3 + github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 github.com/containerd/containerd v1.7.17 github.com/containerd/log v0.1.0 github.com/containers/image/v5 v5.31.0 diff --git a/go.sum b/go.sum index 71e543ac8d..f635f11af8 100644 --- a/go.sum +++ b/go.sum @@ -681,8 +681,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0 github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3 h1:oo9nIgnyiBgYPbcZslRT4y29siuL5EoNJ/t1tr0xEVQ= github.com/mandelsoft/filepath v0.0.0-20240223090642-3e2777258aa3/go.mod h1:LxhqC7khDoRENwooP6f/vWvia9ivj6TqLYrR39zqkN0= -github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460 h1:q44fRqo/PC3eTexd8Q3pO2BTHTABVXsW6DBXRUhC97E= -github.com/mandelsoft/goutils v0.0.0-20240523093855-5385ed52b460/go.mod h1:EbNqk9JceSMq7MJuALB/vlOpoD4MAGE0TenM9TR+C0o= github.com/mandelsoft/goutils v0.0.0-20240527090454-525d51156f92 h1:JKHpPtPpkCA7AVRv5trXmqAcncjbfkjiv4x7wGSJnEc= github.com/mandelsoft/goutils v0.0.0-20240527090454-525d51156f92/go.mod h1:EbNqk9JceSMq7MJuALB/vlOpoD4MAGE0TenM9TR+C0o= github.com/mandelsoft/logging v0.0.0-20240201091719-67180059d6bf h1:WEmgzeArDbp6Aw34jmziMIE5ygo2zpl/atXRq3D7lSw= diff --git a/pkg/contexts/credentials/config/config_test.go b/pkg/contexts/credentials/config/config_test.go index 21a59e4d6d..6871066ebf 100644 --- a/pkg/contexts/credentials/config/config_test.go +++ b/pkg/contexts/credentials/config/config_test.go @@ -146,7 +146,7 @@ var _ = Describe("generic credentials", func() { repo, err := ctx.RepositoryForSpec(spec) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.Repository")) }) It("applies a config for consumers", func() { diff --git a/pkg/contexts/credentials/repositories/aliases/repo_test.go b/pkg/contexts/credentials/repositories/aliases/repo_test.go index 11db237c83..326d38dd56 100644 --- a/pkg/contexts/credentials/repositories/aliases/repo_test.go +++ b/pkg/contexts/credentials/repositories/aliases/repo_test.go @@ -46,7 +46,7 @@ var _ = Describe("alias credentials", func() { repo, err := DefaultContext.RepositoryForConfig([]byte(specdata), nil) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.Repository")) }) It("sets and retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/directcreds/repo_test.go b/pkg/contexts/credentials/repositories/directcreds/repo_test.go index 6bc1f3d552..3694363e89 100644 --- a/pkg/contexts/credentials/repositories/directcreds/repo_test.go +++ b/pkg/contexts/credentials/repositories/directcreds/repo_test.go @@ -30,7 +30,7 @@ var _ = Describe("direct credentials", func() { It("deserializes credentials spec", func() { spec, err := DefaultContext.RepositoryForConfig([]byte(propsdata), nil) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(spec).String()).To(Equal("*directcreds.RepoUrl")) + Expect(reflect.TypeOf(spec).String()).To(Equal("*directcreds.Repository")) }) It("resolved direct credentials", func() { diff --git a/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go b/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go index 69c665b0f5..6945a809ae 100644 --- a/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go +++ b/pkg/contexts/credentials/repositories/dockerconfig/repo_test.go @@ -62,7 +62,7 @@ var _ = Describe("docker config", func() { It("resolves repository", func() { repo := Must(DefaultContext.RepositoryForConfig([]byte(specdata), nil)) - Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.Repository")) }) It("retrieves credentials", func() { @@ -122,7 +122,7 @@ var _ = Describe("docker config", func() { It("resolves repository", func() { repo := Must(DefaultContext.RepositoryForConfig([]byte(specdata), nil)) - Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*dockerconfig.Repository")) }) It("retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go b/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go index 728e83afc6..5c51f5ed28 100644 --- a/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go +++ b/pkg/contexts/credentials/repositories/gardenerconfig/repo_test.go @@ -91,7 +91,7 @@ var _ = Describe("gardener config", func() { repo, err := defaultContext.RepositoryForConfig([]byte(specdata), nil) Expect(err).ToNot(HaveOccurred()) Expect(repo).ToNot(BeNil()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*gardenerconfig.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*gardenerconfig.Repository")) }) It("retrieves credentials from unencrypted server", func() { diff --git a/pkg/contexts/credentials/repositories/memory/config/type.go b/pkg/contexts/credentials/repositories/memory/config/type.go index be6d144191..3e1b5aecd3 100644 --- a/pkg/contexts/credentials/repositories/memory/config/type.go +++ b/pkg/contexts/credentials/repositories/memory/config/type.go @@ -82,7 +82,7 @@ func (a *Config) ApplyTo(ctx cfgcpi.Context, target interface{}) error { mem, ok := repo.(*memory.Repository) if !ok { - return fmt.Errorf("invalid type assertion of type %T to memory.RepoUrl", repo) + return fmt.Errorf("invalid type assertion of type %T to memory.Repository", repo) } for i, e := range a.Credentials { diff --git a/pkg/contexts/credentials/repositories/memory/repo_test.go b/pkg/contexts/credentials/repositories/memory/repo_test.go index 09e847bda4..58af3b1828 100644 --- a/pkg/contexts/credentials/repositories/memory/repo_test.go +++ b/pkg/contexts/credentials/repositories/memory/repo_test.go @@ -45,7 +45,7 @@ var _ = Describe("direct credentials", func() { It("resolves repository", func() { repo, err := DefaultContext.RepositoryForConfig([]byte(specdata), nil) Expect(err).To(Succeed()) - Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*memory.Repository")) }) It("sets and retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/npm/repository_test.go b/pkg/contexts/credentials/repositories/npm/repository_test.go index 6ff9514d37..e7fd29cfa6 100644 --- a/pkg/contexts/credentials/repositories/npm/repository_test.go +++ b/pkg/contexts/credentials/repositories/npm/repository_test.go @@ -48,7 +48,7 @@ var _ = Describe("NPM config - .npmrc", func() { It("resolves repository", func() { repo := Must(DefaultContext.RepositoryForConfig([]byte(specdata), nil)) - Expect(reflect.TypeOf(repo).String()).To(Equal("*npm.RepoUrl")) + Expect(reflect.TypeOf(repo).String()).To(Equal("*npm.Repository")) }) It("retrieves credentials", func() { diff --git a/pkg/contexts/credentials/repositories/npm/suite_test.go b/pkg/contexts/credentials/repositories/npm/suite_test.go index f3a1370c15..e4947738d0 100644 --- a/pkg/contexts/credentials/repositories/npm/suite_test.go +++ b/pkg/contexts/credentials/repositories/npm/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "NPM RepoUrl tests") + RunSpecs(t, "NPM Repository tests") } diff --git a/pkg/contexts/oci/repositories/ctf/repository.go b/pkg/contexts/oci/repositories/ctf/repository.go index 747ea3def7..d65dfe3e83 100644 --- a/pkg/contexts/oci/repositories/ctf/repository.go +++ b/pkg/contexts/oci/repositories/ctf/repository.go @@ -117,7 +117,7 @@ func (a *RepositoryImpl) getIndex() *index.RepositoryIndex { } //////////////////////////////////////////////////////////////////////////////// -// cpi.RepoUrl methods +// cpi.Repository methods func (r *RepositoryImpl) ExistsArtifact(name string, tag string) (bool, error) { return r.getIndex().HasArtifact(name, tag), nil diff --git a/pkg/contexts/ocm/accessmethods/localblob/cli.go b/pkg/contexts/ocm/accessmethods/localblob/cli.go index 5f8edabe9c..9a1d5a0902 100644 --- a/pkg/contexts/ocm/accessmethods/localblob/cli.go +++ b/pkg/contexts/ocm/accessmethods/localblob/cli.go @@ -41,7 +41,7 @@ The type specific specification fields are: - **localReference** *string* - RepoUrl type specific location information as string. The value + Repository type specific location information as string. The value may encode any deep structure, but typically just an access path is sufficient. - **mediaType** *string* diff --git a/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go b/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go index 8267b39b70..b6e55ed373 100644 --- a/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go +++ b/pkg/contexts/ocm/attrs/ociuploadattr/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCI Upload RepoUrl Attribute") + RunSpecs(t, "OCI Upload Repository Attribute") } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go index 82ff6d887e..bf967f24eb 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go @@ -17,7 +17,7 @@ var _ = Describe("Config deserialization Test Environment", func() { }) It("deserializes struct", func() { - cfg := Must(registrations.DecodeConfig[mvn.Config](`{"RepoUrl":"test"}`)) + cfg := Must(registrations.DecodeConfig[mvn.Config](`{"url":"test"}`)) Expect(cfg).To(Equal(&mvn.Config{Url: "test"})) }) }) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go index 027c394622..e254dd1ede 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/registration_test.go @@ -17,7 +17,7 @@ var _ = Describe("Config deserialization Test Environment", func() { }) It("deserializes struct", func() { - cfg := Must(registrations.DecodeConfig[npm.Config](`{"RepoUrl":"test"}`)) + cfg := Must(registrations.DecodeConfig[npm.Config](`{"url":"test"}`)) Expect(cfg).To(Equal(&npm.Config{Url: "test"})) }) }) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go index f3a1370c15..e4947738d0 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/npm/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "NPM RepoUrl tests") + RunSpecs(t, "NPM Repository tests") } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go index a49481cb0f..5473371796 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCI Upload RepoUrl Attribute") + RunSpecs(t, "OCI Upload Repository Attribute") } diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go new file mode 100644 index 0000000000..b8cd73d738 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go @@ -0,0 +1,64 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package mavenblob_test + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/contexts/ocm/elements" + me "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactblob/mavenblob" + "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/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + "github.com/open-component-model/ocm/pkg/maven" + . "github.com/open-component-model/ocm/pkg/testutils" +) + +const ( + mvnPATH = "/testdata/.m2/repository" + FAILPATH = "/testdata/.m2/fail" + MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" + MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" + MAVEN_GROUP_ID = "maven" + MAVEN_ARTIFACT_ID = "maven" + MAVEN_VERSION = "1.1" +) + +var _ = Describe("blobaccess for maven", func() { + + Context("maven filesystem repository", func() { + var env *Builder + var repo *maven.Repository + + BeforeEach(func() { + env = NewBuilder(TestData()) + repo = maven.NewFileRepository(mvnPATH, env.FileSystem()) + }) + + AfterEach(func() { + MustBeSuccessful(env.Cleanup()) + }) + + It("blobaccess for a single file with classifier and extension", func() { + cv := composition.NewComponentVersion(env.OCMContext(), "acme.org/test", "1.0.0") + defer Close(cv) + + coords := maven.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", + maven.WithClassifier("random-content"), maven.WithExtension("json")) + + a := me.ResourceAccessForMavenCoords(env.OCMContext(), Must(elements.ResourceMeta("mavenblob", resourcetypes.OCM_JSON, elements.WithLocalRelation())), repo, coords, me.WithCachingFileSystem(env.FileSystem())) + b := Must(a.BlobAccess()) + defer Close(b) + Expect(string(Must(b.Get()))).To(Equal(`{"some": "test content"}`)) + + MustBeSuccessful(cv.SetResourceAccess(a)) + r := Must(cv.GetResourceByIndex(0)) + m := Must(r.AccessMethod()) + defer Close(m) + Expect(string(Must(m.Get()))).To(Equal(`{"some": "test content"}`)) + }) + }) +}) diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/suite_test.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/suite_test.go new file mode 100644 index 0000000000..a083b2234c --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/suite_test.go @@ -0,0 +1,13 @@ +package mavenblob_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestConfig(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Maven Blob Access Test Suite") +} diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom new file mode 100644 index 0000000000..218894d775 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom @@ -0,0 +1,14 @@ + + + 4.0.0 + fail + repository + 42 + pom + ocm + test + + SAP SE + https://www.sap.com + + diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 new file mode 100644 index 0000000000..3d6c52fe9e --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 @@ -0,0 +1 @@ +44a77645201d1a8fc5213ace787c220eabbd0967 \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json new file mode 100644 index 0000000000..2f1fc35fdc --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json @@ -0,0 +1 @@ +{"some": "test content"} \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 new file mode 100644 index 0000000000..d6836aeaa0 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 @@ -0,0 +1 @@ +f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt new file mode 100644 index 0000000000..b4af84697f --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt @@ -0,0 +1 @@ +some test content \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 new file mode 100644 index 0000000000..55eceeb992 --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 @@ -0,0 +1 @@ +dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..8564f0addae8de5525417df8294d13c0c2a3a7c0 GIT binary patch literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo + + 4.0.0 + com.sap.cloud.sdk + sdk-modules-bom + 5.7.0 + pom + SAP Cloud SDK - Modules BOM + Bill of Materials (BOM) of the SAP Cloud SDK modules. + https://sap.github.io/cloud-sdk/docs/java/getting-started + + SAP SE + https://www.sap.com + + + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + SAP + cloudsdk@sap.com + SAP SE + https://www.sap.com + + + + + + + + UTF-8 + Public + Stable + + 5.7.0 + + + + + com.sap.cloud.sdk + sdk-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + dwc-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + caching + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient4 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient5 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity-scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-destination-service + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-oauth + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-dwc + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-ztis + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience-api + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience4j + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + security + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + servlet-jakarta + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + tenant + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-core + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + rfc + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + datamodel-metadata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator-utility + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-client + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + fluent-result + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + + soap + ${sdk.version} + + + + diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 new file mode 100644 index 0000000000..35f63a2e1f --- /dev/null +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 @@ -0,0 +1 @@ +34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/contexts/ocm/plugin/common/describe.go b/pkg/contexts/ocm/plugin/common/describe.go index 0960854c50..2352d7ed6e 100644 --- a/pkg/contexts/ocm/plugin/common/describe.go +++ b/pkg/contexts/ocm/plugin/common/describe.go @@ -43,7 +43,7 @@ func DescribePluginDescriptorCapabilities(reg api.ActionTypeRegistry, d *descrip if len(d.Uploaders) > 0 { out.Printf("\n") // a working type inference would be really great - ListElements[descriptor.UploaderDescriptor, descriptor.UploaderKey]("RepoUrl Uploaders", d.Uploaders, out) + ListElements[descriptor.UploaderDescriptor, descriptor.UploaderKey]("Repository Uploaders", d.Uploaders, out) } if len(d.Downloaders) > 0 { out.Printf("\n") diff --git a/pkg/contexts/ocm/plugin/descriptor/descriptor.go b/pkg/contexts/ocm/plugin/descriptor/descriptor.go index 2a342bb4f5..a0c9d01bcf 100644 --- a/pkg/contexts/ocm/plugin/descriptor/descriptor.go +++ b/pkg/contexts/ocm/plugin/descriptor/descriptor.go @@ -32,7 +32,7 @@ func (d *Descriptor) Capabilities() []string { caps = append(caps, "Access Methods") } if len(d.Uploaders) > 0 { - caps = append(caps, "RepoUrl Uploaders") + caps = append(caps, "Repository Uploaders") } if len(d.Downloaders) > 0 { caps = append(caps, "Resource Downloaders") diff --git a/pkg/contexts/ocm/plugin/descriptor/keys.go b/pkg/contexts/ocm/plugin/descriptor/keys.go index c6f7b4ec9d..e4288213ca 100644 --- a/pkg/contexts/ocm/plugin/descriptor/keys.go +++ b/pkg/contexts/ocm/plugin/descriptor/keys.go @@ -28,7 +28,7 @@ func (k RepositoryContext) String() string { func (k RepositoryContext) Describe() string { if k.HasRepo() { - return fmt.Sprintf("Default RepoUrl Upload:\n Context Type: %s\n RepositoryType: %s", k.ContextType, k.RepositoryType) + return fmt.Sprintf("Default Repository Upload:\n Context Type: %s\n RepositoryType: %s", k.ContextType, k.RepositoryType) } return "" } diff --git a/pkg/contexts/ocm/repositories/comparch/comparch_test.go b/pkg/contexts/ocm/repositories/comparch/comparch_test.go index 9ecc1fed8c..b3f77b9794 100644 --- a/pkg/contexts/ocm/repositories/comparch/comparch_test.go +++ b/pkg/contexts/ocm/repositories/comparch/comparch_test.go @@ -39,7 +39,7 @@ const ( COMPONENT_VERSION = "1.0.0" ) -var _ = Describe("RepoUrl", func() { +var _ = Describe("Repository", func() { It("marshal/unmarshal simple", func() { octx := ocm.DefaultContext() diff --git a/pkg/contexts/ocm/repositories/composition/suite_test.go b/pkg/contexts/ocm/repositories/composition/suite_test.go index 4b81c81bbc..64a032a7df 100644 --- a/pkg/contexts/ocm/repositories/composition/suite_test.go +++ b/pkg/contexts/ocm/repositories/composition/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCM Composition RepoUrl Test Suite") + RunSpecs(t, "OCM Composition Repository Test Suite") } diff --git a/pkg/contexts/ocm/repositories/genericocireg/suite_test.go b/pkg/contexts/ocm/repositories/genericocireg/suite_test.go index d8a82dcb02..3daa4931bc 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/suite_test.go +++ b/pkg/contexts/ocm/repositories/genericocireg/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Generic OCI OCM RepoUrl Test Suite") + RunSpecs(t, "Generic OCI OCM Repository Test Suite") } diff --git a/pkg/contexts/ocm/repositories/ocireg/suite_test.go b/pkg/contexts/ocm/repositories/ocireg/suite_test.go index 94bcbb31c0..95a1566969 100644 --- a/pkg/contexts/ocm/repositories/ocireg/suite_test.go +++ b/pkg/contexts/ocm/repositories/ocireg/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCI Registry OCM RepoUrl Test Suite") + RunSpecs(t, "OCI Registry OCM Repository Test Suite") } diff --git a/pkg/contexts/ocm/repositories/virtual/suite_test.go b/pkg/contexts/ocm/repositories/virtual/suite_test.go index bc17d60b05..d1241c2c4c 100644 --- a/pkg/contexts/ocm/repositories/virtual/suite_test.go +++ b/pkg/contexts/ocm/repositories/virtual/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "OCM Virtual RepoUrl Suite") + RunSpecs(t, "OCM Virtual Repository Suite") } diff --git a/pkg/contexts/ocm/resolver_test.go b/pkg/contexts/ocm/resolver_test.go index d338956051..4289b85987 100644 --- a/pkg/contexts/ocm/resolver_test.go +++ b/pkg/contexts/ocm/resolver_test.go @@ -51,7 +51,7 @@ var _ = Describe("resolver", func() { cv := Must(ctx.GetResolver().LookupComponentVersion(COMPONENT, VERSION)) /* - err := cv.RepoUrl().Close() + err := cv.Repository().Close() if err != nil { defer cv.Close() Expect(err).To(Succeed()) From 6f62eca99be373fb2d79b981b8af75c494db3d7b Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Mon, 27 May 2024 18:46:18 +0200 Subject: [PATCH 08/13] implement up- and download --- pkg/blobaccess/maven/options.go | 11 +- pkg/blobaccess/maven/utils.go | 12 + .../builtin/maven/identity/identity.go | 20 -- .../handlers/generic/maven/blobhandler.go | 124 +++++++++++ .../generic/maven/blobhandler_test.go | 99 +++++++++ .../generic/{mvn => maven}/registration.go | 50 ++++- .../{mvn => maven}/registration_test.go | 12 +- .../generic/{mvn => maven}/suite_test.go | 2 +- .../sdk-modules-bom-5.7.0-random-content.json | 1 + ...modules-bom-5.7.0-random-content.json.sha1 | 1 + .../sdk-modules-bom-5.7.0-random-content.txt | 1 + ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 0 -> 595 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 0 -> 595 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 + .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ++++++++++++++++++ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 + .../handlers/generic/mvn/blobhandler.go | 186 ---------------- .../handlers/generic/mvn/blobhandler_test.go | 43 ---- pkg/contexts/ocm/blobhandler/handlers/init.go | 2 +- pkg/iotools/hashReaderWriter.go | 140 +++++------- pkg/iotools/hashReaderWriter_test.go | 49 ++-- pkg/maven/access.go | 155 ++++++++++++- pkg/maven/access_test.go | 19 +- pkg/maven/coordinates.go | 23 +- pkg/maven/utils.go | 15 +- 27 files changed, 786 insertions(+), 393 deletions(-) create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go rename pkg/contexts/ocm/blobhandler/handlers/generic/{mvn => maven}/registration.go (60%) rename pkg/contexts/ocm/blobhandler/handlers/generic/{mvn => maven}/registration_test.go (58%) rename pkg/contexts/ocm/blobhandler/handlers/generic/{mvn => maven}/suite_test.go (90%) create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom create mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler_test.go diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index 2ea8939a13..b88b6d2fdd 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -10,7 +10,6 @@ import ( "github.com/mandelsoft/vfs/pkg/vfs" "github.com/open-component-model/ocm/pkg/contexts/credentials" - "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" "github.com/open-component-model/ocm/pkg/contexts/datacontext" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/tmpcache" ocmlog "github.com/open-component-model/ocm/pkg/logging" @@ -56,15 +55,7 @@ func (o *Options) GetCredentials(repo *maven.Repository, groupId string) (maven. case o.Credentials != nil: return MapCredentials(o.Credentials), nil case o.CredentialContext != nil: - consumerid, err := identity.GetConsumerId(repo.String(), groupId) - if err != nil { - return nil, err - } - creds, err := credentials.CredentialsForConsumer(o.CredentialContext, consumerid, identity.IdentityMatcher) - if err != nil { - return nil, err - } - return MapCredentials(creds), nil + return GetCredentials(o.CredentialContext, repo, groupId) default: return nil, nil } diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index 87781cc63e..b7df6cfd50 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -156,3 +156,15 @@ func MapCredentials(creds credentials.Credentials) maven.Credentials { Password: creds.GetProperty(identity.ATTR_PASSWORD), } } + +func GetCredentials(ctx credentials.ContextProvider, repo *Repository, groupId string) (maven.Credentials, error) { + consumerid, err := identity.GetConsumerId(repo.String(), groupId) + if err != nil { + return nil, err + } + creds, err := credentials.CredentialsForConsumer(ctx, consumerid, identity.IdentityMatcher) + if err != nil { + return nil, err + } + return MapCredentials(creds), nil +} diff --git a/pkg/contexts/credentials/builtin/maven/identity/identity.go b/pkg/contexts/credentials/builtin/maven/identity/identity.go index 0a5bf6fc74..7d407a2953 100644 --- a/pkg/contexts/credentials/builtin/maven/identity/identity.go +++ b/pkg/contexts/credentials/builtin/maven/identity/identity.go @@ -1,14 +1,10 @@ package identity import ( - "errors" - "net/http" - . "net/url" "github.com/open-component-model/ocm/pkg/contexts/credentials/cpi" "github.com/open-component-model/ocm/pkg/contexts/credentials/identity/hostpath" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" "github.com/open-component-model/ocm/pkg/listformat" "github.com/open-component-model/ocm/pkg/logging" ) @@ -64,19 +60,3 @@ func GetCredentials(ctx cpi.ContextProvider, repoUrl, groupId string) (cpi.Crede } return cpi.CredentialsForConsumer(ctx.CredentialsContext(), id) } - -func BasicAuth(req *http.Request, ctx accspeccpi.Context, repoUrl, groupId string) (err error) { - credentials, err := GetCredentials(ctx, repoUrl, groupId) - if err != nil { - return err - } - if credentials == nil { - logging.DynamicLogger(REALM).Debug("No credentials found. BasicAuth not required?", "url", repoUrl, "groupId", groupId) - return nil - } - if !credentials.ExistsProperty(ATTR_USERNAME) || !credentials.ExistsProperty(ATTR_PASSWORD) { - return errors.New("missing username or password in credentials") - } - req.SetBasicAuth(credentials.GetProperty(ATTR_USERNAME), credentials.GetProperty(ATTR_PASSWORD)) - return -} diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go new file mode 100644 index 0000000000..5290feff66 --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go @@ -0,0 +1,124 @@ +package maven + +import ( + "crypto" + "github.com/mandelsoft/goutils/finalizer" + "github.com/mandelsoft/vfs/pkg/vfs" + mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" + access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" + "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" + "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" + "github.com/open-component-model/ocm/pkg/iotools" + "github.com/open-component-model/ocm/pkg/logging" + "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/mime" + "github.com/open-component-model/ocm/pkg/utils/tarutils" +) + +const BlobHandlerName = "ocm/" + resourcetypes.MAVEN_ARTIFACT + +type artifactHandler struct { + spec *Config +} + +func NewArtifactHandler(repospec *Config) cpi.BlobHandler { + return &artifactHandler{repospec} +} + +var log = logging.DynamicLogger(identity.REALM) + +func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hint string, _ cpi.AccessSpec, ctx cpi.StorageContext) (_ cpi.AccessSpec, rerr error) { + var finalize finalizer.Finalizer + defer finalize.FinalizeWithErrorPropagation(&rerr) + + // check conditions + if b.spec == nil { + return nil, nil + } + mimeType := blob.MimeType() + if resourcetypes.MAVEN_ARTIFACT != resourceType { + log.Debug("not a MVN artifact", "resourceType", resourceType) + return nil, nil + } + if mime.MIME_TGZ != mimeType { + log.Debug("not a tarball, can't be a complete mvn GAV", "mimeType", mimeType) + return nil, nil + } + + repo, err := b.spec.GetRepository(ctx.GetContext()) + if err != nil { + return nil, err + } + + // setup logger + log := log.WithValues("repository", repo.String()) + // identify artifact + coords, err := maven.Parse(hint) + if err != nil { + return nil, err + } + if coords.Classifier != nil || coords.Extension != nil { + return nil, nil + } + log = log.WithValues("groupId", coords.GroupId, "artifactId", coords.ArtifactId, "version", coords.Version) + log.Debug("identified") + + blobReader, err := blob.Reader() + if err != nil { + return nil, err + } + finalize.Close(blobReader) + tempFs, err := tarutils.ExtractTgzToTempFs(blobReader) + if err != nil { + return nil, err + } + finalize.With(func() error { return vfs.Cleanup(tempFs) }) + files, err := tarutils.ListSortedFilesInDir(tempFs, "", false) + if err != nil { + return nil, err + } + for _, file := range files { + loop := finalize.Nested() + log.Debug("uploading", "file", file) + err := coords.SetClassifierExtensionBy(file) + if err != nil { + return nil, err + } + readHash, err := tempFs.Open(file) + if err != nil { + return nil, err + } + loop.Close(readHash) + // MD5 + SHA1 are still the most used ones in the mvn context + hr := iotools.NewHashReader(readHash, crypto.SHA256, crypto.SHA1, crypto.MD5) + _, err = hr.CalcHashes() + if err != nil { + return nil, err + } + reader, err := tempFs.Open(file) + if err != nil { + return nil, err + } + loop.Close(reader) + creds, err := mavenblob.GetCredentials(ctx.GetContext(), repo, coords.GroupId) + if err != nil { + return nil, err + } + err = repo.Upload(coords, reader, creds, hr.Hashes()) + if err != nil { + return nil, err + } + err = loop.Finalize() + if err != nil { + return nil, err + } + } + + log.Debug("done", "artifact", coords) + url, err := repo.Url() + if err != nil { + return nil, err + } + return access.New(url, coords.GroupId, coords.ArtifactId, coords.Version), nil +} diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go new file mode 100644 index 0000000000..c7a9c6e81e --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go @@ -0,0 +1,99 @@ +package maven_test + +import ( + "encoding/json" + "github.com/mandelsoft/goutils/sliceutils" + "github.com/mandelsoft/vfs/pkg/vfs" + mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" + me "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/maven" + "github.com/open-component-model/ocm/pkg/contexts/ocm/elements" + "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" + "os" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + . "github.com/open-component-model/ocm/pkg/testutils" +) + +const mvnPATH = "/testdata/.m2/repository" + +var _ = Describe("blobhandler generic maven tests", func() { + var env *Builder + var repo *maven.Repository + + BeforeEach(func() { + env = NewBuilder(TestData()) + repo = maven.NewFileRepository(mvnPATH, env.FileSystem()) + }) + + It("Unmarshal upload response Body", func() { + resp := `{ "repo" : "ocm-mvn-test", + "path" : "/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar", + "created" : "2024-04-11T15:09:28.920Z", + "createdBy" : "john.doe", + "downloadUri" : "https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar", + "mimeType" : "application/java-archive", + "size" : "1792", + "checksums" : { + "sha1" : "99d9acac1ff93ac3d52229edec910091af1bc40a", + "md5" : "6cb7520b65d820b3b35773a8daa8368e", + "sha256" : "b19dcd275f72a0cbdead1e5abacb0ef25a0cb55ff36252ef44b1178eeedf9c30" }, + "originalChecksums" : { + "sha256" : "b19dcd275f72a0cbdead1e5abacb0ef25a0cb55ff36252ef44b1178eeedf9c30" }, + "uri" : "https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar" }` + var body maven.Body + err := json.Unmarshal([]byte(resp), &body) + Expect(err).To(BeNil()) + Expect(body.Repo).To(Equal("ocm-mvn-test")) + Expect(body.DownloadUri).To(Equal("https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar")) + Expect(body.Uri).To(Equal("https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar")) + Expect(body.MimeType).To(Equal("application/java-archive")) + Expect(body.Size).To(Equal("1792")) + Expect(body.Checksums["md5"]).To(Equal("6cb7520b65d820b3b35773a8daa8368e")) + Expect(body.Checksums["sha1"]).To(Equal("99d9acac1ff93ac3d52229edec910091af1bc40a")) + Expect(body.Checksums["sha256"]).To(Equal("b19dcd275f72a0cbdead1e5abacb0ef25a0cb55ff36252ef44b1178eeedf9c30")) + Expect(body.Checksums["sha512"]).To(Equal("")) + }) + + 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()))) + defer Close(bacc) + ocmrepo := composition.NewRepository(env) + defer Close(ocmrepo) + cv := composition.NewComponentVersion(env, "acme.org/test", "1.0.0") + MustBeSuccessful(cv.SetResourceBlob(Must(elements.ResourceMeta("test", resourcetypes.MAVEN_ARTIFACT)), bacc, coords.GAV(), nil)) + MustBeSuccessful(ocmrepo.AddComponentVersion(cv)) + l := sliceutils.Transform(Must(vfs.ReadDir(env.FileSystem(), "target/com/sap/cloud/sdk/sdk-modules-bom/5.7.0")), + func(info os.FileInfo) string { + return info.Name() + }) + Expect(l).To(ConsistOf( + "sdk-modules-bom-5.7.0-random-content.json", + "sdk-modules-bom-5.7.0-random-content.json.md5", + "sdk-modules-bom-5.7.0-random-content.json.sha1", + "sdk-modules-bom-5.7.0-random-content.json.sha256", + "sdk-modules-bom-5.7.0-random-content.txt", + "sdk-modules-bom-5.7.0-random-content.txt.md5", + "sdk-modules-bom-5.7.0-random-content.txt.sha1", + "sdk-modules-bom-5.7.0-random-content.txt.sha256", + "sdk-modules-bom-5.7.0-sources.jar", + "sdk-modules-bom-5.7.0-sources.jar.md5", + "sdk-modules-bom-5.7.0-sources.jar.sha1", + "sdk-modules-bom-5.7.0-sources.jar.sha256", + "sdk-modules-bom-5.7.0.jar", + "sdk-modules-bom-5.7.0.jar.md5", + "sdk-modules-bom-5.7.0.jar.sha1", + "sdk-modules-bom-5.7.0.jar.sha256", + "sdk-modules-bom-5.7.0.pom", + "sdk-modules-bom-5.7.0.pom.md5", + "sdk-modules-bom-5.7.0.pom.sha1", + "sdk-modules-bom-5.7.0.pom.sha256")) + }) + +}) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go similarity index 60% rename from pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go rename to pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go index 1ab2a37bb9..00fdb3e8c1 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go @@ -1,23 +1,59 @@ -package mvn +package maven import ( "encoding/json" "fmt" - "github.com/mandelsoft/goutils/errors" - + "github.com/mandelsoft/goutils/general" + "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "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/mime" "github.com/open-component-model/ocm/pkg/registrations" + "github.com/open-component-model/ocm/pkg/utils" ) +func init() { + cpi.RegisterBlobHandlerRegistrationHandler(BlobHandlerName, &RegistrationHandler{}) +} + type Config struct { - Url string `json:"url"` + Url string `json:"url"` + Path string `json:"path"` + FileSystem vfs.FileSystem `json:"-"` +} + +func NewFileConfig(path string, fss ...vfs.FileSystem) *Config { + return &Config{ + Path: path, + FileSystem: utils.FileSystem(fss...), + } +} + +func NewUrlConfig(url string, fss ...vfs.FileSystem) *Config { + return &Config{ + Url: url, + FileSystem: utils.FileSystem(fss...), + } } type rawConfig Config +func (c *Config) GetRepository(ctx cpi.ContextProvider) (*maven.Repository, error) { + if c.Url != "" && c.Path != "" { + return nil, fmt.Errorf("cannot specify both url and path") + } + if c.Url != "" { + return maven.NewUrlRepository(c.Url, general.OptionalDefaulted(vfsattr.Get(ctx.OCMContext()), c.FileSystem)) + } + if c.Path != "" { + return maven.NewFileRepository(c.Path, general.OptionalDefaulted(vfsattr.Get(ctx.OCMContext()), c.FileSystem)), nil + } + return nil, fmt.Errorf("must specify either url or path") +} + func (c *Config) UnmarshalJSON(data []byte) error { err := json.Unmarshal(data, &c.Url) if err == nil { @@ -33,10 +69,6 @@ func (c *Config) UnmarshalJSON(data []byte) error { return nil } -func init() { - cpi.RegisterBlobHandlerRegistrationHandler(BlobHandlerName, &RegistrationHandler{}) -} - type RegistrationHandler struct{} var _ cpi.BlobHandlerRegistrationHandler = (*RegistrationHandler)(nil) @@ -46,7 +78,7 @@ func (r *RegistrationHandler) RegisterByName(handler string, ctx cpi.Context, co return true, fmt.Errorf("invalid %s handler %q", resourcetypes.MAVEN_ARTIFACT, handler) } if config == nil { - return true, fmt.Errorf("mvn target specification required") + return true, fmt.Errorf("maven target specification required") } cfg, err := registrations.DecodeConfig[Config](config) if err != nil { diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go similarity index 58% rename from pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go rename to pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go index bf967f24eb..834dcb365e 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/registration_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go @@ -1,23 +1,23 @@ -package mvn_test +package maven_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/maven" . "github.com/open-component-model/ocm/pkg/testutils" - "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/mvn" "github.com/open-component-model/ocm/pkg/registrations" ) var _ = Describe("Config deserialization Test Environment", func() { It("deserializes string", func() { - cfg := Must(registrations.DecodeConfig[mvn.Config]("test")) - Expect(cfg).To(Equal(&mvn.Config{Url: "test"})) + cfg := Must(registrations.DecodeConfig[maven.Config]("test")) + Expect(cfg).To(Equal(&maven.Config{Url: "test"})) }) It("deserializes struct", func() { - cfg := Must(registrations.DecodeConfig[mvn.Config](`{"url":"test"}`)) - Expect(cfg).To(Equal(&mvn.Config{Url: "test"})) + cfg := Must(registrations.DecodeConfig[maven.Config](`{"url":"test"}`)) + Expect(cfg).To(Equal(&maven.Config{Url: "test"})) }) }) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/suite_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go similarity index 90% rename from pkg/contexts/ocm/blobhandler/handlers/generic/mvn/suite_test.go rename to pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go index c62cadc7b0..0892bc9a7f 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/suite_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go @@ -1,4 +1,4 @@ -package mvn_test +package maven_test import ( "testing" diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json new file mode 100644 index 0000000000..2f1fc35fdc --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json @@ -0,0 +1 @@ +{"some": "test content"} \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 new file mode 100644 index 0000000000..d6836aeaa0 --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 @@ -0,0 +1 @@ +f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt new file mode 100644 index 0000000000..b4af84697f --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt @@ -0,0 +1 @@ +some test content \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 new file mode 100644 index 0000000000..55eceeb992 --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 @@ -0,0 +1 @@ +dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..8564f0addae8de5525417df8294d13c0c2a3a7c0 GIT binary patch literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo + + 4.0.0 + com.sap.cloud.sdk + sdk-modules-bom + 5.7.0 + pom + SAP Cloud SDK - Modules BOM + Bill of Materials (BOM) of the SAP Cloud SDK modules. + https://sap.github.io/cloud-sdk/docs/java/getting-started + + SAP SE + https://www.sap.com + + + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + SAP + cloudsdk@sap.com + SAP SE + https://www.sap.com + + + + + + + + UTF-8 + Public + Stable + + 5.7.0 + + + + + com.sap.cloud.sdk + sdk-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + dwc-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-core + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + caching + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient4 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-apache-httpclient5 + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + cloudplatform-connectivity-scp-cf + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-destination-service + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-oauth + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-dwc + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + connectivity-ztis + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience-api + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + resilience4j + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + security + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + servlet-jakarta + ${sdk.version} + + + com.sap.cloud.sdk.cloudplatform + tenant + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-core + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + s4hana-connectivity + ${sdk.version} + + + com.sap.cloud.sdk.s4hana + rfc + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + datamodel-metadata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator-utility + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-client + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + odata-v4-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-core + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + openapi-generator + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + fluent-result + ${sdk.version} + + + com.sap.cloud.sdk.datamodel + + soap + ${sdk.version} + + + + diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 new file mode 100644 index 0000000000..35f63a2e1f --- /dev/null +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 @@ -0,0 +1 @@ +34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go deleted file mode 100644 index 7e787ed32d..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler.go +++ /dev/null @@ -1,186 +0,0 @@ -package mvn - -import ( - "context" - "crypto" - "encoding/json" - "fmt" - "io" - "net/http" - "strings" - - "github.com/mandelsoft/goutils/errors" - "github.com/mandelsoft/goutils/optionutils" - "github.com/mandelsoft/vfs/pkg/vfs" - - "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" - "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" - access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" - "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi/accspeccpi" - "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" - "github.com/open-component-model/ocm/pkg/iotools" - "github.com/open-component-model/ocm/pkg/logging" - "github.com/open-component-model/ocm/pkg/maven" - "github.com/open-component-model/ocm/pkg/mime" - "github.com/open-component-model/ocm/pkg/utils/tarutils" -) - -const BlobHandlerName = "ocm/" + resourcetypes.MAVEN_ARTIFACT - -type artifactHandler struct { - spec *Config -} - -func NewArtifactHandler(repospec *Config) cpi.BlobHandler { - return &artifactHandler{repospec} -} - -var log = logging.DynamicLogger(identity.REALM) - -func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hint string, _ cpi.AccessSpec, ctx cpi.StorageContext) (cpi.AccessSpec, error) { - // check conditions - if b.spec == nil { - return nil, nil - } - mimeType := blob.MimeType() - if resourcetypes.MAVEN_ARTIFACT != resourceType { - log.Debug("not a MVN artifact", "resourceType", resourceType) - return nil, nil - } - if mime.MIME_TGZ != mimeType { - log.Debug("not a tarball, can't be a complete mvn GAV", "mimeType", mimeType) - return nil, nil - } - if b.spec.Url == "" { - return nil, errors.New("MVN repository url not provided") - } - - // setup logger - log := log.WithValues("repository", b.spec.Url) - // identify artifact - artifact, err := maven.Parse(hint) - if err != nil { - return nil, err - } - log = log.WithValues("groupId", artifact.GroupId, "artifactId", artifact.ArtifactId, "version", artifact.Version) - log.Debug("identified") - - blobReader, err := blob.Reader() - if err != nil { - return nil, err - } - defer blobReader.Close() - tempFs, err := tarutils.ExtractTgzToTempFs(blobReader) - if err != nil { - return nil, err - } - defer vfs.Cleanup(tempFs) - files, err := tarutils.ListSortedFilesInDir(tempFs, "", false) - if err != nil { - return nil, err - } - for _, file := range files { - e := func() error { - log.Debug("uploading", "file", file) - err := artifact.SetClassifierExtensionBy(file) - if err != nil { - return err - } - readHash, err := tempFs.Open(file) - if err != nil { - return err - } - defer readHash.Close() - // MD5 + SHA1 are still the most used ones in the mvn context - hr := iotools.NewHashReader(readHash, crypto.SHA256, crypto.SHA1, crypto.MD5) - _, err = hr.CalcHashes() - if err != nil { - return err - } - reader, err := tempFs.Open(file) - if err != nil { - return err - } - defer reader.Close() - repo, err := maven.NewUrlRepository(b.spec.Url, vfsattr.Get(ctx.GetContext())) - if err != nil { - return err - } - return deploy(artifact, repo, reader, ctx.GetContext(), hr) - }() - if e != nil { - return nil, e - } - } - - log.Debug("done", "artifact", artifact) - return access.New(b.spec.Url, artifact.GroupId, artifact.ArtifactId, artifact.Version, maven.WithClassifier(optionutils.AsValue(artifact.Classifier)), maven.WithExtension(optionutils.AsValue(artifact.Extension))), nil -} - -// deploy an artifact to the specified destination. See https://jfrog.com/help/r/jfrog-rest-apis/deploy-artifact -func deploy(coords *maven.Coordinates, repo *maven.Repository, reader io.ReadCloser, ctx accspeccpi.Context, hashes *iotools.HashReader) (err error) { - req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, coords.Location(repo).String(), reader) - if err != nil { - return - } - err = identity.BasicAuth(req, ctx, repo.String(), coords.GroupPath()) - if err != nil { - return - } - // give the remote server a chance to decide based upon the checksum policy - for k, v := range hashes.HttpHeader() { - req.Header.Set(k, v) - } - - // Execute the request - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return - } - defer resp.Body.Close() - - // Check the response - if resp.StatusCode != http.StatusCreated { - all, e := io.ReadAll(resp.Body) - if e != nil { - return e - } - return fmt.Errorf("http (%d) - failed to upload coords: %s", resp.StatusCode, string(all)) - } - log.Debug("uploaded", "coords", coords, "extension", coords.Extension, "classifier", coords.Classifier) - - // Validate the response - especially the hash values with the ones we've tried to send - respBody, err := io.ReadAll(resp.Body) - if err != nil { - return - } - var artifactBody Body - err = json.Unmarshal(respBody, &artifactBody) - if err != nil { - return - } - - // let's check only SHA256 for now - digest := hashes.GetString(crypto.SHA256) - remoteDigest := artifactBody.Checksums[strings.ReplaceAll(strings.ToLower(crypto.SHA256.String()), "-", "")] - if remoteDigest == "" { - log.Warn("no checksum found for algorithm, we can't guarantee that the coords has been uploaded correctly", "algorithm", crypto.SHA256) - } else if remoteDigest != digest { - return errors.New("failed to upload coords: checksums do not match") - } - log.Debug("digests are ok", "remoteDigest", remoteDigest, "digest", digest) - return -} - -// Body is the response struct of a deployment from the MVN repository (JFrog Artifactory). -type Body struct { - Repo string `json:"repo"` - Path string `json:"path"` - DownloadUri string `json:"downloadUri"` - Uri string `json:"uri"` - MimeType string `json:"mimeType"` - Size string `json:"size"` - Checksums map[string]string `json:"checksums"` -} diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler_test.go deleted file mode 100644 index a632ace444..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/mvn/blobhandler_test.go +++ /dev/null @@ -1,43 +0,0 @@ -package mvn_test - -import ( - "encoding/json" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/mvn" -) - -var _ = Describe("blobhandler generic mvn tests", func() { - - It("Unmarshal deploy response Body", func() { - resp := `{ "repo" : "ocm-mvn-test", - "path" : "/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar", - "created" : "2024-04-11T15:09:28.920Z", - "createdBy" : "john.doe", - "downloadUri" : "https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar", - "mimeType" : "application/java-archive", - "size" : "1792", - "checksums" : { - "sha1" : "99d9acac1ff93ac3d52229edec910091af1bc40a", - "md5" : "6cb7520b65d820b3b35773a8daa8368e", - "sha256" : "b19dcd275f72a0cbdead1e5abacb0ef25a0cb55ff36252ef44b1178eeedf9c30" }, - "originalChecksums" : { - "sha256" : "b19dcd275f72a0cbdead1e5abacb0ef25a0cb55ff36252ef44b1178eeedf9c30" }, - "uri" : "https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar" }` - var body mvn.Body - err := json.Unmarshal([]byte(resp), &body) - Expect(err).To(BeNil()) - Expect(body.Repo).To(Equal("ocm-mvn-test")) - Expect(body.DownloadUri).To(Equal("https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar")) - Expect(body.Uri).To(Equal("https://ocm.sofware/repository/ocm-mvn-test/open-component-model/hello-ocm/0.0.2/hello-ocm-0.0.2.jar")) - Expect(body.MimeType).To(Equal("application/java-archive")) - Expect(body.Size).To(Equal("1792")) - Expect(body.Checksums["md5"]).To(Equal("6cb7520b65d820b3b35773a8daa8368e")) - Expect(body.Checksums["sha1"]).To(Equal("99d9acac1ff93ac3d52229edec910091af1bc40a")) - Expect(body.Checksums["sha256"]).To(Equal("b19dcd275f72a0cbdead1e5abacb0ef25a0cb55ff36252ef44b1178eeedf9c30")) - Expect(body.Checksums["sha512"]).To(Equal("")) - }) - -}) diff --git a/pkg/contexts/ocm/blobhandler/handlers/init.go b/pkg/contexts/ocm/blobhandler/handlers/init.go index b318fe2c9e..3fd4df2811 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/init.go +++ b/pkg/contexts/ocm/blobhandler/handlers/init.go @@ -1,7 +1,7 @@ package handlers import ( - _ "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/mvn" + _ "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/maven" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/npm" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/ocirepo" _ "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/oci/ocirepo" diff --git a/pkg/iotools/hashReaderWriter.go b/pkg/iotools/hashReaderWriter.go index b74863f7e7..f36d74b58d 100644 --- a/pkg/iotools/hashReaderWriter.go +++ b/pkg/iotools/hashReaderWriter.go @@ -5,42 +5,79 @@ import ( "fmt" "hash" "io" + "net/http" "strings" "github.com/mandelsoft/goutils/errors" ) +type Hashes map[crypto.Hash]hash.Hash + +func NewHashes(algorithms ...crypto.Hash) Hashes { + hashMap := make(Hashes, len(algorithms)) + for _, algorithm := range algorithms { + hashMap[algorithm] = algorithm.New() + } + return hashMap +} + +func (h Hashes) Write(c int, buf []byte) { + if c > 0 { + for _, hash := range h { + hash.Write(buf[:c]) + } + } +} + +func (h Hashes) AsHttpHeader() http.Header { + headers := make(http.Header, len(h)) + for algorithm := range h { + headers.Set(headerName(algorithm), h.GetString(algorithm)) + } + return headers +} + +func (h Hashes) GetBytes(algorithm crypto.Hash) []byte { + hash := h[algorithm] + if hash != nil { + return hash.Sum(nil) + } + return nil +} + +func (h Hashes) GetString(algorithm crypto.Hash) string { + return fmt.Sprintf("%x", h.GetBytes(algorithm)) +} + +func headerName(algorithm crypto.Hash) string { + a := strings.ReplaceAll(algorithm.String(), "-", "") + return "X-Checksum-" + a[:1] + strings.ToLower(a[1:]) +} + +//////////////////////////////////////////////////////////////////////////////// + type HashReader struct { reader io.Reader - hashMap map[crypto.Hash]hash.Hash + hashMap Hashes } func NewHashReader(delegate io.Reader, algorithms ...crypto.Hash) *HashReader { newInstance := HashReader{ reader: delegate, - hashMap: initMap(algorithms), + hashMap: NewHashes(algorithms...), } return &newInstance } func (h *HashReader) Read(buf []byte) (int, error) { c, err := h.reader.Read(buf) - return write(h, c, buf, err) -} - -func (h *HashReader) GetString(algorithm crypto.Hash) string { - return getString(h, algorithm) -} - -func (h *HashReader) GetBytes(algorithm crypto.Hash) []byte { - return getBytes(h, algorithm) -} - -func (h *HashReader) HttpHeader() map[string]string { - return httpHeader(h) + if err == nil { + h.hashMap.Write(c, buf) + } + return c, err } -func (h *HashReader) hashes() map[crypto.Hash]hash.Hash { +func (h *HashReader) Hashes() Hashes { return h.hashMap } @@ -69,84 +106,25 @@ func (h *HashReader) CalcHashes() (int64, error) { type HashWriter struct { writer io.Writer - hashMap map[crypto.Hash]hash.Hash + hashMap Hashes } func NewHashWriter(w io.Writer, algorithms ...crypto.Hash) *HashWriter { newInstance := HashWriter{ writer: w, - hashMap: initMap(algorithms), + hashMap: NewHashes(algorithms...), } return &newInstance } func (h *HashWriter) Write(buf []byte) (int, error) { c, err := h.writer.Write(buf) - return write(h, c, buf, err) -} - -func (h *HashWriter) GetString(algorithm crypto.Hash) string { - return getString(h, algorithm) -} - -func (h *HashWriter) GetBytes(algorithm crypto.Hash) []byte { - return getBytes(h, algorithm) -} - -func (h *HashWriter) HttpHeader() map[string]string { - return httpHeader(h) -} - -func (h *HashWriter) hashes() map[crypto.Hash]hash.Hash { - return h.hashMap -} - -//////////////////////////////////////////////////////////////////////////////// - -type hashes interface { - hashes() map[crypto.Hash]hash.Hash -} - -func getString(h hashes, algorithm crypto.Hash) string { - return fmt.Sprintf("%x", getBytes(h, algorithm)) -} - -func getBytes(h hashes, algorithm crypto.Hash) []byte { - hash := h.hashes()[algorithm] - if hash != nil { - return hash.Sum(nil) - } - return nil -} - -func httpHeader(h hashes) map[string]string { - headers := make(map[string]string, len(h.hashes())) - for algorithm := range h.hashes() { - headers[headerName(algorithm)] = getString(h, algorithm) - } - return headers -} - -func initMap(algorithms []crypto.Hash) map[crypto.Hash]hash.Hash { - hashMap := make(map[crypto.Hash]hash.Hash, len(algorithms)) - for _, algorithm := range algorithms { - hashMap[algorithm] = algorithm.New() - } - return hashMap -} - -func write(h hashes, c int, buf []byte, err error) (int, error) { - if err == nil && c > 0 { - for _, hash := range h.hashes() { - hash.Write(buf[:c]) - } + if err == nil { + h.hashMap.Write(c, buf) } return c, err } -//////////////////////////////////////////////////////////////////////////////// - -func headerName(hash crypto.Hash) string { - a := strings.ReplaceAll(hash.String(), "-", "") - return "X-Checksum-" + a[:1] + strings.ToLower(a[1:]) +func (h *HashWriter) Hashes() Hashes { + return h.hashMap } diff --git a/pkg/iotools/hashReaderWriter_test.go b/pkg/iotools/hashReaderWriter_test.go index bda2a6fc3d..457fa15342 100644 --- a/pkg/iotools/hashReaderWriter_test.go +++ b/pkg/iotools/hashReaderWriter_test.go @@ -26,26 +26,29 @@ var _ = Describe("Hash Reader Writer tests", func() { It("test HashWriter", func() { s := "Hello Hash!" var b bytes.Buffer - hr := iotools.NewHashWriter(io.Writer(&b)) - hr.Write([]byte(s)) + hw := iotools.NewHashWriter(io.Writer(&b)) + hw.Write([]byte(s)) + hashes := hw.Hashes() Expect(b.String()).To(Equal(s)) - Expect(hr.GetBytes(0)).To(BeNil()) + Expect(hashes.GetBytes(0)).To(BeNil()) b.Reset() w := io.Writer(&b) - hr = iotools.NewHashWriter(w, crypto.SHA1) - hr.Write([]byte(s)) + hw = iotools.NewHashWriter(w, crypto.SHA1) + hw.Write([]byte(s)) + hashes = hw.Hashes() Expect(b.String()).To(Equal(s)) - Expect(hr.GetBytes(0)).To(BeNil()) - Expect(hr.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) + Expect(hashes.GetBytes(0)).To(BeNil()) + Expect(hashes.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) b.Reset() - hr = iotools.NewHashWriter(io.Writer(&b), crypto.SHA1, crypto.MD5) - hr.Write([]byte(s)) + hw = iotools.NewHashWriter(io.Writer(&b), crypto.SHA1, crypto.MD5) + hw.Write([]byte(s)) + hashes = hw.Hashes() Expect(b.String()).To(Equal(s)) - Expect(hr.GetBytes(0)).To(BeNil()) - Expect(hr.GetString(crypto.MD5)).To(Equal("c10e8df2e378a1584359b0e546cf0149")) - Expect(hr.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) + Expect(hashes.GetBytes(0)).To(BeNil()) + Expect(hashes.GetString(crypto.MD5)).To(Equal("c10e8df2e378a1584359b0e546cf0149")) + Expect(hashes.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) }) It("test HashReader", func() { @@ -53,27 +56,29 @@ var _ = Describe("Hash Reader Writer tests", func() { hr := iotools.NewHashReader(strings.NewReader(s)) buf := make([]byte, len(s)) hr.Read(buf) - Expect(hr.GetBytes(0)).To(BeNil()) + hashes := hr.Hashes() + Expect(hashes.GetBytes(0)).To(BeNil()) Expect(string(buf)).To(Equal(s)) hr = iotools.NewHashReader(strings.NewReader(s), crypto.SHA1) hr.Read(buf) - Expect(hr.GetBytes(0)).To(BeNil()) - Expect(hr.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) + hashes = hr.Hashes() + Expect(hashes.GetBytes(0)).To(BeNil()) + Expect(hashes.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) hr = iotools.NewHashReader(strings.NewReader(s), crypto.SHA1) cnt, err := hr.CalcHashes() + hashes = hr.Hashes() Expect(err).To(BeNil()) Expect(cnt).To(Equal(int64(len(s)))) - Expect(hr.GetBytes(0)).To(BeNil()) - Expect(hr.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) + Expect(hashes.GetBytes(0)).To(BeNil()) + Expect(hashes.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) hr = iotools.NewHashReader(strings.NewReader(s), crypto.SHA1, crypto.MD5) hr.Read(buf) - Expect(hr.GetBytes(crypto.SHA256)).To(BeNil()) - Expect(hr.GetString(crypto.MD5)).To(Equal("c10e8df2e378a1584359b0e546cf0149")) - Expect(hr.GetString(crypto.MD5)).To(Equal("c10e8df2e378a1584359b0e546cf0149")) - Expect(hr.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) - Expect(hr.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) + hashes = hr.Hashes() + Expect(hashes.GetBytes(crypto.SHA256)).To(BeNil()) + Expect(hashes.GetString(crypto.MD5)).To(Equal("c10e8df2e378a1584359b0e546cf0149")) + Expect(hashes.GetString(crypto.SHA1)).To(Equal("5c075ed604db0adc524edd3516e8f0258ca6e58d")) }) }) diff --git a/pkg/maven/access.go b/pkg/maven/access.go index e471be0013..7d7a5d928e 100644 --- a/pkg/maven/access.go +++ b/pkg/maven/access.go @@ -9,12 +9,16 @@ import ( "context" "crypto" "encoding/json" + "fmt" "github.com/cloudflare/cfssl/log" "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/goutils/general" "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/utils/tarutils" + "golang.org/x/exp/maps" "golang.org/x/net/html" "io" "net/http" @@ -162,6 +166,155 @@ func (l *Location) GetReader(creds Credentials) (io.ReadCloser, error) { return resp.Body, nil } +func (r *Repository) Url() (string, error) { + if r.url != "" { + return r.url, nil + } + p, err := vfs.Canonical(r.fs, r.path, false) + if err != nil { + return "", err + } + return "file://localhost" + p, nil +} + +// Body is the response struct of a deployment from the MVN repository (JFrog Artifactory). +type Body struct { + Repo string `json:"repo"` + Path string `json:"path"` + DownloadUri string `json:"downloadUri"` + Uri string `json:"uri"` + MimeType string `json:"mimeType"` + Size string `json:"size"` + Checksums map[string]string `json:"checksums"` +} + +func (r *Repository) Download(coords *Coordinates, creds Credentials, enforceVerification ...bool) (io.ReadCloser, error) { + files, err := r.GavFiles(coords, creds) + if err != nil { + return nil, err + } + algorithm, ok := files[coords.FileName()] + if !ok { + return nil, errors.ErrNotFound("file", coords.FileName(), coords.GAV()) + } + + var digest string + loc := coords.Location(r) + if algorithm != 0 { + digestFile := loc.AddExtension(HashExt(algorithm)) + reader, err := digestFile.GetReader(creds) + if err != nil { + return nil, err + } + digestData, err := io.ReadAll(reader) + if err != nil { + return nil, err + } + digest = string(digestData) + } else { + if general.Optional(enforceVerification...) { + return nil, fmt.Errorf("unable to verify, no digest available in target repository") + } + } + + reader, err := loc.GetReader(creds) + if err != nil { + return nil, err + } + if algorithm != 0 { + reader = iotools.VerifyingReaderWithHash(reader, algorithm, digest) + } + return reader, nil +} + +func (r *Repository) Upload(coords *Coordinates, reader io.ReadCloser, creds Credentials, hashes iotools.Hashes) (rerr error) { + finalize := finalizer.Finalizer{} + defer finalize.FinalizeWithErrorPropagation(&rerr) + + loc := coords.Location(r) + if r.IsFileSystem() { + err := loc.fs.MkdirAll(vfs.Dir(loc.fs, loc.path), 0o755) + if err != nil { + return err + } + f, err := loc.fs.OpenFile(loc.path, vfs.O_WRONLY|vfs.O_CREATE|vfs.O_TRUNC, 0o644) + if err != nil { + return err + } + finalize.Close(f) + + _, err = io.Copy(f, reader) + if err != nil { + return err + } + + for algorithm := range hashes { + digest := hashes.GetString(algorithm) + p := loc.path + "." + HashExt(algorithm) + err = vfs.WriteFile(loc.fs, p, []byte(digest), 0o644) + if err != nil { + return err + } + } + return nil + } + + req, err := http.NewRequestWithContext(context.Background(), http.MethodPut, loc.String(), reader) + if err != nil { + return err + } + if creds != nil { + err = creds.SetForRequest(req) + if err != nil { + return err + } + } + // give the remote server a chance to decide based upon the checksum policy + for k, v := range hashes.AsHttpHeader() { + req.Header[k] = v + } + + // Execute the request + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return err + } + finalize.Close(resp.Body) + + // Check the response + if resp.StatusCode != http.StatusCreated { + all, e := io.ReadAll(resp.Body) + if e != nil { + return e + } + return fmt.Errorf("http (%d) - failed to upload coords: %s", resp.StatusCode, string(all)) + } + Log.Debug("uploaded", "coords", coords, "extension", coords.Extension, "classifier", coords.Classifier) + + // Validate the response - especially the hash values with the ones we've tried to send + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + var artifactBody Body + err = json.Unmarshal(respBody, &artifactBody) + if err != nil { + return err + } + + algorithm := bestAvailableHash(maps.Keys(hashes)) + digest := hashes.GetString(algorithm) + remoteDigest := artifactBody.Checksums[strings.ReplaceAll(strings.ToLower(algorithm.String()), "-", "")] + if remoteDigest == "" { + Log.Warn("no checksum found for algorithm, we can't guarantee that the coords has been uploaded correctly", "algorithm", algorithm.String()) + } else if remoteDigest != digest { + return errors.New("failed to upload coords: checksums do not match") + } + Log.Debug("digests are ok", "remoteDigest", remoteDigest, "digest", digest) + return err +} + func (r *Repository) GetFileMeta(c *Coordinates, file string, hash crypto.Hash, creds Credentials) (*FileMeta, error) { coords := c.Copy() err := coords.SetClassifierExtensionBy(file) @@ -247,7 +400,7 @@ func filesAndHashes(fileList []string) map[string]crypto.Hash { result := make(map[string]crypto.Hash, len(fileList)/2) for _, file := range fileList { if IsResource(file) { - result[file] = bestAvailableHash(fileList, file) + result[file] = bestAvailableHashForFile(fileList, file) log.Debug("found", "file", file) } } diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go index f4d395067c..748bc81b78 100644 --- a/pkg/maven/access_test.go +++ b/pkg/maven/access_test.go @@ -2,6 +2,7 @@ package maven_test import ( "crypto" + "io" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -50,7 +51,7 @@ sdk-modules-bom-5.7.0.pom: 3 Expect(hash).To(Equal("34ccdeb9c008f8aaef90873fc636b09d3ae5c709")) }) - It("", func() { + It("access dedicated file", func() { coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) meta := Must(repo.GetFileMeta(coords, "sdk-modules-bom-5.7.0.pom", crypto.SHA1, nil)) Expect(meta).To(YAMLEqual(` @@ -111,5 +112,21 @@ sdk-modules-bom-5.7.0.jar: 3 sdk-modules-bom-5.7.0-sources.jar: 3 `)) }) + + It("download dedicated file", func() { + coords := me.NewCoordinates("com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) + reader := Must(repo.Download(coords, nil, true)) + data := Must(io.ReadAll(reader)) + Expect(len(data)).To(Equal(7153)) + MustBeSuccessful(reader.Close()) + }) + + It("download dedicated file with filed digest verification", func() { + coords := me.NewCoordinates("test", "repository", "42", me.WithClassifier(""), me.WithExtension("pom")) + repo := me.NewFileRepository(FAILPATH, env) + reader := Must(repo.Download(coords, nil, true)) + _ = Must(io.ReadAll(reader)) + Expect(reader.Close()).To(MatchError("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7")) + }) }) }) diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index 3e8db32718..e257eb8e75 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -75,7 +75,6 @@ func NewCoordinates(groupId, artifactId, version string, opts ...CoordinateOptio // GAV returns the GAV coordinates of the Maven Coordinates. func (c *Coordinates) GAV() string { - NewCoordinates("a", "b", "c", WithClassifier("a"), WithExtension("c")) return c.GroupId + ":" + c.ArtifactId + ":" + c.Version } @@ -93,20 +92,24 @@ func (c *Coordinates) GavLocation(repo *Repository) *Location { return repo.AddPath(c.GavPath()) } -// FilePath returns the Maven Coordinates's GAV-name with classifier and extension. -// Which is equal to the URL-path of the artifact in the repository. -// Default extension is jar. -func (c *Coordinates) FilePath() string { - path := c.GavPath() + "/" + c.FileNamePrefix() +func (c *Coordinates) FileName() string { + file := c.FileNamePrefix() if optionutils.AsValue(c.Classifier) != "" { - path += "-" + *c.Classifier + file += "-" + *c.Classifier } if optionutils.AsValue(c.Extension) != "" { - path += "." + *c.Extension + file += "." + *c.Extension } else { - path += ".jar" + file += ".jar" } - return path + return file +} + +// FilePath returns the Maven Coordinates's GAV-name with classifier and extension. +// Which is equal to the URL-path of the artifact in the repository. +// Default extension is jar. +func (c *Coordinates) FilePath() string { + return c.GavPath() + "/" + c.FileName() } func (c *Coordinates) Location(repo *Repository) *Location { diff --git a/pkg/maven/utils.go b/pkg/maven/utils.go index 3d3cd747f0..a2eb4f5181 100644 --- a/pkg/maven/utils.go +++ b/pkg/maven/utils.go @@ -18,9 +18,9 @@ func HashExt(h crypto.Hash) string { var hashes = [5]crypto.Hash{crypto.SHA512, crypto.SHA256, crypto.SHA1, crypto.MD5} -// bestAvailableHash returns the best available hash for the given file. +// bestAvailableHashForFile returns the best available hash for the given file. // It first checks for SHA-512, then SHA-256, SHA-1, and finally MD5. If nothing is found, it returns 0. -func bestAvailableHash(list []string, filename string) crypto.Hash { +func bestAvailableHashForFile(list []string, filename string) crypto.Hash { for _, hash := range hashes { if slices.Contains(list, filename+"."+HashExt(hash)) { return hash @@ -28,3 +28,14 @@ func bestAvailableHash(list []string, filename string) crypto.Hash { } return 0 } + +// bestAvailableHashForFile returns the best available hash for the given file. +// It first checks for SHA-512, then SHA-256, SHA-1, and finally MD5. If nothing is found, it returns 0. +func bestAvailableHash(list []crypto.Hash) crypto.Hash { + for _, hash := range hashes { + if slices.Contains(list, hash) { + return hash + } + } + return 0 +} From b0fd0008c464ac3ad1fa22695b81430b43f413f6 Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Tue, 28 May 2024 10:02:20 +0200 Subject: [PATCH 09/13] make prepare --- .golangci.yaml | 3 ++ .../controllercmds/common/manifests.go | 3 +- .../commands/controllercmds/install/cmd.go | 2 +- .../commands/controllercmds/uninstall/cmd.go | 7 +-- .../uninstall/uninstall_cert_manager.go | 4 +- .../commands/misccmds/credentials/get/cmd.go | 2 +- .../commands/ocmcmds/common/addhdlrs/utils.go | 2 +- .../common/handlers/pluginhdlr/typehandler.go | 2 +- .../common/handlers/vershdlr/typehandler.go | 2 +- .../common/inputs/types/maven/input_test.go | 2 + .../ocmcmds/common/inputs/types/maven/spec.go | 9 ++-- .../common/options/schemaoption/option.go | 2 +- cmds/ocm/commands/ocmcmds/common/resources.go | 4 +- cmds/ocm/commands/ocmcmds/common/utils.go | 2 +- .../commands/ocmcmds/components/add/cmd.go | 2 +- .../ocmcmds/components/download/cmd.go | 2 +- .../ocmcmds/components/transfer/cmd.go | 2 +- cmds/ocm/commands/ocmcmds/ctf/transfer/cmd.go | 2 +- .../commands/ocmcmds/plugins/install/cmd.go | 2 +- .../commands/toicmds/package/bootstrap/cmd.go | 2 +- .../commands/toicmds/package/describe/cmd.go | 2 +- cmds/ocm/commands/verbs/controller/cmd.go | 2 +- cmds/ocm/pkg/utils/command.go | 2 +- cmds/ocm/pkg/utils/handling.go | 1 + .../plugin_accessmethod_compose.md | 7 +-- docs/pluginreference/plugin_descriptor.md | 7 +-- .../plugin_valueset_compose.md | 7 +-- .../ocm_add_resource-configuration.md | 53 ++++++++++++++++--- docs/reference/ocm_add_resources.md | 53 ++++++++++++++++--- .../reference/ocm_add_source-configuration.md | 53 ++++++++++++++++--- docs/reference/ocm_add_sources.md | 53 ++++++++++++++++--- docs/reference/ocm_logging.md | 1 + docs/reference/ocm_ocm-accessmethods.md | 8 +-- docs/reference/ocm_ocm-uploadhandlers.md | 4 +- .../ocm_transfer_commontransportarchive.md | 4 +- .../ocm_transfer_componentversions.md | 4 +- .../lib/tour/01-getting-started/README.md | 14 ++--- .../README.md | 2 +- pkg/blobaccess/maven/access_test.go | 8 +-- pkg/blobaccess/maven/utils.go | 5 +- pkg/common/accessio/retry_test.go | 1 + pkg/contexts/config/gc_test.go | 2 +- pkg/contexts/credentials/gc_test.go | 2 +- .../repositories/npm/repository_test.go | 2 +- .../repositories/vault/repo_int_test.go | 8 +-- .../repositories/vault/repo_test.go | 2 +- pkg/contexts/oci/gc_test.go | 2 +- pkg/contexts/oci/repositories/ctf/ctf_test.go | 2 +- .../ocm/accessmethods/maven/method_test.go | 10 ++-- .../handlers/generic/maven/blobhandler.go | 2 + .../generic/maven/blobhandler_test.go | 16 +++--- .../handlers/generic/maven/registration.go | 2 + .../generic/maven/registration_test.go | 2 +- .../v3alpha1/jsonscheme/bindata.go | 2 +- .../versions/v2/jsonscheme/bindata.go | 2 +- .../artifactblob/helmblob/helmblob_test.go | 5 +- .../artifactblob/mavenblob/access_test.go | 7 +-- pkg/contexts/ocm/gc_test.go | 2 +- pkg/contexts/ocm/plugin/cache/updater.go | 2 +- .../repositories/genericocireg/repo_test.go | 3 +- pkg/contexts/ocm/transfer/autohandler_test.go | 1 + pkg/contexts/ocm/utils/localize/format.go | 2 +- pkg/exception/exception_test.go | 1 + pkg/maven/access.go | 14 ++--- pkg/maven/coordinates.go | 2 +- pkg/refmgmt/finalized/finalized_test.go | 2 +- pkg/testutils/tcp.go | 3 +- 67 files changed, 318 insertions(+), 131 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 8a105b4382..9e4ab89249 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -134,6 +134,9 @@ linters-settings: line-length: 120 gosec: exclude-generated: true + gocritic: + disabled-checks: + - elseif issues: exclude: diff --git a/cmds/ocm/commands/controllercmds/common/manifests.go b/cmds/ocm/commands/controllercmds/common/manifests.go index bf1a5b07d9..c54bc5a7c6 100644 --- a/cmds/ocm/commands/controllercmds/common/manifests.go +++ b/cmds/ocm/commands/controllercmds/common/manifests.go @@ -7,9 +7,10 @@ import ( "path/filepath" "github.com/fluxcd/pkg/ssa" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "github.com/open-component-model/ocm/pkg/contexts/clictx" "github.com/open-component-model/ocm/pkg/out" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) func Install(ctx context.Context, octx clictx.Context, sm *ssa.ResourceManager, releaseURL, baseURL, manifest, filename, version string, dryRun bool) error { diff --git a/cmds/ocm/commands/controllercmds/install/cmd.go b/cmds/ocm/commands/controllercmds/install/cmd.go index 5d5a5b8bea..25427a1ba5 100644 --- a/cmds/ocm/commands/controllercmds/install/cmd.go +++ b/cmds/ocm/commands/controllercmds/install/cmd.go @@ -6,7 +6,6 @@ import ( "time" "github.com/fluxcd/pkg/ssa" - "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common" "github.com/spf13/cobra" "github.com/spf13/pflag" corev1 "k8s.io/api/core/v1" @@ -15,6 +14,7 @@ import ( "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common" "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/names" "github.com/open-component-model/ocm/cmds/ocm/commands/verbs" "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" diff --git a/cmds/ocm/commands/controllercmds/uninstall/cmd.go b/cmds/ocm/commands/controllercmds/uninstall/cmd.go index 3c1e497462..47c06530c4 100644 --- a/cmds/ocm/commands/controllercmds/uninstall/cmd.go +++ b/cmds/ocm/commands/controllercmds/uninstall/cmd.go @@ -6,15 +6,16 @@ import ( "time" "github.com/fluxcd/pkg/ssa" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "k8s.io/cli-runtime/pkg/genericclioptions" + "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common" "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/names" "github.com/open-component-model/ocm/cmds/ocm/commands/verbs" "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/contexts/clictx" "github.com/open-component-model/ocm/pkg/out" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "k8s.io/cli-runtime/pkg/genericclioptions" ) var ( diff --git a/cmds/ocm/commands/controllercmds/uninstall/uninstall_cert_manager.go b/cmds/ocm/commands/controllercmds/uninstall/uninstall_cert_manager.go index 944c881eb0..e0380e264b 100644 --- a/cmds/ocm/commands/controllercmds/uninstall/uninstall_cert_manager.go +++ b/cmds/ocm/commands/controllercmds/uninstall/uninstall_cert_manager.go @@ -2,12 +2,14 @@ package uninstall import ( "context" - _ "embed" "fmt" "os" + _ "embed" + "github.com/fluxcd/pkg/ssa" "github.com/mandelsoft/filepath/pkg/filepath" + "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/common" "github.com/open-component-model/ocm/pkg/out" ) diff --git a/cmds/ocm/commands/misccmds/credentials/get/cmd.go b/cmds/ocm/commands/misccmds/credentials/get/cmd.go index 48e5f574b4..a634692cb9 100644 --- a/cmds/ocm/commands/misccmds/credentials/get/cmd.go +++ b/cmds/ocm/commands/misccmds/credentials/get/cmd.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/listformat" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -15,6 +14,7 @@ import ( "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/contexts/clictx" "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/listformat" "github.com/open-component-model/ocm/pkg/out" ) diff --git a/cmds/ocm/commands/ocmcmds/common/addhdlrs/utils.go b/cmds/ocm/commands/ocmcmds/common/addhdlrs/utils.go index 08ee455eb0..53743e4521 100644 --- a/cmds/ocm/commands/ocmcmds/common/addhdlrs/utils.go +++ b/cmds/ocm/commands/ocmcmds/common/addhdlrs/utils.go @@ -8,7 +8,6 @@ import ( "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" - "github.com/open-component-model/ocm/pkg/errkind" "gopkg.in/yaml.v3" "k8s.io/apimachinery/pkg/util/validation/field" @@ -18,6 +17,7 @@ import ( "github.com/open-component-model/ocm/pkg/common/accessio" "github.com/open-component-model/ocm/pkg/contexts/clictx" "github.com/open-component-model/ocm/pkg/contexts/ocm" + "github.com/open-component-model/ocm/pkg/errkind" "github.com/open-component-model/ocm/pkg/runtime" utils2 "github.com/open-component-model/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/utils/template" diff --git a/cmds/ocm/commands/ocmcmds/common/handlers/pluginhdlr/typehandler.go b/cmds/ocm/commands/ocmcmds/common/handlers/pluginhdlr/typehandler.go index 4ba9f91550..b24da832ed 100644 --- a/cmds/ocm/commands/ocmcmds/common/handlers/pluginhdlr/typehandler.go +++ b/cmds/ocm/commands/ocmcmds/common/handlers/pluginhdlr/typehandler.go @@ -4,7 +4,7 @@ import ( "strings" "github.com/mandelsoft/goutils/errors" - + "github.com/open-component-model/ocm/cmds/ocm/pkg/output" "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/contexts/clictx" diff --git a/cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/typehandler.go b/cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/typehandler.go index 875da9e575..83967edd1e 100644 --- a/cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/typehandler.go +++ b/cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/typehandler.go @@ -6,8 +6,8 @@ import ( "sort" "github.com/Masterminds/semver/v3" - "github.com/mandelsoft/goutils/errors" + "github.com/open-component-model/ocm/cmds/ocm/pkg/output" "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/contexts/clictx" diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go index 95663b6166..5b2ad27621 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go @@ -2,10 +2,12 @@ package maven_test import ( "crypto" + . "github.com/mandelsoft/goutils/testutils" . "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/contexts/ocm/accessmethods/localblob" "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc" "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/comparch" 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 2e5a39abf7..b07c924979 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/spec.go @@ -2,14 +2,15 @@ package maven import ( "fmt" - "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/cpi" - mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" - "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" - "github.com/open-component-model/ocm/pkg/maven" + "k8s.io/apimachinery/pkg/util/validation/field" "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" + mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" + "github.com/open-component-model/ocm/pkg/maven" ) type Spec struct { diff --git a/cmds/ocm/commands/ocmcmds/common/options/schemaoption/option.go b/cmds/ocm/commands/ocmcmds/common/options/schemaoption/option.go index 46df9fc6ab..5e463f0058 100644 --- a/cmds/ocm/commands/ocmcmds/common/options/schemaoption/option.go +++ b/cmds/ocm/commands/ocmcmds/common/options/schemaoption/option.go @@ -2,12 +2,12 @@ package schemaoption import ( "github.com/mandelsoft/goutils/errors" - "github.com/open-component-model/ocm/pkg/errkind" "github.com/spf13/pflag" "github.com/open-component-model/ocm/cmds/ocm/pkg/options" "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/errkind" "github.com/open-component-model/ocm/pkg/listformat" utils2 "github.com/open-component-model/ocm/pkg/utils" ) diff --git a/cmds/ocm/commands/ocmcmds/common/resources.go b/cmds/ocm/commands/ocmcmds/common/resources.go index d64c52e427..db8b5697b6 100644 --- a/cmds/ocm/commands/ocmcmds/common/resources.go +++ b/cmds/ocm/commands/ocmcmds/common/resources.go @@ -4,11 +4,10 @@ import ( "encoding/json" "fmt" - "github.com/mandelsoft/goutils/sliceutils" _ "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/inputs/types" - utils2 "github.com/open-component-model/ocm/pkg/utils" "github.com/mandelsoft/goutils/errors" + "github.com/mandelsoft/goutils/sliceutils" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/spf13/pflag" "golang.org/x/text/cases" @@ -33,6 +32,7 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/comparch" "github.com/open-component-model/ocm/pkg/logging" "github.com/open-component-model/ocm/pkg/mime" + utils2 "github.com/open-component-model/ocm/pkg/utils" ) const ComponentVersionTag = "" diff --git a/cmds/ocm/commands/ocmcmds/common/utils.go b/cmds/ocm/commands/ocmcmds/common/utils.go index 27df8f52f2..5985d94681 100644 --- a/cmds/ocm/commands/ocmcmds/common/utils.go +++ b/cmds/ocm/commands/ocmcmds/common/utils.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/mandelsoft/goutils/errors" - + "github.com/open-component-model/ocm/cmds/ocm/pkg/options" "github.com/open-component-model/ocm/pkg/contexts/clictx" "github.com/open-component-model/ocm/pkg/contexts/ocm" diff --git a/cmds/ocm/commands/ocmcmds/components/add/cmd.go b/cmds/ocm/commands/ocmcmds/components/add/cmd.go index cce645da04..648babe18a 100644 --- a/cmds/ocm/commands/ocmcmds/components/add/cmd.go +++ b/cmds/ocm/commands/ocmcmds/components/add/cmd.go @@ -3,12 +3,12 @@ package add import ( "fmt" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/general" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/formatoption" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/addhdlrs" diff --git a/cmds/ocm/commands/ocmcmds/components/download/cmd.go b/cmds/ocm/commands/ocmcmds/components/download/cmd.go index 76759a6bb2..1735291dad 100644 --- a/cmds/ocm/commands/ocmcmds/components/download/cmd.go +++ b/cmds/ocm/commands/ocmcmds/components/download/cmd.go @@ -4,9 +4,9 @@ import ( "path" "strings" + "github.com/mandelsoft/goutils/errors" "github.com/spf13/cobra" - "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/destoption" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/formatoption" ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" diff --git a/cmds/ocm/commands/ocmcmds/components/transfer/cmd.go b/cmds/ocm/commands/ocmcmds/components/transfer/cmd.go index 81c577ae13..f91a39b22d 100644 --- a/cmds/ocm/commands/ocmcmds/components/transfer/cmd.go +++ b/cmds/ocm/commands/ocmcmds/components/transfer/cmd.go @@ -4,12 +4,12 @@ import ( "encoding/json" "fmt" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/maputils" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/closureoption" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/formatoption" ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" diff --git a/cmds/ocm/commands/ocmcmds/ctf/transfer/cmd.go b/cmds/ocm/commands/ocmcmds/ctf/transfer/cmd.go index beb4daa7e7..d57aefdaeb 100644 --- a/cmds/ocm/commands/ocmcmds/ctf/transfer/cmd.go +++ b/cmds/ocm/commands/ocmcmds/ctf/transfer/cmd.go @@ -1,9 +1,9 @@ package transfer import ( + "github.com/mandelsoft/goutils/errors" "github.com/spf13/cobra" - "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/closureoption" "github.com/open-component-model/ocm/cmds/ocm/commands/common/options/formatoption" ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" diff --git a/cmds/ocm/commands/ocmcmds/plugins/install/cmd.go b/cmds/ocm/commands/ocmcmds/plugins/install/cmd.go index d5b4182cdb..2462191b93 100644 --- a/cmds/ocm/commands/ocmcmds/plugins/install/cmd.go +++ b/cmds/ocm/commands/ocmcmds/plugins/install/cmd.go @@ -3,10 +3,10 @@ package install import ( "fmt" + "github.com/mandelsoft/goutils/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/mandelsoft/goutils/errors" ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/handlers/pluginhdlr" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/repooption" diff --git a/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go b/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go index 96554e0287..8555d8bdde 100644 --- a/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go +++ b/cmds/ocm/commands/toicmds/package/bootstrap/cmd.go @@ -3,11 +3,11 @@ package bootstrap import ( "fmt" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/mandelsoft/goutils/errors" ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/handlers/comphdlr" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/lookupoption" diff --git a/cmds/ocm/commands/toicmds/package/describe/cmd.go b/cmds/ocm/commands/toicmds/package/describe/cmd.go index 994570c0c7..cccf87782c 100644 --- a/cmds/ocm/commands/toicmds/package/describe/cmd.go +++ b/cmds/ocm/commands/toicmds/package/describe/cmd.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" + "github.com/mandelsoft/goutils/errors" "github.com/spf13/cobra" - "github.com/mandelsoft/goutils/errors" ocmcommon "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/handlers/comphdlr" "github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/lookupoption" diff --git a/cmds/ocm/commands/verbs/controller/cmd.go b/cmds/ocm/commands/verbs/controller/cmd.go index 3ad8733b2c..a79e2741f7 100644 --- a/cmds/ocm/commands/verbs/controller/cmd.go +++ b/cmds/ocm/commands/verbs/controller/cmd.go @@ -1,11 +1,11 @@ package controller import ( - "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/uninstall" "github.com/spf13/cobra" "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/install" "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/names" + "github.com/open-component-model/ocm/cmds/ocm/commands/controllercmds/uninstall" "github.com/open-component-model/ocm/cmds/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/contexts/clictx" ) diff --git a/cmds/ocm/pkg/utils/command.go b/cmds/ocm/pkg/utils/command.go index aec015928b..212cd13c7d 100644 --- a/cmds/ocm/pkg/utils/command.go +++ b/cmds/ocm/pkg/utils/command.go @@ -4,10 +4,10 @@ import ( "reflect" "strings" + "github.com/mandelsoft/goutils/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/cmds/ocm/pkg/options" "github.com/open-component-model/ocm/pkg/cobrautils" "github.com/open-component-model/ocm/pkg/contexts/clictx" diff --git a/cmds/ocm/pkg/utils/handling.go b/cmds/ocm/pkg/utils/handling.go index d0592950c1..ba2d2193a1 100644 --- a/cmds/ocm/pkg/utils/handling.go +++ b/cmds/ocm/pkg/utils/handling.go @@ -6,6 +6,7 @@ import ( "reflect" "github.com/mandelsoft/goutils/errors" + "github.com/open-component-model/ocm/cmds/ocm/pkg/output" ) diff --git a/docs/pluginreference/plugin_accessmethod_compose.md b/docs/pluginreference/plugin_accessmethod_compose.md index d9c0455651..7c1fa77577 100644 --- a/docs/pluginreference/plugin_accessmethod_compose.md +++ b/docs/pluginreference/plugin_accessmethod_compose.md @@ -35,20 +35,21 @@ by the plugin name. The following predefined option types can be used: - - accessClassifier: [*string*] mvn classifier - - accessExtension: [*string*] mvn extension name - - accessGroup: [*string*] GroupID or namespace - accessHostname: [*string*] hostname used for access - accessPackage: [*string*] package or object name - accessRegistry: [*string*] registry base URL - accessRepository: [*string*] repository URL - accessVersion: [*string*] version for access specification + - artifactId: [*string*] artifact id - body: [*string*] body of a http request - bucket: [*string*] bucket name + - classifier: [*string*] mvn classifier - comment: [*string*] comment field value - commit: [*string*] git commit id - digest: [*string*] blob digest + - extension: [*string*] mvn extension name - globalAccess: [*map[string]YAML*] access specification for global access + - groupId: [*string*] group id or namespace - header: [*string:string,string*] http headers - hint: [*string*] (repository) hint for local artifacts - mediaType: [*string*] media type for artifact blob representation diff --git a/docs/pluginreference/plugin_descriptor.md b/docs/pluginreference/plugin_descriptor.md index c3ecbdd8a4..45e09eef59 100644 --- a/docs/pluginreference/plugin_descriptor.md +++ b/docs/pluginreference/plugin_descriptor.md @@ -120,20 +120,21 @@ It uses the following fields: The following predefined option types can be used: - - accessClassifier: [*string*] mvn classifier - - accessExtension: [*string*] mvn extension name - - accessGroup: [*string*] GroupID or namespace - accessHostname: [*string*] hostname used for access - accessPackage: [*string*] package or object name - accessRegistry: [*string*] registry base URL - accessRepository: [*string*] repository URL - accessVersion: [*string*] version for access specification + - artifactId: [*string*] artifact id - body: [*string*] body of a http request - bucket: [*string*] bucket name + - classifier: [*string*] mvn classifier - comment: [*string*] comment field value - commit: [*string*] git commit id - digest: [*string*] blob digest + - extension: [*string*] mvn extension name - globalAccess: [*map[string]YAML*] access specification for global access + - groupId: [*string*] group id or namespace - header: [*string:string,string*] http headers - hint: [*string*] (repository) hint for local artifacts - mediaType: [*string*] media type for artifact blob representation diff --git a/docs/pluginreference/plugin_valueset_compose.md b/docs/pluginreference/plugin_valueset_compose.md index 09bf007037..a2bb2b101c 100644 --- a/docs/pluginreference/plugin_valueset_compose.md +++ b/docs/pluginreference/plugin_valueset_compose.md @@ -35,20 +35,21 @@ by the plugin name. The following predefined option types can be used: - - accessClassifier: [*string*] mvn classifier - - accessExtension: [*string*] mvn extension name - - accessGroup: [*string*] GroupID or namespace - accessHostname: [*string*] hostname used for access - accessPackage: [*string*] package or object name - accessRegistry: [*string*] registry base URL - accessRepository: [*string*] repository URL - accessVersion: [*string*] version for access specification + - artifactId: [*string*] artifact id - body: [*string*] body of a http request - bucket: [*string*] bucket name + - classifier: [*string*] mvn classifier - comment: [*string*] comment field value - commit: [*string*] git commit id - digest: [*string*] blob digest + - extension: [*string*] mvn extension name - globalAccess: [*map[string]YAML*] access specification for global access + - groupId: [*string*] group id or namespace - header: [*string:string,string*] http headers - hint: [*string*] (repository) hint for local artifacts - mediaType: [*string*] media type for artifact blob representation diff --git a/docs/reference/ocm_add_resource-configuration.md b/docs/reference/ocm_add_resource-configuration.md index 679bcc2f27..5f6b563566 100644 --- a/docs/reference/ocm_add_resource-configuration.md +++ b/docs/reference/ocm_add_resource-configuration.md @@ -24,20 +24,21 @@ resource-configuration, resourceconfig, rsccfg, rcfg ``` --access YAML blob access specification (YAML) - --accessClassifier string mvn classifier - --accessExtension string mvn extension name - --accessGroup string GroupID or namespace --accessHostname string hostname used for access --accessPackage string package or object name --accessRegistry string registry base URL --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification + --artifactId string artifact id --body string body of a http request --bucket string bucket name + --classifier string mvn classifier --commit string git commit id --digest string blob digest + --extension string mvn extension name --globalAccess YAML access specification for global access + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -53,7 +54,11 @@ resource-configuration, resourceconfig, rsccfg, rcfg #### Input Specification Options ``` + --artifactId string artifact id --body string body of a http request + --classifier string mvn classifier + --extension string mvn extension name + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -368,6 +373,40 @@ with the field type in the input field: Options used to configure fields: --hint, --inputCompress, --inputHelmRepository, --inputPath, --inputVersion, --mediaType +- Input type maven + + The repoUrl is the url pointing either to the http endpoint of a maven + repository (e.g. https://repo.maven.apache.org/maven2/) or to a file system based + maven repository (e.g. file://local/directory). + + This blob type specification supports the following fields: + - **repoUrl** *string* + + This REQUIRED property describes the url from which the resource is to be + accessed. + + - **groupId** *string* + + This REQUIRED property describes the groupId of a maven artifact. + + - **artifactId** *string* + + This REQUIRED property describes artifactId of a maven artifact. + + - **version** *string* + + This REQUIRED property describes the version of a maven artifact. + + - **classifier** *string* + + This OPTIONAL property describes the classifier of a maven artifact. + + - **extension** *string* + + This OPTIONAL property describes the extension of a maven artifact. + + Options used to configure fields: --artifactId, --classifier, --extension, --groupId, --inputPath, --inputVersion, --url + - Input type ociArtifact The path must denote an OCI image reference. @@ -582,7 +621,7 @@ shown below. - **repoUrl** *string* - Repository URL with or without scheme. + RepoUrl URL with or without scheme. - **ref** (optional) *string* @@ -683,7 +722,7 @@ shown below. Options used to configure fields: --globalAccess, --hint, --mediaType, --reference -- Access type mvn +- Access type maven This method implements the access of a Maven (mvn) artifact in a Maven repository. @@ -692,7 +731,7 @@ shown below. The type specific specification fields are: - - **repository** *string* + - **repoUrl** *string* Base URL of the Maven (mvn) repository @@ -716,7 +755,7 @@ shown below. The optional extension of the Maven (mvn) artifact - Options used to configure fields: --accessClassifier, --accessExtension, --accessGroup, --accessPackage, --accessRepository, --accessVersion + Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId - Access type none diff --git a/docs/reference/ocm_add_resources.md b/docs/reference/ocm_add_resources.md index 9e8878f8e8..f3c245d46c 100644 --- a/docs/reference/ocm_add_resources.md +++ b/docs/reference/ocm_add_resources.md @@ -30,20 +30,21 @@ resources, resource, res, r ``` --access YAML blob access specification (YAML) - --accessClassifier string mvn classifier - --accessExtension string mvn extension name - --accessGroup string GroupID or namespace --accessHostname string hostname used for access --accessPackage string package or object name --accessRegistry string registry base URL --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification + --artifactId string artifact id --body string body of a http request --bucket string bucket name + --classifier string mvn classifier --commit string git commit id --digest string blob digest + --extension string mvn extension name --globalAccess YAML access specification for global access + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -59,7 +60,11 @@ resources, resource, res, r #### Input Specification Options ``` + --artifactId string artifact id --body string body of a http request + --classifier string mvn classifier + --extension string mvn extension name + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -378,6 +383,40 @@ with the field type in the input field: Options used to configure fields: --hint, --inputCompress, --inputHelmRepository, --inputPath, --inputVersion, --mediaType +- Input type maven + + The repoUrl is the url pointing either to the http endpoint of a maven + repository (e.g. https://repo.maven.apache.org/maven2/) or to a file system based + maven repository (e.g. file://local/directory). + + This blob type specification supports the following fields: + - **repoUrl** *string* + + This REQUIRED property describes the url from which the resource is to be + accessed. + + - **groupId** *string* + + This REQUIRED property describes the groupId of a maven artifact. + + - **artifactId** *string* + + This REQUIRED property describes artifactId of a maven artifact. + + - **version** *string* + + This REQUIRED property describes the version of a maven artifact. + + - **classifier** *string* + + This OPTIONAL property describes the classifier of a maven artifact. + + - **extension** *string* + + This OPTIONAL property describes the extension of a maven artifact. + + Options used to configure fields: --artifactId, --classifier, --extension, --groupId, --inputPath, --inputVersion, --url + - Input type ociArtifact The path must denote an OCI image reference. @@ -592,7 +631,7 @@ shown below. - **repoUrl** *string* - Repository URL with or without scheme. + RepoUrl URL with or without scheme. - **ref** (optional) *string* @@ -693,7 +732,7 @@ shown below. Options used to configure fields: --globalAccess, --hint, --mediaType, --reference -- Access type mvn +- Access type maven This method implements the access of a Maven (mvn) artifact in a Maven repository. @@ -702,7 +741,7 @@ shown below. The type specific specification fields are: - - **repository** *string* + - **repoUrl** *string* Base URL of the Maven (mvn) repository @@ -726,7 +765,7 @@ shown below. The optional extension of the Maven (mvn) artifact - Options used to configure fields: --accessClassifier, --accessExtension, --accessGroup, --accessPackage, --accessRepository, --accessVersion + Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId - Access type none diff --git a/docs/reference/ocm_add_source-configuration.md b/docs/reference/ocm_add_source-configuration.md index f7d2b4fc32..2002d73d88 100644 --- a/docs/reference/ocm_add_source-configuration.md +++ b/docs/reference/ocm_add_source-configuration.md @@ -24,20 +24,21 @@ source-configuration, sourceconfig, srccfg, scfg ``` --access YAML blob access specification (YAML) - --accessClassifier string mvn classifier - --accessExtension string mvn extension name - --accessGroup string GroupID or namespace --accessHostname string hostname used for access --accessPackage string package or object name --accessRegistry string registry base URL --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification + --artifactId string artifact id --body string body of a http request --bucket string bucket name + --classifier string mvn classifier --commit string git commit id --digest string blob digest + --extension string mvn extension name --globalAccess YAML access specification for global access + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -53,7 +54,11 @@ source-configuration, sourceconfig, srccfg, scfg #### Input Specification Options ``` + --artifactId string artifact id --body string body of a http request + --classifier string mvn classifier + --extension string mvn extension name + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -368,6 +373,40 @@ with the field type in the input field: Options used to configure fields: --hint, --inputCompress, --inputHelmRepository, --inputPath, --inputVersion, --mediaType +- Input type maven + + The repoUrl is the url pointing either to the http endpoint of a maven + repository (e.g. https://repo.maven.apache.org/maven2/) or to a file system based + maven repository (e.g. file://local/directory). + + This blob type specification supports the following fields: + - **repoUrl** *string* + + This REQUIRED property describes the url from which the resource is to be + accessed. + + - **groupId** *string* + + This REQUIRED property describes the groupId of a maven artifact. + + - **artifactId** *string* + + This REQUIRED property describes artifactId of a maven artifact. + + - **version** *string* + + This REQUIRED property describes the version of a maven artifact. + + - **classifier** *string* + + This OPTIONAL property describes the classifier of a maven artifact. + + - **extension** *string* + + This OPTIONAL property describes the extension of a maven artifact. + + Options used to configure fields: --artifactId, --classifier, --extension, --groupId, --inputPath, --inputVersion, --url + - Input type ociArtifact The path must denote an OCI image reference. @@ -582,7 +621,7 @@ shown below. - **repoUrl** *string* - Repository URL with or without scheme. + RepoUrl URL with or without scheme. - **ref** (optional) *string* @@ -683,7 +722,7 @@ shown below. Options used to configure fields: --globalAccess, --hint, --mediaType, --reference -- Access type mvn +- Access type maven This method implements the access of a Maven (mvn) artifact in a Maven repository. @@ -692,7 +731,7 @@ shown below. The type specific specification fields are: - - **repository** *string* + - **repoUrl** *string* Base URL of the Maven (mvn) repository @@ -716,7 +755,7 @@ shown below. The optional extension of the Maven (mvn) artifact - Options used to configure fields: --accessClassifier, --accessExtension, --accessGroup, --accessPackage, --accessRepository, --accessVersion + Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId - Access type none diff --git a/docs/reference/ocm_add_sources.md b/docs/reference/ocm_add_sources.md index 746d02c5ee..c6d152b88f 100644 --- a/docs/reference/ocm_add_sources.md +++ b/docs/reference/ocm_add_sources.md @@ -29,20 +29,21 @@ sources, source, src, s ``` --access YAML blob access specification (YAML) - --accessClassifier string mvn classifier - --accessExtension string mvn extension name - --accessGroup string GroupID or namespace --accessHostname string hostname used for access --accessPackage string package or object name --accessRegistry string registry base URL --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification + --artifactId string artifact id --body string body of a http request --bucket string bucket name + --classifier string mvn classifier --commit string git commit id --digest string blob digest + --extension string mvn extension name --globalAccess YAML access specification for global access + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -58,7 +59,11 @@ sources, source, src, s #### Input Specification Options ``` + --artifactId string artifact id --body string body of a http request + --classifier string mvn classifier + --extension string mvn extension name + --groupId string group id or namespace --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -376,6 +381,40 @@ with the field type in the input field: Options used to configure fields: --hint, --inputCompress, --inputHelmRepository, --inputPath, --inputVersion, --mediaType +- Input type maven + + The repoUrl is the url pointing either to the http endpoint of a maven + repository (e.g. https://repo.maven.apache.org/maven2/) or to a file system based + maven repository (e.g. file://local/directory). + + This blob type specification supports the following fields: + - **repoUrl** *string* + + This REQUIRED property describes the url from which the resource is to be + accessed. + + - **groupId** *string* + + This REQUIRED property describes the groupId of a maven artifact. + + - **artifactId** *string* + + This REQUIRED property describes artifactId of a maven artifact. + + - **version** *string* + + This REQUIRED property describes the version of a maven artifact. + + - **classifier** *string* + + This OPTIONAL property describes the classifier of a maven artifact. + + - **extension** *string* + + This OPTIONAL property describes the extension of a maven artifact. + + Options used to configure fields: --artifactId, --classifier, --extension, --groupId, --inputPath, --inputVersion, --url + - Input type ociArtifact The path must denote an OCI image reference. @@ -590,7 +629,7 @@ shown below. - **repoUrl** *string* - Repository URL with or without scheme. + RepoUrl URL with or without scheme. - **ref** (optional) *string* @@ -691,7 +730,7 @@ shown below. Options used to configure fields: --globalAccess, --hint, --mediaType, --reference -- Access type mvn +- Access type maven This method implements the access of a Maven (mvn) artifact in a Maven repository. @@ -700,7 +739,7 @@ shown below. The type specific specification fields are: - - **repository** *string* + - **repoUrl** *string* Base URL of the Maven (mvn) repository @@ -724,7 +763,7 @@ shown below. The optional extension of the Maven (mvn) artifact - Options used to configure fields: --accessClassifier, --accessExtension, --accessGroup, --accessPackage, --accessRepository, --accessVersion + Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId - Access type none diff --git a/docs/reference/ocm_logging.md b/docs/reference/ocm_logging.md index f72d0b3fcb..5c16d3652d 100644 --- a/docs/reference/ocm_logging.md +++ b/docs/reference/ocm_logging.md @@ -24,6 +24,7 @@ The following *realms* are used by the command line tool: - ocm/compdesc: component descriptor handling - ocm/config: configuration management - ocm/context: context lifecycle + - ocm/credentials: Credentials - ocm/credentials/dockerconfig: docker config handling as credential repository - ocm/credentials/vault: HashiCorp Vault Access - ocm/downloader: Downloaders diff --git a/docs/reference/ocm_ocm-accessmethods.md b/docs/reference/ocm_ocm-accessmethods.md index 1c02801075..7242264576 100644 --- a/docs/reference/ocm_ocm-accessmethods.md +++ b/docs/reference/ocm_ocm-accessmethods.md @@ -82,7 +82,7 @@ shown below. - **repoUrl** *string* - Repository URL with or without scheme. + RepoUrl URL with or without scheme. - **ref** (optional) *string* @@ -183,7 +183,7 @@ shown below. Options used to configure fields: --globalAccess, --hint, --mediaType, --reference -- Access type mvn +- Access type maven This method implements the access of a Maven (mvn) artifact in a Maven repository. @@ -192,7 +192,7 @@ shown below. The type specific specification fields are: - - **repository** *string* + - **repoUrl** *string* Base URL of the Maven (mvn) repository @@ -216,7 +216,7 @@ shown below. The optional extension of the Maven (mvn) artifact - Options used to configure fields: --accessClassifier, --accessExtension, --accessGroup, --accessPackage, --accessRepository, --accessVersion + Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId - Access type none diff --git a/docs/reference/ocm_ocm-uploadhandlers.md b/docs/reference/ocm_ocm-uploadhandlers.md index d3b3219957..aacbd0744f 100644 --- a/docs/reference/ocm_ocm-uploadhandlers.md +++ b/docs/reference/ocm_ocm-uploadhandlers.md @@ -73,9 +73,9 @@ The following handler names are possible: sub namespace of the form <plugin name>/<handler> - - ocm/mvnArtifact: uploading mvn artifacts + - ocm/mavenArtifact: uploading mvn artifacts - The ocm/mvnArtifact uploader is able to upload mvn artifacts (whole GAV only!) + The ocm/mavenArtifact uploader is able to upload mvn artifacts (whole GAV only!) as artifact archive according to the mvn artifact spec. If registered the default mime type is: application/x-tgz diff --git a/docs/reference/ocm_transfer_commontransportarchive.md b/docs/reference/ocm_transfer_commontransportarchive.md index c3f6c2d20a..2bc7d29c0a 100644 --- a/docs/reference/ocm_transfer_commontransportarchive.md +++ b/docs/reference/ocm_transfer_commontransportarchive.md @@ -147,9 +147,9 @@ The uploader name may be a path expression with the following possibilities: sub namespace of the form <plugin name>/<handler> - - ocm/mvnArtifact: uploading mvn artifacts + - ocm/mavenArtifact: uploading mvn artifacts - The ocm/mvnArtifact uploader is able to upload mvn artifacts (whole GAV only!) + The ocm/mavenArtifact uploader is able to upload mvn artifacts (whole GAV only!) as artifact archive according to the mvn artifact spec. If registered the default mime type is: application/x-tgz diff --git a/docs/reference/ocm_transfer_componentversions.md b/docs/reference/ocm_transfer_componentversions.md index f251617d44..0f56569bae 100644 --- a/docs/reference/ocm_transfer_componentversions.md +++ b/docs/reference/ocm_transfer_componentversions.md @@ -204,9 +204,9 @@ The uploader name may be a path expression with the following possibilities: sub namespace of the form <plugin name>/<handler> - - ocm/mvnArtifact: uploading mvn artifacts + - ocm/mavenArtifact: uploading mvn artifacts - The ocm/mvnArtifact uploader is able to upload mvn artifacts (whole GAV only!) + The ocm/mavenArtifact uploader is able to upload mvn artifacts (whole GAV only!) as artifact archive according to the mvn artifact spec. If registered the default mime type is: application/x-tgz diff --git a/examples/lib/tour/01-getting-started/README.md b/examples/lib/tour/01-getting-started/README.md index 76423db018..5f807a67f3 100644 --- a/examples/lib/tour/01-getting-started/README.md +++ b/examples/lib/tour/01-getting-started/README.md @@ -164,32 +164,32 @@ differ, because the code always describes the latest version): ``` resources of the latest version: - version: 0.9.0 + version: 0.10.0 provider: ocm.software 1: name: ocmcli extra identity: "architecture"="amd64","os"="linux" resource type: executable - access: Local blob sha256:1de1c90f23d0a3dbb8d8646f09380f1da257f9d10796b42dc4ef85e8df93a135[] + access: Local blob sha256:e2d8f578083e9317bd199b3f374b7ea60e7f28cf989e8d39ae0ea54ac4fa8847[] 2: name: ocmcli extra identity: "architecture"="arm64","os"="linux" resource type: executable - access: Local blob sha256:ca049bb09399020ce0822fd18c0a534ae0d02c3e0180f05dd4faccf61176a267[] + access: Local blob sha256:2acef3da732a6674fb047f3d60f0dabcbb60ffeb8dd362a169df97c4dc4489a8[] 3: name: ocmcli extra identity: "architecture"="arm64","os"="darwin" resource type: executable - access: Local blob sha256:1e32b3f1a08c72e3187b247f8931ea9d0554240fd452a4df129d6036c62b0476[] + access: Local blob sha256:b05fbc5e8aaa3622e2ecc39ead7f066030fd183c625b0dc202dbac8131f06d1d[] 4: name: ocmcli extra identity: "architecture"="amd64","os"="darwin" resource type: executable - access: Local blob sha256:04708d2f9845dd6d52f2b8f94e930f3a74a1a098b7ee401e001307d4b4fcc703[] + access: Local blob sha256:aec88249f7e5a395eaa18ac6017831b275c7de90d3c10f0cd9e572027ad6c6e9[] 5: name: ocmcli extra identity: "architecture"="amd64","os"="windows" resource type: executable - access: Local blob sha256:e8cf5dfd1ab02ab982e6f1a425d426fc1f7dc83e6385d26d0477525a4a66c629[] + access: Local blob sha256:cdbac49bd004aa2a8b89fafb9e845f45bfcfaab2df402296f55b403b9b1035a2[] 6: name: ocmcli-image extra identity: resource type: ociImage - access: OCI artifact ghcr.io/open-component-model/ocm/ocm.software/ocmcli/ocmcli-image:0.9.0 + access: OCI artifact ghcr.io/open-component-model/ocm/ocm.software/ocmcli/ocmcli-image:0.10.0 ``` Resources have some metadata, like their identity and a resource type. diff --git a/examples/lib/tour/02-composing-a-component-version/README.md b/examples/lib/tour/02-composing-a-component-version/README.md index 74953c7385..effd262404 100644 --- a/examples/lib/tour/02-composing-a-component-version/README.md +++ b/examples/lib/tour/02-composing-a-component-version/README.md @@ -212,7 +212,7 @@ The above case could also be written as follows: ```go res := textblob.ResourceAccess(cv.GetContext(), meta, yamldata, - textblob.WithimeType(mime.MIME_YAML)) + textblob.WithMimeType(mime.MIME_YAML)) err = cv.SetResourceAccess(res) if err != nil { return errors.Wrapf(err, "cannot add yaml document") diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index f900e7c717..cbf89d83f2 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -5,15 +5,17 @@ package maven_test import ( + "time" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - me "github.com/open-component-model/ocm/pkg/blobaccess/maven" . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" - "github.com/open-component-model/ocm/pkg/maven" . "github.com/open-component-model/ocm/pkg/testutils" + + me "github.com/open-component-model/ocm/pkg/blobaccess/maven" + "github.com/open-component-model/ocm/pkg/maven" "github.com/open-component-model/ocm/pkg/utils/tarutils" - "time" ) const ( diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index b7df6cfd50..9fff7a1856 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -5,11 +5,14 @@ package maven import ( + "io" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/goutils/optionutils" "github.com/mandelsoft/vfs/pkg/osfs" "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/bpi" @@ -22,8 +25,6 @@ import ( "github.com/open-component-model/ocm/pkg/mime" "github.com/open-component-model/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/utils/tarutils" - "github.com/opencontainers/go-digest" - "io" ) type coords = *maven.Coordinates diff --git a/pkg/common/accessio/retry_test.go b/pkg/common/accessio/retry_test.go index 73d764ff19..e67df7cf49 100644 --- a/pkg/common/accessio/retry_test.go +++ b/pkg/common/accessio/retry_test.go @@ -9,6 +9,7 @@ import ( . "github.com/open-component-model/ocm/pkg/testutils" "github.com/mandelsoft/goutils/errors" + "github.com/open-component-model/ocm/pkg/common/accessio" ) diff --git a/pkg/contexts/config/gc_test.go b/pkg/contexts/config/gc_test.go index 79e38c2974..996cb23388 100644 --- a/pkg/contexts/config/gc_test.go +++ b/pkg/contexts/config/gc_test.go @@ -6,9 +6,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/runtimefinalizer" me "github.com/open-component-model/ocm/pkg/contexts/config" + "github.com/open-component-model/ocm/pkg/runtimefinalizer" ) var _ = Describe("area test", func() { diff --git a/pkg/contexts/credentials/gc_test.go b/pkg/contexts/credentials/gc_test.go index 648e9a9e9c..c96f94c418 100644 --- a/pkg/contexts/credentials/gc_test.go +++ b/pkg/contexts/credentials/gc_test.go @@ -6,9 +6,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/runtimefinalizer" me "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/runtimefinalizer" ) var _ = Describe("area test", func() { diff --git a/pkg/contexts/credentials/repositories/npm/repository_test.go b/pkg/contexts/credentials/repositories/npm/repository_test.go index e7fd29cfa6..82694bcc48 100644 --- a/pkg/contexts/credentials/repositories/npm/repository_test.go +++ b/pkg/contexts/credentials/repositories/npm/repository_test.go @@ -6,7 +6,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/runtimefinalizer" . "github.com/open-component-model/ocm/pkg/testutils" "github.com/open-component-model/ocm/pkg/common" @@ -14,6 +13,7 @@ import ( npmCredentials "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/npm/identity" "github.com/open-component-model/ocm/pkg/contexts/credentials/cpi" local "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/npm" + "github.com/open-component-model/ocm/pkg/runtimefinalizer" ) var _ = Describe("NPM config - .npmrc", func() { diff --git a/pkg/contexts/credentials/repositories/vault/repo_int_test.go b/pkg/contexts/credentials/repositories/vault/repo_int_test.go index 2ce1308d90..c45289edbd 100644 --- a/pkg/contexts/credentials/repositories/vault/repo_int_test.go +++ b/pkg/contexts/credentials/repositories/vault/repo_int_test.go @@ -9,20 +9,20 @@ import ( "os/exec" "time" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/hashicorp/vault-client-go" "github.com/hashicorp/vault-client-go/schema" "github.com/mandelsoft/goutils/errors" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "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/identity/hostpath" me "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault" "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault/identity" "github.com/open-component-model/ocm/pkg/runtime" - . "github.com/open-component-model/ocm/pkg/testutils" ) type vaultMode string diff --git a/pkg/contexts/credentials/repositories/vault/repo_test.go b/pkg/contexts/credentials/repositories/vault/repo_test.go index 5eb7bdc748..72e3ee2d5c 100644 --- a/pkg/contexts/credentials/repositories/vault/repo_test.go +++ b/pkg/contexts/credentials/repositories/vault/repo_test.go @@ -7,12 +7,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/testutils" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/credentials" me "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault" "github.com/open-component-model/ocm/pkg/contexts/credentials/repositories/vault/identity" - . "github.com/open-component-model/ocm/pkg/testutils" ) const ( diff --git a/pkg/contexts/oci/gc_test.go b/pkg/contexts/oci/gc_test.go index 404dbad31e..bc48501b92 100644 --- a/pkg/contexts/oci/gc_test.go +++ b/pkg/contexts/oci/gc_test.go @@ -6,9 +6,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/runtimefinalizer" me "github.com/open-component-model/ocm/pkg/contexts/oci" + "github.com/open-component-model/ocm/pkg/runtimefinalizer" ) var _ = Describe("area test", func() { diff --git a/pkg/contexts/oci/repositories/ctf/ctf_test.go b/pkg/contexts/oci/repositories/ctf/ctf_test.go index 34aa84669f..5ca0cd470c 100644 --- a/pkg/contexts/oci/repositories/ctf/ctf_test.go +++ b/pkg/contexts/oci/repositories/ctf/ctf_test.go @@ -10,13 +10,13 @@ import ( . "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ctf/testhelper" . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/logging" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "github.com/mandelsoft/goutils/errors" "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" diff --git a/pkg/contexts/ocm/accessmethods/maven/method_test.go b/pkg/contexts/ocm/accessmethods/maven/method_test.go index 34d9efd5f6..4877687be0 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/method_test.go @@ -2,20 +2,20 @@ package maven_test import ( "crypto" - me "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" - "github.com/open-component-model/ocm/pkg/utils/tarutils" "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + . "github.com/open-component-model/ocm/pkg/testutils" "github.com/open-component-model/ocm/pkg/contexts/ocm" + me "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" - . "github.com/open-component-model/ocm/pkg/env" - . "github.com/open-component-model/ocm/pkg/env/builder" "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/mime" - . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/open-component-model/ocm/pkg/utils/tarutils" ) const ( diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go index 5290feff66..494285ca91 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go @@ -2,8 +2,10 @@ package maven import ( "crypto" + "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/vfs/pkg/vfs" + mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" "github.com/open-component-model/ocm/pkg/contexts/credentials/builtin/maven/identity" access "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/maven" 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 c7a9c6e81e..b0a5b8c720 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go @@ -2,21 +2,23 @@ package maven_test import ( "encoding/json" + "os" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/mandelsoft/goutils/sliceutils" "github.com/mandelsoft/vfs/pkg/vfs" + mavenblob "github.com/open-component-model/ocm/pkg/blobaccess/maven" me "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/maven" "github.com/open-component-model/ocm/pkg/contexts/ocm/elements" "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" - "os" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - . "github.com/open-component-model/ocm/pkg/env" - . "github.com/open-component-model/ocm/pkg/env/builder" - . "github.com/open-component-model/ocm/pkg/testutils" ) const mvnPATH = "/testdata/.m2/repository" diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go index 00fdb3e8c1..96c4c1130a 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go @@ -3,9 +3,11 @@ package maven import ( "encoding/json" "fmt" + "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/general" "github.com/mandelsoft/vfs/pkg/vfs" + "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes" diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go index 834dcb365e..e64514fbc6 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration_test.go @@ -3,9 +3,9 @@ package maven_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/maven" . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/open-component-model/ocm/pkg/contexts/ocm/blobhandler/handlers/generic/maven" "github.com/open-component-model/ocm/pkg/registrations" ) diff --git a/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go b/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go index a2263cdc9c..ae7cccff72 100644 --- a/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go +++ b/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go @@ -1,6 +1,6 @@ // Code generated by go-bindata. (@generated) DO NOT EDIT. -//Package jsonscheme generated by go-bindata.// sources: +// Package jsonscheme generated by go-bindata.// sources: // ../../../../../../../../resources/component-descriptor-ocm-v3-schema.yaml package jsonscheme diff --git a/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go b/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go index 7b2dd6aa3f..fa64fd8342 100644 --- a/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go +++ b/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go @@ -1,6 +1,6 @@ // Code generated by go-bindata. (@generated) DO NOT EDIT. -//Package jsonscheme generated by go-bindata.// sources: +// Package jsonscheme generated by go-bindata.// sources: // ../../../../../../../resources/component-descriptor-v2-schema.yaml package jsonscheme diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go b/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go index f3d247d474..546edd562c 100644 --- a/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go @@ -7,14 +7,15 @@ package helmblob_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env/builder" + . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/open-component-model/ocm/pkg/common/accessobj" metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1" "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" me "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactblob/helmblob" ctfocm "github.com/open-component-model/ocm/pkg/contexts/ocm/repositories/ctf" "github.com/open-component-model/ocm/pkg/env" - . "github.com/open-component-model/ocm/pkg/env/builder" - . "github.com/open-component-model/ocm/pkg/testutils" ) var _ = Describe("", func() { diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go index b8cd73d738..777d45ac64 100644 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go @@ -7,14 +7,15 @@ package mavenblob_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + . "github.com/open-component-model/ocm/pkg/env" + . "github.com/open-component-model/ocm/pkg/env/builder" + . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/open-component-model/ocm/pkg/contexts/ocm/elements" me "github.com/open-component-model/ocm/pkg/contexts/ocm/elements/artifactblob/mavenblob" "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/env" - . "github.com/open-component-model/ocm/pkg/env/builder" "github.com/open-component-model/ocm/pkg/maven" - . "github.com/open-component-model/ocm/pkg/testutils" ) const ( diff --git a/pkg/contexts/ocm/gc_test.go b/pkg/contexts/ocm/gc_test.go index 2896ae9406..a4ad5f81a7 100644 --- a/pkg/contexts/ocm/gc_test.go +++ b/pkg/contexts/ocm/gc_test.go @@ -6,9 +6,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/runtimefinalizer" me "github.com/open-component-model/ocm/pkg/contexts/ocm" + "github.com/open-component-model/ocm/pkg/runtimefinalizer" ) var _ = Describe("area test", func() { diff --git a/pkg/contexts/ocm/plugin/cache/updater.go b/pkg/contexts/ocm/plugin/cache/updater.go index 0f28269d02..cde2925a3a 100644 --- a/pkg/contexts/ocm/plugin/cache/updater.go +++ b/pkg/contexts/ocm/plugin/cache/updater.go @@ -194,7 +194,7 @@ func (o *PluginUpdater) download(session ocm.Session, cv ocm.ComponentVersionAcc break } wrong = r - } else { //nolint: gocritic // yes + } else { if name != "" { wrong = r } diff --git a/pkg/contexts/ocm/repositories/genericocireg/repo_test.go b/pkg/contexts/ocm/repositories/genericocireg/repo_test.go index 29347bb13c..206e0d8464 100644 --- a/pkg/contexts/ocm/repositories/genericocireg/repo_test.go +++ b/pkg/contexts/ocm/repositories/genericocireg/repo_test.go @@ -9,12 +9,11 @@ import ( . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/testutils" + "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/vfs/pkg/osfs" "github.com/mandelsoft/vfs/pkg/vfs" "github.com/opencontainers/go-digest" - "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" diff --git a/pkg/contexts/ocm/transfer/autohandler_test.go b/pkg/contexts/ocm/transfer/autohandler_test.go index 2370e26828..92bdcea68c 100644 --- a/pkg/contexts/ocm/transfer/autohandler_test.go +++ b/pkg/contexts/ocm/transfer/autohandler_test.go @@ -6,6 +6,7 @@ import ( . "github.com/open-component-model/ocm/pkg/testutils" "github.com/mandelsoft/goutils/errors" + "github.com/open-component-model/ocm/pkg/contexts/ocm/transfer" "github.com/open-component-model/ocm/pkg/contexts/ocm/transfer/transferhandler" "github.com/open-component-model/ocm/pkg/contexts/ocm/transfer/transferhandler/spiff" diff --git a/pkg/contexts/ocm/utils/localize/format.go b/pkg/contexts/ocm/utils/localize/format.go index 39a91bc6e0..0944c15994 100644 --- a/pkg/contexts/ocm/utils/localize/format.go +++ b/pkg/contexts/ocm/utils/localize/format.go @@ -48,7 +48,7 @@ func (m *ImageMapping) Evaluate(idx int, cv ocm.ComponentVersionAccess, resolver name := "image mapping" if m.Name != "" { name = fmt.Sprintf("%s %q", name, m.Name) - } else { //nolint: gocritic // yes + } else { if idx >= 0 { name = fmt.Sprintf("%s %d", name, idx+1) } diff --git a/pkg/exception/exception_test.go b/pkg/exception/exception_test.go index 33e95ccda5..b6bdf5e9d0 100644 --- a/pkg/exception/exception_test.go +++ b/pkg/exception/exception_test.go @@ -7,6 +7,7 @@ import ( . "github.com/onsi/gomega" "github.com/mandelsoft/goutils/errors" + "github.com/open-component-model/ocm/pkg/exception" ) diff --git a/pkg/maven/access.go b/pkg/maven/access.go index 7d7a5d928e..dac7e314f4 100644 --- a/pkg/maven/access.go +++ b/pkg/maven/access.go @@ -10,20 +10,22 @@ import ( "crypto" "encoding/json" "fmt" + "io" + "net/http" + "net/url" + "strings" + "github.com/cloudflare/cfssl/log" "github.com/mandelsoft/goutils/errors" "github.com/mandelsoft/goutils/finalizer" "github.com/mandelsoft/goutils/general" "github.com/mandelsoft/vfs/pkg/vfs" + "golang.org/x/exp/maps" + "golang.org/x/net/html" + "github.com/open-component-model/ocm/pkg/iotools" "github.com/open-component-model/ocm/pkg/utils" "github.com/open-component-model/ocm/pkg/utils/tarutils" - "golang.org/x/exp/maps" - "golang.org/x/net/html" - "io" - "net/http" - "net/url" - "strings" ) type Repository struct { diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index e257eb8e75..40ee7d4de3 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -58,7 +58,7 @@ type Coordinates struct { // Version of the Maven (mvn) artifact. Version string `json:"version"` // Classifier of the Maven (mvn) artifact. - Classifier *string `json:"classifier,omitempty"` //TODO: make it a pointer to differentiate between empty and none + Classifier *string `json:"classifier,omitempty"` // Extension of the Maven (mvn) artifact. Extension *string `json:"extension,omitempty"` } diff --git a/pkg/refmgmt/finalized/finalized_test.go b/pkg/refmgmt/finalized/finalized_test.go index 7bf4640cb5..5847592b0d 100644 --- a/pkg/refmgmt/finalized/finalized_test.go +++ b/pkg/refmgmt/finalized/finalized_test.go @@ -6,10 +6,10 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/open-component-model/ocm/pkg/runtimefinalizer" "github.com/open-component-model/ocm/pkg/refmgmt" "github.com/open-component-model/ocm/pkg/refmgmt/finalized" + "github.com/open-component-model/ocm/pkg/runtimefinalizer" ) type Interface interface { diff --git a/pkg/testutils/tcp.go b/pkg/testutils/tcp.go index 99dedd49c9..d00bffed35 100644 --- a/pkg/testutils/tcp.go +++ b/pkg/testutils/tcp.go @@ -6,9 +6,10 @@ package testutils import ( "context" - "github.com/mandelsoft/goutils/errors" "net" "time" + + "github.com/mandelsoft/goutils/errors" ) func PingTCPServer(address string, dur time.Duration) error { From bd805ba7eda3584981526e960e2ade25ef4336df Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Tue, 28 May 2024 13:48:40 +0200 Subject: [PATCH 10/13] fix refactoring errors --- .../common/inputs/types/directory/spec.go | 2 +- .../ocmcmds/common/inputs/types/maven/cli.go | 4 - .../ocmcmds/plugins/describe/cmd_test.go | 4 +- .../ocmcmds/plugins/describe/describe.go | 2 +- pkg/blobaccess/maven/access_test.go | 10 +- pkg/blobaccess/maven/options.go | 4 - pkg/blobaccess/maven/utils.go | 4 - .../builtin/maven/identity/identity.go | 8 +- .../repositories/vault/repo_int_test.go | 1 - pkg/contexts/ocm/accessmethods/github/cli.go | 2 +- pkg/contexts/ocm/accessmethods/maven/cli.go | 14 +- .../ocm/accessmethods/maven/method.go | 12 +- .../ocm/accessmethods/maven/method_test.go | 12 +- .../ocm/accessmethods/maven/suite_test.go | 2 +- .../ocm/accessmethods/options/standard.go | 8 +- .../handlers/generic/maven/blobhandler.go | 4 +- .../generic/maven/blobhandler_test.go | 4 +- .../handlers/generic/maven/registration.go | 8 +- .../handlers/generic/maven/suite_test.go | 2 +- .../artifactblob/helmblob/helmblob_test.go | 6 - .../artifactblob/mavenblob/access_test.go | 10 +- pkg/contexts/ocm/session.go | 2 +- pkg/contexts/ocm/utils/localize/format.go | 6 +- pkg/maven/access.go | 233 +++++++++--------- pkg/maven/access_test.go | 8 +- pkg/maven/coordinates.go | 14 +- pkg/maven/coordinates_test.go | 4 - pkg/maven/logging.go | 6 +- pkg/maven/suite_test.go | 2 +- pkg/maven/utils.go | 4 - pkg/testutils/tcp.go | 4 - pkg/toi/drivers/docker/driver.go | 2 +- pkg/utils/tarutils/pack.go | 2 +- 33 files changed, 180 insertions(+), 230 deletions(-) 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 04efcddeb5..4084b544ab 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/directory/spec.go @@ -14,7 +14,7 @@ import ( type Spec struct { cpi.MediaFileSpec `json:",inline"` - // PreserveDir defines that the directory specified in the BasePath field should be included in the blob. + // PreserveDir defines that the directory specified in the Path field should be included in the blob. // Only supported for Type dir. PreserveDir *bool `json:"preserveDir,omitempty"` // IncludeFiles is a list of shell file name patterns that describe the files that should be included. diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go index 5c417805b5..88b6fcbc63 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/cli.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import ( diff --git a/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go b/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go index 04cbdd97d9..2dc4707514 100644 --- a/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go +++ b/cmds/ocm/commands/ocmcmds/plugins/describe/cmd_test.go @@ -39,7 +39,7 @@ var _ = Describe("Test Environment", func() { ` Plugin Name: action Plugin Version: v1 -BasePath: ` + path + `/action +Path: ` + path + `/action Status: valid Source: manually installed Capabilities: Actions @@ -64,7 +64,7 @@ Actions: ---------------------- Plugin Name: test Plugin Version: v1 -BasePath: ` + path + `/test +Path: ` + path + `/test Status: valid Source: manually installed Capabilities: Access Methods diff --git a/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go b/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go index 8df5cfd5b8..67da8d3f48 100644 --- a/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go +++ b/cmds/ocm/commands/ocmcmds/plugins/describe/describe.go @@ -11,7 +11,7 @@ import ( func DescribePlugin(p plugin.Plugin, out common.Printer) { out.Printf("Plugin Name: %s\n", p.Name()) out.Printf("Plugin Version: %s\n", p.Version()) - out.Printf("BasePath: %s\n", p.Path()) + out.Printf("Path: %s\n", p.Path()) if !p.IsValid() { out.Printf("Status: %s\n", p.Error()) diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index cbf89d83f2..0e0b00953a 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven_test import ( @@ -19,8 +15,8 @@ import ( ) const ( - mvnPATH = "/testdata/.m2/repository" - FAILPATH = "/testdata/.m2/fail" + MAVEN_PATH = "/testdata/.m2/repository" + FAIL_PATH = "/testdata/.m2/fail" MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" MAVEN_GROUP_ID = "maven" @@ -36,7 +32,7 @@ var _ = Describe("blobaccess for maven", func() { BeforeEach(func() { env = NewBuilder(TestData()) - repo = maven.NewFileRepository(mvnPATH, env.FileSystem()) + repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) AfterEach(func() { diff --git a/pkg/blobaccess/maven/options.go b/pkg/blobaccess/maven/options.go index b88b6d2fdd..8ceae8c2ea 100644 --- a/pkg/blobaccess/maven/options.go +++ b/pkg/blobaccess/maven/options.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import ( diff --git a/pkg/blobaccess/maven/utils.go b/pkg/blobaccess/maven/utils.go index 9fff7a1856..b1f4d774ba 100644 --- a/pkg/blobaccess/maven/utils.go +++ b/pkg/blobaccess/maven/utils.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import ( diff --git a/pkg/contexts/credentials/builtin/maven/identity/identity.go b/pkg/contexts/credentials/builtin/maven/identity/identity.go index 7d407a2953..491e38b453 100644 --- a/pkg/contexts/credentials/builtin/maven/identity/identity.go +++ b/pkg/contexts/credentials/builtin/maven/identity/identity.go @@ -10,17 +10,17 @@ import ( ) const ( - // CONSUMER_TYPE is the mvn repository type. + // CONSUMER_TYPE is the maven repository type. CONSUMER_TYPE = "MavenRepository" - // ATTR_USERNAME is the username attribute. Required for login at any mvn registry. + // ATTR_USERNAME is the username attribute. Required for login at any maven registry. ATTR_USERNAME = cpi.ATTR_USERNAME - // ATTR_PASSWORD is the password attribute. Required for login at any mvn registry. + // ATTR_PASSWORD is the password attribute. Required for login at any maven registry. ATTR_PASSWORD = cpi.ATTR_PASSWORD ) // REALM the logging realm / prefix. -var REALM = logging.DefineSubRealm("Maven repository", "mvn") +var REALM = logging.DefineSubRealm("Maven repository", "maven") func init() { attrs := listformat.FormatListElements("", listformat.StringElementDescriptionList{ diff --git a/pkg/contexts/credentials/repositories/vault/repo_int_test.go b/pkg/contexts/credentials/repositories/vault/repo_int_test.go index c45289edbd..3109660a3e 100644 --- a/pkg/contexts/credentials/repositories/vault/repo_int_test.go +++ b/pkg/contexts/credentials/repositories/vault/repo_int_test.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/vault-client-go" "github.com/hashicorp/vault-client-go/schema" - "github.com/mandelsoft/goutils/errors" "github.com/open-component-model/ocm/pkg/common" "github.com/open-component-model/ocm/pkg/contexts/credentials" diff --git a/pkg/contexts/ocm/accessmethods/github/cli.go b/pkg/contexts/ocm/accessmethods/github/cli.go index 82cf2e43a8..22e9f538e8 100644 --- a/pkg/contexts/ocm/accessmethods/github/cli.go +++ b/pkg/contexts/ocm/accessmethods/github/cli.go @@ -31,7 +31,7 @@ The type specific specification fields are: - **repoUrl** *string* - RepoUrl URL with or without scheme. + Repository URL with or without scheme. - **ref** (optional) *string* diff --git a/pkg/contexts/ocm/accessmethods/maven/cli.go b/pkg/contexts/ocm/accessmethods/maven/cli.go index 15554e4472..db82b8a8b9 100644 --- a/pkg/contexts/ocm/accessmethods/maven/cli.go +++ b/pkg/contexts/ocm/accessmethods/maven/cli.go @@ -30,7 +30,7 @@ func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error { } var usage = ` -This method implements the access of a Maven (mvn) artifact in a Maven repository. +This method implements the access of a Maven artifact in a Maven repository. ` var formatV1 = ` @@ -38,25 +38,25 @@ The type specific specification fields are: - **repoUrl** *string* - Base URL of the Maven (mvn) repository + URL of the Maven repository - **groupId** *string* - The groupId of the Maven (mvn) artifact + The groupId of the Maven artifact - **artifactId** *string* - The artifactId of the Maven (mvn) artifact + The artifactId of the Maven artifact - **version** *string* - The version name of the Maven (mvn) artifact + The version name of the Maven artifact - **classifier** *string* - The optional classifier of the Maven (mvn) artifact + The optional classifier of the Maven artifact - **extension** *string* - The optional extension of the Maven (mvn) artifact + The optional extension of the Maven artifact ` diff --git a/pkg/contexts/ocm/accessmethods/maven/method.go b/pkg/contexts/ocm/accessmethods/maven/method.go index 2a31a3fc69..d377c884fd 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method.go +++ b/pkg/contexts/ocm/accessmethods/maven/method.go @@ -14,7 +14,7 @@ import ( "github.com/open-component-model/ocm/pkg/runtime" ) -// Type is the access type of Maven (mvn) repository. +// Type is the access type of Maven repository. const ( Type = "maven" TypeV1 = Type + runtime.VersionSeparator + "v1" @@ -25,11 +25,11 @@ func init() { accspeccpi.RegisterAccessType(accspeccpi.NewAccessSpecType[*AccessSpec](TypeV1, accspeccpi.WithFormatSpec(formatV1), accspeccpi.WithConfigHandler(ConfigHandler()))) } -// AccessSpec describes the access for a Maven (mvn) artifact. +// AccessSpec describes the access for a Maven artifact. type AccessSpec struct { runtime.ObjectVersionedType `json:",inline"` - // RepoUrl is the base URL of the Maven (mvn) repository. + // RepoUrl is the base URL of the Maven repository. RepoUrl string `json:"repoUrl"` maven.Coordinates `json:",inline"` @@ -54,7 +54,7 @@ func WithOptionalExtension(e *string) Option { var _ accspeccpi.AccessSpec = (*AccessSpec)(nil) -// New creates a new Maven (mvn) repository access spec version v1. +// New creates a new Maven repository access spec version v1. func New(repository, groupId, artifactId, version string, opts ...Option) *AccessSpec { accessSpec := &AccessSpec{ ObjectVersionedType: runtime.NewVersionedTypedObject(Type), @@ -64,7 +64,7 @@ func New(repository, groupId, artifactId, version string, opts ...Option) *Acces return accessSpec } -// NewForCoordinates creates a new Maven (mvn) repository access spec version v1. +// NewForCoordinates creates a new Maven repository access spec version v1. func NewForCoordinates(repository string, coords *maven.Coordinates, opts ...Option) *AccessSpec { optionutils.ApplyOptions(coords, opts...) accessSpec := &AccessSpec{ @@ -76,7 +76,7 @@ func NewForCoordinates(repository string, coords *maven.Coordinates, opts ...Opt } func (a *AccessSpec) Describe(_ accspeccpi.Context) string { - return fmt.Sprintf("Maven (mvn) package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.RepoUrl, a.Coordinates.FilePath()) + return fmt.Sprintf("Maven package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.RepoUrl, a.Coordinates.FilePath()) } func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool { diff --git a/pkg/contexts/ocm/accessmethods/maven/method_test.go b/pkg/contexts/ocm/accessmethods/maven/method_test.go index 4877687be0..37e9dfa2c8 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/method_test.go @@ -19,7 +19,7 @@ import ( ) const ( - mvnPATH = "/testdata/.m2/repository" + MAVEN_PATH = "/testdata/.m2/repository" FAILPATH = "/testdata/fail" MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" @@ -28,7 +28,7 @@ const ( MAVEN_VERSION = "1.1" ) -var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { +var _ = Describe("local accessmethods.maven.AccessSpec tests", func() { var env *Builder var cv ocm.ComponentVersionAccess @@ -42,7 +42,7 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { }) It("accesses local artifact", func() { - acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") + acc := me.New("file://"+MAVEN_PATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0") m := Must(acc.AccessMethod(cv)) defer Close(m) Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) @@ -61,7 +61,7 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { }) It("accesses local artifact with empty classifier and with extension", func() { - acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) + acc := me.New("file://"+MAVEN_PATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithClassifier(""), me.WithExtension("pom")) m := Must(acc.AccessMethod(cv)) defer Close(m) Expect(m.MimeType()).To(Equal(mime.MIME_XML)) @@ -82,7 +82,7 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { }) It("accesses local artifact with extension", func() { - acc := me.New("file://"+mvnPATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) + acc := me.New("file://"+MAVEN_PATH, "com.sap.cloud.sdk", "sdk-modules-bom", "5.7.0", me.WithExtension("pom")) m := Must(acc.AccessMethod(cv)) defer Close(m) Expect(m.MimeType()).To(Equal(mime.MIME_TGZ)) @@ -97,7 +97,7 @@ var _ = Describe("local accessmethods.mvn.AccessSpec tests", func() { It("Describe", func() { acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) - Expect(acc.Describe(nil)).To(Equal("Maven (mvn) package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) + Expect(acc.Describe(nil)).To(Equal("Maven package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) }) It("detects digests mismatch", func() { diff --git a/pkg/contexts/ocm/accessmethods/maven/suite_test.go b/pkg/contexts/ocm/accessmethods/maven/suite_test.go index 0892bc9a7f..d43b2dbd6b 100644 --- a/pkg/contexts/ocm/accessmethods/maven/suite_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Maven (mvn) Test Suite") + RunSpecs(t, "Maven Test Suite") } diff --git a/pkg/contexts/ocm/accessmethods/options/standard.go b/pkg/contexts/ocm/accessmethods/options/standard.go index 2b399ae853..cc666b3ecc 100644 --- a/pkg/contexts/ocm/accessmethods/options/standard.go +++ b/pkg/contexts/ocm/accessmethods/options/standard.go @@ -19,10 +19,10 @@ var ReferenceOption = RegisterOption(NewStringOptionType("reference", "reference var PackageOption = RegisterOption(NewStringOptionType("accessPackage", "package or object name")) // ArtifactOption. -var ArtifactOption = RegisterOption(NewStringOptionType("artifactId", "artifact id")) +var ArtifactOption = RegisterOption(NewStringOptionType("artifactId", "maven artifact id")) // GroupOption. -var GroupOption = RegisterOption(NewStringOptionType("groupId", "group id or namespace")) +var GroupOption = RegisterOption(NewStringOptionType("groupId", "maven group id")) // RepositoryOption. var RepositoryOption = RegisterOption(NewStringOptionType("accessRepository", "repository URL")) @@ -63,7 +63,7 @@ var HTTPRedirectOption = RegisterOption(NewBoolOptionType("noredirect", "http re var CommentOption = RegisterOption(NewStringOptionType("comment", "comment field value")) // ClassifierOption the optional classifier of a maven resource. -var ClassifierOption = RegisterOption(NewStringOptionType("classifier", "mvn classifier")) +var ClassifierOption = RegisterOption(NewStringOptionType("classifier", "maven classifier")) // ExtensionOption the optional extension of a maven resource. -var ExtensionOption = RegisterOption(NewStringOptionType("extension", "mvn extension name")) +var ExtensionOption = RegisterOption(NewStringOptionType("extension", "maven extension name")) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go index 494285ca91..76dd8689bc 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler.go @@ -44,7 +44,7 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi return nil, nil } if mime.MIME_TGZ != mimeType { - log.Debug("not a tarball, can't be a complete mvn GAV", "mimeType", mimeType) + log.Debug("not a tarball, can't be a complete maven GAV", "mimeType", mimeType) return nil, nil } @@ -92,7 +92,7 @@ func (b *artifactHandler) StoreBlob(blob cpi.BlobAccess, resourceType string, hi return nil, err } loop.Close(readHash) - // MD5 + SHA1 are still the most used ones in the mvn context + // MD5 + SHA1 are still the most used ones in the maven context hr := iotools.NewHashReader(readHash, crypto.SHA256, crypto.SHA1, crypto.MD5) _, err = hr.CalcHashes() if err != nil { 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 b0a5b8c720..abe3f48a2f 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go @@ -21,7 +21,7 @@ import ( "github.com/open-component-model/ocm/pkg/maven" ) -const mvnPATH = "/testdata/.m2/repository" +const MAVEN_PATH = "/testdata/.m2/repository" var _ = Describe("blobhandler generic maven tests", func() { var env *Builder @@ -29,7 +29,7 @@ var _ = Describe("blobhandler generic maven tests", func() { BeforeEach(func() { env = NewBuilder(TestData()) - repo = maven.NewFileRepository(mvnPATH, env.FileSystem()) + repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) It("Unmarshal upload response Body", func() { diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go index 96c4c1130a..f6024503c2 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/registration.go @@ -97,13 +97,13 @@ func (r *RegistrationHandler) RegisterByName(handler string, ctx cpi.Context, co } func (r *RegistrationHandler) GetHandlers(_ cpi.Context) registrations.HandlerInfos { - return registrations.NewLeafHandlerInfo("uploading mvn artifacts", ` -The `+BlobHandlerName+` uploader is able to upload mvn artifacts (whole GAV only!) -as artifact archive according to the mvn artifact spec. + return registrations.NewLeafHandlerInfo("uploading maven artifacts", ` +The `+BlobHandlerName+` uploader is able to upload maven artifacts (whole GAV only!) +as artifact archive according to the maven artifact spec. If registered the default mime type is: `+mime.MIME_TGZ+` It accepts a plain string for the URL or a config with the following field: -'url': the URL of the mvn repository. +'url': the URL of the maven repository. `, ) } diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go index 0892bc9a7f..d43b2dbd6b 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Maven (mvn) Test Suite") + RunSpecs(t, "Maven Test Suite") } diff --git a/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go b/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go index 546edd562c..1889da3ee4 100644 --- a/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go +++ b/pkg/contexts/ocm/elements/artifactblob/helmblob/helmblob_test.go @@ -1,12 +1,7 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package helmblob_test import ( . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" . "github.com/open-component-model/ocm/pkg/env/builder" . "github.com/open-component-model/ocm/pkg/testutils" @@ -31,7 +26,6 @@ var _ = Describe("", func() { }) It("", func() { - Expect(1).To(Equal(1)) ctf := Must(ctfocm.Open(e, accessobj.ACC_CREATE, "/repo", 0o700, e, ctfocm.FormatDirectory)) defer Close(ctf) cv := Must(ctf.NewComponentVersion("ocm.software/test-component", "1.0.0")) diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go index 777d45ac64..9155610440 100644 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package mavenblob_test import ( @@ -19,8 +15,8 @@ import ( ) const ( - mvnPATH = "/testdata/.m2/repository" - FAILPATH = "/testdata/.m2/fail" + MAVEN_PATH = "/testdata/.m2/repository" + FAIL_PATH = "/testdata/.m2/fail" MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" MAVEN_GROUP_ID = "maven" @@ -36,7 +32,7 @@ var _ = Describe("blobaccess for maven", func() { BeforeEach(func() { env = NewBuilder(TestData()) - repo = maven.NewFileRepository(mvnPATH, env.FileSystem()) + repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) AfterEach(func() { diff --git a/pkg/contexts/ocm/session.go b/pkg/contexts/ocm/session.go index 52d2dc4c95..d9a1cd8d77 100644 --- a/pkg/contexts/ocm/session.go +++ b/pkg/contexts/ocm/session.go @@ -102,7 +102,7 @@ func (s *session) LookupRepository(ctx Context, spec RepositorySpec) (Repository // The repo's closer function should only be added once with add closer. Otherwise, it would be attempted to close // an already closed object. Thus, we only want to add the repo's closer function, if it was not already cached // (and thus, consequently already added to the sessions close). - // Session has to take over responsibility for open repositories for the RepoUrl Cache because the objects + // Session has to take over responsibility for open repositories for the Repository Cache because the objects // opened during a session have to be closed in the reverse order they were opened (e.g. components opened based // on a previously opened repository have to be closed first). if !cached { diff --git a/pkg/contexts/ocm/utils/localize/format.go b/pkg/contexts/ocm/utils/localize/format.go index 0944c15994..da1018ad3e 100644 --- a/pkg/contexts/ocm/utils/localize/format.go +++ b/pkg/contexts/ocm/utils/localize/format.go @@ -34,11 +34,11 @@ type ImageMapping struct { // The optional variants for the value determination - // BasePath in target to substitute by the image tag/digest + // Path in target to substitute by the image tag/digest Tag string `json:"tag,omitempty"` - // BasePath in target to substitute the image repository + // Path in target to substitute the image repository Repository string `json:"repository,omitempty"` - // BasePath in target to substitute the complete image + // Path in target to substitute the complete image Image string `json:"image,omitempty"` } diff --git a/pkg/maven/access.go b/pkg/maven/access.go index dac7e314f4..3fc972b83e 100644 --- a/pkg/maven/access.go +++ b/pkg/maven/access.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import ( @@ -28,55 +24,15 @@ import ( "github.com/open-component-model/ocm/pkg/utils/tarutils" ) -type Repository struct { - Location -} - -type Location struct { - url string - path string - fs vfs.FileSystem -} - -func (l *Location) MarshalJSON() ([]byte, error) { - return json.Marshal(l.String()) -} - -func (l *Location) IsFileSystem() bool { - return l.path != "" -} - -func (l *Location) AddPath(path string) *Location { - result := *l - var p *string - if result.url != "" { - p = &result.url - } else { - p = &result.path - } - - if !strings.HasSuffix(*p, "/") { - *p += "/" - } - *p += path - return &result -} - -func (l *Location) AddExtension(ext string) *Location { - result := *l - var p *string - if result.url != "" { - p = &result.url - } else { - p = &result.path - } - - *p += "." + ext - return &result +type FileMeta struct { + MimeType string + HashType crypto.Hash + Hash string + Location *Location } -func (l *Location) String() string { - return general.Conditional(l.path != "", l.path, l.url) +type Repository struct { + Location } func NewFileRepository(path string, fss ...vfs.FileSystem) *Repository { @@ -102,72 +58,6 @@ func NewUrlRepository(repoUrl string, fss ...vfs.FileSystem) (*Repository, error }}, nil } -type FileMeta struct { - MimeType string - HashType crypto.Hash - Hash string - Location *Location -} - -type Credentials interface { - SetForRequest(req *http.Request) error -} -type BasicAuthCredentials struct { - Username string - Password string -} - -func (b *BasicAuthCredentials) SetForRequest(req *http.Request) error { - req.SetBasicAuth(b.Username, b.Password) - return nil -} - -func (l *Location) GetHash(creds Credentials, hash crypto.Hash) (string, error) { - // getStringData reads all data from the given URL and returns it as a string. - r, err := l.AddExtension(HashExt(hash)).GetReader(creds) - if err != nil { - return "", err - } - defer r.Close() - b, err := io.ReadAll(r) - if err != nil { - return "", err - } - return string(b), nil -} - -func (l *Location) GetReader(creds Credentials) (io.ReadCloser, error) { - if l.path != "" { - return l.fs.OpenFile(l.path, vfs.O_RDONLY, 0o600) - } - - req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, l.url, nil) - if err != nil { - return nil, err - } - if creds != nil { - err = creds.SetForRequest(req) - if err != nil { - return nil, err - } - } - httpClient := &http.Client{} - resp, err := httpClient.Do(req) - if err != nil { - return nil, err - } - if resp.StatusCode != http.StatusOK { - defer resp.Body.Close() - buf := &bytes.Buffer{} - _, err = io.Copy(buf, io.LimitReader(resp.Body, 2000)) - if err == nil { - Log.Error("http", "code", resp.Status, "repo", l.url, "body", buf.String()) - } - return nil, errors.Newf("http %s error - %s", resp.Status, l.url) - } - return resp.Body, nil -} - func (r *Repository) Url() (string, error) { if r.url != "" { return r.url, nil @@ -356,7 +246,7 @@ func gavFilesFromDisk(fs vfs.FileSystem, dir string) (map[string]crypto.Hash, er return filesAndHashes(files), nil } -// gavOnlineFiles returns the files of the Maven (mvn) artifact in the repository and their available digests. +// gavOnlineFiles returns the files of the Maven artifact in the repository and their available digests. func gavOnlineFiles(repo *Repository, coords *Coordinates, creds Credentials) (map[string]crypto.Hash, error) { log := Log.WithValues("RepoUrl", repo.String(), "GAV", coords.GavPath()) log.Debug("gavOnlineFiles") @@ -408,3 +298,110 @@ func filesAndHashes(fileList []string) map[string]crypto.Hash { } return result } + +type Location struct { + url string + path string + fs vfs.FileSystem +} + +func (l *Location) MarshalJSON() ([]byte, error) { + return json.Marshal(l.String()) +} + +func (l *Location) IsFileSystem() bool { + return l.path != "" +} + +func (l *Location) AddPath(path string) *Location { + result := *l + var p *string + if result.url != "" { + p = &result.url + } else { + p = &result.path + } + + if !strings.HasSuffix(*p, "/") { + *p += "/" + } + *p += path + return &result +} + +func (l *Location) AddExtension(ext string) *Location { + result := *l + var p *string + if result.url != "" { + p = &result.url + } else { + p = &result.path + } + + *p += "." + ext + return &result +} + +func (l *Location) String() string { + return general.Conditional(l.path != "", l.path, l.url) +} + +func (l *Location) GetHash(creds Credentials, hash crypto.Hash) (string, error) { + // getStringData reads all data from the given URL and returns it as a string. + r, err := l.AddExtension(HashExt(hash)).GetReader(creds) + if err != nil { + return "", err + } + defer r.Close() + b, err := io.ReadAll(r) + if err != nil { + return "", err + } + return string(b), nil +} + +func (l *Location) GetReader(creds Credentials) (io.ReadCloser, error) { + if l.path != "" { + return l.fs.OpenFile(l.path, vfs.O_RDONLY, 0o600) + } + + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, l.url, nil) + if err != nil { + return nil, err + } + if creds != nil { + err = creds.SetForRequest(req) + if err != nil { + return nil, err + } + } + httpClient := &http.Client{} + resp, err := httpClient.Do(req) + if err != nil { + return nil, err + } + if resp.StatusCode != http.StatusOK { + defer resp.Body.Close() + buf := &bytes.Buffer{} + _, err = io.Copy(buf, io.LimitReader(resp.Body, 2000)) + if err == nil { + Log.Error("http", "code", resp.Status, "repo", l.url, "body", buf.String()) + } + return nil, errors.Newf("http %s error - %s", resp.Status, l.url) + } + return resp.Body, nil +} + +type Credentials interface { + SetForRequest(req *http.Request) error +} + +type BasicAuthCredentials struct { + Username string + Password string +} + +func (b *BasicAuthCredentials) SetForRequest(req *http.Request) error { + req.SetBasicAuth(b.Username, b.Password) + return nil +} diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go index 748bc81b78..f4b6031069 100644 --- a/pkg/maven/access_test.go +++ b/pkg/maven/access_test.go @@ -16,8 +16,8 @@ import ( ) const ( - mvnPATH = "/testdata/.m2/repository" - FAILPATH = "/testdata/.m2/fail" + MAVEN_PATH = "/testdata/.m2/repository" + FAIL_PATH = "/testdata/.m2/fail" ) var _ = Describe("local accessmethods.me.AccessSpec tests", func() { @@ -26,7 +26,7 @@ var _ = Describe("local accessmethods.me.AccessSpec tests", func() { BeforeEach(func() { env = NewBuilder(TestData()) - repo = me.NewFileRepository(mvnPATH, env.FileSystem()) + repo = me.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) AfterEach(func() { @@ -123,7 +123,7 @@ sdk-modules-bom-5.7.0-sources.jar: 3 It("download dedicated file with filed digest verification", func() { coords := me.NewCoordinates("test", "repository", "42", me.WithClassifier(""), me.WithExtension("pom")) - repo := me.NewFileRepository(FAILPATH, env) + repo := me.NewFileRepository(FAIL_PATH, env) reader := Must(repo.Download(coords, nil, true)) _ = Must(io.ReadAll(reader)) Expect(reader.Close()).To(MatchError("SHA-1 digest mismatch: expected 44a77645201d1a8fc5213ace787c220eabbd0967, found b3242b8c31f8ce14f729b8fd132ac77bc4bc5bf7")) diff --git a/pkg/maven/coordinates.go b/pkg/maven/coordinates.go index 40ee7d4de3..fa1767ba4e 100644 --- a/pkg/maven/coordinates.go +++ b/pkg/maven/coordinates.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import ( @@ -51,15 +47,15 @@ func (o WithExtension) ApplyTo(c *Coordinates) { // Coordinates holds the typical Maven coordinates groupId, artifactId, version. Optional also classifier and extension. // https://maven.apache.org/ref/3.9.6/maven-core/artifact-handlers.html type Coordinates struct { - // GroupId of the Maven (mvn) artifact. + // GroupId of the Maven artifact. GroupId string `json:"groupId"` - // ArtifactId of the Maven (mvn) artifact. + // ArtifactId of the Maven artifact. ArtifactId string `json:"artifactId"` - // Version of the Maven (mvn) artifact. + // Version of the Maven artifact. Version string `json:"version"` - // Classifier of the Maven (mvn) artifact. + // Classifier of the Maven artifact. Classifier *string `json:"classifier,omitempty"` - // Extension of the Maven (mvn) artifact. + // Extension of the Maven artifact. Extension *string `json:"extension,omitempty"` } diff --git a/pkg/maven/coordinates_test.go b/pkg/maven/coordinates_test.go index 24dbcf4a0a..9a7aa6300a 100644 --- a/pkg/maven/coordinates_test.go +++ b/pkg/maven/coordinates_test.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven_test import ( diff --git a/pkg/maven/logging.go b/pkg/maven/logging.go index beea3c7d0c..17bfd5df54 100644 --- a/pkg/maven/logging.go +++ b/pkg/maven/logging.go @@ -1,11 +1,7 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import "github.com/open-component-model/ocm/pkg/logging" -var REALM = logging.DefineSubRealm("Maven repository", "mvn") +var REALM = logging.DefineSubRealm("Maven repository", "maven") var Log = logging.DynamicLogger(REALM) diff --git a/pkg/maven/suite_test.go b/pkg/maven/suite_test.go index 0892bc9a7f..d43b2dbd6b 100644 --- a/pkg/maven/suite_test.go +++ b/pkg/maven/suite_test.go @@ -9,5 +9,5 @@ import ( func TestConfig(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Maven (mvn) Test Suite") + RunSpecs(t, "Maven Test Suite") } diff --git a/pkg/maven/utils.go b/pkg/maven/utils.go index a2eb4f5181..8ed697c43a 100644 --- a/pkg/maven/utils.go +++ b/pkg/maven/utils.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maven import ( diff --git a/pkg/testutils/tcp.go b/pkg/testutils/tcp.go index d00bffed35..05286141e0 100644 --- a/pkg/testutils/tcp.go +++ b/pkg/testutils/tcp.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package testutils import ( diff --git a/pkg/toi/drivers/docker/driver.go b/pkg/toi/drivers/docker/driver.go index 58549980df..d35d71f380 100644 --- a/pkg/toi/drivers/docker/driver.go +++ b/pkg/toi/drivers/docker/driver.go @@ -159,7 +159,7 @@ func pullImage(ctx context.Context, cli command.Cli, imageName string) error { return fmt.Errorf("unable to parse normalized name: %w", err) } - // Resolve the RepoUrl name from fqn to RepositoryInfo + // Resolve the Repository name from fqn to RepositoryInfo repoInfo, err := registry.ParseRepositoryInfo(ref) if err != nil { return fmt.Errorf("unable to parse repository info: %w", err) diff --git a/pkg/utils/tarutils/pack.go b/pkg/utils/tarutils/pack.go index c5158283e1..c65ce25a78 100644 --- a/pkg/utils/tarutils/pack.go +++ b/pkg/utils/tarutils/pack.go @@ -44,7 +44,7 @@ func CreateTarFromFs(fs vfs.FileSystem, path string, compress func(w io.Writer) type TarFileSystemOptions struct { IncludeFiles []string ExcludeFiles []string - // PreserveDir defines that the directory specified in the BasePath field should be included in the blob. + // PreserveDir defines that the directory specified in the Path field should be included in the blob. // Only supported for Type dir. PreserveDir bool FollowSymlinks bool From 58e529ce285729ee5c9adc6f700cc3f2ba792fbe Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Tue, 28 May 2024 13:57:38 +0200 Subject: [PATCH 11/13] run make generate --- .../plugin_accessmethod_compose.md | 8 ++--- docs/pluginreference/plugin_descriptor.md | 8 ++--- .../plugin_valueset_compose.md | 8 ++--- .../ocm_add_resource-configuration.md | 32 +++++++++---------- docs/reference/ocm_add_resources.md | 32 +++++++++---------- .../reference/ocm_add_source-configuration.md | 32 +++++++++---------- docs/reference/ocm_add_sources.md | 32 +++++++++---------- docs/reference/ocm_logging.md | 2 +- docs/reference/ocm_ocm-accessmethods.md | 16 +++++----- docs/reference/ocm_ocm-uploadhandlers.md | 8 ++--- .../ocm_transfer_commontransportarchive.md | 8 ++--- .../ocm_transfer_componentversions.md | 8 ++--- .../v3alpha1/jsonscheme/bindata.go | 2 +- .../versions/v2/jsonscheme/bindata.go | 2 +- 14 files changed, 99 insertions(+), 99 deletions(-) diff --git a/docs/pluginreference/plugin_accessmethod_compose.md b/docs/pluginreference/plugin_accessmethod_compose.md index 7c1fa77577..e451f8f7c7 100644 --- a/docs/pluginreference/plugin_accessmethod_compose.md +++ b/docs/pluginreference/plugin_accessmethod_compose.md @@ -40,16 +40,16 @@ The following predefined option types can be used: - accessRegistry: [*string*] registry base URL - accessRepository: [*string*] repository URL - accessVersion: [*string*] version for access specification - - artifactId: [*string*] artifact id + - artifactId: [*string*] maven artifact id - body: [*string*] body of a http request - bucket: [*string*] bucket name - - classifier: [*string*] mvn classifier + - classifier: [*string*] maven classifier - comment: [*string*] comment field value - commit: [*string*] git commit id - digest: [*string*] blob digest - - extension: [*string*] mvn extension name + - extension: [*string*] maven extension name - globalAccess: [*map[string]YAML*] access specification for global access - - groupId: [*string*] group id or namespace + - groupId: [*string*] maven group id - header: [*string:string,string*] http headers - hint: [*string*] (repository) hint for local artifacts - mediaType: [*string*] media type for artifact blob representation diff --git a/docs/pluginreference/plugin_descriptor.md b/docs/pluginreference/plugin_descriptor.md index 45e09eef59..e2c05f2bae 100644 --- a/docs/pluginreference/plugin_descriptor.md +++ b/docs/pluginreference/plugin_descriptor.md @@ -125,16 +125,16 @@ The following predefined option types can be used: - accessRegistry: [*string*] registry base URL - accessRepository: [*string*] repository URL - accessVersion: [*string*] version for access specification - - artifactId: [*string*] artifact id + - artifactId: [*string*] maven artifact id - body: [*string*] body of a http request - bucket: [*string*] bucket name - - classifier: [*string*] mvn classifier + - classifier: [*string*] maven classifier - comment: [*string*] comment field value - commit: [*string*] git commit id - digest: [*string*] blob digest - - extension: [*string*] mvn extension name + - extension: [*string*] maven extension name - globalAccess: [*map[string]YAML*] access specification for global access - - groupId: [*string*] group id or namespace + - groupId: [*string*] maven group id - header: [*string:string,string*] http headers - hint: [*string*] (repository) hint for local artifacts - mediaType: [*string*] media type for artifact blob representation diff --git a/docs/pluginreference/plugin_valueset_compose.md b/docs/pluginreference/plugin_valueset_compose.md index a2bb2b101c..f7513c805b 100644 --- a/docs/pluginreference/plugin_valueset_compose.md +++ b/docs/pluginreference/plugin_valueset_compose.md @@ -40,16 +40,16 @@ The following predefined option types can be used: - accessRegistry: [*string*] registry base URL - accessRepository: [*string*] repository URL - accessVersion: [*string*] version for access specification - - artifactId: [*string*] artifact id + - artifactId: [*string*] maven artifact id - body: [*string*] body of a http request - bucket: [*string*] bucket name - - classifier: [*string*] mvn classifier + - classifier: [*string*] maven classifier - comment: [*string*] comment field value - commit: [*string*] git commit id - digest: [*string*] blob digest - - extension: [*string*] mvn extension name + - extension: [*string*] maven extension name - globalAccess: [*map[string]YAML*] access specification for global access - - groupId: [*string*] group id or namespace + - groupId: [*string*] maven group id - header: [*string:string,string*] http headers - hint: [*string*] (repository) hint for local artifacts - mediaType: [*string*] media type for artifact blob representation diff --git a/docs/reference/ocm_add_resource-configuration.md b/docs/reference/ocm_add_resource-configuration.md index 5f6b563566..533a494438 100644 --- a/docs/reference/ocm_add_resource-configuration.md +++ b/docs/reference/ocm_add_resource-configuration.md @@ -30,15 +30,15 @@ resource-configuration, resourceconfig, rsccfg, rcfg --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request --bucket string bucket name - --classifier string mvn classifier + --classifier string maven classifier --commit string git commit id --digest string blob digest - --extension string mvn extension name + --extension string maven extension name --globalAccess YAML access specification for global access - --groupId string group id or namespace + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -54,11 +54,11 @@ resource-configuration, resourceconfig, rsccfg, rcfg #### Input Specification Options ``` - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request - --classifier string mvn classifier - --extension string mvn extension name - --groupId string group id or namespace + --classifier string maven classifier + --extension string maven extension name + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -621,7 +621,7 @@ shown below. - **repoUrl** *string* - RepoUrl URL with or without scheme. + Repository URL with or without scheme. - **ref** (optional) *string* @@ -724,7 +724,7 @@ shown below. - Access type maven - This method implements the access of a Maven (mvn) artifact in a Maven repository. + This method implements the access of a Maven artifact in a Maven repository. The following versions are supported: - Version v1 @@ -733,27 +733,27 @@ shown below. - **repoUrl** *string* - Base URL of the Maven (mvn) repository + URL of the Maven repository - **groupId** *string* - The groupId of the Maven (mvn) artifact + The groupId of the Maven artifact - **artifactId** *string* - The artifactId of the Maven (mvn) artifact + The artifactId of the Maven artifact - **version** *string* - The version name of the Maven (mvn) artifact + The version name of the Maven artifact - **classifier** *string* - The optional classifier of the Maven (mvn) artifact + The optional classifier of the Maven artifact - **extension** *string* - The optional extension of the Maven (mvn) artifact + The optional extension of the Maven artifact Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId diff --git a/docs/reference/ocm_add_resources.md b/docs/reference/ocm_add_resources.md index f3c245d46c..944f87bf64 100644 --- a/docs/reference/ocm_add_resources.md +++ b/docs/reference/ocm_add_resources.md @@ -36,15 +36,15 @@ resources, resource, res, r --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request --bucket string bucket name - --classifier string mvn classifier + --classifier string maven classifier --commit string git commit id --digest string blob digest - --extension string mvn extension name + --extension string maven extension name --globalAccess YAML access specification for global access - --groupId string group id or namespace + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -60,11 +60,11 @@ resources, resource, res, r #### Input Specification Options ``` - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request - --classifier string mvn classifier - --extension string mvn extension name - --groupId string group id or namespace + --classifier string maven classifier + --extension string maven extension name + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -631,7 +631,7 @@ shown below. - **repoUrl** *string* - RepoUrl URL with or without scheme. + Repository URL with or without scheme. - **ref** (optional) *string* @@ -734,7 +734,7 @@ shown below. - Access type maven - This method implements the access of a Maven (mvn) artifact in a Maven repository. + This method implements the access of a Maven artifact in a Maven repository. The following versions are supported: - Version v1 @@ -743,27 +743,27 @@ shown below. - **repoUrl** *string* - Base URL of the Maven (mvn) repository + URL of the Maven repository - **groupId** *string* - The groupId of the Maven (mvn) artifact + The groupId of the Maven artifact - **artifactId** *string* - The artifactId of the Maven (mvn) artifact + The artifactId of the Maven artifact - **version** *string* - The version name of the Maven (mvn) artifact + The version name of the Maven artifact - **classifier** *string* - The optional classifier of the Maven (mvn) artifact + The optional classifier of the Maven artifact - **extension** *string* - The optional extension of the Maven (mvn) artifact + The optional extension of the Maven artifact Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId diff --git a/docs/reference/ocm_add_source-configuration.md b/docs/reference/ocm_add_source-configuration.md index 2002d73d88..7ebe3f1241 100644 --- a/docs/reference/ocm_add_source-configuration.md +++ b/docs/reference/ocm_add_source-configuration.md @@ -30,15 +30,15 @@ source-configuration, sourceconfig, srccfg, scfg --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request --bucket string bucket name - --classifier string mvn classifier + --classifier string maven classifier --commit string git commit id --digest string blob digest - --extension string mvn extension name + --extension string maven extension name --globalAccess YAML access specification for global access - --groupId string group id or namespace + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -54,11 +54,11 @@ source-configuration, sourceconfig, srccfg, scfg #### Input Specification Options ``` - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request - --classifier string mvn classifier - --extension string mvn extension name - --groupId string group id or namespace + --classifier string maven classifier + --extension string maven extension name + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -621,7 +621,7 @@ shown below. - **repoUrl** *string* - RepoUrl URL with or without scheme. + Repository URL with or without scheme. - **ref** (optional) *string* @@ -724,7 +724,7 @@ shown below. - Access type maven - This method implements the access of a Maven (mvn) artifact in a Maven repository. + This method implements the access of a Maven artifact in a Maven repository. The following versions are supported: - Version v1 @@ -733,27 +733,27 @@ shown below. - **repoUrl** *string* - Base URL of the Maven (mvn) repository + URL of the Maven repository - **groupId** *string* - The groupId of the Maven (mvn) artifact + The groupId of the Maven artifact - **artifactId** *string* - The artifactId of the Maven (mvn) artifact + The artifactId of the Maven artifact - **version** *string* - The version name of the Maven (mvn) artifact + The version name of the Maven artifact - **classifier** *string* - The optional classifier of the Maven (mvn) artifact + The optional classifier of the Maven artifact - **extension** *string* - The optional extension of the Maven (mvn) artifact + The optional extension of the Maven artifact Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId diff --git a/docs/reference/ocm_add_sources.md b/docs/reference/ocm_add_sources.md index c6d152b88f..d2120df821 100644 --- a/docs/reference/ocm_add_sources.md +++ b/docs/reference/ocm_add_sources.md @@ -35,15 +35,15 @@ sources, source, src, s --accessRepository string repository URL --accessType string type of blob access specification --accessVersion string version for access specification - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request --bucket string bucket name - --classifier string mvn classifier + --classifier string maven classifier --commit string git commit id --digest string blob digest - --extension string mvn extension name + --extension string maven extension name --globalAccess YAML access specification for global access - --groupId string group id or namespace + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --mediaType string media type for artifact blob representation @@ -59,11 +59,11 @@ sources, source, src, s #### Input Specification Options ``` - --artifactId string artifact id + --artifactId string maven artifact id --body string body of a http request - --classifier string mvn classifier - --extension string mvn extension name - --groupId string group id or namespace + --classifier string maven classifier + --extension string maven extension name + --groupId string maven group id --header :,,... http headers (default {}) --hint string (repository) hint for local artifacts --input YAML blob input specification (YAML) @@ -629,7 +629,7 @@ shown below. - **repoUrl** *string* - RepoUrl URL with or without scheme. + Repository URL with or without scheme. - **ref** (optional) *string* @@ -732,7 +732,7 @@ shown below. - Access type maven - This method implements the access of a Maven (mvn) artifact in a Maven repository. + This method implements the access of a Maven artifact in a Maven repository. The following versions are supported: - Version v1 @@ -741,27 +741,27 @@ shown below. - **repoUrl** *string* - Base URL of the Maven (mvn) repository + URL of the Maven repository - **groupId** *string* - The groupId of the Maven (mvn) artifact + The groupId of the Maven artifact - **artifactId** *string* - The artifactId of the Maven (mvn) artifact + The artifactId of the Maven artifact - **version** *string* - The version name of the Maven (mvn) artifact + The version name of the Maven artifact - **classifier** *string* - The optional classifier of the Maven (mvn) artifact + The optional classifier of the Maven artifact - **extension** *string* - The optional extension of the Maven (mvn) artifact + The optional extension of the Maven artifact Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId diff --git a/docs/reference/ocm_logging.md b/docs/reference/ocm_logging.md index 5c16d3652d..1f6b89b152 100644 --- a/docs/reference/ocm_logging.md +++ b/docs/reference/ocm_logging.md @@ -28,7 +28,7 @@ The following *realms* are used by the command line tool: - ocm/credentials/dockerconfig: docker config handling as credential repository - ocm/credentials/vault: HashiCorp Vault Access - ocm/downloader: Downloaders - - ocm/mvn: Maven repository + - ocm/maven: Maven repository - ocm/npm: NPM registry - ocm/oci/mapping: OCM to OCI Registry Mapping - ocm/oci/ocireg: OCI repository handling diff --git a/docs/reference/ocm_ocm-accessmethods.md b/docs/reference/ocm_ocm-accessmethods.md index 7242264576..8ae09db829 100644 --- a/docs/reference/ocm_ocm-accessmethods.md +++ b/docs/reference/ocm_ocm-accessmethods.md @@ -82,7 +82,7 @@ shown below. - **repoUrl** *string* - RepoUrl URL with or without scheme. + Repository URL with or without scheme. - **ref** (optional) *string* @@ -185,7 +185,7 @@ shown below. - Access type maven - This method implements the access of a Maven (mvn) artifact in a Maven repository. + This method implements the access of a Maven artifact in a Maven repository. The following versions are supported: - Version v1 @@ -194,27 +194,27 @@ shown below. - **repoUrl** *string* - Base URL of the Maven (mvn) repository + URL of the Maven repository - **groupId** *string* - The groupId of the Maven (mvn) artifact + The groupId of the Maven artifact - **artifactId** *string* - The artifactId of the Maven (mvn) artifact + The artifactId of the Maven artifact - **version** *string* - The version name of the Maven (mvn) artifact + The version name of the Maven artifact - **classifier** *string* - The optional classifier of the Maven (mvn) artifact + The optional classifier of the Maven artifact - **extension** *string* - The optional extension of the Maven (mvn) artifact + The optional extension of the Maven artifact Options used to configure fields: --accessRepository, --accessVersion, --artifactId, --classifier, --extension, --groupId diff --git a/docs/reference/ocm_ocm-uploadhandlers.md b/docs/reference/ocm_ocm-uploadhandlers.md index aacbd0744f..5c6ac57448 100644 --- a/docs/reference/ocm_ocm-uploadhandlers.md +++ b/docs/reference/ocm_ocm-uploadhandlers.md @@ -73,14 +73,14 @@ The following handler names are possible: sub namespace of the form <plugin name>/<handler> - - ocm/mavenArtifact: uploading mvn artifacts + - ocm/mavenArtifact: uploading maven artifacts - The ocm/mavenArtifact uploader is able to upload mvn artifacts (whole GAV only!) - as artifact archive according to the mvn artifact spec. + The ocm/mavenArtifact uploader is able to upload maven artifacts (whole GAV only!) + as artifact archive according to the maven artifact spec. If registered the default mime type is: application/x-tgz It accepts a plain string for the URL or a config with the following field: - 'url': the URL of the mvn repository. + 'url': the URL of the maven repository. diff --git a/docs/reference/ocm_transfer_commontransportarchive.md b/docs/reference/ocm_transfer_commontransportarchive.md index 2bc7d29c0a..eaa4b1f1fb 100644 --- a/docs/reference/ocm_transfer_commontransportarchive.md +++ b/docs/reference/ocm_transfer_commontransportarchive.md @@ -147,14 +147,14 @@ The uploader name may be a path expression with the following possibilities: sub namespace of the form <plugin name>/<handler> - - ocm/mavenArtifact: uploading mvn artifacts + - ocm/mavenArtifact: uploading maven artifacts - The ocm/mavenArtifact uploader is able to upload mvn artifacts (whole GAV only!) - as artifact archive according to the mvn artifact spec. + The ocm/mavenArtifact uploader is able to upload maven artifacts (whole GAV only!) + as artifact archive according to the maven artifact spec. If registered the default mime type is: application/x-tgz It accepts a plain string for the URL or a config with the following field: - 'url': the URL of the mvn repository. + 'url': the URL of the maven repository. diff --git a/docs/reference/ocm_transfer_componentversions.md b/docs/reference/ocm_transfer_componentversions.md index 0f56569bae..b58c17b15f 100644 --- a/docs/reference/ocm_transfer_componentversions.md +++ b/docs/reference/ocm_transfer_componentversions.md @@ -204,14 +204,14 @@ The uploader name may be a path expression with the following possibilities: sub namespace of the form <plugin name>/<handler> - - ocm/mavenArtifact: uploading mvn artifacts + - ocm/mavenArtifact: uploading maven artifacts - The ocm/mavenArtifact uploader is able to upload mvn artifacts (whole GAV only!) - as artifact archive according to the mvn artifact spec. + The ocm/mavenArtifact uploader is able to upload maven artifacts (whole GAV only!) + as artifact archive according to the maven artifact spec. If registered the default mime type is: application/x-tgz It accepts a plain string for the URL or a config with the following field: - 'url': the URL of the mvn repository. + 'url': the URL of the maven repository. diff --git a/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go b/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go index ae7cccff72..a2263cdc9c 100644 --- a/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go +++ b/pkg/contexts/ocm/compdesc/versions/ocm.software/v3alpha1/jsonscheme/bindata.go @@ -1,6 +1,6 @@ // Code generated by go-bindata. (@generated) DO NOT EDIT. -// Package jsonscheme generated by go-bindata.// sources: +//Package jsonscheme generated by go-bindata.// sources: // ../../../../../../../../resources/component-descriptor-ocm-v3-schema.yaml package jsonscheme diff --git a/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go b/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go index fa64fd8342..7b2dd6aa3f 100644 --- a/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go +++ b/pkg/contexts/ocm/compdesc/versions/v2/jsonscheme/bindata.go @@ -1,6 +1,6 @@ // Code generated by go-bindata. (@generated) DO NOT EDIT. -// Package jsonscheme generated by go-bindata.// sources: +//Package jsonscheme generated by go-bindata.// sources: // ../../../../../../../resources/component-descriptor-v2-schema.yaml package jsonscheme From 6cec30367b654786379cd67c230831fe9eca7333 Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Tue, 28 May 2024 19:11:57 +0200 Subject: [PATCH 12/13] reuse maven testdata --- .../common/inputs/types/maven/input_test.go | 7 +- .../types/maven/testdata/resources1.yaml | 2 +- pkg/blobaccess/maven/access_test.go | 4 +- .../sdk-modules-bom-5.7.0-random-content.json | 1 - ...modules-bom-5.7.0-random-content.json.sha1 | 1 - .../sdk-modules-bom-5.7.0-random-content.txt | 1 - ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 595 -> 0 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 595 -> 0 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ------------------ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 - .../ocm/accessmethods/maven/method_test.go | 15 +- .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ------------------ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 - .../fail/test/repository/42/repository-42.pom | 14 -- .../test/repository/42/repository-42.pom.sha1 | 1 - .../generic/maven/blobhandler_test.go | 4 +- .../sdk-modules-bom-5.7.0-random-content.json | 1 - ...modules-bom-5.7.0-random-content.json.sha1 | 1 - .../sdk-modules-bom-5.7.0-random-content.txt | 1 - ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 595 -> 0 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 595 -> 0 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ------------------ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 - pkg/contexts/ocm/cpi/builder.go | 50 +++++ pkg/contexts/ocm/cpi/interface.go | 4 - .../artifactblob/mavenblob/access_test.go | 4 +- .../fail/test/repository/42/repository-42.pom | 14 -- .../test/repository/42/repository-42.pom.sha1 | 1 - .../sdk-modules-bom-5.7.0-random-content.json | 1 - ...modules-bom-5.7.0-random-content.json.sha1 | 1 - .../sdk-modules-bom-5.7.0-random-content.txt | 1 - ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 595 -> 0 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 595 -> 0 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ------------------ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 - pkg/env/env.go | 96 ++++++-- pkg/maven/access_test.go | 4 +- pkg/maven/maventest/testdata.go | 13 ++ .../fail/test/repository/42/repository-42.pom | 0 .../test/repository/42/repository-42.pom.sha1 | 0 .../sdk-modules-bom-5.7.0-random-content.json | 0 ...modules-bom-5.7.0-random-content.json.sha1 | 0 .../sdk-modules-bom-5.7.0-random-content.txt | 0 ...-modules-bom-5.7.0-random-content.txt.sha1 | 0 .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 0 .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 0 .../5.7.0/sdk-modules-bom-5.7.0.pom | 0 .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 0 pkg/maven/mypackage/main.go | 15 ++ pkg/maven/mypackage/mysubpackage/somefile.go | 36 +++ .../fail/test/repository/42/repository-42.pom | 14 -- .../test/repository/42/repository-42.pom.sha1 | 1 - .../sdk-modules-bom-5.7.0-random-content.json | 1 - ...modules-bom-5.7.0-random-content.json.sha1 | 1 - .../sdk-modules-bom-5.7.0-random-content.txt | 1 - ...-modules-bom-5.7.0-random-content.txt.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0-sources.jar | Bin 595 -> 0 bytes .../sdk-modules-bom-5.7.0-sources.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.jar | Bin 595 -> 0 bytes .../5.7.0/sdk-modules-bom-5.7.0.jar.sha1 | 1 - .../5.7.0/sdk-modules-bom-5.7.0.pom | 210 ------------------ .../5.7.0/sdk-modules-bom-5.7.0.pom.sha1 | 1 - pkg/utils/package.go | 44 ++++ 74 files changed, 256 insertions(+), 1166 deletions(-) delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom delete mode 100644 pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 delete mode 100644 pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom delete mode 100644 pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 delete mode 100644 pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom delete mode 100644 pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom.sha1 delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom delete mode 100644 pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 create mode 100644 pkg/contexts/ocm/cpi/builder.go delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom delete mode 100644 pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 create mode 100644 pkg/maven/maventest/testdata.go rename pkg/{blobaccess/maven => maven/maventest}/testdata/.m2/fail/test/repository/42/repository-42.pom (100%) rename pkg/{blobaccess/maven => maven/maventest}/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom (100%) rename {cmds/ocm/commands/ocmcmds/common/inputs/types/maven => pkg/maven/maventest}/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 (100%) create mode 100644 pkg/maven/mypackage/main.go create mode 100644 pkg/maven/mypackage/mysubpackage/somefile.go delete mode 100644 pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom delete mode 100644 pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom delete mode 100644 pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 create mode 100644 pkg/utils/package.go diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go index 5b2ad27621..7731e45ac5 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/input_test.go @@ -2,6 +2,7 @@ package maven_test import ( "crypto" + "github.com/open-component-model/ocm/pkg/maven/maventest" . "github.com/mandelsoft/goutils/testutils" . "github.com/onsi/ginkgo/v2" @@ -24,7 +25,7 @@ var _ = Describe("Test Environment", func() { var env *TestEnv BeforeEach(func() { - env = NewTestEnv(TestData()) + env = NewTestEnv(TestData(), maventest.TestData("/maven/testdata")) Expect(env.Execute("create", "ca", "-ft", "directory", "test.de/x", VERSION, "--provider", "mandelsoft", "--file", ARCH)).To(Succeed()) }) @@ -61,7 +62,7 @@ name: testdata type: mavenArtifact ` Expect(env.Execute("add", "resources", "--file", ARCH, "--resource", meta, "--inputType", "maven", - "--inputPath", "testdata/.m2/repository", "--groupId", "com.sap.cloud.sdk", "--artifactId", "sdk-modules-bom", + "--inputPath", "/maven/testdata/.m2/repository", "--groupId", "com.sap.cloud.sdk", "--artifactId", "sdk-modules-bom", "--inputVersion", "5.7.0", "--classifier", "", "--extension", "pom")).To(Succeed()) data, err := env.ReadFile(env.Join(ARCH, comparch.ComponentDescriptorFileName)) Expect(err).To(Succeed()) @@ -80,7 +81,7 @@ name: testdata type: mavenArtifact ` Expect(env.Execute("add", "resources", "--file", ARCH, "--resource", meta, "--inputType", "maven", - "--inputPath", "testdata/.m2/repository", "--groupId", "com.sap.cloud.sdk", "--artifactId", "sdk-modules-bom", + "--inputPath", "/maven/testdata/.m2/repository", "--groupId", "com.sap.cloud.sdk", "--artifactId", "sdk-modules-bom", "--inputVersion", "5.7.0", "--extension", "pom")).To(Succeed()) data, err := env.ReadFile(env.Join(ARCH, comparch.ComponentDescriptorFileName)) Expect(err).To(Succeed()) diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml index 952a1ecb7a..161a29b424 100644 --- a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml +++ b/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/resources1.yaml @@ -2,7 +2,7 @@ name: myblob type: mavenArtifact input: type: maven - path: .m2/repository + path: ../maven/testdata/.m2/repository groupId: com.sap.cloud.sdk artifactId: sdk-modules-bom version: 5.7.0 \ No newline at end of file diff --git a/pkg/blobaccess/maven/access_test.go b/pkg/blobaccess/maven/access_test.go index 0e0b00953a..e2e10c96df 100644 --- a/pkg/blobaccess/maven/access_test.go +++ b/pkg/blobaccess/maven/access_test.go @@ -1,11 +1,11 @@ package maven_test import ( + "github.com/open-component-model/ocm/pkg/maven/maventest" "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" . "github.com/open-component-model/ocm/pkg/testutils" @@ -31,7 +31,7 @@ var _ = Describe("blobaccess for maven", func() { var repo *maven.Repository BeforeEach(func() { - env = NewBuilder(TestData()) + env = NewBuilder(maventest.TestData()) repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json deleted file mode 100644 index 2f1fc35fdc..0000000000 --- a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json +++ /dev/null @@ -1 +0,0 @@ -{"some": "test content"} \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 deleted file mode 100644 index d6836aeaa0..0000000000 --- a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 +++ /dev/null @@ -1 +0,0 @@ -f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt deleted file mode 100644 index b4af84697f..0000000000 --- a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt +++ /dev/null @@ -1 +0,0 @@ -some test content \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 deleted file mode 100644 index 55eceeb992..0000000000 --- a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 +++ /dev/null @@ -1 +0,0 @@ -dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar deleted file mode 100644 index 8564f0addae8de5525417df8294d13c0c2a3a7c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo - - 4.0.0 - com.sap.cloud.sdk - sdk-modules-bom - 5.7.0 - pom - SAP Cloud SDK - Modules BOM - Bill of Materials (BOM) of the SAP Cloud SDK modules. - https://sap.github.io/cloud-sdk/docs/java/getting-started - - SAP SE - https://www.sap.com - - - - The Apache Software License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - SAP - cloudsdk@sap.com - SAP SE - https://www.sap.com - - - - - - - - UTF-8 - Public - Stable - - 5.7.0 - - - - - com.sap.cloud.sdk - sdk-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - dwc-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - caching - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient4 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient5 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity-scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-destination-service - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-oauth - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-dwc - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-ztis - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience-api - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience4j - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - security - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - servlet-jakarta - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - tenant - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-core - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - rfc - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - datamodel-metadata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator-utility - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-client - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - fluent-result - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - - soap - ${sdk.version} - - - - diff --git a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 deleted file mode 100644 index 35f63a2e1f..0000000000 --- a/pkg/blobaccess/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/contexts/ocm/accessmethods/maven/method_test.go b/pkg/contexts/ocm/accessmethods/maven/method_test.go index 37e9dfa2c8..20310c92d0 100644 --- a/pkg/contexts/ocm/accessmethods/maven/method_test.go +++ b/pkg/contexts/ocm/accessmethods/maven/method_test.go @@ -2,11 +2,11 @@ package maven_test import ( "crypto" + "github.com/open-component-model/ocm/pkg/maven/maventest" "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" . "github.com/open-component-model/ocm/pkg/testutils" @@ -20,7 +20,7 @@ import ( const ( MAVEN_PATH = "/testdata/.m2/repository" - FAILPATH = "/testdata/fail" + FAILPATH = "/testdata/.m2/fail" MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" MAVEN_CENTRAL_ADDRESS = "repo.maven.apache.org:443" MAVEN_GROUP_ID = "maven" @@ -33,7 +33,7 @@ var _ = Describe("local accessmethods.maven.AccessSpec tests", func() { var cv ocm.ComponentVersionAccess BeforeEach(func() { - env = NewBuilder(TestData()) + env = NewBuilder(maventest.TestData()) cv = &cpi.DummyComponentVersionAccess{env.OCMContext()} }) @@ -56,8 +56,8 @@ var _ = Describe("local accessmethods.maven.AccessSpec tests", func() { break } } - Expect(dr.Size()).To(Equal(int64(1109))) - Expect(dr.Digest().String()).To(Equal("SHA-1:4ee125ffe4f7690588833f1217a13cc741e4df5f")) + Expect(dr.Size()).To(Equal(int64(1570))) + Expect(dr.Digest().String()).To(Equal("SHA-1:359d02795bcc737e81c7f2f0ac32f49351d41867")) }) It("accesses local artifact with empty classifier and with extension", func() { @@ -90,14 +90,15 @@ var _ = Describe("local accessmethods.maven.AccessSpec tests", func() { defer Close(r) dr := iotools.NewDigestReaderWithHash(crypto.SHA1, r) list := Must(tarutils.ListArchiveContentFromReader(dr)) - Expect(list).To(HaveLen(1)) + Expect(list).To(ConsistOf("sdk-modules-bom-5.7.0.pom")) + Expect(dr.Size()).To(Equal(int64(1109))) Expect(dr.Digest().String()).To(Equal("SHA-1:4ee125ffe4f7690588833f1217a13cc741e4df5f")) }) It("Describe", func() { acc := me.New("file://"+FAILPATH, "test", "repository", "42", me.WithExtension("pom")) - Expect(acc.Describe(nil)).To(Equal("Maven package 'test:repository:42::pom' in repository 'file:///testdata/fail' path 'test/repository/42/repository-42.pom'")) + Expect(acc.Describe(nil)).To(Equal("Maven package 'test:repository:42::pom' in repository 'file:///testdata/.m2/fail' path 'test/repository/42/repository-42.pom'")) }) It("detects digests mismatch", func() { diff --git a/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom b/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom deleted file mode 100644 index b3baaee32f..0000000000 --- a/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom +++ /dev/null @@ -1,210 +0,0 @@ - - - 4.0.0 - com.sap.cloud.sdk - sdk-modules-bom - 5.7.0 - pom - SAP Cloud SDK - Modules BOM - Bill of Materials (BOM) of the SAP Cloud SDK modules. - https://sap.github.io/cloud-sdk/docs/java/getting-started - - SAP SE - https://www.sap.com - - - - The Apache Software License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - SAP - cloudsdk@sap.com - SAP SE - https://www.sap.com - - - - - - - - UTF-8 - Public - Stable - - 5.7.0 - - - - - com.sap.cloud.sdk - sdk-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - dwc-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - caching - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient4 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient5 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity-scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-destination-service - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-oauth - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-dwc - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-ztis - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience-api - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience4j - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - security - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - servlet-jakarta - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - tenant - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-core - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - rfc - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - datamodel-metadata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator-utility - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-client - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - fluent-result - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - - soap - ${sdk.version} - - - - diff --git a/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 deleted file mode 100644 index 35f63a2e1f..0000000000 --- a/pkg/contexts/ocm/accessmethods/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom b/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom deleted file mode 100644 index 218894d775..0000000000 --- a/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom +++ /dev/null @@ -1,14 +0,0 @@ - - - 4.0.0 - fail - repository - 42 - pom - ocm - test - - SAP SE - https://www.sap.com - - diff --git a/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom.sha1 b/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom.sha1 deleted file mode 100644 index 3d6c52fe9e..0000000000 --- a/pkg/contexts/ocm/accessmethods/maven/testdata/fail/test/repository/42/repository-42.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -44a77645201d1a8fc5213ace787c220eabbd0967 \ No newline at end of file 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 abe3f48a2f..76532ed6bf 100644 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go +++ b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/blobhandler_test.go @@ -2,11 +2,11 @@ package maven_test import ( "encoding/json" + "github.com/open-component-model/ocm/pkg/maven/maventest" "os" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" . "github.com/open-component-model/ocm/pkg/testutils" @@ -28,7 +28,7 @@ var _ = Describe("blobhandler generic maven tests", func() { var repo *maven.Repository BeforeEach(func() { - env = NewBuilder(TestData()) + env = NewBuilder(maventest.TestData()) repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json deleted file mode 100644 index 2f1fc35fdc..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json +++ /dev/null @@ -1 +0,0 @@ -{"some": "test content"} \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 deleted file mode 100644 index d6836aeaa0..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 +++ /dev/null @@ -1 +0,0 @@ -f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt deleted file mode 100644 index b4af84697f..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt +++ /dev/null @@ -1 +0,0 @@ -some test content \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 deleted file mode 100644 index 55eceeb992..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 +++ /dev/null @@ -1 +0,0 @@ -dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar deleted file mode 100644 index 8564f0addae8de5525417df8294d13c0c2a3a7c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo - - 4.0.0 - com.sap.cloud.sdk - sdk-modules-bom - 5.7.0 - pom - SAP Cloud SDK - Modules BOM - Bill of Materials (BOM) of the SAP Cloud SDK modules. - https://sap.github.io/cloud-sdk/docs/java/getting-started - - SAP SE - https://www.sap.com - - - - The Apache Software License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - SAP - cloudsdk@sap.com - SAP SE - https://www.sap.com - - - - - - - - UTF-8 - Public - Stable - - 5.7.0 - - - - - com.sap.cloud.sdk - sdk-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - dwc-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - caching - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient4 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient5 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity-scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-destination-service - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-oauth - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-dwc - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-ztis - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience-api - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience4j - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - security - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - servlet-jakarta - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - tenant - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-core - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - rfc - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - datamodel-metadata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator-utility - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-client - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - fluent-result - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - - soap - ${sdk.version} - - - - diff --git a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 deleted file mode 100644 index 35f63a2e1f..0000000000 --- a/pkg/contexts/ocm/blobhandler/handlers/generic/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/contexts/ocm/cpi/builder.go b/pkg/contexts/ocm/cpi/builder.go new file mode 100644 index 0000000000..ea045d4983 --- /dev/null +++ b/pkg/contexts/ocm/cpi/builder.go @@ -0,0 +1,50 @@ +package cpi + +import ( + "context" + + "github.com/open-component-model/ocm/pkg/contexts/credentials" + "github.com/open-component-model/ocm/pkg/contexts/datacontext" + "github.com/open-component-model/ocm/pkg/contexts/oci" + "github.com/open-component-model/ocm/pkg/contexts/ocm/internal" +) + +func WithContext(ctx context.Context) internal.Builder { + return internal.Builder{}.WithContext(ctx) +} + +func WithCredentials(ctx credentials.Context) internal.Builder { + return internal.Builder{}.WithCredentials(ctx) +} + +func WithOCIRepositories(ctx oci.Context) internal.Builder { + return internal.Builder{}.WithOCIRepositories(ctx) +} + +func WithRepositoyTypeScheme(scheme RepositoryTypeScheme) internal.Builder { + return internal.Builder{}.WithRepositoyTypeScheme(scheme) +} + +func WithRepositoryDelegation(reg RepositoryDelegationRegistry) internal.Builder { + return internal.Builder{}.WithRepositoryDelegation(reg) +} + +func WithAccessypeScheme(scheme AccessTypeScheme) internal.Builder { + return internal.Builder{}.WithAccessTypeScheme(scheme) +} + +func WithRepositorySpecHandlers(reg RepositorySpecHandlers) internal.Builder { + return internal.Builder{}.WithRepositorySpecHandlers(reg) +} + +func WithBlobHandlers(reg BlobHandlerRegistry) internal.Builder { + return internal.Builder{}.WithBlobHandlers(reg) +} + +func WithBlobDigesters(reg BlobDigesterRegistry) internal.Builder { + return internal.Builder{}.WithBlobDigesters(reg) +} + +func New(mode ...datacontext.BuilderMode) Context { + return internal.Builder{}.New(mode...) +} diff --git a/pkg/contexts/ocm/cpi/interface.go b/pkg/contexts/ocm/cpi/interface.go index 1e62109d1b..8b605836ea 100644 --- a/pkg/contexts/ocm/cpi/interface.go +++ b/pkg/contexts/ocm/cpi/interface.go @@ -110,10 +110,6 @@ func DefaultBlobHandlerProvider(ctx Context) BlobHandlerProvider { return internal.DefaultBlobHandlerProvider(ctx) } -func New() Context { - return internal.Builder{}.New() -} - func NewResourceMeta(name string, typ string, relation metav1.ResourceRelation) *ResourceMeta { return compdesc.NewResourceMeta(name, typ, relation) } diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go index 9155610440..8bf2b4fdd9 100644 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go +++ b/pkg/contexts/ocm/elements/artifactblob/mavenblob/access_test.go @@ -3,8 +3,8 @@ package mavenblob_test import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" + "github.com/open-component-model/ocm/pkg/maven/maventest" . "github.com/open-component-model/ocm/pkg/testutils" "github.com/open-component-model/ocm/pkg/contexts/ocm/elements" @@ -31,7 +31,7 @@ var _ = Describe("blobaccess for maven", func() { var repo *maven.Repository BeforeEach(func() { - env = NewBuilder(TestData()) + env = NewBuilder(maventest.TestData()) repo = maven.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom deleted file mode 100644 index 218894d775..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom +++ /dev/null @@ -1,14 +0,0 @@ - - - 4.0.0 - fail - repository - 42 - pom - ocm - test - - SAP SE - https://www.sap.com - - diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 deleted file mode 100644 index 3d6c52fe9e..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -44a77645201d1a8fc5213ace787c220eabbd0967 \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json deleted file mode 100644 index 2f1fc35fdc..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json +++ /dev/null @@ -1 +0,0 @@ -{"some": "test content"} \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 deleted file mode 100644 index d6836aeaa0..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 +++ /dev/null @@ -1 +0,0 @@ -f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt deleted file mode 100644 index b4af84697f..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt +++ /dev/null @@ -1 +0,0 @@ -some test content \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 deleted file mode 100644 index 55eceeb992..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 +++ /dev/null @@ -1 +0,0 @@ -dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar deleted file mode 100644 index 8564f0addae8de5525417df8294d13c0c2a3a7c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo - - 4.0.0 - com.sap.cloud.sdk - sdk-modules-bom - 5.7.0 - pom - SAP Cloud SDK - Modules BOM - Bill of Materials (BOM) of the SAP Cloud SDK modules. - https://sap.github.io/cloud-sdk/docs/java/getting-started - - SAP SE - https://www.sap.com - - - - The Apache Software License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - SAP - cloudsdk@sap.com - SAP SE - https://www.sap.com - - - - - - - - UTF-8 - Public - Stable - - 5.7.0 - - - - - com.sap.cloud.sdk - sdk-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - dwc-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - caching - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient4 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient5 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity-scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-destination-service - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-oauth - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-dwc - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-ztis - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience-api - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience4j - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - security - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - servlet-jakarta - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - tenant - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-core - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - rfc - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - datamodel-metadata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator-utility - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-client - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - fluent-result - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - - soap - ${sdk.version} - - - - diff --git a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 deleted file mode 100644 index 35f63a2e1f..0000000000 --- a/pkg/contexts/ocm/elements/artifactblob/mavenblob/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/env/env.go b/pkg/env/env.go index ffbabb5de9..e9ed777518 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -3,6 +3,9 @@ package env import ( "bytes" "fmt" + "github.com/mandelsoft/filepath/pkg/filepath" + "github.com/mandelsoft/goutils/general" + "runtime" "runtime/debug" "strings" @@ -21,7 +24,7 @@ import ( "github.com/open-component-model/ocm/pkg/contexts/credentials" "github.com/open-component-model/ocm/pkg/contexts/datacontext/attrs/vfsattr" "github.com/open-component-model/ocm/pkg/contexts/oci" - "github.com/open-component-model/ocm/pkg/contexts/ocm" + ocm "github.com/open-component-model/ocm/pkg/contexts/ocm/cpi" "github.com/open-component-model/ocm/pkg/utils" ) @@ -199,7 +202,7 @@ type tdOpt struct { modifiable bool } -func TestData(paths ...string) tdOpt { +func testData(modifiable bool, paths ...string) tdOpt { path := "/testdata" source := "testdata" @@ -214,30 +217,85 @@ func TestData(paths ...string) tdOpt { panic("invalid number of arguments") } return tdOpt{ - path: path, - source: source, + path: path, + source: source, + modifiable: modifiable, } } +func TestData(paths ...string) tdOpt { + return testData(false, paths...) +} + func ModifiableTestData(paths ...string) tdOpt { - path := "/testdata" - source := "testdata" + return testData(true, paths...) +} + +func projectTestData(modifiable bool, source string, dest ...string) Option { + path := "." + for count := 0; count < 20; count++ { + if ok, err := vfs.FileExists(osfs.OsFs, filepath.Join(path, "go.mod")); err != nil || ok { + if err != nil { + panic(err) + } + path = filepath.Join(path, source) + break + } + if count == 19 { + panic("could not find go.mod (within 20 steps)") + } - switch len(paths) { - case 0: - case 1: - source = paths[0] - case 2: - source = paths[0] - path = paths[1] - default: - panic("invalid number of arguments") + path = filepath.Join(path, "..") } - return tdOpt{ - path: path, - source: source, - modifiable: true, + + return testData(modifiable, path, general.OptionalDefaulted("/testdata", dest...)) +} + +func ProjectTestData(source string, dest ...string) Option { + return projectTestData(false, source, dest...) +} + +func ModifiableProjectTestData(source string, dest ...string) Option { + return projectTestData(true, source, dest...) +} + +func projectTestDataForCaller(modifiable bool, dest ...string) Option { + pc, _, _, ok := runtime.Caller(2) + if !ok { + panic("unable to find caller") + } + + // Get the function details from the program counter + caller := runtime.FuncForPC(pc) + if caller == nil { + panic("unable to find caller") } + + fullFuncName := caller.Name() + + // Split the name to extract the package path + // Assuming the format: "package/path.functionName" + lastSlashIndex := strings.LastIndex(fullFuncName, "/") + if lastSlashIndex == -1 { + panic("unable to find package name") + } + + funcIndex := strings.Index(fullFuncName[lastSlashIndex:], ".") + packagePath := fullFuncName[:lastSlashIndex+funcIndex] + path, ok := strings.CutPrefix(packagePath, "github.com/open-component-model/ocm/") + if !ok { + panic("unable to find package name") + } + + return projectTestData(modifiable, filepath.Join(path, "testdata"), dest...) +} + +func ProjectTestDataForCaller(dest ...string) Option { + return projectTestDataForCaller(false, dest...) +} + +func ModifiableProjectTestDataForCaller(dest ...string) Option { + return projectTestDataForCaller(true, dest...) } func (o tdOpt) OptionHandler() OptionHandler { diff --git a/pkg/maven/access_test.go b/pkg/maven/access_test.go index f4b6031069..4696286597 100644 --- a/pkg/maven/access_test.go +++ b/pkg/maven/access_test.go @@ -6,13 +6,13 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - . "github.com/open-component-model/ocm/pkg/env" . "github.com/open-component-model/ocm/pkg/env/builder" . "github.com/open-component-model/ocm/pkg/testutils" "github.com/mandelsoft/goutils/optionutils" me "github.com/open-component-model/ocm/pkg/maven" + "github.com/open-component-model/ocm/pkg/maven/maventest" ) const ( @@ -25,7 +25,7 @@ var _ = Describe("local accessmethods.me.AccessSpec tests", func() { var repo *me.Repository BeforeEach(func() { - env = NewBuilder(TestData()) + env = NewBuilder(maventest.TestData()) repo = me.NewFileRepository(MAVEN_PATH, env.FileSystem()) }) diff --git a/pkg/maven/maventest/testdata.go b/pkg/maven/maventest/testdata.go new file mode 100644 index 0000000000..1cfe4d8c22 --- /dev/null +++ b/pkg/maven/maventest/testdata.go @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package maventest + +import ( + "github.com/open-component-model/ocm/pkg/env" +) + +func TestData(dest ...string) env.Option { + return env.ProjectTestDataForCaller(dest...) +} diff --git a/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom b/pkg/maven/maventest/testdata/.m2/fail/test/repository/42/repository-42.pom similarity index 100% rename from pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom rename to pkg/maven/maventest/testdata/.m2/fail/test/repository/42/repository-42.pom diff --git a/pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 b/pkg/maven/maventest/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 similarity index 100% rename from pkg/blobaccess/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 rename to pkg/maven/maventest/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar.sha1 diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.jar.sha1 diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom diff --git a/cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 similarity index 100% rename from cmds/ocm/commands/ocmcmds/common/inputs/types/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 rename to pkg/maven/maventest/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 diff --git a/pkg/maven/mypackage/main.go b/pkg/maven/mypackage/main.go new file mode 100644 index 0000000000..958d3239dd --- /dev/null +++ b/pkg/maven/mypackage/main.go @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "fmt" + "github.com/open-component-model/ocm/pkg/maven/mypackage/mysubpackage" +) + +func main() { + packageName := mysubpackage.GetPackageName(mysubpackage.SampleFunction) + fmt.Println("Package name:", packageName) +} diff --git a/pkg/maven/mypackage/mysubpackage/somefile.go b/pkg/maven/mypackage/mysubpackage/somefile.go new file mode 100644 index 0000000000..86ebeeb422 --- /dev/null +++ b/pkg/maven/mypackage/mysubpackage/somefile.go @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package mysubpackage + +import ( + "reflect" + "runtime" + "strings" +) + +// Sample function to analyze +func SampleFunction() {} + +func GetPackageName(i interface{}) string { + // Get the function's pointer + ptr := reflect.ValueOf(i).Pointer() + // Retrieve the function's runtime information + funcForPC := runtime.FuncForPC(ptr) + if funcForPC == nil { + return "unknown" + } + // Get the full name of the function, including the package path + fullFuncName := funcForPC.Name() + + // Split the name to extract the package path + // Assuming the format: "package/path.functionName" + lastSlashIndex := strings.LastIndex(fullFuncName, "/") + if lastSlashIndex == -1 { + return "unknown" + } + + packagePath := fullFuncName[:lastSlashIndex] + return packagePath +} diff --git a/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom b/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom deleted file mode 100644 index 218894d775..0000000000 --- a/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom +++ /dev/null @@ -1,14 +0,0 @@ - - - 4.0.0 - fail - repository - 42 - pom - ocm - test - - SAP SE - https://www.sap.com - - diff --git a/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 b/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 deleted file mode 100644 index 3d6c52fe9e..0000000000 --- a/pkg/maven/testdata/.m2/fail/test/repository/42/repository-42.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -44a77645201d1a8fc5213ace787c220eabbd0967 \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json deleted file mode 100644 index 2f1fc35fdc..0000000000 --- a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json +++ /dev/null @@ -1 +0,0 @@ -{"some": "test content"} \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 deleted file mode 100644 index d6836aeaa0..0000000000 --- a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.json.sha1 +++ /dev/null @@ -1 +0,0 @@ -f0763ff4add043560aa3827cea06bf9335b87f73 \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt deleted file mode 100644 index b4af84697f..0000000000 --- a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt +++ /dev/null @@ -1 +0,0 @@ -some test content \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 deleted file mode 100644 index 55eceeb992..0000000000 --- a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-random-content.txt.sha1 +++ /dev/null @@ -1 +0,0 @@ -dbabd43828eccd27e3a109b58454e4ff43c8673e \ No newline at end of file diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0-sources.jar deleted file mode 100644 index 8564f0addae8de5525417df8294d13c0c2a3a7c0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 595 zcmWIWW@h1HVBlb2I6ZY+1OpP_WME~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo~0p0C?y-!rFuymj?1@_OrPojY@WbCAIm;|EWR^t^m^Jbf>guG$i0z|{3Z zQZu9C$@67uqD!Y`e=7P|#0a#Cor7naNwg)65ZVVl++yk z{N!Byg6wqtq@4Vu#N_1E;$r>W#In>p{gTw;l9a@fME%s^D&0A%HfJ3D=4gl*pE23j>4+%YaO}g$OGf$YN$76k=px&<0`# F1^|3_lo - - 4.0.0 - com.sap.cloud.sdk - sdk-modules-bom - 5.7.0 - pom - SAP Cloud SDK - Modules BOM - Bill of Materials (BOM) of the SAP Cloud SDK modules. - https://sap.github.io/cloud-sdk/docs/java/getting-started - - SAP SE - https://www.sap.com - - - - The Apache Software License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - SAP - cloudsdk@sap.com - SAP SE - https://www.sap.com - - - - - - - - UTF-8 - Public - Stable - - 5.7.0 - - - - - com.sap.cloud.sdk - sdk-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - dwc-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-core - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - caching - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient4 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-apache-httpclient5 - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - cloudplatform-connectivity-scp-cf - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-destination-service - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-oauth - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-dwc - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - connectivity-ztis - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience-api - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - resilience4j - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - security - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - servlet-jakarta - ${sdk.version} - - - com.sap.cloud.sdk.cloudplatform - tenant - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-core - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - s4hana-connectivity - ${sdk.version} - - - com.sap.cloud.sdk.s4hana - rfc - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - datamodel-metadata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator-utility - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-client - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - odata-v4-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-core - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - openapi-generator - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - fluent-result - ${sdk.version} - - - com.sap.cloud.sdk.datamodel - - soap - ${sdk.version} - - - - diff --git a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 b/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 deleted file mode 100644 index 35f63a2e1f..0000000000 --- a/pkg/maven/testdata/.m2/repository/com/sap/cloud/sdk/sdk-modules-bom/5.7.0/sdk-modules-bom-5.7.0.pom.sha1 +++ /dev/null @@ -1 +0,0 @@ -34ccdeb9c008f8aaef90873fc636b09d3ae5c709 \ No newline at end of file diff --git a/pkg/utils/package.go b/pkg/utils/package.go new file mode 100644 index 0000000000..932a765982 --- /dev/null +++ b/pkg/utils/package.go @@ -0,0 +1,44 @@ +package utils + +import ( + "fmt" + "reflect" + "runtime" + "strings" +) + +const MODULE_PATH = "github.com/open-component-model/ocm" + +func GetPackageNameForFunc(i interface{}) (string, error) { + // Get the function's pointer + ptr := reflect.ValueOf(i).Pointer() + // Retrieve the function's runtime information + funcForPC := runtime.FuncForPC(ptr) + if funcForPC == nil { + return "", fmt.Errorf("could not determine package name") + } + // Get the full name of the function, including the package path + fullFuncName := funcForPC.Name() + + // Split the name to extract the package path + // Assuming the format: "package/path.functionName" + lastSlashIndex := strings.LastIndex(fullFuncName, "/") + if lastSlashIndex == -1 { + return "", fmt.Errorf("could not determine package name") + } + + packagePath := fullFuncName[:lastSlashIndex] + return packagePath, nil +} + +func GetPackagePathFromProjectRootForFunc(i interface{}) (string, error) { + pkg, err := GetPackageNameForFunc(i) + if err != nil { + return "", err + } + path, ok := strings.CutPrefix(pkg, "github.com/open-component-model/ocm/") + if !ok { + return "", fmt.Errorf("prefix %q not found in %q", MODULE_PATH, pkg) + } + return path, nil +} From 22b80126321d1e8c5a3cd6550b5b0dee2ba0dcba Mon Sep 17 00:00:00 2001 From: Fabian Burth Date: Tue, 28 May 2024 19:20:46 +0200 Subject: [PATCH 13/13] remove spdx and order imports --- pkg/env/env.go | 4 +-- pkg/maven/maventest/testdata.go | 4 --- pkg/maven/mypackage/main.go | 15 -------- pkg/maven/mypackage/mysubpackage/somefile.go | 36 -------------------- 4 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 pkg/maven/mypackage/main.go delete mode 100644 pkg/maven/mypackage/mysubpackage/somefile.go diff --git a/pkg/env/env.go b/pkg/env/env.go index e9ed777518..2f4da4b7e3 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -3,14 +3,14 @@ package env import ( "bytes" "fmt" - "github.com/mandelsoft/filepath/pkg/filepath" - "github.com/mandelsoft/goutils/general" "runtime" "runtime/debug" "strings" "github.com/DataDog/gostackparse" + "github.com/mandelsoft/filepath/pkg/filepath" "github.com/mandelsoft/goutils/exception" + "github.com/mandelsoft/goutils/general" "github.com/mandelsoft/vfs/pkg/composefs" "github.com/mandelsoft/vfs/pkg/layerfs" "github.com/mandelsoft/vfs/pkg/memoryfs" diff --git a/pkg/maven/maventest/testdata.go b/pkg/maven/maventest/testdata.go index 1cfe4d8c22..64f0c103e8 100644 --- a/pkg/maven/maventest/testdata.go +++ b/pkg/maven/maventest/testdata.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - package maventest import ( diff --git a/pkg/maven/mypackage/main.go b/pkg/maven/mypackage/main.go deleted file mode 100644 index 958d3239dd..0000000000 --- a/pkg/maven/mypackage/main.go +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - -package main - -import ( - "fmt" - "github.com/open-component-model/ocm/pkg/maven/mypackage/mysubpackage" -) - -func main() { - packageName := mysubpackage.GetPackageName(mysubpackage.SampleFunction) - fmt.Println("Package name:", packageName) -} diff --git a/pkg/maven/mypackage/mysubpackage/somefile.go b/pkg/maven/mypackage/mysubpackage/somefile.go deleted file mode 100644 index 86ebeeb422..0000000000 --- a/pkg/maven/mypackage/mysubpackage/somefile.go +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Open Component Model contributors. -// -// SPDX-License-Identifier: Apache-2.0 - -package mysubpackage - -import ( - "reflect" - "runtime" - "strings" -) - -// Sample function to analyze -func SampleFunction() {} - -func GetPackageName(i interface{}) string { - // Get the function's pointer - ptr := reflect.ValueOf(i).Pointer() - // Retrieve the function's runtime information - funcForPC := runtime.FuncForPC(ptr) - if funcForPC == nil { - return "unknown" - } - // Get the full name of the function, including the package path - fullFuncName := funcForPC.Name() - - // Split the name to extract the package path - // Assuming the format: "package/path.functionName" - lastSlashIndex := strings.LastIndex(fullFuncName, "/") - if lastSlashIndex == -1 { - return "unknown" - } - - packagePath := fullFuncName[:lastSlashIndex] - return packagePath -}