From f94134faa090b8d7d03c75461085b14f03d5a960 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Fri, 26 Jan 2024 12:56:33 +0800 Subject: [PATCH] perf: support redis url with `rediss` protocol #127 --- backend/services/connection_service.go | 30 +++++++++++-------- .../components/dialogs/ConnectionDialog.vue | 9 +++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index 0395b31..2d14bba 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -528,21 +528,27 @@ func (c *connectionService) ParseConnectURL(url string) (resp types.JSResp) { if len(addrPart) > 1 { port, _ = strconv.Atoi(addrPart[1]) } + var sslServerName string + if urlOpt.TLSConfig != nil { + sslServerName = urlOpt.TLSConfig.ServerName + } resp.Success = true resp.Data = struct { - Addr string `json:"addr"` - Port int `json:"port"` - Username string `json:"username"` - Password string `json:"password"` - ConnTimeout int64 `json:"connTimeout"` - ExecTimeout int64 `json:"execTimeout"` + Addr string `json:"addr"` + Port int `json:"port"` + Username string `json:"username"` + Password string `json:"password"` + ConnTimeout int64 `json:"connTimeout"` + ExecTimeout int64 `json:"execTimeout"` + SSLServerName string `json:"sslServerName,omitempty"` }{ - Addr: addr, - Port: port, - Username: urlOpt.Username, - Password: urlOpt.Password, - ConnTimeout: int64(urlOpt.DialTimeout.Seconds()), - ExecTimeout: int64(urlOpt.ReadTimeout.Seconds()), + Addr: addr, + Port: port, + Username: urlOpt.Username, + Password: urlOpt.Password, + ConnTimeout: int64(urlOpt.DialTimeout.Seconds()), + ExecTimeout: int64(urlOpt.ReadTimeout.Seconds()), + SSLServerName: sslServerName, } return } diff --git a/frontend/src/components/dialogs/ConnectionDialog.vue b/frontend/src/components/dialogs/ConnectionDialog.vue index 67d3a89..3ac4235 100644 --- a/frontend/src/components/dialogs/ConnectionDialog.vue +++ b/frontend/src/components/dialogs/ConnectionDialog.vue @@ -270,7 +270,7 @@ const onClose = () => { const pasteFromClipboard = async () => { // url example: - // redis://user:password@localhost:6789/3?dial_timeout=3&db=1&read_timeout=6s&max_retries=2 + // rediss://user:password@localhost:6789/3?dial_timeout=3&db=1&read_timeout=6s&max_retries=2 let opt = {} try { opt = await connectionStore.parseUrlFromClipboard() @@ -288,6 +288,13 @@ const pasteFromClipboard = async () => { if (opt.execTimeout > 0) { generalForm.value.execTimeout = opt.execTimeout } + const { sslServerName = null } = opt + if (sslServerName != null) { + generalForm.value.ssl.enable = true + if (!isEmpty(sslServerName)) { + generalForm.value.ssl.sni = sslServerName + } + } $message.success(i18n.t('dialogue.connection.parse_pass', { url: opt.url })) }