Validate checks the metadata for known issues and sanitizes string characters.
()
| 86 | // Validate checks the metadata for known issues and sanitizes string |
| 87 | // characters. |
| 88 | func (md *Metadata) Validate() error { |
| 89 | if md == nil { |
| 90 | return ValidationError("chart.metadata is required") |
| 91 | } |
| 92 | |
| 93 | md.Name = sanitizeString(md.Name) |
| 94 | md.Description = sanitizeString(md.Description) |
| 95 | md.Home = sanitizeString(md.Home) |
| 96 | md.Icon = sanitizeString(md.Icon) |
| 97 | md.Condition = sanitizeString(md.Condition) |
| 98 | md.Tags = sanitizeString(md.Tags) |
| 99 | md.AppVersion = sanitizeString(md.AppVersion) |
| 100 | md.KubeVersion = sanitizeString(md.KubeVersion) |
| 101 | for i := range md.Sources { |
| 102 | md.Sources[i] = sanitizeString(md.Sources[i]) |
| 103 | } |
| 104 | for i := range md.Keywords { |
| 105 | md.Keywords[i] = sanitizeString(md.Keywords[i]) |
| 106 | } |
| 107 | |
| 108 | if md.APIVersion == "" { |
| 109 | return ValidationError("chart.metadata.apiVersion is required") |
| 110 | } |
| 111 | if md.Name == "" { |
| 112 | return ValidationError("chart.metadata.name is required") |
| 113 | } |
| 114 | |
| 115 | if md.Name == "." || md.Name == ".." { |
| 116 | return ValidationErrorf("chart.metadata.name %q is not allowed", md.Name) |
| 117 | } |
| 118 | if md.Name != filepath.Base(md.Name) { |
| 119 | return ValidationErrorf("chart.metadata.name %q is invalid", md.Name) |
| 120 | } |
| 121 | |
| 122 | if md.Version == "" { |
| 123 | return ValidationError("chart.metadata.version is required") |
| 124 | } |
| 125 | if !isValidSemver(md.Version) { |
| 126 | return ValidationErrorf("chart.metadata.version %q is invalid", md.Version) |
| 127 | } |
| 128 | if !isValidChartType(md.Type) { |
| 129 | return ValidationError("chart.metadata.type must be application or library") |
| 130 | } |
| 131 | |
| 132 | for _, m := range md.Maintainers { |
| 133 | if err := m.Validate(); err != nil { |
| 134 | return err |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Aliases need to be validated here to make sure that the alias name does |
| 139 | // not contain any illegal characters. |
| 140 | dependencies := map[string]*Dependency{} |
| 141 | for _, dependency := range md.Dependencies { |
| 142 | if err := dependency.Validate(); err != nil { |
| 143 | return err |
| 144 | } |
| 145 | key := dependency.Name |