@ -23,6 +23,8 @@ import (
"io"
"io"
"strings"
"strings"
"github.com/Masterminds/semver"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
orascontext "oras.land/oras-go/pkg/context"
orascontext "oras.land/oras-go/pkg/context"
"oras.land/oras-go/pkg/registry"
"oras.land/oras-go/pkg/registry"
@ -46,6 +48,35 @@ func ContainsTag(tags []string, tag string) bool {
return false
return false
}
}
func GetTagMatchingVersionOrConstraint ( tags [ ] string , versionString string ) ( string , error ) {
var constraint * semver . Constraints
if versionString == "" {
// If string is empty, set wildcard constraint
constraint , _ = semver . NewConstraint ( "*" )
} else {
// Otherwise set constraint to the string given
var err error
constraint , err = semver . NewConstraint ( versionString )
if err != nil {
return "" , err
}
}
// Otherwise try to find the first available version matching the string,
// in case it is a constraint
for _ , v := range tags {
test , err := semver . NewVersion ( v )
if err != nil {
continue
}
if constraint . Check ( test ) {
return v , nil
}
}
return "" , errors . Errorf ( "Could not locate a version matching provided version string %s" , versionString )
}
// extractChartMeta is used to extract a chart metadata from a byte array
// extractChartMeta is used to extract a chart metadata from a byte array
func extractChartMeta ( chartData [ ] byte ) ( * chart . Metadata , error ) {
func extractChartMeta ( chartData [ ] byte ) ( * chart . Metadata , error ) {
ch , err := loader . LoadArchive ( bytes . NewReader ( chartData ) )
ch , err := loader . LoadArchive ( bytes . NewReader ( chartData ) )