github.com/apptainer/singularity@v3.1.1+incompatible/cmd/internal/cli/key_list.go (about) 1 // Copyright (c) 2017-2019, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package cli 7 8 import ( 9 "fmt" 10 "os" 11 12 "github.com/spf13/cobra" 13 "github.com/sylabs/singularity/docs" 14 "github.com/sylabs/singularity/pkg/sypgp" 15 ) 16 17 var secret bool 18 19 func init() { 20 KeyListCmd.Flags().SetInterspersed(false) 21 22 KeyListCmd.Flags().BoolVarP(&secret, "secret", "s", false, "list private keys instead of the default which displays public ones") 23 KeyListCmd.Flags().SetAnnotation("secret", "envkey", []string{"SECRET"}) 24 } 25 26 // KeyListCmd is `singularity key list' and lists local store OpenPGP keys 27 var KeyListCmd = &cobra.Command{ 28 Args: cobra.ExactArgs(0), 29 DisableFlagsInUseLine: true, 30 Run: func(cmd *cobra.Command, args []string) { 31 if err := doKeyListCmd(secret); err != nil { 32 os.Exit(2) 33 } 34 }, 35 36 Use: docs.KeyListUse, 37 Short: docs.KeyListShort, 38 Long: docs.KeyListLong, 39 Example: docs.KeyListExample, 40 } 41 42 func doKeyListCmd(secret bool) error { 43 if secret == false { 44 fmt.Printf("Public key listing (%s):\n\n", sypgp.PublicPath()) 45 sypgp.PrintPubKeyring() 46 } else { 47 fmt.Printf("Private key listing (%s):\n\n", sypgp.SecretPath()) 48 sypgp.PrintPrivKeyring() 49 } 50 51 return nil 52 }