From 7c236ccc3a9c4c9261ed347bc78329ec91288d94 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 11 Apr 2023 10:26:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B0=E6=8D=AE=E5=BA=93=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20ServiceName=20=E6=98=BE=E7=A4=BA=20(#573)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/app_install.go | 12 +- backend/app/dto/response/app.go | 8 +- backend/app/repo/app_install.go | 2 + backend/app/service/app_install.go | 11 +- backend/router/ro_app.go | 2 +- cmd/server/docs/docs.go | 104 ++++++++++++------ cmd/server/docs/swagger.json | 104 ++++++++++++------ cmd/server/docs/swagger.yaml | 66 +++++++---- frontend/src/api/interface/app.ts | 4 + frontend/src/api/modules/app.ts | 4 +- frontend/src/lang/modules/en.ts | 3 + frontend/src/lang/modules/zh.ts | 3 + frontend/src/views/database/mysql/index.vue | 2 +- .../database/mysql/root-password/index.vue | 26 +++-- frontend/src/views/database/redis/index.vue | 2 +- .../views/database/redis/password/index.vue | 44 ++++++-- 16 files changed, 273 insertions(+), 124 deletions(-) diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index b4c54bec9..1f055b475 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -93,24 +93,24 @@ func (b *BaseApi) LoadPort(c *gin.Context) { // @Tags App // @Summary Search app password by key -// @Description 获取应用密码 +// @Description 获取应用连接信息 // @Accept json // @Param key path string true "request" -// @Success 200 {string} password +// @Success 200 {string} response.DatabaseConn // @Security ApiKeyAuth -// @Router /apps/installed/loadpassword/:key [get] -func (b *BaseApi) LoadPassword(c *gin.Context) { +// @Router /apps/installed/conninfo/:key [get] +func (b *BaseApi) LoadConnInfo(c *gin.Context) { key, ok := c.Params.Get("key") if !ok { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path")) return } - password, err := appInstallService.LoadPassword(key) + conn, err := appInstallService.LoadConnInfo(key) if err != nil { helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) return } - helper.SuccessWithData(c, password) + helper.SuccessWithData(c, conn) } // @Tags App diff --git a/backend/app/dto/response/app.go b/backend/app/dto/response/app.go index df991376f..8f8bf9b73 100644 --- a/backend/app/dto/response/app.go +++ b/backend/app/dto/response/app.go @@ -1,8 +1,9 @@ package response import ( - "github.com/1Panel-dev/1Panel/backend/app/model" "time" + + "github.com/1Panel-dev/1Panel/backend/app/model" ) type AppRes struct { @@ -55,6 +56,11 @@ type AppInstalledDTO struct { CanUpdate bool `json:"canUpdate"` } +type DatabaseConn struct { + Password string `json:"password"` + ServiceName string `json:"serviceName"` +} + type AppService struct { Label string `json:"label"` Value string `json:"value"` diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index e5475c884..5c6d44d28 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -148,6 +148,7 @@ type RootInfo struct { Password string `json:"password"` UserPassword string `json:"userPassword"` ContainerName string `json:"containerName"` + ServiceName string `json:"serviceName"` Param string `json:"param"` Env string `json:"env"` Key string `json:"key"` @@ -187,6 +188,7 @@ func (a *AppInstallRepo) LoadBaseInfo(key string, name string) (*RootInfo, error info.Port = int64(appInstall.HttpPort) info.HttpsPort = int64(appInstall.HttpsPort) info.ID = appInstall.ID + info.ServiceName = appInstall.ServiceName info.ContainerName = appInstall.ContainerName info.Name = appInstall.Name info.Env = appInstall.Env diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index f02fde28e..2049f53e6 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -38,7 +38,7 @@ type IAppInstallService interface { Page(req request.AppInstalledSearch) (int64, []response.AppInstalledDTO, error) CheckExist(key string) (*response.AppInstalledCheck, error) LoadPort(key string) (int64, error) - LoadPassword(key string) (string, error) + LoadConnInfo(key string) (response.DatabaseConn, error) SearchForWebsite(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) Operate(ctx context.Context, req request.AppInstalledOperate) error Update(req request.AppInstalledUpdate) error @@ -133,12 +133,15 @@ func (a *AppInstallService) LoadPort(key string) (int64, error) { return app.Port, nil } -func (a *AppInstallService) LoadPassword(key string) (string, error) { +func (a *AppInstallService) LoadConnInfo(key string) (response.DatabaseConn, error) { + var data response.DatabaseConn app, err := appInstallRepo.LoadBaseInfo(key, "") if err != nil { - return "", nil + return data, nil } - return app.Password, nil + data.Password = app.Password + data.ServiceName = app.ServiceName + return data, nil } func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) { diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index 7aeb00c92..1f734fb95 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -26,7 +26,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions) appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled) appRouter.GET("/installed/loadport/:key", baseApi.LoadPort) - appRouter.GET("/installed/loadpassword/:key", baseApi.LoadPassword) + appRouter.GET("/installed/conninfo/:key", baseApi.LoadConnInfo) appRouter.GET("/installed/delete/check/:appInstallId", baseApi.DeleteCheck) appRouter.POST("/installed/search", baseApi.SearchAppInstalled) appRouter.POST("/installed/op", baseApi.OperateInstalled) diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index 8bfc6553b..c4d434b36 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -326,6 +326,40 @@ var doc = `{ } } }, + "/apps/installed/conninfo/:key": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取应用连接信息", + "consumes": [ + "application/json" + ], + "tags": [ + "App" + ], + "summary": "Search app password by key", + "parameters": [ + { + "type": "string", + "description": "request", + "name": "key", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, "/apps/installed/delete/check/:appInstallId": { "get": { "security": [ @@ -360,40 +394,6 @@ var doc = `{ } } }, - "/apps/installed/loadpassword/:key": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "获取应用密码", - "consumes": [ - "application/json" - ], - "tags": [ - "App" - ], - "summary": "Search app password by key", - "parameters": [ - { - "type": "string", - "description": "request", - "name": "key", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - } - } - } - }, "/apps/installed/loadport/:key": { "get": { "security": [ @@ -9832,6 +9832,12 @@ var doc = `{ "type": "string" } }, + "iptables": { + "type": "boolean" + }, + "isSwarm": { + "type": "boolean" + }, "liveRestore": { "type": "boolean" }, @@ -10215,6 +10221,9 @@ var doc = `{ "key" ] }, + "passPhrase": { + "type": "string" + }, "password": { "type": "string" }, @@ -10258,9 +10267,21 @@ var doc = `{ "name": { "type": "string" }, + "passPhrase": { + "type": "string" + }, + "password": { + "type": "string" + }, "port": { "type": "integer" }, + "privateKey": { + "type": "string" + }, + "rememberPassword": { + "type": "boolean" + }, "user": { "type": "string" } @@ -10296,6 +10317,9 @@ var doc = `{ "name": { "type": "string" }, + "passPhrase": { + "type": "string" + }, "password": { "type": "string" }, @@ -10307,6 +10331,9 @@ var doc = `{ "privateKey": { "type": "string" }, + "rememberPassword": { + "type": "boolean" + }, "user": { "type": "string" } @@ -11569,6 +11596,9 @@ var doc = `{ "required": { "type": "string" }, + "resource": { + "type": "string" + }, "shortDescEn": { "type": "string" }, @@ -12939,6 +12969,9 @@ var doc = `{ "required": { "type": "string" }, + "resource": { + "type": "string" + }, "shortDescEn": { "type": "string" }, @@ -13269,6 +13302,9 @@ var doc = `{ "runtimeID": { "type": "integer" }, + "runtimeName": { + "type": "string" + }, "sitePath": { "type": "string" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 85bcb4974..09953b2ba 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -312,6 +312,40 @@ } } }, + "/apps/installed/conninfo/:key": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "获取应用连接信息", + "consumes": [ + "application/json" + ], + "tags": [ + "App" + ], + "summary": "Search app password by key", + "parameters": [ + { + "type": "string", + "description": "request", + "name": "key", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, "/apps/installed/delete/check/:appInstallId": { "get": { "security": [ @@ -346,40 +380,6 @@ } } }, - "/apps/installed/loadpassword/:key": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "获取应用密码", - "consumes": [ - "application/json" - ], - "tags": [ - "App" - ], - "summary": "Search app password by key", - "parameters": [ - { - "type": "string", - "description": "request", - "name": "key", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - } - } - } - }, "/apps/installed/loadport/:key": { "get": { "security": [ @@ -9818,6 +9818,12 @@ "type": "string" } }, + "iptables": { + "type": "boolean" + }, + "isSwarm": { + "type": "boolean" + }, "liveRestore": { "type": "boolean" }, @@ -10201,6 +10207,9 @@ "key" ] }, + "passPhrase": { + "type": "string" + }, "password": { "type": "string" }, @@ -10244,9 +10253,21 @@ "name": { "type": "string" }, + "passPhrase": { + "type": "string" + }, + "password": { + "type": "string" + }, "port": { "type": "integer" }, + "privateKey": { + "type": "string" + }, + "rememberPassword": { + "type": "boolean" + }, "user": { "type": "string" } @@ -10282,6 +10303,9 @@ "name": { "type": "string" }, + "passPhrase": { + "type": "string" + }, "password": { "type": "string" }, @@ -10293,6 +10317,9 @@ "privateKey": { "type": "string" }, + "rememberPassword": { + "type": "boolean" + }, "user": { "type": "string" } @@ -11555,6 +11582,9 @@ "required": { "type": "string" }, + "resource": { + "type": "string" + }, "shortDescEn": { "type": "string" }, @@ -12925,6 +12955,9 @@ "required": { "type": "string" }, + "resource": { + "type": "string" + }, "shortDescEn": { "type": "string" }, @@ -13255,6 +13288,9 @@ "runtimeID": { "type": "integer" }, + "runtimeName": { + "type": "string" + }, "sitePath": { "type": "string" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 7f89be649..2565fa81f 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -448,6 +448,10 @@ definitions: items: type: string type: array + iptables: + type: boolean + isSwarm: + type: boolean liveRestore: type: boolean registryMirrors: @@ -701,6 +705,8 @@ definitions: - password - key type: string + passPhrase: + type: string password: type: string port: @@ -734,8 +740,16 @@ definitions: type: integer name: type: string + passPhrase: + type: string + password: + type: string port: type: integer + privateKey: + type: string + rememberPassword: + type: boolean user: type: string type: object @@ -756,6 +770,8 @@ definitions: type: integer name: type: string + passPhrase: + type: string password: type: string port: @@ -764,6 +780,8 @@ definitions: type: integer privateKey: type: string + rememberPassword: + type: boolean user: type: string required: @@ -1605,6 +1623,8 @@ definitions: type: integer required: type: string + resource: + type: string shortDescEn: type: string shortDescZh: @@ -2520,6 +2540,8 @@ definitions: type: integer required: type: string + resource: + type: string shortDescEn: type: string shortDescZh: @@ -2738,6 +2760,8 @@ definitions: type: string runtimeID: type: integer + runtimeName: + type: string sitePath: type: string status: @@ -2991,6 +3015,27 @@ paths: summary: Search default config by key tags: - App + /apps/installed/conninfo/:key: + get: + consumes: + - application/json + description: 获取应用连接信息 + parameters: + - description: request + in: path + name: key + required: true + type: string + responses: + "200": + description: OK + schema: + type: string + security: + - ApiKeyAuth: [] + summary: Search app password by key + tags: + - App /apps/installed/delete/check/:appInstallId: get: consumes: @@ -3012,27 +3057,6 @@ paths: summary: Check before delete tags: - App - /apps/installed/loadpassword/:key: - get: - consumes: - - application/json - description: 获取应用密码 - parameters: - - description: request - in: path - name: key - required: true - type: string - responses: - "200": - description: OK - schema: - type: string - security: - - ApiKeyAuth: [] - summary: Search app password by key - tags: - - App /apps/installed/loadport/:key: get: consumes: diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 42bc0b44f..2e4b4b154 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -127,6 +127,10 @@ export namespace App { installPath: string; } + export interface DatabaseConnInfo { + password: string; + serviceName: string; + } export interface AppInstallResource { type: string; name: string; diff --git a/frontend/src/api/modules/app.ts b/frontend/src/api/modules/app.ts index 7b191458f..8679ea3a7 100644 --- a/frontend/src/api/modules/app.ts +++ b/frontend/src/api/modules/app.ts @@ -46,8 +46,8 @@ export const GetAppPort = (key: string) => { return http.get(`apps/installed/loadport/${key}`); }; -export const GetAppPassword = (key: string) => { - return http.get(`apps/installed/loadpassword/${key}`); +export const GetAppConnInfo = (key: string) => { + return http.get(`apps/installed/conninfo/${key}`); }; export const CheckAppInstalled = (key: string) => { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index fb73db4f0..1fd2ee733 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -294,7 +294,10 @@ const message = { permission: 'Permission', permissionForIP: 'IP', permissionAll: 'All of them(%)', + databaseConnInfo: 'Conn info', rootPassword: 'Root password', + serviceName: 'Service Name', + serviceNameHelper: 'Access between containers in the same network.', backupList: 'Backup', backList: 'Return', loadBackup: 'Import', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index c20aa7cc7..be483b1fe 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -299,7 +299,10 @@ const message = { permission: '权限', permissionForIP: '指定 IP', permissionAll: '所有人(%)', + databaseConnInfo: '连接信息', rootPassword: 'root 密码', + serviceName: '服务名称', + serviceNameHelper: '用于同一 network 下的容器间访问', backupList: '备份列表', backList: '返回列表', loadBackup: '导入备份', diff --git a/frontend/src/views/database/mysql/index.vue b/frontend/src/views/database/mysql/index.vue index fac809f26..126f6da98 100644 --- a/frontend/src/views/database/mysql/index.vue +++ b/frontend/src/views/database/mysql/index.vue @@ -18,7 +18,7 @@ {{ $t('database.create') }} - {{ $t('database.rootPassword') }} + {{ $t('database.databaseConnInfo') }} {{ $t('database.remoteAccess') }} diff --git a/frontend/src/views/database/mysql/root-password/index.vue b/frontend/src/views/database/mysql/root-password/index.vue index 6a04929ac..104792f0b 100644 --- a/frontend/src/views/database/mysql/root-password/index.vue +++ b/frontend/src/views/database/mysql/root-password/index.vue @@ -1,7 +1,7 @@ + + {{ form.serviceName }} + {{ $t('database.serviceNameHelper') }} + @@ -34,22 +38,24 @@