fix: 解决 redis 修改密码报错的问题 (#2271)

pull/2272/head
ssongliu 2023-09-13 14:10:11 +08:00 committed by GitHub
parent 47cfa0c730
commit 6f250e63db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 20 deletions

View File

@ -92,13 +92,13 @@ func (b *BaseApi) UpdateRedisConf(c *gin.Context) {
// @Summary Change redis password
// @Description 更新 redis 密码
// @Accept json
// @Param request body dto.ChangeDBInfo true "request"
// @Param request body dto.ChangeRedisPass true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /databases/redis/password [post]
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFuntions":[],"formatZH":"修改 redis 数据库密码","formatEN":"change the password of the redis database"}
func (b *BaseApi) ChangeRedisPassword(c *gin.Context) {
var req dto.ChangeDBInfo
var req dto.ChangeRedisPass
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return

View File

@ -172,6 +172,10 @@ type UploadRecover struct {
}
// redis
type ChangeRedisPass struct {
Value string `json:"value" validate:"required"`
}
type RedisConfUpdate struct {
Timeout string `json:"timeout"`
Maxclients string `json:"maxclients"`

View File

@ -21,7 +21,7 @@ type RedisService struct{}
type IRedisService interface {
UpdateConf(req dto.RedisConfUpdate) error
UpdatePersistenceConf(req dto.RedisConfPersistenceUpdate) error
ChangePassword(info dto.ChangeDBInfo) error
ChangePassword(info dto.ChangeRedisPass) error
LoadStatus() (*dto.RedisStatus, error)
LoadConf() (*dto.RedisConf, error)
@ -54,7 +54,7 @@ func (u *RedisService) UpdateConf(req dto.RedisConfUpdate) error {
return nil
}
func (u *RedisService) ChangePassword(req dto.ChangeDBInfo) error {
func (u *RedisService) ChangePassword(req dto.ChangeRedisPass) error {
if err := updateInstallInfoInDB("redis", "", "password", true, req.Value); err != nil {
return err
}

View File

@ -4561,7 +4561,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.ChangeDBInfo"
"$ref": "#/definitions/dto.ChangeRedisPass"
}
}
],
@ -11946,6 +11946,17 @@ const docTemplate = `{
}
}
},
"dto.ChangeRedisPass": {
"type": "object",
"required": [
"value"
],
"properties": {
"value": {
"type": "string"
}
}
},
"dto.CleanLog": {
"type": "object",
"required": [

View File

@ -4554,7 +4554,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.ChangeDBInfo"
"$ref": "#/definitions/dto.ChangeRedisPass"
}
}
],
@ -11939,6 +11939,17 @@
}
}
},
"dto.ChangeRedisPass": {
"type": "object",
"required": [
"value"
],
"properties": {
"value": {
"type": "string"
}
}
},
"dto.CleanLog": {
"type": "object",
"required": [

View File

@ -163,6 +163,13 @@ definitions:
- groupID
- id
type: object
dto.ChangeRedisPass:
properties:
value:
type: string
required:
- value
type: object
dto.CleanLog:
properties:
logType:
@ -6925,7 +6932,7 @@ paths:
name: request
required: true
schema:
$ref: '#/definitions/dto.ChangeDBInfo'
$ref: '#/definitions/dto.ChangeRedisPass'
responses:
"200":
description: OK

View File

@ -74,12 +74,11 @@ export const loadRedisConf = () => {
export const redisPersistenceConf = () => {
return http.get<Database.RedisPersistenceConf>(`/databases/redis/persistence/conf`);
};
export const changeRedisPassword = (params: Database.ChangeInfo) => {
let reqest = deepCopy(params) as Database.ChangeInfo;
if (reqest.value) {
reqest.value = Base64.encode(reqest.value);
export const changeRedisPassword = (value: string) => {
if (value) {
value = Base64.encode(value);
}
return http.post(`/databases/redis/password`, reqest);
return http.post(`/databases/redis/password`, { value: value });
};
export const updateRedisPersistenceConf = (params: Database.RedisConfPersistenceUpdate) => {
return http.post(`/databases/redis/persistence/update`, params);

View File

@ -114,16 +114,9 @@ const loadPassword = async () => {
};
const onSubmit = async () => {
let param = {
id: 0,
from: 'local',
type: 'redis',
database: '',
value: form.value.password,
};
loading.value = true;
emit('closeTerminal');
await changeRedisPassword(param)
await changeRedisPassword(form.value.password)
.then(() => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));