)
// DoGet is for get request
-func DoGet(targetURL string) (respBytes []byte, statusCode int, err error) {
- req, err := http.NewRequest("GET", targetURL, nil)
+func DoGet(targetURL string, pbytes []byte) (respBytes []byte, statusCode int, err error) {
+ if len(pbytes) == 0 {
+ log.Printf("DoGet body length is zero(0) !!")
+ }
+
+ encryptedReqByte, err := securemgr.EncryptByte(pbytes)
if err != nil {
+ log.Println("data encryption failed !!")
+ respBytes = nil
return
}
+ buff := bytes.NewBuffer(encryptedReqByte)
+
+ req, err := http.NewRequest("GET", targetURL, buff)
+ if err != nil {
+ return
+ }
+
+ // Content-Type Header
+ req.Header.Add("Content-Type", "application/json")
+
var netTransport = &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
defer resp.Body.Close()
+ // @TODO: decrypt only if status is OK
statusCode = resp.StatusCode
encryptedRespByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
defer resp.Body.Close()
+ // @TODO: decrypt only if status is OK
statusCode = resp.StatusCode
encryptedRespByte, err := ioutil.ReadAll(resp.Body)
if err != nil {
// DoGetScoreRemoteDevice for getting score in remote device
func DoGetScoreRemoteDevice(appName string, target string) (scoreValue float64, err error) {
targetURL := ConstPrefixHTTP + target + ":" +
- strconv.Itoa(ConstWellknownPort) + ConstGetScoreURI + appName
+ strconv.Itoa(ConstWellknownPort) + ConstGetScoreURI
- respBytes, statusCode, err := DoGet(targetURL)
+ appNameInfo := make(map[string]interface{})
+ appNameInfo["appName"] = appName
+
+ reqbytes, err := json.Marshal(appNameInfo)
+ if common.CheckError(err) == true {
+ return
+ }
+
+ respBytes, statusCode, err := DoGet(targetURL, reqbytes)
if common.CheckError(err) == true {
return scoreValue, err
}
ConstServiceExecuteURI = "/api/v1/servicemgr/services"
// ConstGetScoreURI is URI for getting score value
- ConstGetScoreURI = "/api/v1/scoringmgr/score/"
+ ConstGetScoreURI = "/api/v1/scoringmgr/score"
// ConstServiceStatusNotiURI is URI for notification status of service
ConstServiceStatusNotiURI = "/api/v1/servicemgr/services/notification/"
"os/exec"
"restapi/httpclient"
- "github.com/gorilla/mux"
-
"discoverymgr"
"scoringmgr"
"securemgr"
func APIV1ScoringmgrScoreLibnameGet(w http.ResponseWriter, r *http.Request) {
log.Printf("[%s] APIV1ScoringmgrScoreLibnameGet", logPrefix)
- vars := mux.Vars(r)
- libName := vars["libname"]
+ // vars := mux.Vars(r)
+ // libName := vars["libname"]
+ // name := libName
+
+ encryptedReqByte, _ := ioutil.ReadAll(r.Body)
+ appNameInfo, err := securemgr.DecryptByteToJson(encryptedReqByte)
+ if err != nil {
+ return
+ }
+
+ name := appNameInfo["appName"]
- name := libName
target := httpclient.ConstLocalTarget
- scoreValue, err := scoringmgr.GetScore(target, name)
+ scoreValue, err := scoringmgr.GetScore(target, name.(string))
respInfo := make(map[string]interface{})
respInfo["ScoreValue"] = scoreValue
package v1
import (
+ "common"
"encoding/json"
"log"
"net/http"
log.Println("testURL:", testURL)
}
-func TestAPIV1DiscoverymgrDevicesGet(t *testing.T) {
- targetURI := ConstDiscoverymgrDevices
- testGet(t, targetURI, http.StatusOK)
-}
+// func TestAPIV1DiscoverymgrDevicesGet(t *testing.T) {
+// targetURI := ConstDiscoverymgrDevices
+// testGet(t, targetURI, http.StatusOK, nil)
+// }
func TestAPIV1DiscoverymgrDevicesPost(t *testing.T) {
getDevice(t, ConstDiscoverymgrDevices, ConstAppName, http.StatusOK)
func TestAPIV1ScoringmgrScoreLibnameGet(t *testing.T) {
targetURI := ConstScoremgrScore
- testGet(t, targetURI+"/mysum", http.StatusOK)
+
+ appNameInfoSample := make(map[string]interface{})
+ appNameSample := "/usr/share/mysum"
+ appNameInfoSample["appName"] = appNameSample
+
+ reqbytes, err := json.Marshal(appNameInfoSample)
+
+ if common.CheckError(err) == true {
+ return
+ }
+
+ testGet(t, targetURI, reqbytes)
}
func TestAPIV1ServicemgrServicesNotificationServiceIDPost(t *testing.T) {
}
}
-func testGet(t *testing.T, targetURI string, statusCode int) {
+func testGet(t *testing.T, targetURI string, reqbytes []byte) {
t.Helper()
- resByte, resStatusCode, err := httpclient.DoGet(testURL + targetURI)
+ resByte, resStatusCode, err := httpclient.DoGet(testURL+targetURI, reqbytes)
if err != nil {
t.Log(err.Error())
t.Error()
t.Error()
}
- AssertEqualInt(t, resStatusCode, statusCode)
+ AssertEqualInt(t, resStatusCode, http.StatusOK)
return
}
Route{
"APIV1ScoringmgrScoreLibnameGet",
strings.ToUpper("Get"),
- "/api/v1/scoringmgr/score/{libname}",
+ "/api/v1/scoringmgr/score",
APIV1ScoringmgrScoreLibnameGet,
},
}
}
if strings.Compare(target, outboundIP) == 0 || strings.Compare(target, httpclient.ConstLocalTarget) == 0 {
+ log.Println("getScoreLocalEnv(): ", name, ", IP:", target)
scoreValue, err = getScoreLocalEnv(name)
} else {
+ log.Println("DoGetScoreRemoteDevice(): ", name, ", IP:", target)
scoreValue, err = httpclient.DoGetScoreRemoteDevice(name, target)
}