You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/07 10:28:48 UTC

[GitHub] [apisix-dashboard] nic-chen commented on a change in pull request #2362: feat: storage grafana path in to etcd

nic-chen commented on a change in pull request #2362:
URL: https://github.com/apache/apisix-dashboard/pull/2362#discussion_r820568610



##########
File path: api/internal/handler/handler_test.go
##########
@@ -38,7 +38,7 @@ func TestSpecCodeResponse(t *testing.T) {
 	resp = SpecCodeResponse(err)
 	assert.Equal(t, &data.SpecCodeResponse{StatusCode: http.StatusNotFound}, resp)
 
-	err = errors.New("system error")
+	err = errors.New("system_config error")

Review comment:
       why change this?

##########
File path: api/internal/core/entity/entity.go
##########
@@ -304,3 +304,12 @@ type StreamRoute struct {
 	UpstreamID interface{}            `json:"upstream_id,omitempty"`
 	Plugins    map[string]interface{} `json:"plugins,omitempty"`
 }
+
+// swagger:model SystemConfig
+type SystemConfig struct {
+	ConfigName string                 `json:"config_name"`
+	Desc       string                 `json:"desc,omitempty"`
+	Payload    map[string]interface{} `json:"payload,omitempty"`

Review comment:
       does `Payload` need to be a map? maybe some configurations are string, float, or something?

##########
File path: api/internal/handler/system_config/system_config.go
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package system_config
+
+import (
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/apisix/manager-api/internal/handler"
+	"github.com/gin-gonic/gin"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/shiningrush/droplet/wrapper"
+	wgin "github.com/shiningrush/droplet/wrapper/gin"
+	"net/http"
+	"reflect"
+	"time"
+)
+
+type Handler struct {
+	systemConfig store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+	return &Handler{
+		systemConfig: store.GetStore(store.HubKeySystemConfig),
+	}, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+	r.GET("/apisix/admin/system_config/:config_name", wgin.Wraps(h.Get,
+		wrapper.InputType(reflect.TypeOf(GetInput{}))))
+	r.POST("/apisix/admin/system_config", wgin.Wraps(h.Post,
+		wrapper.InputType(reflect.TypeOf(entity.SystemConfig{}))))
+	r.PUT("/apisix/admin/system_config", wgin.Wraps(h.Put,
+		wrapper.InputType(reflect.TypeOf(entity.SystemConfig{}))))
+	r.DELETE("/apisix/admin/system_config/:config_name", wgin.Wraps(h.Delete,
+		wrapper.InputType(reflect.TypeOf(DeleteInput{}))))
+}
+
+type GetInput struct {
+	ConfigName string `auto_read:"config_name,path" validate:"required"`
+}
+
+func (h *Handler) Get(c droplet.Context) (interface{}, error) {
+	input := c.Input().(*GetInput)
+	r, err := h.systemConfig.Get(c.Context(), input.ConfigName)
+
+	if err != nil {
+		return &data.SpecCodeResponse{StatusCode: http.StatusNotFound}, err
+	}
+
+	return r, nil
+}
+
+func (h *Handler) Post(c droplet.Context) (interface{}, error) {
+	input := c.Input().(*entity.SystemConfig)
+	input.CreateTime = time.Now().Unix()
+	input.UpdateTime = time.Now().Unix()
+
+	// create
+	res, err := h.systemConfig.Create(c.Context(), input)

Review comment:
       need JSON schema verification before create

##########
File path: api/internal/core/store/storehub.go
##########
@@ -229,5 +230,17 @@ func InitStores() error {
 		return err
 	}
 
+	err = InitStore(HubKeySystemConfig, GenericStoreOption{
+		BasePath: conf.ETCDConfig.Prefix + "/system_config",
+		ObjType:  reflect.TypeOf(entity.SystemConfig{}),
+		KeyFunc: func(obj interface{}) string {
+			r := obj.(*entity.SystemConfig)
+			return utils.InterfaceToString(r.ConfigName)

Review comment:
       `r.ConfigName` is not an interface

##########
File path: api/internal/handler/system_config/system_config_test.go
##########
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package system_config
+
+import (
+	"errors"
+	"github.com/apisix/manager-api/internal/core/entity"
+	"github.com/apisix/manager-api/internal/core/store"
+	"github.com/shiningrush/droplet"
+	"github.com/shiningrush/droplet/data"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"

Review comment:
       code style




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org