-
Notifications
You must be signed in to change notification settings - Fork 44
/
PublicImageRest.go
83 lines (65 loc) · 2.08 KB
/
PublicImageRest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Cloud Control Manager's Rest Runtime of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2022.09.
package restruntime
import (
cmrt "github.com/cloud-barista/cb-spider/api-runtime/common-runtime"
cres "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
// REST API (echo)
"net/http"
"net/url"
"github.com/labstack/echo/v4"
)
// ================ Image Handler
func ListImage(c echo.Context) error {
cblog.Info("call ListImage()")
var req struct {
ConnectionName string
}
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
// To support for Get-Query Param Type API
if req.ConnectionName == "" {
req.ConnectionName = c.QueryParam("ConnectionName")
}
// Call common-runtime API
result, err := cmrt.ListImage(req.ConnectionName, rsImage)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
var jsonResult struct {
Result []*cres.ImageInfo `json:"image"`
}
jsonResult.Result = result
return c.JSON(http.StatusOK, &jsonResult)
}
func GetImage(c echo.Context) error {
cblog.Info("call GetImage()")
var req struct {
ConnectionName string
}
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
// To support for Get-Query Param Type API
if req.ConnectionName == "" {
req.ConnectionName = c.QueryParam("ConnectionName")
}
// Call common-runtime API
encodededImageName := c.Param("Name")
decodedImageName, err := url.QueryUnescape(encodededImageName)
if err != nil {
cblog.Fatal(err)
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
result, err := cmrt.GetImage(req.ConnectionName, rsImage, decodedImageName)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
return c.JSON(http.StatusOK, result)
}