What happened
:
Some REST API's HTTP methods are inappropriate.
What you expected to happen
:
How to reproduce it (as minimally and precisely as possible)
:
Anything else we need to know?
:
Environment
Proposed solution
:
cb-tumblebug/src/api/rest/server/server.go
- g.POST("/:nsId/resources/filterSpecs", rest_mcir.RestFilterSpecs)
- g.POST("/:nsId/resources/filterSpecsByRange", rest_mcir.RestFilterSpecsByRange)
- g.POST("/:nsId/resources/testSortSpecs", rest_mcir.RestTestSortSpecs)
-
- g.POST("/:nsId/resources/searchImage", rest_mcir.RestSearchImage)
+ g.GET("/:nsId/resources/filterSpecs", rest_mcir.RestFilterSpecs)
+ g.GET("/:nsId/resources/filterSpecsByRange", rest_mcir.RestFilterSpecsByRange)
+ g.GET("/:nsId/resources/testSortSpecs", rest_mcir.RestTestSortSpecs)
+
+ g.GET("/:nsId/resources/searchImage", rest_mcir.RestSearchImage)
In addition, related Swagger annotations also need to be updated.
cb-tumblebug/src/api/rest/server/mcir/spec.go
-// @Router /ns/{nsId}/resources/filterSpecs [post]
+// @Router /ns/{nsId}/resources/filterSpecs [get]
+ Swagger doc ํ์ผ๋ re-generate ํ์๋ฉด ์ข์ต๋๋ค.
๋ค๋ง ์ฒซ ๊ธฐ์ฌ์๊ป์ Swagger doc ํ์ผ ์
๋ฐ์ดํธ๊ฐ ์ด๋ ค์ฐ์๋ค๋ฉด
์ด ๋ถ๋ถ์ ๋นผ๊ณ PR์ ์ฌ๋ ค ์ฃผ์๋ฉด
CB-Tumblebug ๋ฉ์ธํ
์ด๋๊ฐ ์ถํ์ ๋ณ๋์ PR์์ Swagger doc ํ์ผ์ ์
๋ฐ์ดํธํ๋ ๊ฒ๋ ๊ฐ๋ฅํฉ๋๋ค. ๐
+ ๋ง์ฝ cb-webtool ์์ ํด๋น REST API ๋ฅผ ํ์ฉ์ค์ด์๋ค๋ฉด,
cb-webtool ์์ CB-Tumblebug ์ ํธ์ถํ๋ ๋ถ๋ถ์
HTTP method ๋ ์
๋ฐ์ดํธ๊ฐ ํ์ํฉ๋๋ค.
Any other context
:
@jihoon-seo
ํน์ ํด๋น REST method๋ Swagger API ์์ Body๊ฐ ์๋ GET method๋ฅผ ํ์ฉํ์ง ์์์,
์๋์ ์ผ๋ก POST method๋ก ์ง์ ํ ๊ฒ์ ์๋๊ฐ์? ^^
ref: https://github.com/cloud-barista/cb-tumblebug/discussions/502
@seokho-son ๋ง๋ค์.. ๊น๋นกํ์ต๋๋ค ๐ข
๋ค์ REST API๋ ํธ์ถํ ๋ JSON body๋ฅผ ์ ์ด์ผ ํ๋๋ฐ GET method๋ก ๋์ด ์์ต๋๋ค.
cb-tumblebug/src/api/rest/server/server.go
e.GET("/tumblebug/lookupSpec", rest_mcir.RestLookupSpec)
e.GET("/tumblebug/lookupImage", rest_mcir.RestLookupImage)
cb-tumblebug/src/api/rest/server/mcir/spec.go
// Request structure for RestLookupSpec
type RestLookupSpecRequest struct {
ConnectionName string `json:"connectionName"`
CspSpecName string `json:"cspSpecName"`
}
// RestLookupSpec godoc
// @Summary Lookup spec
// @Description Lookup spec
// @Tags [Admin] Cloud environment management
// @Accept json
// @Produce json
// @Param lookupSpecReq body RestLookupSpecRequest true "Specify connectionName & cspSpecName"
// @Success 200 {object} mcir.SpiderSpecInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /lookupSpec [get]
func RestLookupSpec(c echo.Context) error {
u := &RestLookupSpecRequest{}
if err := c.Bind(u); err != nil {
return err
}
fmt.Println("[Lookup spec]: " + u.CspSpecName)
content, err := mcir.LookupSpec(u.ConnectionName, u.CspSpecName)
if err != nil {
common.CBLog.Error(err)
return c.JSONBlob(http.StatusNotFound, []byte(err.Error()))
}
return c.JSON(http.StatusOK, &content)
}
cb-tumblebug/src/api/rest/server/mcir/image.go
// Request structure for RestLookupImage
type RestLookupImageRequest struct {
ConnectionName string `json:"connectionName"`
CspImageId string `json:"cspImageId"`
}
// RestLookupImage godoc
// @Summary Lookup image
// @Description Lookup image
// @Tags [Admin] Cloud environment management
// @Accept json
// @Produce json
// @Param lookupImageReq body RestLookupImageRequest true "Specify connectionName & cspImageId"
// @Success 200 {object} mcir.SpiderImageInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /lookupImage [get]
func RestLookupImage(c echo.Context) error {
u := &RestLookupImageRequest{}
if err := c.Bind(u); err != nil {
return err
}
fmt.Println("[Lookup image]: " + u.CspImageId)
content, err := mcir.LookupImage(u.ConnectionName, u.CspImageId)
if err != nil {
common.CBLog.Error(err)
return c.JSONBlob(http.StatusNotFound, []byte(err.Error()))
}
return c.JSON(http.StatusOK, &content)
}
์๋ REST API๋ค์ ์ผ๋ฐ์ ์ธ REST ์คํ์ผ๊ณผ ๋ค๋ฅด๊ฒ ๋์ด ์์ต๋๋ค.
e.GET("/tumblebug/lookupSpecs", rest_mcir.RestLookupSpecList)
e.GET("/tumblebug/lookupSpec", rest_mcir.RestLookupSpec)
e.GET("/tumblebug/lookupImages", rest_mcir.RestLookupImageList)
e.GET("/tumblebug/lookupImage", rest_mcir.RestLookupImage)
cf) ์ผ๋ฐ์ ์ธ REST ์คํ์ผ
e.GET("/tumblebug/region", rest_common.RestGetRegionList)
e.GET("/tumblebug/region/:regionName", rest_common.RestGetRegion)
@jihoon-seo
Request์ body ๊ฐ์ ๋ฃ์ด์ REST API๋ฅผ ํธ์ถํ๊ธฐ ์ํด์ method๋ฅผ e.GET ์์ e.POST ๋ก ๋ณ๊ฒฝํ๋ผ๋ ๋ป์ผ๋ก
์ดํดํ๋๋ฐ ํน์ ๋ง์๊น์?
@atg0831 ํ์ํฉ๋๋ค.. ^0^
@jihoon-seo ์ ๊ท ๊ธฐ์ฌ์๋ฅผ ์ํด, ํด๋น ์ด์์ ๋ํด์ ์กฐ๊ธ ์์ธํ๊ฒ ๊ฐ์ด๋ ๋ถํ ๋๋ ค๋ ๋ ๊น์? ^^