83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"oci-portal/internal/oci"
|
|
)
|
|
|
|
// listRegions 返回本地维护的完整区域表(含友好名称),不发起云端请求。
|
|
func listRegions(c *gin.Context) {
|
|
regions, err := oci.AllRegions()
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, regions)
|
|
}
|
|
|
|
func (h *ociConfigHandler) regionSubscriptions(c *gin.Context) {
|
|
id, ok := pathID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
subs, err := h.svc.RegionSubscriptions(c.Request.Context(), id)
|
|
if err != nil {
|
|
respondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, subs)
|
|
}
|
|
|
|
type subscribeRegionRequest struct {
|
|
RegionKey string `json:"regionKey" binding:"required"`
|
|
}
|
|
|
|
func (h *ociConfigHandler) subscribeRegion(c *gin.Context) {
|
|
id, ok := pathID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
var req subscribeRegionRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
subs, err := h.svc.SubscribeRegion(c.Request.Context(), id, req.RegionKey)
|
|
if err != nil {
|
|
respondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, subs)
|
|
}
|
|
|
|
func (h *ociConfigHandler) limits(c *gin.Context) {
|
|
id, ok := pathID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
scopeType := strings.ToUpper(c.Query("scopeType"))
|
|
if scopeType != "" && scopeType != "GLOBAL" && scopeType != "REGION" && scopeType != "AD" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "scopeType must be GLOBAL / REGION / AD"})
|
|
return
|
|
}
|
|
q := oci.LimitsQuery{
|
|
Region: c.Query("region"),
|
|
Service: c.DefaultQuery("service", "compute"),
|
|
Name: c.Query("name"),
|
|
ScopeType: scopeType,
|
|
AvailabilityDomain: c.Query("availabilityDomain"),
|
|
NonZero: c.Query("nonZero") == "true",
|
|
WithAvailability: c.Query("withAvailability") == "true",
|
|
}
|
|
values, err := h.svc.Limits(c.Request.Context(), id, q)
|
|
if err != nil {
|
|
respondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, values)
|
|
}
|