This repository has been archived by the owner on Oct 23, 2021. It is now read-only.
/
pfd_app_transaction_put.go
102 lines (83 loc) · 2.45 KB
/
pfd_app_transaction_put.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2020 Intel Corporation
package af
import (
"context"
"encoding/json"
"net/http"
)
func putPfdAppTransaction(cliCtx context.Context, pfdTs PfdData,
afCtx *Context, pfdID string, appID string) (PfdData,
*http.Response, []byte, error) {
cliCfg := NewConfiguration(afCtx)
cli := NewClient(cliCfg)
tsRet, resp, respBody, err :=
cli.PfdManagementAppPutAPI.PfdAppTransactionPut(cliCtx,
afCtx.cfg.AfID, pfdID, appID, pfdTs)
if err != nil {
return PfdData{}, resp, respBody, err
}
return tsRet, resp, respBody, nil
}
// PutPfdAppTransaction function
func PutPfdAppTransaction(w http.ResponseWriter, r *http.Request) {
var (
err error
pfdTs PfdData
resp *http.Response
pfdTransactionID string
appID string
pfdRsp PfdData
pfdRespJSON []byte
respBody []byte
)
afCtx := r.Context().Value(keyType("af-ctx")).(*Context)
if afCtx == nil {
errRspHeader(&w, "APP PUT", "af-ctx retrieved from request is nil",
http.StatusInternalServerError)
return
}
cliCtx, cancel := context.WithCancel(context.Background())
defer cancel()
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
if err = json.NewDecoder(r.Body).Decode(&pfdTs); err != nil {
errRspHeader(&w, "APP PUT", err.Error(), http.StatusBadRequest)
return
}
pfdTransactionID = getPfdTransIDFromURL(r)
appID = getPfdAppIDFromURL(r)
pfdRsp, resp, respBody, err = putPfdAppTransaction(cliCtx, pfdTs, afCtx,
pfdTransactionID, appID)
// TBD how to validate the PUT response
if err != nil {
log.Errf("Pfd Management App Put : %s", err.Error())
if resp != nil {
w.WriteHeader(getStatusCode(resp))
if _, err = w.Write(respBody); err != nil {
errRspHeader(&w, "APP PUT", err.Error(),
http.StatusInternalServerError)
return
}
} else {
w.WriteHeader(http.StatusInternalServerError)
}
return
}
// Updating the Self Application Link
self, err := updateAppLink(afCtx.cfg, r, pfdRsp)
if err != nil {
errRspHeader(&w, "APP PUT", err.Error(), http.StatusInternalServerError)
return
}
pfdRsp.Self = Link(self)
pfdRespJSON, err = json.Marshal(pfdRsp)
if err != nil {
errRspHeader(&w, "APP PUT", err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(resp.StatusCode)
if _, err = w.Write(pfdRespJSON); err != nil {
errRspHeader(&w, "APP PUT", err.Error(), http.StatusInternalServerError)
return
}
}