Skip to content

Commit

Permalink
Add the Tumblebug endpoint to config
Browse files Browse the repository at this point in the history
  • Loading branch information
yunkon-kim committed May 24, 2024
1 parent c53c96d commit 6cab49e
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 273 deletions.
5 changes: 3 additions & 2 deletions cmd/cm-beetle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func main() {
}
log.Debug().Msgf("port number: %s", *port)

common.SpiderRestUrl = common.NVL(os.Getenv("SPIDER_REST_URL"), "http://localhost:1024/spider")
common.DragonflyRestUrl = common.NVL(os.Getenv("DRAGONFLY_REST_URL"), "http://localhost:9090/dragonfly")
// common.SpiderRestUrl = common.NVL(os.Getenv("SPIDER_REST_URL"), "http://localhost:1024/spider")
// common.DragonflyRestUrl = common.NVL(os.Getenv("DRAGONFLY_REST_URL"), "http://localhost:9090/dragonfly")
common.TumblebugRestUrl = common.NVL(os.Getenv("TUMBLEBUG_REST_URL"), "http://localhost:1323/tumblebug")
common.DBUrl = common.NVL(os.Getenv("DB_URL"), "localhost:3306")
common.DBDatabase = common.NVL(os.Getenv("DB_DATABASE"), "cb_beetle")
common.DBUser = common.NVL(os.Getenv("DB_USER"), "cb_beetle")
Expand Down
4 changes: 2 additions & 2 deletions conf/setup.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export CBSTORE_ROOT=$CMBEETLE_ROOT
export CBLOG_ROOT=$CMBEETLE_ROOT
#export CBSPIDER_CALLMETHOD=REST
#export CBSPIDER_REST_URL=http://localhost:1024/spider
#export CBTUMBLEBUG_CALLMETHOD=REST
#export CBTUMBLEBUG_REST_URL=http://localhost:1323/tumblebug
export CBTUMBLEBUG_CALLMETHOD=REST
export CBTUMBLEBUG_REST_URL=http://localhost:1323/tumblebug

## Logger configuration
# Set log file path (default logfile path: ./cm-beetle.log)
Expand Down
74 changes: 37 additions & 37 deletions pkg/core/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,40 +326,40 @@ func EndRequestWithLog(c echo.Context, reqID string, err error, responseData int
return c.JSON(http.StatusNotFound, map[string]string{"message": "Invalid Request ID"})
}

// ForwardRequestToAny forwards the given request to the specified path
func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) (interface{}, error) {
client := resty.New()
var callResult interface{}

url := SpiderRestUrl + "/" + reqPath

var requestBodyBytes []byte
var ok bool
if requestBodyBytes, ok = requestBody.([]byte); !ok {
return nil, fmt.Errorf("requestBody is not []byte type")
}

var requestBodyMap map[string]interface{}
err := json.Unmarshal(requestBodyBytes, &requestBodyMap)
if err != nil {
return nil, fmt.Errorf("JSON unmarshal error: %v", err)
}

err = ExecuteHttpRequest(
client,
method,
url,
nil,
SetUseBody(requestBodyMap),
&requestBodyMap,
&callResult,
MediumDuration,
)

if err != nil {
log.Error().Err(err).Msg("")
return nil, err
}

return callResult, nil
}
// // ForwardRequestToAny forwards the given request to the specified path
// func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) (interface{}, error) {
// client := resty.New()
// var callResult interface{}

// url := SpiderRestUrl + "/" + reqPath

// var requestBodyBytes []byte
// var ok bool
// if requestBodyBytes, ok = requestBody.([]byte); !ok {
// return nil, fmt.Errorf("requestBody is not []byte type")
// }

// var requestBodyMap map[string]interface{}
// err := json.Unmarshal(requestBodyBytes, &requestBodyMap)
// if err != nil {
// return nil, fmt.Errorf("JSON unmarshal error: %v", err)
// }

// err = ExecuteHttpRequest(
// client,
// method,
// url,
// nil,
// SetUseBody(requestBodyMap),
// &requestBodyMap,
// &callResult,
// MediumDuration,
// )

