-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
46 lines (37 loc) · 1 KB
/
main.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
package main
import (
"context"
"encoding/base64"
"fmt"
"os"
"github.com/venafi/vsign/pkg/endpoint"
"github.com/venafi/vsign/pkg/vsign"
)
func main() {
vSignCfg, err := vsign.BuildConfigWithAuth(context.Background(), os.Getenv("TPP_URL"), &endpoint.Authentication{}, "")
if err != nil {
panic(fmt.Errorf("error building config"))
}
vSignCfg.Credentials.AccessToken = os.Getenv("ACCESS_TOKEN")
vSignCfg.Project = os.Getenv("TPP_PROJECT")
connector, err := vsign.NewClient(&vSignCfg)
if err != nil {
panic(fmt.Errorf("unable to connect to %s: %s", vSignCfg.ConnectorType, err))
}
e, err := connector.GetEnvironment()
if err != nil {
panic(fmt.Errorf(err.Error()))
}
sig, err := connector.Sign(&endpoint.SignOption{
KeyID: e.KeyID,
Mechanism: 64,
DigestAlg: "sha256",
Payload: []byte(base64.StdEncoding.EncodeToString([]byte("this is a test payload"))),
B64Flag: true,
RawFlag: false,
})
if err != nil {
panic(err)
}
fmt.Println(base64.StdEncoding.EncodeToString(sig))
}