4
vendor/helm.sh/helm/v3/pkg/chart/chart.go
vendored
4
vendor/helm.sh/helm/v3/pkg/chart/chart.go
vendored
@@ -17,6 +17,7 @@ package chart
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -26,6 +27,9 @@ const APIVersionV1 = "v1"
|
||||
// APIVersionV2 is the API version number for version 2.
|
||||
const APIVersionV2 = "v2"
|
||||
|
||||
// aliasNameFormat defines the characters that are legal in an alias name.
|
||||
var aliasNameFormat = regexp.MustCompile("^[a-zA-Z0-9_-]+$")
|
||||
|
||||
// Chart is a helm package that contains metadata, a default config, zero or more
|
||||
// optionally parameterizable templates, and zero or more charts (dependencies).
|
||||
type Chart struct {
|
||||
|
||||
7
vendor/helm.sh/helm/v3/pkg/chart/errors.go
vendored
7
vendor/helm.sh/helm/v3/pkg/chart/errors.go
vendored
@@ -15,9 +15,16 @@ limitations under the License.
|
||||
|
||||
package chart
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ValidationError represents a data validation error.
|
||||
type ValidationError string
|
||||
|
||||
func (v ValidationError) Error() string {
|
||||
return "validation: " + string(v)
|
||||
}
|
||||
|
||||
// ValidationErrorf takes a message and formatting options and creates a ValidationError
|
||||
func ValidationErrorf(msg string, args ...interface{}) ValidationError {
|
||||
return ValidationError(fmt.Sprintf(msg, args...))
|
||||
}
|
||||
|
||||
19
vendor/helm.sh/helm/v3/pkg/chart/loader/load.go
vendored
19
vendor/helm.sh/helm/v3/pkg/chart/loader/load.go
vendored
@@ -73,10 +73,11 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
|
||||
c := new(chart.Chart)
|
||||
subcharts := make(map[string][]*BufferedFile)
|
||||
|
||||
// do not rely on assumed ordering of files in the chart and crash
|
||||
// if Chart.yaml was not coming early enough to initialize metadata
|
||||
for _, f := range files {
|
||||
c.Raw = append(c.Raw, &chart.File{Name: f.Name, Data: f.Data})
|
||||
switch {
|
||||
case f.Name == "Chart.yaml":
|
||||
if f.Name == "Chart.yaml" {
|
||||
if c.Metadata == nil {
|
||||
c.Metadata = new(chart.Metadata)
|
||||
}
|
||||
@@ -89,6 +90,13 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
|
||||
if c.Metadata.APIVersion == "" {
|
||||
c.Metadata.APIVersion = chart.APIVersionV1
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range files {
|
||||
switch {
|
||||
case f.Name == "Chart.yaml":
|
||||
// already processed
|
||||
continue
|
||||
case f.Name == "Chart.lock":
|
||||
c.Lock = new(chart.Lock)
|
||||
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil {
|
||||
@@ -123,6 +131,9 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
|
||||
if err := yaml.Unmarshal(f.Data, &c.Lock); err != nil {
|
||||
return c, errors.Wrap(err, "cannot load requirements.lock")
|
||||
}
|
||||
if c.Metadata == nil {
|
||||
c.Metadata = new(chart.Metadata)
|
||||
}
|
||||
if c.Metadata.APIVersion == chart.APIVersionV1 {
|
||||
c.Files = append(c.Files, &chart.File{Name: f.Name, Data: f.Data})
|
||||
}
|
||||
@@ -143,6 +154,10 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if c.Metadata == nil {
|
||||
return c, errors.New("Chart.yaml file is missing")
|
||||
}
|
||||
|
||||
if err := c.Validate(); err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
||||
19
vendor/helm.sh/helm/v3/pkg/chart/metadata.go
vendored
19
vendor/helm.sh/helm/v3/pkg/chart/metadata.go
vendored
@@ -81,6 +81,15 @@ func (md *Metadata) Validate() error {
|
||||
if !isValidChartType(md.Type) {
|
||||
return ValidationError("chart.metadata.type must be application or library")
|
||||
}
|
||||
|
||||
// Aliases need to be validated here to make sure that the alias name does
|
||||
// not contain any illegal characters.
|
||||
for _, dependency := range md.Dependencies {
|
||||
if err := validateDependency(dependency); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// TODO validate valid semver here?
|
||||
return nil
|
||||
}
|
||||
@@ -92,3 +101,13 @@ func isValidChartType(in string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// validateDependency checks for common problems with the dependency datastructure in
|
||||
// the chart. This check must be done at load time before the dependency's charts are
|
||||
// loaded.
|
||||
func validateDependency(dep *Dependency) error {
|
||||
if len(dep.Alias) > 0 && !aliasNameFormat.MatchString(dep.Alias) {
|
||||
return ValidationErrorf("dependency %q has disallowed characters in the alias", dep.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user