-
Notifications
You must be signed in to change notification settings - Fork 199
/
repo_fetch.go
80 lines (64 loc) · 3.54 KB
/
repo_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package repo
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/flant/werf/cmd/werf/helm/common"
)
const fetchDesc = `
Retrieve a package from a package repository, and download it locally.
This is useful for fetching packages to inspect, modify, or repackage. It can
also be used to perform cryptographic verification of a chart without installing
the chart.
There are options for unpacking the chart after download. This will create a
directory for the chart and uncompress into that directory.
If the --verify flag is specified, the requested chart MUST have a provenance
file, and MUST pass the verification process. Failure in any part of this will
result in an error, and the chart will not be saved locally.
`
func newRepoFetchCmd() *cobra.Command {
var commonCmdData common.HelmCmdData
downloadChartOptions := &common.DownloadChartOptions{Out: os.Stdout}
cmd := &cobra.Command{
Use: "fetch [chart URL | repo/chartname] [...]",
Short: "Download a chart from a repository and (optionally) unpack it in local directory",
Long: fetchDesc,
DisableFlagsInUseLine: true,
RunE: func(cmd *cobra.Command, args []string) error {
if downloadChartOptions.Keyring != "" {
downloadChartOptions.Keyring = os.ExpandEnv(downloadChartOptions.Keyring)
}
if len(args) == 0 {
return fmt.Errorf("need at least one argument, url or repo/name of the chart")
}
common.InitHelmSettings(&commonCmdData)
if downloadChartOptions.Version == "" && downloadChartOptions.Devel {
downloadChartOptions.Version = ">0.0.0-0"
}
for i := 0; i < len(args); i++ {
downloadChartOptions.ChartRef = args[i]
if err := common.DownloadChart(downloadChartOptions); err != nil {
return err
}
}
return nil
},
}
f := cmd.Flags()
f.BoolVar(&downloadChartOptions.Untar, "untar", false, "if set to true, will untar the chart after downloading it")
f.StringVar(&downloadChartOptions.UntarDir, "untardir", ".", "if untar is specified, this flag specifies the name of the directory into which the chart is expanded")
f.BoolVar(&downloadChartOptions.Verify, "verify", false, "verify the package against its signature")
f.BoolVar(&downloadChartOptions.VerifyLater, "prov", false, "fetch the provenance file, but don't perform verification")
f.StringVar(&downloadChartOptions.Version, "version", "", "specific version of a chart. Without this, the latest version is fetched")
f.StringVar(&downloadChartOptions.Keyring, "keyring", common.DefaultKeyring(), "keyring containing public keys")
f.StringVarP(&downloadChartOptions.DestDir, "destination", "d", ".", "location to write the chart. If this and tardir are specified, tardir is appended to this")
f.StringVar(&downloadChartOptions.RepoURL, "repo", "", "chart repository url where to locate the requested chart")
f.StringVar(&downloadChartOptions.CertFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&downloadChartOptions.KeyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.StringVar(&downloadChartOptions.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
f.BoolVar(&downloadChartOptions.Devel, "devel", false, "use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.")
f.StringVar(&downloadChartOptions.Username, "username", "", "chart repository username")
f.StringVar(&downloadChartOptions.Password, "password", "", "chart repository password")
common.SetupHelmHome(&commonCmdData, cmd)
return cmd
}