forked from cloudfoundry/gorouter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.go
40 lines (31 loc) · 867 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"
"github.com/cloudfoundry/gorouter/route_service"
"github.com/cloudfoundry/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)
}
signature, err := route_service.SignatureFromHeaders(sigEncoded, metaEncoded, crypto)
if err != nil {
fmt.Printf("Failed to read signature: %s\n", err.Error())
os.Exit(1)
}
printSignature(signature)
}
func printSignature(signature route_service.Signature) {
signatureJson, _ := json.MarshalIndent(&signature, "", " ")
fmt.Printf("Decoded Signature:\n%s\n\n", signatureJson)
}