Cb-tumblebug: Fix some REST API's HTTP methods

Created on 12 Aug 2021  ยท  9Comments  ยท  Source: cloud-barista/cb-tumblebug

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

  • Source version or branch:
  • OS:
  • Others:

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
:

bug help wanted good first issue

All 9 comments

@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 ์‹ ๊ทœ ๊ธฐ์—ฌ์ž๋ฅผ ์œ„ํ•ด, ํ•ด๋‹น ์ด์Šˆ์— ๋Œ€ํ•ด์„œ ์กฐ๊ธˆ ์ƒ์„ธํ•˜๊ฒŒ ๊ฐ€์ด๋“œ ๋ถ€ํƒ ๋“œ๋ ค๋„ ๋ ๊นŒ์š”? ^^

Was this page helpful?
0 / 5 - 0 ratings