|
7 | 7 | "github.com/1Panel-dev/1Panel/backend/app/dto" |
8 | 8 | "github.com/1Panel-dev/1Panel/backend/constant" |
9 | 9 | "github.com/1Panel-dev/1Panel/backend/global" |
10 | | - "github.com/1Panel-dev/1Panel/backend/utils/copier" |
| 10 | + "github.com/1Panel-dev/1Panel/backend/utils/encrypt" |
11 | 11 | "github.com/gin-gonic/gin" |
12 | 12 | ) |
13 | 13 |
|
@@ -36,15 +36,25 @@ func (b *BaseApi) CreateHost(c *gin.Context) { |
36 | 36 | helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
37 | 37 | return |
38 | 38 | } |
39 | | - req.Password = string(password) |
| 39 | + passwordItem, err := encrypt.StringEncrypt(string(password)) |
| 40 | + if err != nil { |
| 41 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 42 | + return |
| 43 | + } |
| 44 | + req.Password = passwordItem |
40 | 45 | } |
41 | 46 | if req.AuthMode == "key" && len(req.PrivateKey) != 0 { |
42 | 47 | privateKey, err := base64.StdEncoding.DecodeString(req.PrivateKey) |
43 | 48 | if err != nil { |
44 | 49 | helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
45 | 50 | return |
46 | 51 | } |
47 | | - req.PrivateKey = string(privateKey) |
| 52 | + keyItem, err := encrypt.StringEncrypt(string(privateKey)) |
| 53 | + if err != nil { |
| 54 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 55 | + return |
| 56 | + } |
| 57 | + req.Password = keyItem |
48 | 58 | } |
49 | 59 |
|
50 | 60 | host, err := hostService.Create(req) |
@@ -148,33 +158,6 @@ func (b *BaseApi) SearchHost(c *gin.Context) { |
148 | 158 | }) |
149 | 159 | } |
150 | 160 |
|
151 | | -// @Tags Host |
152 | | -// @Summary Load host info |
153 | | -// @Description 加载主机信息 |
154 | | -// @Accept json |
155 | | -// @Param id path integer true "request" |
156 | | -// @Success 200 {object} dto.HostInfo |
157 | | -// @Security ApiKeyAuth |
158 | | -// @Router /hosts/:id [get] |
159 | | -func (b *BaseApi) GetHostInfo(c *gin.Context) { |
160 | | - id, err := helper.GetParamID(c) |
161 | | - if err != nil { |
162 | | - helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
163 | | - return |
164 | | - } |
165 | | - host, err := hostService.GetHostInfo(id) |
166 | | - if err != nil { |
167 | | - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
168 | | - return |
169 | | - } |
170 | | - var hostDto dto.HostInfo |
171 | | - if err := copier.Copy(&hostDto, host); err != nil { |
172 | | - helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
173 | | - return |
174 | | - } |
175 | | - helper.SuccessWithData(c, hostDto) |
176 | | -} |
177 | | - |
178 | 161 | // @Tags Host |
179 | 162 | // @Summary Delete host |
180 | 163 | // @Description 删除主机 |
@@ -227,15 +210,25 @@ func (b *BaseApi) UpdateHost(c *gin.Context) { |
227 | 210 | helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
228 | 211 | return |
229 | 212 | } |
230 | | - req.Password = string(password) |
| 213 | + passwordItem, err := encrypt.StringEncrypt(string(password)) |
| 214 | + if err != nil { |
| 215 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 216 | + return |
| 217 | + } |
| 218 | + req.Password = passwordItem |
231 | 219 | } |
232 | 220 | if req.AuthMode == "key" && len(req.PrivateKey) != 0 { |
233 | 221 | privateKey, err := base64.StdEncoding.DecodeString(req.PrivateKey) |
234 | 222 | if err != nil { |
235 | 223 | helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
236 | 224 | return |
237 | 225 | } |
238 | | - req.PrivateKey = string(privateKey) |
| 226 | + keyItem, err := encrypt.StringEncrypt(string(privateKey)) |
| 227 | + if err != nil { |
| 228 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 229 | + return |
| 230 | + } |
| 231 | + req.PrivateKey = keyItem |
239 | 232 | } |
240 | 233 |
|
241 | 234 | upMap := make(map[string]interface{}) |
|
0 commit comments