-
Notifications
You must be signed in to change notification settings - Fork 0
/
keys.1.13.update_key_description.go
58 lines (47 loc) · 1.21 KB
/
keys.1.13.update_key_description.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
package keys
import (
"encoding/json"
"io"
"net/http"
"strings"
"github.com/snowpal/pitch-building-blocks-sdk/lib"
helpers2 "github.com/snowpal/pitch-building-blocks-sdk/lib/helpers"
"github.com/snowpal/pitch-building-blocks-sdk/lib/structs/response"
)
type UpdateKeyDescReqBody struct {
Description string `json:"keyDescription"`
}
func UpdateKeyDescription(jwtToken string, reqBody UpdateKeyDescReqBody, keyId string) (response.Key, error) {
resKey := response.Key{}
requestBody, err := helpers2.GetRequestBody(reqBody)
if err != nil {
return resKey, err
}
payload := strings.NewReader(requestBody)
var route string
route, err = helpers2.GetRoute(lib.RouteKeysUpdateKeyDescription, keyId)
if err != nil {
return resKey, err
}
var req *http.Request
req, err = http.NewRequest(http.MethodPatch, route, payload)
if err != nil {
return resKey, err
}
helpers2.AddUserHeaders(jwtToken, req)
var res *http.Response
res, err = helpers2.MakeRequest(req)
if err != nil {
return resKey, err
}
defer helpers2.CloseBody(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return resKey, err
}
err = json.Unmarshal(body, &resKey)
if err != nil {
return resKey, err
}
return resKey, nil
}