-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
49 lines (40 loc) · 1.26 KB
/
client.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
// Copyright © 2021 HyTrust, Inc. All Rights Reserved.
package main
import (
"context"
"log"
"time"
"google.golang.org/grpc"
k8spb "src/v1beta1"
)
func main() {
cc, err := grpc.Dial("unix:///etc/kubernetes/pki/test.sock", grpc.WithInsecure())
if err != nil {
log.Fatal("Socket creation failed: %v", err)
}
defer cc.Close()
c := k8spb.NewKeyManagementServiceClient(cc)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
version := "1"
r, err := c.Version(ctx, &k8spb.VersionRequest{Version: version})
if err != nil {
log.Fatal("Could not check version: %v", err)
}
log.Printf("Version: %s", r.GetVersion())
log.Printf("Name: %s", r.GetRuntimeName())
log.Printf("RuntimeVersion: %s", r.GetRuntimeVersion())
b := []byte("teststring")
encOut, err := c.Encrypt(ctx, &k8spb.EncryptRequest{Plain: b})
if err != nil {
log.Fatal("Could not encrypt: %v", err)
}
ctext := encOut.GetCipher()
log.Printf("Cipher: %s", ctext)
decOut, err := c.Decrypt(ctx, &k8spb.DecryptRequest{Cipher: ctext})
if err != nil {
log.Fatal("Could not encrypt: %v", err)
}
ptext := decOut.GetPlain()
log.Printf("Plain: %s", ptext)
}