/
keys_search.go
53 lines (43 loc) · 1.44 KB
/
keys_search.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
// Copyright (c) 2018, 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/internal/pkg/sylog"
"github.com/sylabs/singularity/pkg/sypgp"
"github.com/sylabs/singularity/src/docs"
)
func init() {
KeysSearchCmd.Flags().SetInterspersed(false)
KeysSearchCmd.Flags().StringVarP(&keyServerURL, "url", "u", defaultKeysServer, "specify the key server URL")
KeysSearchCmd.Flags().SetAnnotation("url", "envkey", []string{"URL"})
}
// KeysSearchCmd is `singularity keys search' and look for public keys from a key server
var KeysSearchCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: sylabsToken,
Run: func(cmd *cobra.Command, args []string) {
if err := doKeysSearchCmd(args[0], keyServerURL); err != nil {
sylog.Errorf("search failed: %s", err)
os.Exit(2)
}
},
Use: docs.KeysSearchUse,
Short: docs.KeysSearchShort,
Long: docs.KeysSearchLong,
Example: docs.KeysSearchExample,
}
func doKeysSearchCmd(search string, url string) error {
// get keyring with matching search string
list, err := sypgp.SearchPubkey(search, url, authToken)
if err != nil {
return err
}
fmt.Println(list)
return nil
}