-
Notifications
You must be signed in to change notification settings - Fork 225
/
read.go
40 lines (31 loc) · 924 Bytes
/
read.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
package commands
import (
"encoding/json"
"fmt"
"os"
"code.cloudfoundry.org/gorouter/routeservice"
"code.cloudfoundry.org/gorouter/test_util/rss/common"
"github.com/codegangsta/cli"
)
func ReadSignature(c *cli.Context) {
sigEncoded := c.String("signature")
metaEncoded := c.String("metadata")
if sigEncoded == "" || metaEncoded == "" {
cli.ShowCommandHelp(c, "read")
os.Exit(1)
}
crypto, err := common.CreateCrypto(c)
if err != nil {
os.Exit(1)
}
signatureContents, err := routeservice.SignatureContentsFromHeaders(sigEncoded, metaEncoded, crypto)
if err != nil {
fmt.Printf("Failed to read signature: %s\n", err.Error())
os.Exit(1)
}
printSignatureContents(signatureContents)
}
func printSignatureContents(signatureContents routeservice.SignatureContents) {
signatureJson, _ := json.MarshalIndent(&signatureContents, "", " ")
fmt.Printf("Decoded Signature:\n%s\n\n", signatureJson)
}