Newer
Older
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
package akmsCkmsClient
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type CkmsAkmsClient struct {
url string
}
func NewCkmsAkmsClient(url string) CkmsAkmsClient {
return CkmsAkmsClient{
url: url,
}
}
type PushKSAKeyRequest struct {
RequestID string `json:"request_ID"`
ProcessID string `json:"process_ID"`
KSAKeys []KSAKey `json:"ksa_keys"`
}
type KSAKey struct {
KeyID string `json:"key_ID"`
Key string `json:"key"`
}
func (c *CkmsAkmsClient) SendKSAKeys(requestID string, processID string, ksaKeys []KSAKey) error {
pushRequest := PushKSAKeyRequest{
RequestID: requestID,
ProcessID: processID,
KSAKeys: ksaKeys,
}
jsonData, err := json.Marshal(pushRequest)
if err != nil {
fmt.Println("Error marshaling JSON:", err)
return err
}
resp, err := http.Post(c.url, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error sending POST request:", err)
return err
}
err = resp.Body.Close()
if err != nil {
fmt.Println("Error closing response body:", err)
}
if resp.StatusCode != http.StatusNoContent {
fmt.Println("Unexpected response status code:", resp.StatusCode)
return err
}
return nil
}