Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extend plugin API to support transfer handlers #937

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/config/wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ toi
toiexecutor
toolset
transportarchive
transferhandler
typehandler
typename
unmarshaller
Expand Down
8 changes: 6 additions & 2 deletions api/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ func AsTags(tag string) []string {
}

func StandardOCIRef(host, repository, version string) string {
return fmt.Sprintf("%s%s%s", host, grammar.RepositorySeparator, RelativeOCIRef(repository, version))
}

func RelativeOCIRef(repository, version string) string {
sep := grammar.TagSeparator
i := strings.Index(version, grammar.DigestSeparator)
if i > 1 {
return fmt.Sprintf("%s%s%s%s%s", host, grammar.RepositorySeparator, repository, sep, version)
return fmt.Sprintf("%s%s%s", repository, sep, version)
}
if ok, _ := artdesc.IsDigest(version); ok {
sep = grammar.DigestSeparator
if strings.HasPrefix(version, sep) {
sep = ""
}
}
return fmt.Sprintf("%s%s%s%s%s", host, grammar.RepositorySeparator, repository, sep, version)
return fmt.Sprintf("%s%s%s", repository, sep, version)
}

func IsIntermediate(spec RepositorySpec) bool {
Expand Down
9 changes: 5 additions & 4 deletions api/ocm/cpi/accspeccpi/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ type (

AccessType = internal.AccessType

AccessMethodImpl = internal.AccessMethodImpl
AccessMethod = internal.AccessMethod
AccessSpec = internal.AccessSpec
AccessSpecRef = internal.AccessSpecRef
AccessMethodImpl = internal.AccessMethodImpl
AccessMethod = internal.AccessMethod
UniformAccessSpecInfo = internal.UniformAccessSpecInfo
AccessSpec = internal.AccessSpec
AccessSpecRef = internal.AccessSpecRef

HintProvider = internal.HintProvider
GlobalAccessProvider = internal.GlobalAccessProvider
Expand Down
3 changes: 3 additions & 0 deletions api/ocm/cpi/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type (
ComponentLister = internal.ComponentLister
ComponentAccess = internal.ComponentAccess
ComponentVersionAccess = internal.ComponentVersionAccess
UniformAccessSpecInfo = internal.UniformAccessSpecInfo
AccessSpec = internal.AccessSpec
AccessSpecDecoder = internal.AccessSpecDecoder
GenericAccessSpec = internal.GenericAccessSpec
Expand Down Expand Up @@ -183,6 +184,8 @@ func ToGenericRepositorySpec(spec RepositorySpec) (*GenericRepositorySpec, error

type AccessSpecRef = internal.AccessSpecRef

var _ AccessSpec = &AccessSpecRef{}

func NewAccessSpecRef(spec AccessSpec) *AccessSpecRef {
return internal.NewAccessSpecRef(spec)
}
Expand Down
6 changes: 6 additions & 0 deletions api/ocm/extensions/accessmethods/compose/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("Composition blob %s", a.Id)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
}
}

func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool {
return true
}
Expand Down
14 changes: 14 additions & 0 deletions api/ocm/extensions/accessmethods/github/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("GitHub commit %s[%s]", a.RepoURL, a.Commit)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
u, err := url.Parse(a.RepoURL)
if err != nil {
u = &url.URL{}
}
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: u.Hostname(),
Port: u.Port(),
Path: u.Path,
Info: a.Commit,
}
}

func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool {
return false
}
Expand Down
15 changes: 15 additions & 0 deletions api/ocm/extensions/accessmethods/helm/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helm
import (
"fmt"
"io"
"net/url"
"strings"
"sync"

Expand Down Expand Up @@ -63,6 +64,20 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("Helm chart %s:%s in repository %s", a.GetChartName(), a.GetVersion(), a.HelmRepository)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
u, err := url.Parse(a.HelmRepository)
if err != nil {
u = &url.URL{}
}
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: u.Hostname(),
Port: u.Port(),
Path: u.Path,
Info: a.HelmChart,
}
}