// if err != nil {
// log.Error().Err(err).Msg("")
// return nil, err
// }

// return callResult, nil
// }
10 changes: 6 additions & 4 deletions pkg/core/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ var SystemReady bool
var CBLog *logrus.Logger
var CBStore icbs.Store

var SpiderRestUrl string
var DragonflyRestUrl string
// var SpiderRestUrl string
// var DragonflyRestUrl string
var TumblebugRestUrl string
var DBUrl string
var DBDatabase string
var DBUser string
Expand All @@ -50,8 +51,9 @@ var err error
var ORM *xorm.Engine

const (
StrSpiderRestUrl string = "SPIDER_REST_URL"
StrDragonflyRestUrl string = "DRAGONFLY_REST_URL"
// StrSpiderRestUrl string = "SPIDER_REST_URL"
// StrDragonflyRestUrl string = "DRAGONFLY_REST_URL"
StrTumblebugRestUrl string = "TUMBLEBUG_REST_URL"
StrDBUrl string = "DB_URL"
StrDBDatabase string = "DB_DATABASE"
StrDBUser string = "DB_USER"
Expand Down
30 changes: 18 additions & 12 deletions pkg/core/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ func UpdateGlobalVariable(id string) error {
}

switch id {
case StrSpiderRestUrl:
SpiderRestUrl = configInfo.Value
fmt.Println("<SPIDER_REST_URL> " + SpiderRestUrl)
case StrDragonflyRestUrl:
DragonflyRestUrl = configInfo.Value
fmt.Println("<DRAGONFLY_REST_URL> " + DragonflyRestUrl)
// case StrSpiderRestUrl:
// SpiderRestUrl = configInfo.Value
// fmt.Println("<SPIDER_REST_URL> " + SpiderRestUrl)
// case StrDragonflyRestUrl:
// DragonflyRestUrl = configInfo.Value
// fmt.Println("<DRAGONFLY_REST_URL> " + DragonflyRestUrl)
case StrTumblebugRestUrl:
TumblebugRestUrl = configInfo.Value
fmt.Println("<TUMBELBUG_REST_URL> " + TumblebugRestUrl)
case StrDBUrl:
DBUrl = configInfo.Value
fmt.Println("<DB_URL> " + DBUrl)
Expand All @@ -167,12 +170,15 @@ func UpdateGlobalVariable(id string) error {
func InitConfig(id string) error {

switch id {
case StrSpiderRestUrl:
SpiderRestUrl = NVL(os.Getenv("SPIDER_REST_URL"), "http://localhost:1024/spider")
fmt.Println("<SPIDER_REST_URL> " + SpiderRestUrl)
case StrDragonflyRestUrl:
DragonflyRestUrl = NVL(os.Getenv("DRAGONFLY_REST_URL"), "http://localhost:9090/dragonfly")
fmt.Println("<DRAGONFLY_REST_URL> " + DragonflyRestUrl)
// case StrSpiderRestUrl:
// SpiderRestUrl = NVL(os.Getenv("SPIDER_REST_URL"), "http://localhost:1024/spider")
// fmt.Println("<SPIDER_REST_URL> " + SpiderRestUrl)
// case StrDragonflyRestUrl:
// DragonflyRestUrl = NVL(os.Getenv("DRAGONFLY_REST_URL"), "http://localhost:9090/dragonfly")
// fmt.Println("<DRAGONFLY_REST_URL> " + DragonflyRestUrl)
case StrTumblebugRestUrl:
TumblebugRestUrl = NVL(os.Getenv("TUMBLEBUG_REST_URL"), "http://localhost:1323/tumblebug")
fmt.Println("<TUMBLEBUG_REST_URL> " + TumblebugRestUrl)
case StrDBUrl:
DBUrl = NVL(os.Getenv("DB_URL"), "localhost:3306")
fmt.Println("<DB_URL> " + DBUrl)
Expand Down
Loading

0 comments on commit 6cab49e

Please sign in to comment.