Skip to content

Commit

Permalink
feat: remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Sep 10, 2024
1 parent 3271f59 commit cc77e46
Show file tree
Hide file tree
Showing 26 changed files with 11 additions and 726 deletions.
3 changes: 0 additions & 3 deletions api/ocm/compdesc/componentdescriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,6 @@ type Reference struct {
Digest *metav1.DigestSpec `json:"digest,omitempty"`
}

// Deprecated: use Reference.
type ComponentReference = Reference

func NewComponentReference(name, componentName, version string, extraIdentity metav1.Identity) *Reference {
return &Reference{
ElementMeta: ElementMeta{
Expand Down
131 changes: 0 additions & 131 deletions api/ocm/compdesc/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,12 @@ import (
"ocm.software/ocm/api/utils/selector"
)

// GetResourceAccessByIdentity returns a pointer to the resource that matches the given identity.
//
// Deprecated: use GetResourceByIdentity.
func (cd *ComponentDescriptor) GetResourceAccessByIdentity(id v1.Identity) *Resource {
dig := id.Digest()
for i, res := range cd.Resources {
if bytes.Equal(res.GetIdentityDigest(cd.Resources), dig) {
return &cd.Resources[i]
}
}
return nil
}

// GetResourceByRegexSelector returns resources that match the given selectors.
//
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetResourceByRegexSelector(sel interface{}) (Resources, error) {
identitySelector, err := selector.ParseRegexSelector(sel)
if err != nil {
return nil, fmt.Errorf("unable to parse selector: %w", err)
}
return cd.GetResourcesByIdentitySelectors(identitySelector)
}

// GetResourcesByIdentitySelectors returns resources that match the given identity selectors.
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetResourcesByIdentitySelectors(selectors ...IdentitySelector) (Resources, error) {
return cd.GetResourcesBySelectors(selectors, nil)
}

// GetResourcesByResourceSelectors returns resources that match the given resource selectors.
//
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetResourcesByResourceSelectors(selectors ...ResourceSelector) (Resources, error) {
return cd.GetResourcesBySelectors(nil, selectors)
}

// GetResourcesBySelectors returns resources that match the given selector.
//
// Deprecated: use GetResources with appropriate selectors.
Expand Down Expand Up @@ -78,71 +47,6 @@ func (cd *ComponentDescriptor) GetResourcesBySelectors(selectors []IdentitySelec
return resources, nil
}

// GetExternalResources returns external resource with the given type, name and version.
//
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetExternalResources(rtype, name, version string) (Resources, error) {
return cd.GetResourcesBySelectors(
[]selector.Interface{
ByName(name),
ByVersion(version),
},
[]ResourceSelector{
ByResourceType(rtype),
ByRelation(v1.ExternalRelation),
})
}

// GetExternalResource returns external resource with the given type, name and version.
//
// If multiple resources match, the first one is returned.
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetExternalResource(rtype, name, version string) (Resource, error) {
resources, err := cd.GetExternalResources(rtype, name, version)
if err != nil {
return Resource{}, err
}
// at least one resource must be defined, otherwise the getResourceBySelectors functions returns a NotFound err.
return resources[0], nil
}

// GetLocalResources returns all local resources with the given type, name and version.
func (cd *ComponentDescriptor) GetLocalResources(rtype, name, version string) (Resources, error) {
return cd.GetResourcesBySelectors(
[]selector.Interface{
ByName(name),
ByVersion(version),
},
[]ResourceSelector{
ByResourceType(rtype),
ByRelation(v1.LocalRelation),
})
}

// GetLocalResource returns a local resource with the given type, name and version.
//
// If multiple resources match, the first one is returned.
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetLocalResource(rtype, name, version string) (Resource, error) {
resources, err := cd.GetLocalResources(rtype, name, version)
if err != nil {
return Resource{}, err
}
// at least one resource must be defined, otherwise the getResourceBySelectors functions returns a NotFound err.
return resources[0], nil
}

// GetResourcesByType returns all resources that match the given type and selectors.
//
// Deprecated: use GetResources with appropriate selectors.
func (cd *ComponentDescriptor) GetResourcesByType(rtype string, selectors ...IdentitySelector) (Resources, error) {
return cd.GetResourcesBySelectors(
selectors,
[]ResourceSelector{
ByResourceType(rtype),
})
}

// GetResourcesByName returns all local and external resources with a name.
//
// Deprecated: use GetResources with appropriate selectors.
Expand All @@ -152,21 +56,6 @@ func (cd *ComponentDescriptor) GetResourcesByName(name string, selectors ...Iden
nil)
}

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

// GetSourceAccessByIdentity returns a pointer to the source that matches the given identity.
//
// Deprecated: use GetSourceByIdentity.
func (cd *ComponentDescriptor) GetSourceAccessByIdentity(id v1.Identity) *Source {
dig := id.Digest()
for i, res := range cd.Sources {
if bytes.Equal(res.GetIdentityDigest(cd.Sources), dig) {
return &cd.Sources[i]
}
}
return nil
}

// GetSourcesByIdentitySelectors returns references that match the given selector.
//
// Deprecated: use GetSources with appropriate selectors.
Expand Down Expand Up @@ -197,26 +86,6 @@ func (cd *ComponentDescriptor) GetSourcesByName(name string, selectors ...Identi

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

// GetComponentReferences returns all component references that matches the given selectors.
//
// Deprectated: use GetReferences with appropriate selectors.
func (cd *ComponentDescriptor) GetComponentReferences(selectors ...IdentitySelector) ([]Reference, error) {
refs := make([]Reference, 0)
for _, ref := range cd.References {
ok, err := selector.MatchSelectors(ref.GetIdentity(cd.References), selectors...)
if err != nil {
return nil, fmt.Errorf("unable to match selector for resource %s: %w", ref.Name, err)
}
if ok {
refs = append(refs, ref)
}
}
if len(refs) == 0 {
return refs, NotFound
}
return refs, nil
}

// GetComponentReferenceIndex returns the index of a given component reference.
// If the index is not found -1 is returned.
// Deprecated: use GetReferenceIndex.
Expand Down
18 changes: 0 additions & 18 deletions api/ocm/consts/deprecated.go

This file was deleted.

7 changes: 0 additions & 7 deletions api/ocm/cpi/modopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ func SkipVerify(flag ...bool) internal.ModOptionImpl {
return internal.SkipVerify(flag...)
}

// SkipDigest disables digest creation if enabled.
//
// Deprecated: for legacy code, only.
func SkipDigest(flag ...bool) internal.ModOptionImpl {
return internal.SkipDigest(flag...)
}

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

func CompleteModificationOptions(ctx ContextProvider, m *ModificationOptions) {
Expand Down
40 changes: 0 additions & 40 deletions api/ocm/cpi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,12 @@ import (
"io"

"ocm.software/ocm/api/utils/blobaccess/blobaccess"
"ocm.software/ocm/api/utils/iotools"
)

type AccessMethodSource interface {
AccessMethod() (AccessMethod, error)
}

// ResourceReader gets a Reader for a given resource/source access.
// It provides a Reader handling the Close contract for the access method
// by connecting the access method's Close method to the Readers Close method .
// Deprecated: use GetResourceReader.
// It must be deprecated because of the support of free-floating ReSourceAccess
// implementations, they not necessarily provide an AccessMethod.
func ResourceReader(s AccessMethodSource) (io.ReadCloser, error) {
meth, err := s.AccessMethod()
if err != nil {
return nil, err
}
return toResourceReaderForMethod(meth)
}

// ResourceMimeReader gets a Reader for a given resource/source access.
// It provides a Reader handling the Close contract for the access method
// by connecting the access method's Close method to the Readers Close method.
// Additionally, the mime type is returned.
// Deprecated: use GetResourceMimeReader.
// It must be deprecated because of the support of free-floating ReSourceAccess
// implementations, they not necessarily provide an AccessMethod.
func ResourceMimeReader(s AccessMethodSource) (io.ReadCloser, string, error) {
meth, err := s.AccessMethod()
if err != nil {
return nil, "", err
}
r, err := toResourceReaderForMethod(meth)
return r, meth.MimeType(), err
}

func toResourceReaderForMethod(meth AccessMethod) (io.ReadCloser, error) {
r, err := meth.Reader()
if err != nil {
meth.Close()
return nil, err
}
return iotools.AddReaderCloser(r, meth, "access method"), nil
}

// GetResourceMimeReader gets a Reader for a given resource/source access.
// It provides a Reader handling the Close contract for the access method.
func GetResourceReader(acc AccessProvider) (io.ReadCloser, error) {
Expand Down
3 changes: 0 additions & 3 deletions api/ocm/cpi/view_rsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ var (
_ ComponentVersionProvider = (*ComponentVersionBasedAccessProvider)(nil)
)

// Deprecated: use ComponentVersionBasedAccessProvider.
type BaseAccess = ComponentVersionBasedAccessProvider

func NewBaseAccess(cv ComponentVersionAccess, acc compdesc.AccessSpec) *ComponentVersionBasedAccessProvider {
return &ComponentVersionBasedAccessProvider{vers: cv, access: acc}
}
Expand Down
22 changes: 0 additions & 22 deletions api/ocm/ocmutils/resourceref.go

This file was deleted.

35 changes: 0 additions & 35 deletions api/ocm/resolver.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/ocm/resolvers/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("resolver", func() {
})

It("orders resolver rules", func() {
m := ocm.NewMatchingResolver(ocm.DefaultContext()).(*internal.MatchingResolver)
m := resolvers.NewMatchingResolver(ocm.DefaultContext()).(*internal.MatchingResolver)

spec1 := ocireg.NewRepositorySpec("host1.org", nil)
spec2 := ocireg.NewRepositorySpec("host2.org", nil)
Expand Down
8 changes: 0 additions & 8 deletions api/ocm/tools/signing/deprecated.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/ocm/tools/signing/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ applying to version "github.com/mandelsoft/test:v1"[github.com/mandelsoft/test:v
src := Must(ctf.Open(env.OCMContext(), accessobj.ACC_WRITABLE, ARCH, 0, env))
defer Close(src, "ctf")

resolver := ocm.NewCompoundResolver(src)
resolver := resolvers.NewCompoundResolver(src)

cv := Must(resolver.LookupComponentVersion(COMPONENTC, VERSION))
defer Close(cv, "cv")
Expand Down
8 changes: 4 additions & 4 deletions api/ocm/tools/signing/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,21 @@ func mergeProviderLabel(cv, tcv ocm.ComponentVersionAccess, merged *compdesc.Com
func resourceLabel(cv, tcv ocm.ComponentVersionAccess, merged *compdesc.ComponentDescriptor) {
rid := metav1.NewIdentity("testdata")
ra := Must(cv.GetResource(rid))
tr := NotNil(merged.GetResourceAccessByIdentity(rid))
tr := NotNil(merged.GetResourceByIdentity(rid))

ra.Meta().SetLabel(LABEL_VOL, "changed-resource-volatile")
tr.SetLabel(LABEL_VOL, "changed-resource-volatile")
}

func mergeResourceLabel(cv, tcv ocm.ComponentVersionAccess, merged *compdesc.ComponentDescriptor) {
rid := metav1.NewIdentity("testdata")
tr := NotNil(merged.GetResourceAccessByIdentity(rid))
tr := NotNil(merged.GetResourceByIdentity(rid))

ra := NotNil(cv.GetDescriptor().GetResourceAccessByIdentity(rid))
ra := NotNil(cv.GetDescriptor().GetResourceByIdentity(rid))
ra.SetLabel(LABEL_VOL_NEW, "new-resource-volatile")
tr.SetLabel(LABEL_VOL_NEW, "new-resource-volatile")

ra = NotNil(tcv.GetDescriptor().GetResourceAccessByIdentity(rid))
ra = NotNil(tcv.GetDescriptor().GetResourceByIdentity(rid))
ra.SetLabel(LABEL_VOL_LOCAL, "local-resource-volatile")
tr.SetLabel(LABEL_VOL_LOCAL, "local-resource-volatile")
}
Expand Down
Loading

0 comments on commit cc77e46

Please sign in to comment.