func (a *AccessSpec) IsLocal(ctx accspeccpi.Context) bool {
return false
}
Expand Down
7 changes: 7 additions & 0 deletions api/ocm/extensions/accessmethods/localblob/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("Local blob %s[%s]", a.LocalReference, a.ReferenceName)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Info: a.LocalReference,
}
}

func (a *AccessSpec) IsLocal(accspeccpi.Context) bool {
return true
}
Expand Down
15 changes: 15 additions & 0 deletions api/ocm/extensions/accessmethods/maven/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package maven

import (
"fmt"
"net/url"

"github.com/mandelsoft/goutils/optionutils"

Expand Down Expand Up @@ -78,6 +79,20 @@ func (a *AccessSpec) Describe(_ accspeccpi.Context) string {
return fmt.Sprintf("Maven package '%s' in repository '%s' path '%s'", a.Coordinates.String(), a.RepoUrl, a.Coordinates.FilePath())
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
u, err := url.Parse(a.RepoUrl)
if err != nil {
u = &url.URL{}
}
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: u.Hostname(),
Port: u.Port(),
Path: u.Path,
Info: a.Coordinates.String(),
}
}

func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool {
return false
}
Expand Down
6 changes: 6 additions & 0 deletions api/ocm/extensions/accessmethods/none/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return "none"
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
}
}

func (s *AccessSpec) IsLocal(context accspeccpi.Context) bool {
return false
}
Expand Down
15 changes: 15 additions & 0 deletions api/ocm/extensions/accessmethods/npm/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package npm

import (
"fmt"
"net/url"

"ocm.software/ocm/api/ocm/cpi/accspeccpi"
"ocm.software/ocm/api/utils/blobaccess/blobaccess"
Expand Down Expand Up @@ -49,6 +50,20 @@ func (a *AccessSpec) Describe(_ accspeccpi.Context) string {
return fmt.Sprintf("NPM package %s:%s in registry %s", a.Package, a.Version, a.Registry)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
u, err := url.Parse(a.Registry)
if err != nil {
u = &url.URL{}
}
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: u.Hostname(),
Port: u.Port(),
Path: u.Path,
Info: a.GetReferenceHint(nil),
}
}

func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool {
return false
}
Expand Down
19 changes: 19 additions & 0 deletions api/ocm/extensions/accessmethods/ociartifact/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("OCI artifact %s", a.ImageReference)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
ref, _ := oci.ParseRef(a.ImageReference)
host, port := ref.HostPort()

r := ref.Repository
if ref.Tag != nil {
r += ":" + *ref.Tag
}
if ref.Digest != nil {
r += "@" + ref.Digest.String()
}
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: host,
Port: port,
Info: r,
}
}

func (_ *AccessSpec) IsLocal(accspeccpi.Context) bool {
return false
}
Expand Down
17 changes: 17 additions & 0 deletions api/ocm/extensions/accessmethods/ociblob/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ociblob
import (
"fmt"
"io"
"strings"
"sync"

"github.com/mandelsoft/goutils/errors"
Expand Down Expand Up @@ -62,6 +63,22 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("OCI blob %s in repository %s", a.Digest, a.Reference)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
segs := strings.Split(a.Reference, "/")
comps := strings.Split(segs[0], ":")
port := ""
if len(comps) > 1 {
port = comps[1]
}
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: comps[0],
Port: port,
Path: strings.Join(segs[1:], "/"),
Info: a.Digest.String(),
}
}

func (s *AccessSpec) IsLocal(context accspeccpi.Context) bool {
return false
}
Expand Down
15 changes: 15 additions & 0 deletions api/ocm/extensions/accessmethods/ocm/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ func (a *AccessSpec) Describe(ctx accspeccpi.Context) string {
return fmt.Sprintf("OCM resource %s%s", a.ResourceRef.String(), comp)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
ref := a.OCMRepository.AsUniformSpec(ctx)
if ref == nil {
return &accspeccpi.UniformAccessSpecInfo{Kind: Type}
}
host, port := ref.HostPort()
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Host: host,
Port: port,
Path: ref.SubPath,
Info: ref.Info,
}
}

