github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/cmd/helm/verify.go (about) 1 /* 2 Copyright The Helm Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package main 17 18 import ( 19 "fmt" 20 "io" 21 22 "github.com/spf13/cobra" 23 24 "github.com/stefanmcshane/helm/cmd/helm/require" 25 "github.com/stefanmcshane/helm/pkg/action" 26 ) 27 28 const verifyDesc = ` 29 Verify that the given chart has a valid provenance file. 30 31 Provenance files provide cryptographic verification that a chart has not been 32 tampered with, and was packaged by a trusted provider. 33 34 This command can be used to verify a local chart. Several other commands provide 35 '--verify' flags that run the same validation. To generate a signed package, use 36 the 'helm package --sign' command. 37 ` 38 39 func newVerifyCmd(out io.Writer) *cobra.Command { 40 client := action.NewVerify() 41 42 cmd := &cobra.Command{ 43 Use: "verify PATH", 44 Short: "verify that a chart at the given path has been signed and is valid", 45 Long: verifyDesc, 46 Args: require.ExactArgs(1), 47 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 48 if len(args) == 0 { 49 // Allow file completion when completing the argument for the path 50 return nil, cobra.ShellCompDirectiveDefault 51 } 52 // No more completions, so disable file completion 53 return nil, cobra.ShellCompDirectiveNoFileComp 54 }, 55 RunE: func(cmd *cobra.Command, args []string) error { 56 err := client.Run(args[0]) 57 if err != nil { 58 return err 59 } 60 61 fmt.Fprint(out, client.Out) 62 63 return nil 64 }, 65 } 66 67 cmd.Flags().StringVar(&client.Keyring, "keyring", defaultKeyring(), "keyring containing public keys") 68 69 return cmd 70 }