示例#1
0
文件: validate.go 项目: jackgr/helm
// ValidateRequest does basic sanity checks on the request.
func ValidateRequest(request *ServiceRequest) error {
	if request.ChartInvocation == nil {
		return fmt.Errorf("Request does not have invocation field")
	}
	if request.Chart == nil {
		return fmt.Errorf("Request does not have chart field")
	}

	chartInv := request.ChartInvocation
	chartFile := request.Chart.Chartfile

	l, err := chart.Parse(chartInv.Type)
	if err != nil {
		return fmt.Errorf("cannot parse chart reference %s: %s", chartInv.Type, err)
	}

	if l.Name != chartFile.Name {
		return fmt.Errorf("Chart invocation type (%s) does not match provided chart (%s)", chartInv.Type, chartFile.Name)
	}

	if chartFile.Expander == nil {
		message := fmt.Sprintf("Chart JSON does not have expander field")
		return fmt.Errorf("%s: %s", chartInv.Name, message)
	}

	return nil
}
示例#2
0
func getTestChartName(t *testing.T) string {
	pc, _, _, _ := runtime.Caller(1)
	cu := getChartURLFromPC(pc)
	cl, err := chart.Parse(cu)
	if err != nil {
		t.Fatalf("cannot parse chart reference %s: %s", cu, err)
	}

	return cl.Name
}
示例#3
0
func parseChartReference(reference string) (*chart.Locator, string, error) {
	l, err := chart.Parse(reference)
	if err != nil {
		return nil, "", fmt.Errorf("cannot parse chart reference %s: %s", reference, err)
	}

	URL, err := l.Long(true)
	if err != nil {
		return nil, "", fmt.Errorf("chart reference %s does not resolve to a URL: %s", reference, err)
	}

	return l, URL, nil
}