func (a *AccessSpec) IsLocal(ctx accspeccpi.Context) bool {
return false
}
Expand Down
4 changes: 4 additions & 0 deletions api/ocm/extensions/accessmethods/plugin/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (s *AccessSpec) Describe(ctx cpi.Context) string {
return s.handler.Describe(s, ctx)
}

func (s *AccessSpec) Info(ctx cpi.Context) *cpi.UniformAccessSpecInfo {
return s.handler.Info(s, ctx)
}

func (_ *AccessSpec) IsLocal(cpi.Context) bool {
return false
}
Expand Down
34 changes: 28 additions & 6 deletions api/ocm/extensions/accessmethods/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewPluginHandler(p plugin.Plugin) *PluginHandler {
return &PluginHandler{plug: p}
}

func (p *PluginHandler) Info(spec *AccessSpec) (*ppi.AccessSpecInfo, error) {
func (p *PluginHandler) GetAccessSpecInfo(spec *AccessSpec) (*ppi.AccessSpecInfo, error) {
if p.info != nil || p.err != nil {
raw, err := spec.UnstructuredVersionedTypedObject.GetRaw()
if err != nil {
Expand All @@ -58,15 +58,15 @@ func (p *PluginHandler) AccessMethod(spec *AccessSpec, cv cpi.ComponentVersionAc
return nil, err
}

info, err := p.Info(spec)
info, err := p.GetAccessSpecInfo(spec)
if err != nil {
return nil, err
}
return accspeccpi.AccessMethodForImplementation(newMethod(p, spec, cv.GetContext(), info, creddata), nil)
}

func (p *PluginHandler) getCredentialData(spec *AccessSpec, cv cpi.ComponentVersionAccess) (json.RawMessage, error) {
info, err := p.Info(spec)
info, err := p.GetAccessSpecInfo(spec)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -94,19 +94,41 @@ func (p *PluginHandler) Describe(spec *AccessSpec, ctx cpi.Context) string {
if mspec == nil {
return "unknown type " + spec.GetType()
}
info, err := p.Info(spec)
info, err := p.GetAccessSpecInfo(spec)
if err != nil {
return err.Error()
}
return info.Short
}

func (p *PluginHandler) Info(spec *AccessSpec, ctx cpi.Context) *cpi.UniformAccessSpecInfo {
mspec := p.GetAccessMethodDescriptor(spec.GetKind(), spec.GetVersion())
if mspec == nil {
return &cpi.UniformAccessSpecInfo{
Kind: spec.GetKind(),
}
}
info, err := p.GetAccessSpecInfo(spec)
if err != nil || info.Info == nil {
return &cpi.UniformAccessSpecInfo{
Kind: spec.GetKind(),
}
}
return &cpi.UniformAccessSpecInfo{
Kind: spec.GetKind(),
Host: info.Info.Host,
Port: info.Info.Port,
Path: info.Info.Path,
Info: info.Info.Info,
}
}

func (p *PluginHandler) GetMimeType(spec *AccessSpec) string {
mspec := p.GetAccessMethodDescriptor(spec.GetKind(), spec.GetVersion())
if mspec == nil {
return "unknown type " + spec.GetType()
}
info, err := p.Info(spec)
info, err := p.GetAccessSpecInfo(spec)
if err != nil {
return ""
}
Expand All @@ -118,7 +140,7 @@ func (p *PluginHandler) GetReferenceHint(spec *AccessSpec, cv cpi.ComponentVersi
if mspec == nil {
return "unknown type " + spec.GetType()
}
info, err := p.Info(spec)
info, err := p.GetAccessSpecInfo(spec)
if err != nil {
return ""
}
Expand Down
7 changes: 7 additions & 0 deletions api/ocm/extensions/accessmethods/relativeociref/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func (a *AccessSpec) Describe(context accspeccpi.Context) string {
return fmt.Sprintf("local OCI artifact %s", a.Reference)
}

func (a *AccessSpec) Info(ctx accspeccpi.Context) *accspeccpi.UniformAccessSpecInfo {
return &accspeccpi.UniformAccessSpecInfo{
Kind: Type,
Info: a.Reference,
}
}

func (a *AccessSpec) IsLocal(context accspeccpi.Context) bool {
return true
}
Expand Down
Loading
Loading