Skip to content

Commit 22d0b73

Browse files
authored
fix: fix model deployment style issues, lint problems, and i18n gaps. (#2556)
* fix: fix model deployment style issues, lint problems, and i18n gaps. * fix: adjust the key not to be displayed on the frontend, tested via the backend. * fix: adjust the sidebar configuration logic to use the default configuration items if they are not defined.
1 parent e8aaed4 commit 22d0b73

29 files changed

+5464
-2859
lines changed

controller/deployment.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controller
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"fmt"
57
"strconv"
68
"strings"
@@ -23,6 +25,20 @@ func getIoAPIKey(c *gin.Context) (string, bool) {
2325
return apiKey, true
2426
}
2527

28+
func GetModelDeploymentSettings(c *gin.Context) {
29+
common.OptionMapRWMutex.RLock()
30+
enabled := common.OptionMap["model_deployment.ionet.enabled"] == "true"
31+
hasAPIKey := strings.TrimSpace(common.OptionMap["model_deployment.ionet.api_key"]) != ""
32+
common.OptionMapRWMutex.RUnlock()
33+
34+
common.ApiSuccess(c, gin.H{
35+
"provider": "io.net",
36+
"enabled": enabled,
37+
"configured": hasAPIKey,
38+
"can_connect": enabled && hasAPIKey,
39+
})
40+
}
41+
2642
func getIoClient(c *gin.Context) (*ionet.Client, bool) {
2743
apiKey, ok := getIoAPIKey(c)
2844
if !ok {
@@ -44,15 +60,28 @@ func TestIoNetConnection(c *gin.Context) {
4460
APIKey string `json:"api_key"`
4561
}
4662

47-
if err := c.ShouldBindJSON(&req); err != nil {
48-
common.ApiErrorMsg(c, "invalid request payload")
63+
rawBody, err := c.GetRawData()
64+
if err != nil {
65+
common.ApiError(c, err)
4966
return
5067
}
68+
if len(bytes.TrimSpace(rawBody)) > 0 {
69+
if err := json.Unmarshal(rawBody, &req); err != nil {
70+
common.ApiErrorMsg(c, "invalid request payload")
71+
return
72+
}
73+
}
5174

5275
apiKey := strings.TrimSpace(req.APIKey)
5376
if apiKey == "" {
54-
common.ApiErrorMsg(c, "api_key is required")
55-
return
77+
common.OptionMapRWMutex.RLock()
78+
storedKey := strings.TrimSpace(common.OptionMap["model_deployment.ionet.api_key"])
79+
common.OptionMapRWMutex.RUnlock()
80+
if storedKey == "" {
81+
common.ApiErrorMsg(c, "api_key is required")
82+
return
83+
}
84+
apiKey = storedKey
5685
}
5786

5887
client := ionet.NewEnterpriseClient(apiKey)

controller/option.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ func GetOptions(c *gin.Context) {
2020
var options []*model.Option
2121
common.OptionMapRWMutex.Lock()
2222
for k, v := range common.OptionMap {
23-
if strings.HasSuffix(k, "Token") || strings.HasSuffix(k, "Secret") || strings.HasSuffix(k, "Key") {
23+
if strings.HasSuffix(k, "Token") ||
24+
strings.HasSuffix(k, "Secret") ||
25+
strings.HasSuffix(k, "Key") ||
26+
strings.HasSuffix(k, "secret") ||
27+
strings.HasSuffix(k, "api_key") {
2428
continue
2529
}
2630
options = append(options, &model.Option{

router/api-router.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,18 @@ func SetApiRouter(router *gin.Engine) {
269269
deploymentsRoute := apiRouter.Group("/deployments")
270270
deploymentsRoute.Use(middleware.AdminAuth())
271271
{
272-
// List and search deployments
272+
deploymentsRoute.GET("/settings", controller.GetModelDeploymentSettings)
273+
deploymentsRoute.POST("/settings/test-connection", controller.TestIoNetConnection)
273274
deploymentsRoute.GET("/", controller.GetAllDeployments)
274275
deploymentsRoute.GET("/search", controller.SearchDeployments)
275-
276-
// Connection utilities
277276
deploymentsRoute.POST("/test-connection", controller.TestIoNetConnection)
278-
279-
// Resource and configuration endpoints
280277
deploymentsRoute.GET("/hardware-types", controller.GetHardwareTypes)
281278
deploymentsRoute.GET("/locations", controller.GetLocations)
282279
deploymentsRoute.GET("/available-replicas", controller.GetAvailableReplicas)
283280
deploymentsRoute.POST("/price-estimation", controller.GetPriceEstimation)
284281
deploymentsRoute.GET("/check-name", controller.CheckClusterNameAvailability)
285-
286-
// Create new deployment
287282
deploymentsRoute.POST("/", controller.CreateDeployment)
288283

289-
// Individual deployment operations
290284
deploymentsRoute.GET("/:id", controller.GetDeployment)
291285
deploymentsRoute.GET("/:id/logs", controller.GetDeploymentLogs)
292286
deploymentsRoute.GET("/:id/containers", controller.ListDeploymentContainers)
@@ -295,14 +289,6 @@ func SetApiRouter(router *gin.Engine) {
295289
deploymentsRoute.PUT("/:id/name", controller.UpdateDeploymentName)
296290
deploymentsRoute.POST("/:id/extend", controller.ExtendDeployment)
297291
deploymentsRoute.DELETE("/:id", controller.DeleteDeployment)
298-
299-
// Future batch operations:
300-
// deploymentsRoute.POST("/:id/start", controller.StartDeployment)
301-
// deploymentsRoute.POST("/:id/stop", controller.StopDeployment)
302-
// deploymentsRoute.POST("/:id/restart", controller.RestartDeployment)
303-
// deploymentsRoute.POST("/batch_delete", controller.BatchDeleteDeployments)
304-
// deploymentsRoute.POST("/batch_start", controller.BatchStartDeployments)
305-
// deploymentsRoute.POST("/batch_stop", controller.BatchStopDeployments)
306292
}
307293
}
308294
}

web/i18next.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export default defineConfig({
2525
"zh",
2626
"en",
2727
"fr",
28-
"ru"
28+
"ru",
29+
"ja",
30+
"vi"
2931
],
3032
extract: {
3133
input: [

0 commit comments

Comments
 (0)