/
key_search.go
53 lines (43 loc) · 1.43 KB
/
key_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) 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/internal/pkg/sylog"
"github.com/sylabs/singularity/pkg/sypgp"
)
func init() {
KeySearchCmd.Flags().SetInterspersed(false)
KeySearchCmd.Flags().StringVarP(&keyServerURL, "url", "u", defaultKeyServer, "specify the key server URL")
KeySearchCmd.Flags().SetAnnotation("url", "envkey", []string{"URL"})
}
// KeySearchCmd is `singularity key search' and look for public keys from a key server
var KeySearchCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
DisableFlagsInUseLine: true,
PreRun: sylabsToken,
Run: func(cmd *cobra.Command, args []string) {
if err := doKeySearchCmd(args[0], keyServerURL); err != nil {
sylog.Errorf("search failed: %s", err)
os.Exit(2)
}
},
Use: docs.KeySearchUse,
Short: docs.KeySearchShort,
Long: docs.KeySearchLong,
Example: docs.KeySearchExample,
}
func doKeySearchCmd(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
}