From 1d7386236e87589ee00a6dca9f3f937442a730eb Mon Sep 17 00:00:00 2001 From: iwanghc Date: Fri, 27 Dec 2024 16:45:29 +0800 Subject: [PATCH 1/4] add: add get database driver logos interface --- sqle/api/app.go | 1 + sqle/api/controller/v1/instance.go | 45 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/sqle/api/app.go b/sqle/api/app.go index 284aba334..bee58021e 100644 --- a/sqle/api/app.go +++ b/sqle/api/app.go @@ -175,6 +175,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti v1Router.POST("/data_resource/handle", v1.OperateDataResourceHandle, sqleMiddleware.OpGlobalAllowed()) v1Router.POST(fmt.Sprintf("%s/connection", dmsV1.InternalDBServiceRouterGroup), v1.CheckInstanceIsConnectable, sqleMiddleware.OpGlobalAllowed()) v1Router.GET("/database_driver_options", v1.GetDatabaseDriverOptions) + v1Router.GET("/database_driver_logos", v1.GetDatabaseDriverLogos) } // project admin and global manage router diff --git a/sqle/api/controller/v1/instance.go b/sqle/api/controller/v1/instance.go index 6b98ff776..8be5ccc9e 100644 --- a/sqle/api/controller/v1/instance.go +++ b/sqle/api/controller/v1/instance.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net/http" + "strings" baseV1 "github.com/actiontech/dms/pkg/dms-common/api/base/v1" dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1" @@ -633,3 +634,47 @@ func convertParamsToInstanceAdditionalParamRes(params params.Params) []*Instance } return res } + +type DatabaseDriverLogosReqV1 struct { + FilterDBTypes string `json:"db_types" query:"db_types"` +} + +type GetDatabaseDriverLogosResV1 struct { + controller.BaseRes + Logos []*DatabaseDriverLogosV1 `json:"data"` +} + +type DatabaseDriverLogosV1 struct { + DBType string `json:"db_type"` + Logo []byte `json:"logo"` +} + +// GetDatabaseDriverLogos get database driver logos +// @Summary 获取数据库插件的Logo图片 +// @Description get database driver logos +// @Id GetDatabaseDriverLogos +// @Tags instance +// @Param db_types query string true "MySQL,Oracle" +// @Security ApiKeyAuth +// @Success 200 {object} v1.GetDatabaseDriverLogosResV1 +// @router /v1/database_driver_logos [get] +func GetDatabaseDriverLogos(c echo.Context) error { + req := new(DatabaseDriverLogosReqV1) + if err := controller.BindAndValidateReq(c, req); err != nil { + return controller.JSONBaseErrorReq(c, err) + } + dbTypes := strings.Split(req.FilterDBTypes, ",") + pluginMgr := driver.GetPluginManager() + allLogos := pluginMgr.AllLogo() + logos := make([]*DatabaseDriverLogosV1, len(dbTypes)) + for i, dbType := range dbTypes { + logos[i] = &DatabaseDriverLogosV1{ + DBType: dbType, + Logo: allLogos[dbType], + } + } + return c.JSON(http.StatusOK, &GetDatabaseDriverLogosResV1{ + Logos: logos, + BaseRes: controller.NewBaseReq(nil), + }) +} From f5dc31f0eb6fdf0725bafd4b5037adf733c55ee6 Mon Sep 17 00:00:00 2001 From: iwanghc Date: Fri, 27 Dec 2024 16:46:11 +0800 Subject: [PATCH 2/4] add: add get database driver logos url register dms --- sqle/dms/common.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sqle/dms/common.go b/sqle/dms/common.go index dd91e3a1b..20ed66fbc 100644 --- a/sqle/dms/common.go +++ b/sqle/dms/common.go @@ -215,6 +215,7 @@ func RegisterAsDMSTarget(sqleConfig *config.SqleOptions) error { Name: "sqle", OperateDataResourceHandleUrl: fmt.Sprintf("http://%s:%d/%s/%s", sqleConfig.APIServiceOpts.Addr, sqleConfig.APIServiceOpts.Port, "v1", "data_resource/handle"), GetDatabaseDriverOptionsUrl: fmt.Sprintf("http://%s:%d/%s/%s", sqleConfig.APIServiceOpts.Addr, sqleConfig.APIServiceOpts.Port, "v1", "database_driver_options"), + GetDatabaseDriverLogosUrl: fmt.Sprintf("http://%s:%d/%s/%s", sqleConfig.APIServiceOpts.Addr, sqleConfig.APIServiceOpts.Port, "v1", "database_driver_logos"), }); err != nil { return fmt.Errorf("failed to register dms plugin for operation data source handle") } From cc48930928cf06a7e284aacf370c2b4bd73ff24f Mon Sep 17 00:00:00 2001 From: iwanghc Date: Fri, 27 Dec 2024 17:37:12 +0800 Subject: [PATCH 3/4] remove: remove get database driver options interface logo param --- sqle/api/controller/v1/instance.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/sqle/api/controller/v1/instance.go b/sqle/api/controller/v1/instance.go index 8be5ccc9e..c6faba0f6 100644 --- a/sqle/api/controller/v1/instance.go +++ b/sqle/api/controller/v1/instance.go @@ -590,7 +590,6 @@ type GetDatabaseDriverOptionsResV1 struct { type DatabaseDriverOptionsV1 struct { DBType string `json:"db_type"` Params []*InstanceAdditionalParamResV1 `json:"params"` - Logo []byte `json:"logo"` } // GetDatabaseDriverOptions get database driver options @@ -604,7 +603,6 @@ type DatabaseDriverOptionsV1 struct { func GetDatabaseDriverOptions(c echo.Context) error { pluginMgr := driver.GetPluginManager() additionalParams := pluginMgr.AllAdditionalParams() - allLogos := pluginMgr.AllLogo() res := &GetDatabaseDriverOptionsResV1{ BaseRes: controller.NewBaseReq(nil), Metas: []*DatabaseDriverOptionsV1{}, @@ -614,7 +612,6 @@ func GetDatabaseDriverOptions(c echo.Context) error { meta := &DatabaseDriverOptionsV1{ DBType: name, Params: convertParamsToInstanceAdditionalParamRes(params), - Logo: allLogos[name], } res.Metas = append(res.Metas, meta) From 7c3212728a93798736f4de7796dcde04e054af3d Mon Sep 17 00:00:00 2001 From: iwanghc Date: Fri, 27 Dec 2024 17:38:43 +0800 Subject: [PATCH 4/4] gen swagger: database driver options modify --- sqle/docs/docs.go | 61 +++++++++++++++++++++++++++++++++++++++++- sqle/docs/swagger.json | 61 +++++++++++++++++++++++++++++++++++++++++- sqle/docs/swagger.yaml | 40 ++++++++++++++++++++++++++- 3 files changed, 159 insertions(+), 3 deletions(-) diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index 2313f7997..564abcca7 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -1271,6 +1271,38 @@ var doc = `{ } } }, + "/v1/database_driver_logos": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get database driver logos", + "tags": [ + "instance" + ], + "summary": "获取数据库插件的Logo图片", + "operationId": "GetDatabaseDriverLogos", + "parameters": [ + { + "type": "string", + "description": "MySQL,Oracle", + "name": "db_types", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetDatabaseDriverLogosResV1" + } + } + } + } + }, "/v1/database_driver_options": { "get": { "security": [ @@ -13056,7 +13088,7 @@ var doc = `{ } } }, - "v1.DatabaseDriverOptionsV1": { + "v1.DatabaseDriverLogosV1": { "type": "object", "properties": { "db_type": { @@ -13067,6 +13099,14 @@ var doc = `{ "items": { "type": "integer" } + } + } + }, + "v1.DatabaseDriverOptionsV1": { + "type": "object", + "properties": { + "db_type": { + "type": "string" }, "params": { "type": "array", @@ -13978,6 +14018,25 @@ var doc = `{ } } }, + "v1.GetDatabaseDriverLogosResV1": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.DatabaseDriverLogosV1" + } + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetDatabaseDriverOptionsResV1": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index e7cbb7dbb..dfc2ee463 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -1255,6 +1255,38 @@ } } }, + "/v1/database_driver_logos": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get database driver logos", + "tags": [ + "instance" + ], + "summary": "获取数据库插件的Logo图片", + "operationId": "GetDatabaseDriverLogos", + "parameters": [ + { + "type": "string", + "description": "MySQL,Oracle", + "name": "db_types", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.GetDatabaseDriverLogosResV1" + } + } + } + } + }, "/v1/database_driver_options": { "get": { "security": [ @@ -13040,7 +13072,7 @@ } } }, - "v1.DatabaseDriverOptionsV1": { + "v1.DatabaseDriverLogosV1": { "type": "object", "properties": { "db_type": { @@ -13051,6 +13083,14 @@ "items": { "type": "integer" } + } + } + }, + "v1.DatabaseDriverOptionsV1": { + "type": "object", + "properties": { + "db_type": { + "type": "string" }, "params": { "type": "array", @@ -13962,6 +14002,25 @@ } } }, + "v1.GetDatabaseDriverLogosResV1": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "example": 0 + }, + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/v1.DatabaseDriverLogosV1" + } + }, + "message": { + "type": "string", + "example": "ok" + } + } + }, "v1.GetDatabaseDriverOptionsResV1": { "type": "object", "properties": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 1338ff5b8..b56d4625f 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -1173,7 +1173,7 @@ definitions: $ref: '#/definitions/v1.ObjectDiffResult' type: array type: object - v1.DatabaseDriverOptionsV1: + v1.DatabaseDriverLogosV1: properties: db_type: type: string @@ -1181,6 +1181,11 @@ definitions: items: type: integer type: array + type: object + v1.DatabaseDriverOptionsV1: + properties: + db_type: + type: string params: items: $ref: '#/definitions/v1.InstanceAdditionalParamResV1' @@ -1805,6 +1810,19 @@ definitions: $ref: '#/definitions/v1.DatabaseComparisonObject' type: object type: object + v1.GetDatabaseDriverLogosResV1: + properties: + code: + example: 0 + type: integer + data: + items: + $ref: '#/definitions/v1.DatabaseDriverLogosV1' + type: array + message: + example: ok + type: string + type: object v1.GetDatabaseDriverOptionsResV1: properties: code: @@ -7057,6 +7075,26 @@ paths: summary: 获取全局工单统计数据 tags: - workflow + /v1/database_driver_logos: + get: + description: get database driver logos + operationId: GetDatabaseDriverLogos + parameters: + - description: MySQL,Oracle + in: query + name: db_types + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.GetDatabaseDriverLogosResV1' + security: + - ApiKeyAuth: [] + summary: 获取数据库插件的Logo图片 + tags: + - instance /v1/database_driver_options: get: description: get database driver options