-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
68 lines (62 loc) · 1.74 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"time"
"github.com/kubemq-io/kubemq-go"
"github.com/kubemq-io/kubemq-targets/pkg/uuid"
"github.com/kubemq-io/kubemq-targets/types"
)
func main() {
dat, err := ioutil.ReadFile("./credentials/aws/redshift-svc/resourceARN.txt")
if err != nil {
log.Fatal(err)
}
resourceARN := string(dat)
client, err := kubemq.NewClient(context.Background(),
kubemq.WithAddress("kubemq-cluster", 50000),
kubemq.WithClientId(uuid.New().String()),
kubemq.WithTransportType(kubemq.TransportTypeGRPC))
if err != nil {
log.Fatal(err)
}
// Create tag
tags := make(map[string]string)
tags["test-key"] = "test-value"
b, err := json.Marshal(tags)
if err != nil {
log.Fatal(err)
}
createRequest := types.NewRequest().
SetMetadataKeyValue("method", "create_tags").
SetMetadataKeyValue("resource_arn", resourceARN).
SetData(b)
getCreate, err := client.SetQuery(createRequest.ToQuery()).
SetChannel("query.aws.redshift.service").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
createResponse, err := types.ParseResponse(getCreate.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("create tag executed, error: %v", createResponse.IsError))
// listRequest
listRequest := types.NewRequest().
SetMetadataKeyValue("method", "list_tags")
queryListResponse, err := client.SetQuery(listRequest.ToQuery()).
SetChannel("query.aws.redshift.service").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
listResponse, err := types.ParseResponse(queryListResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("list tags executed, response: %s", listResponse.Data))
}