|
|
@ -19,11 +19,14 @@ package main
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/ptypes/any"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
|
|
|
|
"k8s.io/helm/pkg/chartutil"
|
|
|
|
"k8s.io/helm/pkg/chartutil"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/util/slice"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const inspectDesc = `
|
|
|
|
const inspectDesc = `
|
|
|
@ -43,6 +46,11 @@ This command inspects a chart (directory, file, or URL) and displays the content
|
|
|
|
of the Charts.yaml file
|
|
|
|
of the Charts.yaml file
|
|
|
|
`
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const readmeChartDesc = `
|
|
|
|
|
|
|
|
This command inspects a chart (directory, file, or URL) and displays the contents
|
|
|
|
|
|
|
|
of the README file
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
|
|
type inspectCmd struct {
|
|
|
|
type inspectCmd struct {
|
|
|
|
chartpath string
|
|
|
|
chartpath string
|
|
|
|
output string
|
|
|
|
output string
|
|
|
@ -60,13 +68,16 @@ type inspectCmd struct {
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
chartOnly = "chart"
|
|
|
|
chartOnly = "chart"
|
|
|
|
valuesOnly = "values"
|
|
|
|
valuesOnly = "values"
|
|
|
|
both = "both"
|
|
|
|
readmeOnly = "readme"
|
|
|
|
|
|
|
|
all = "all"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var readmeFileNames = []string{"readme.md", "readme.txt", "readme"}
|
|
|
|
|
|
|
|
|
|
|
|
func newInspectCmd(out io.Writer) *cobra.Command {
|
|
|
|
func newInspectCmd(out io.Writer) *cobra.Command {
|
|
|
|
insp := &inspectCmd{
|
|
|
|
insp := &inspectCmd{
|
|
|
|
out: out,
|
|
|
|
out: out,
|
|
|
|
output: both,
|
|
|
|
output: all,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inspectCommand := &cobra.Command{
|
|
|
|
inspectCommand := &cobra.Command{
|
|
|
@ -125,51 +136,72 @@ func newInspectCmd(out io.Writer) *cobra.Command {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readmeSubCmd := &cobra.Command{
|
|
|
|
|
|
|
|
Use: "readme [CHART]",
|
|
|
|
|
|
|
|
Short: "shows inspect readme",
|
|
|
|
|
|
|
|
Long: readmeChartDesc,
|
|
|
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
|
|
|
insp.output = readmeOnly
|
|
|
|
|
|
|
|
if err := checkArgsLength(len(args), "chart name"); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cp, err := locateChartPath(insp.repoURL, args[0], insp.version, insp.verify, insp.keyring,
|
|
|
|
|
|
|
|
insp.certFile, insp.keyFile, insp.caFile)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
insp.chartpath = cp
|
|
|
|
|
|
|
|
return insp.run()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmds := []*cobra.Command{inspectCommand, readmeSubCmd, valuesSubCmd, chartSubCmd}
|
|
|
|
vflag := "verify"
|
|
|
|
vflag := "verify"
|
|
|
|
vdesc := "verify the provenance data for this chart"
|
|
|
|
vdesc := "verify the provenance data for this chart"
|
|
|
|
inspectCommand.Flags().BoolVar(&insp.verify, vflag, false, vdesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().BoolVar(&insp.verify, vflag, false, vdesc)
|
|
|
|
subCmd.Flags().BoolVar(&insp.verify, vflag, false, vdesc)
|
|
|
|
chartSubCmd.Flags().BoolVar(&insp.verify, vflag, false, vdesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kflag := "keyring"
|
|
|
|
kflag := "keyring"
|
|
|
|
kdesc := "path to the keyring containing public verification keys"
|
|
|
|
kdesc := "path to the keyring containing public verification keys"
|
|
|
|
kdefault := defaultKeyring()
|
|
|
|
kdefault := defaultKeyring()
|
|
|
|
inspectCommand.Flags().StringVar(&insp.keyring, kflag, kdefault, kdesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().StringVar(&insp.keyring, kflag, kdefault, kdesc)
|
|
|
|
subCmd.Flags().StringVar(&insp.keyring, kflag, kdefault, kdesc)
|
|
|
|
chartSubCmd.Flags().StringVar(&insp.keyring, kflag, kdefault, kdesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
verflag := "version"
|
|
|
|
verflag := "version"
|
|
|
|
verdesc := "version of the chart. By default, the newest chart is shown"
|
|
|
|
verdesc := "version of the chart. By default, the newest chart is shown"
|
|
|
|
inspectCommand.Flags().StringVar(&insp.version, verflag, "", verdesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().StringVar(&insp.version, verflag, "", verdesc)
|
|
|
|
subCmd.Flags().StringVar(&insp.version, verflag, "", verdesc)
|
|
|
|
chartSubCmd.Flags().StringVar(&insp.version, verflag, "", verdesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
repoURL := "repo"
|
|
|
|
repoURL := "repo"
|
|
|
|
repoURLdesc := "chart repository url where to locate the requested chart"
|
|
|
|
repoURLdesc := "chart repository url where to locate the requested chart"
|
|
|
|
inspectCommand.Flags().StringVar(&insp.repoURL, repoURL, "", repoURLdesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().StringVar(&insp.repoURL, repoURL, "", repoURLdesc)
|
|
|
|
subCmd.Flags().StringVar(&insp.repoURL, repoURL, "", repoURLdesc)
|
|
|
|
chartSubCmd.Flags().StringVar(&insp.repoURL, repoURL, "", repoURLdesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
certFile := "cert-file"
|
|
|
|
certFile := "cert-file"
|
|
|
|
certFiledesc := "verify certificates of HTTPS-enabled servers using this CA bundle"
|
|
|
|
certFiledesc := "verify certificates of HTTPS-enabled servers using this CA bundle"
|
|
|
|
inspectCommand.Flags().StringVar(&insp.certFile, certFile, "", certFiledesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().StringVar(&insp.certFile, certFile, "", certFiledesc)
|
|
|
|
subCmd.Flags().StringVar(&insp.certFile, certFile, "", certFiledesc)
|
|
|
|
chartSubCmd.Flags().StringVar(&insp.certFile, certFile, "", certFiledesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
keyFile := "key-file"
|
|
|
|
keyFile := "key-file"
|
|
|
|
keyFiledesc := "identify HTTPS client using this SSL key file"
|
|
|
|
keyFiledesc := "identify HTTPS client using this SSL key file"
|
|
|
|
inspectCommand.Flags().StringVar(&insp.keyFile, keyFile, "", keyFiledesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().StringVar(&insp.keyFile, keyFile, "", keyFiledesc)
|
|
|
|
subCmd.Flags().StringVar(&insp.keyFile, keyFile, "", keyFiledesc)
|
|
|
|
chartSubCmd.Flags().StringVar(&insp.keyFile, keyFile, "", keyFiledesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
caFile := "ca-file"
|
|
|
|
caFile := "ca-file"
|
|
|
|
caFiledesc := "chart repository url where to locate the requested chart"
|
|
|
|
caFiledesc := "chart repository url where to locate the requested chart"
|
|
|
|
inspectCommand.Flags().StringVar(&insp.caFile, caFile, "", caFiledesc)
|
|
|
|
for _, subCmd := range cmds {
|
|
|
|
valuesSubCmd.Flags().StringVar(&insp.caFile, caFile, "", caFiledesc)
|
|
|
|
subCmd.Flags().StringVar(&insp.caFile, caFile, "", caFiledesc)
|
|
|
|
chartSubCmd.Flags().StringVar(&insp.caFile, caFile, "", caFiledesc)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inspectCommand.AddCommand(valuesSubCmd)
|
|
|
|
for _, subCmd := range cmds[1:] {
|
|
|
|
inspectCommand.AddCommand(chartSubCmd)
|
|
|
|
inspectCommand.AddCommand(subCmd)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return inspectCommand
|
|
|
|
return inspectCommand
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -184,16 +216,35 @@ func (i *inspectCmd) run() error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if i.output == chartOnly || i.output == both {
|
|
|
|
if i.output == chartOnly || i.output == all {
|
|
|
|
fmt.Fprintln(i.out, string(cf))
|
|
|
|
fmt.Fprintln(i.out, string(cf))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (i.output == valuesOnly || i.output == both) && chrt.Values != nil {
|
|
|
|
if (i.output == valuesOnly || i.output == all) && chrt.Values != nil {
|
|
|
|
if i.output == both {
|
|
|
|
if i.output == all {
|
|
|
|
fmt.Fprintln(i.out, "---")
|
|
|
|
fmt.Fprintln(i.out, "---")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Fprintln(i.out, chrt.Values.Raw)
|
|
|
|
fmt.Fprintln(i.out, chrt.Values.Raw)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if i.output == readmeOnly || i.output == all {
|
|
|
|
|
|
|
|
if i.output == all {
|
|
|
|
|
|
|
|
fmt.Fprintln(i.out, "---")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
readme := findReadme(chrt.Files)
|
|
|
|
|
|
|
|
if readme == nil {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(i.out, string(readme.Value))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func findReadme(files []*any.Any) (file *any.Any) {
|
|
|
|
|
|
|
|
for _, file := range files {
|
|
|
|
|
|
|
|
if slice.ContainsString(readmeFileNames, strings.ToLower(file.TypeUrl), nil) {
|
|
|
|
|
|
|
|
return file
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|