From 08bf357db48c2e67f6c4c4d532d7c9d80aa26874 Mon Sep 17 00:00:00 2001 From: zhangjianjun Date: Wed, 30 Mar 2022 17:47:45 +0800 Subject: [PATCH] Calling the interface put error of gitee --- cve-vulner-manager/taskhandler/issue.go | 2 +- cve-vulner-manager/util/http.go | 43 ++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cve-vulner-manager/taskhandler/issue.go b/cve-vulner-manager/taskhandler/issue.go index 28231d1..9330b46 100644 --- a/cve-vulner-manager/taskhandler/issue.go +++ b/cve-vulner-manager/taskhandler/issue.go @@ -257,7 +257,7 @@ func UpdateEntIssueDetail(enterpriseId, issueId int64, token, planAt, deadLine s "deadline": "%s", "priority": "%v" }`, token, planAt, deadLine, priority) - resp, err := util.HTTPPatch(url, requestBody) + resp, err := util.HTTPPutMap(url, requestBody) if err != nil { logs.Error("UpdateEntIssueDetail, Update issue failed, issueId: ", issueId, ",err: ", err) diff --git a/cve-vulner-manager/util/http.go b/cve-vulner-manager/util/http.go index e02242d..8ba2c0e 100644 --- a/cve-vulner-manager/util/http.go +++ b/cve-vulner-manager/util/http.go @@ -321,7 +321,7 @@ func HTTPPut(url string, requestBody string) ([]map[string]interface{}, error) { client := &http.Client{} resp, err := client.Do(req) if err != nil { - logs.Error("PATCH request failed, err: ", err, "body: ", requestBody, "url:", url) + logs.Error("PUT request failed, err: ", err, "body: ", requestBody, "url:", url) return nil, err } defer resp.Body.Close() @@ -348,6 +348,47 @@ func HTTPPut(url string, requestBody string) ([]map[string]interface{}, error) { return iss, nil } +func HTTPPutMap(url string, requestBody string) (map[string]interface{}, error) { + req, err := http.NewRequest("PUT", url, bytes.NewBuffer([]byte(requestBody))) + urls := strings.Split(url, "access_token") + if len(urls) > 0 { + url = urls[0] + } + defer common.Catchs() + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/json") + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + logs.Error("PUT request failed, err: ", err, "body: ", requestBody, "url:", url) + return nil, err + } + defer resp.Body.Close() + logs.Info("response Status:", resp.Status, "url: ", url) + logs.Info("response Headers:", resp.Header, "url: ", url) + status, _ := strconv.Atoi(resp.Status) + if status > 300 { + logs.Error("Patch request failed, err: ", err, "body: ", requestBody, "url:", url) + return nil, err + } + body, err := ioutil.ReadAll(resp.Body) + fmt.Println("response Body:", string(body)) + if err != nil || body == nil || len(body) == 0 { + logs.Error("PUT failed, err: ", err, "body: ", requestBody) + return nil, err + } + logs.Info("PUT successed!, body: ", string(body)) + var iss map[string]interface{} + err = json.Unmarshal(body, &iss) + if err != nil { + logs.Error(err, string(body)) + return nil, err + } + return iss, nil +} + func HTTPPostCom(req map[string]interface{}, url string) ([]byte, error) { logs.Info("post req_body: ", req) bytesData, err := json.Marshal(req) -- Gitee