Jaycean commented on a change in pull request #1245:
URL: https://github.com/apache/apisix-dashboard/pull/1245#discussion_r557803573



##########
File path: api/internal/handler/route_export/route_export.go
##########
@@ -0,0 +1,432 @@
+/*
+ * 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 route_export
+
+import (
+       "encoding/json"
+       "fmt"
+       "reflect"
+       "regexp"
+       "strings"
+
+       "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/apisix/manager-api/internal/log"
+       "github.com/apisix/manager-api/internal/utils"
+       "github.com/getkin/kin-openapi/openapi3"
+       "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"
+)
+
+type Handler struct {
+       routeStore    store.Interface
+       upstreamStore store.Interface
+       serviceStore  store.Interface
+}
+
+func NewHandler() (handler.RouteRegister, error) {
+       return &Handler{
+               routeStore:    store.GetStore(store.HubKeyRoute),
+               upstreamStore: store.GetStore(store.HubKeyUpstream),
+               serviceStore:  store.GetStore(store.HubKeyService),
+       }, nil
+}
+
+func (h *Handler) ApplyRoute(r *gin.Engine) {
+       r.POST("/apisix/admin/routes/export/:ids", wgin.Wraps(h.ExportRoutes,
+               wrapper.InputType(reflect.TypeOf(ExportInput{}))))
+}
+
+type ExportInput struct {
+       IDs string `auto_read:"ids,path"`
+}
+
+func (h *Handler) ExportRoutes(c droplet.Context) (interface{}, error) {
+       input := c.Input().(*ExportInput)
+       ids := strings.Split(input.IDs, ",")
+       routes := []*entity.Route{}
+
+       for _, id := range ids {
+               route, err := h.routeStore.Get(id)
+               if err != nil {
+                       return nil, err
+               }
+               routes = append(routes, route.(*entity.Route))
+       }
+
+       swagger, err := h.routeToOpenApi3(routes)
+       if err != nil {
+               return nil, err
+       }
+       return swagger, nil
+}
+
+type AuthType string
+
+const (
+       BasicAuth AuthType = "basic-auth"
+       KeyAuth   AuthType = "key-auth"
+       JWTAuth   AuthType = "jwt-auth"
+)
+
+var (
+       openApi = "3.0.0"
+       title   = "RoutesExport"
+       service interface{}
+       err     error
+)
+
+func (h *Handler) routeToOpenApi3(routes []*entity.Route) (*openapi3.Swagger, 
error) {
+       paths := openapi3.Paths{}

Review comment:
       Basicauth, keyauth and jwtauth are three kinds of authentication 
methods. I don't think they should be changed in the program, so I use constants




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to