Skip to content

Commit

Permalink
Merge branch 'main' into npm/auth_access
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf authored May 2, 2024
2 parents fe9be68 + 0b2baf5 commit 63b6c13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
22 changes: 13 additions & 9 deletions pkg/contexts/ocm/repositories/genericocireg/component.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package genericocireg

import (
Expand Down Expand Up @@ -73,12 +69,12 @@ func (c *componentAccessImpl) GetName() string {

////////////////////////////////////////////////////////////////////////////////

func toTag(v string) string {
func toTag(v string) (string, error) {
_, err := semver.NewVersion(v)
if err != nil {
panic(errors.Wrapf(err, "%s is no semver version", v))
return "", err
}
return strings.ReplaceAll(v, "+", META_SEPARATOR)
return strings.ReplaceAll(v, "+", META_SEPARATOR), nil
}

func toVersion(t string) string {
Expand Down Expand Up @@ -132,7 +128,11 @@ func (c *componentAccessImpl) HasVersion(vers string) (bool, error) {
}

func (c *componentAccessImpl) LookupVersion(version string) (*repocpi.ComponentVersionAccessInfo, error) {
acc, err := c.namespace.GetArtifact(toTag(version))
tag, err := toTag(version)
if err != nil {
return nil, err
}
acc, err := c.namespace.GetArtifact(tag)
if err != nil {
if errors.IsErrNotFound(err) {
return nil, cpi.ErrComponentVersionNotFoundWrap(err, c.name, version)
Expand All @@ -151,7 +151,11 @@ func (c *componentAccessImpl) NewVersion(version string, overrides ...bool) (*re
return nil, accessio.ErrReadOnly
}
override := utils.Optional(overrides...)
acc, err := c.namespace.GetArtifact(toTag(version))
tag, err := toTag(version)
if err != nil {
return nil, err
}
acc, err := c.namespace.GetArtifact(tag)
if err == nil {
if override {
return newComponentVersionAccess(accessobj.ACC_CREATE, c, version, acc, false)
Expand Down
10 changes: 5 additions & 5 deletions pkg/contexts/ocm/repositories/genericocireg/componentversion.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package genericocireg

import (
Expand Down Expand Up @@ -222,7 +218,11 @@ func (c *ComponentVersionContainer) Update() error {
}

logger.Debug("add oci artifact")
if _, err := c.comp.namespace.AddArtifact(c.manifest, toTag(c.version)); err != nil {
tag, err := toTag(c.version)
if err != nil {
return err
}
if _, err := c.comp.namespace.AddArtifact(c.manifest, tag); err != nil {
return fmt.Errorf("unable to add artifact: %w", err)
}
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/contexts/ocm/repositories/genericocireg/repo_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0

package genericocireg_test

import (
"fmt"
"path"
"reflect"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/open-component-model/ocm/pkg/testutils"

"github.com/mandelsoft/vfs/pkg/osfs"
"github.com/mandelsoft/vfs/pkg/vfs"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/opencontainers/go-digest"

"github.com/open-component-model/ocm/pkg/blobaccess"
Expand Down Expand Up @@ -50,6 +44,7 @@ import (
"github.com/open-component-model/ocm/pkg/finalizer"
"github.com/open-component-model/ocm/pkg/mime"
"github.com/open-component-model/ocm/pkg/signing/hasher/sha256"
. "github.com/open-component-model/ocm/pkg/testutils"
)

var DefaultContext = ocm.New()
Expand Down Expand Up @@ -79,6 +74,15 @@ var _ = Describe("component repository mapping", func() {
vfs.Cleanup(tempfs)
})

It("Don't Panik! When it's not a semver.org conform version. #756", func() {
repo := Must(DefaultContext.RepositoryForSpec(spec))
comp := Must(repo.LookupComponent(COMPONENT))
cva, err := comp.NewVersion("v1.two.zeo-2")
Expect(err).To(HaveOccurred())
Expect(cva).To(BeNil())
Expect(err.Error()).To(Equal("Invalid Semantic Version"))
})

It("creates a dummy component", func() {
var finalize finalizer.Finalizer
defer Defer(finalize.Finalize)
Expand Down

0 comments on commit 63b6c13

Please sign in to comment.