CloudWatch: Refactor around handleGetRegions (#65713)

* Create minimal EC2 interface

* convert regions variable to a function returning a copy

* Add test for multiple calls to regions to check regionsCache

* Add returns to handler after error

* Refactor handleGetRegions
This commit is contained in:
Shirley
2023-04-11 19:55:57 +02:00
committed by GitHub
parent 92e591d2e1
commit ae23ef5b41
8 changed files with 129 additions and 42 deletions
+4
View File
@@ -37,19 +37,23 @@ func handleResourceReq(handleFunc handleFn) func(rw http.ResponseWriter, req *ht
err := req.ParseForm()
if err != nil {
writeResponse(rw, http.StatusBadRequest, fmt.Sprintf("unexpected error %v", err))
return
}
data, err := handleFunc(pluginContext, req.URL.Query())
if err != nil {
writeResponse(rw, http.StatusBadRequest, fmt.Sprintf("unexpected error %v", err))
return
}
body, err := json.Marshal(data)
if err != nil {
writeResponse(rw, http.StatusBadRequest, fmt.Sprintf("unexpected error %v", err))
return
}
rw.WriteHeader(http.StatusOK)
_, err = rw.Write(body)
if err != nil {
logger.Error("Unable to write HTTP response", "error", err)
return
}
}
}