Skip to content

Commit

Permalink
validate chart name
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
  • Loading branch information
jdolitsky committed Jan 13, 2019
1 parent 079a598 commit c0e204f
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions cmd/chart-scanner/scan.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package main

import (
"bytes"
"fmt"
"log"
"path"
"path/filepath"
"strings"

"github.com/chartmuseum/storage"
"k8s.io/helm/pkg/chartutil"
)

func check(backend storage.Backend) error {
Expand All @@ -19,18 +23,33 @@ func scan(backend storage.Backend, prefix string, debug bool) {
fullPath := path.Join(prefix, object.Path)
isChartPackage := strings.HasSuffix(fullPath, ".tgz")
if isChartPackage {
validateChartPackage(fullPath, debug)
validateChartPackage(backend, fullPath, debug)
} else {
scan(backend, fullPath, debug)
}
}
}

func validateChartPackage(filePath string, debug bool) {
func validateChartPackage(backend storage.Backend, filePath string, debug bool) {
object, err := backend.GetObject(filePath)
if err != nil {
log.Printf("ERROR %s could not be retrieved\n", filePath)
exitCode = 1
return
}
chart, err := chartutil.LoadArchive(bytes.NewBuffer(object.Content))
if err != nil {
log.Printf("ERROR %s could not be loaded as a chart\n", filePath)
exitCode = 1
return
}
name := chart.Metadata.Name
if !strings.HasPrefix(filepath.Base(filePath), fmt.Sprintf("%s-", name)) {
log.Printf("ERROR %s has bad chart name \"%s\"\n", filePath, name)
exitCode = 1
return
}
if debug {
log.Printf("DEBUG %s is valid\n", filePath)
}

exitCode = 1
log.Printf("ERROR %s is invalid: bad chart name\n", filePath)
}

0 comments on commit c0e204f

Please sign in to comment.