/
verify.go
69 lines (57 loc) · 1.83 KB
/
verify.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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/signing"
"github.com/sylabs/singularity/src/docs"
)
var (
sifGroupID uint32 // -g groupid specification
sifDescID uint32 // -i id specification
)
func init() {
VerifyCmd.Flags().SetInterspersed(false)
VerifyCmd.Flags().StringVarP(&keyServerURL, "url", "u", defaultKeysServer, "key server URL")
VerifyCmd.Flags().SetAnnotation("url", "envkey", []string{"URL"})
VerifyCmd.Flags().Uint32VarP(&sifGroupID, "groupid", "g", 0, "group ID to be verified")
VerifyCmd.Flags().Uint32VarP(&sifDescID, "id", "i", 0, "descriptor ID to be verified")
SingularityCmd.AddCommand(VerifyCmd)
}
// VerifyCmd singularity verify
var VerifyCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
PreRun: sylabsToken,
Run: func(cmd *cobra.Command, args []string) {
// args[0] contains image path
fmt.Printf("Verifying image: %s\n", args[0])
if err := doVerifyCmd(args[0], keyServerURL); err != nil {
sylog.Errorf("verification failed: %s", err)
os.Exit(2)
}
},
Use: docs.VerifyUse,
Short: docs.VerifyShort,
Long: docs.VerifyLong,
Example: docs.VerifyExample,
}
func doVerifyCmd(cpath, url string) error {
if sifGroupID != 0 && sifDescID != 0 {
return fmt.Errorf("only one of -i or -g may be set")
}
var isGroup bool
var id uint32
if sifGroupID != 0 {
isGroup = true
id = sifGroupID
} else {
id = sifDescID
}
return signing.Verify(cpath, url, id, isGroup, authToken)
}