/
key_list.go
52 lines (42 loc) · 1.35 KB
/
key_list.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
// Copyright (c) 2017-2019, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package cli
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/sylabs/singularity/docs"
"github.com/sylabs/singularity/pkg/sypgp"
)
var secret bool
func init() {
KeyListCmd.Flags().SetInterspersed(false)
KeyListCmd.Flags().BoolVarP(&secret, "secret", "s", false, "list private keys instead of the default which displays public ones")
KeyListCmd.Flags().SetAnnotation("secret", "envkey", []string{"SECRET"})
}
// KeyListCmd is `singularity key list' and lists local store OpenPGP keys
var KeyListCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
if err := doKeyListCmd(secret); err != nil {
os.Exit(2)
}
},
Use: docs.KeyListUse,
Short: docs.KeyListShort,
Long: docs.KeyListLong,
Example: docs.KeyListExample,
}
func doKeyListCmd(secret bool) error {
if secret == false {
fmt.Printf("Public key listing (%s):\n\n", sypgp.PublicPath())
sypgp.PrintPubKeyring()
} else {
fmt.Printf("Private key listing (%s):\n\n", sypgp.SecretPath())
sypgp.PrintPrivKeyring()
}
return nil
}