■ ■ ■ ■ ■ ■
pkg/service/system_setting.go
| skipped 36 lines |
37 | 37 | | UpdateRegistry(arch string, creation dto.SystemRegistryUpdate) (*dto.SystemRegistry, error) |
38 | 38 | | BatchRegistry(op dto.SystemRegistryBatchOp) error |
39 | 39 | | DeleteRegistry(id string) error |
| 40 | + | ChangePassword(repo dto.RepoChangePassword) error |
40 | 41 | | } |
41 | 42 | | |
42 | 43 | | type systemSettingService struct { |
| skipped 165 lines |
208 | 209 | | RepoPort: r.RepoPort, |
209 | 210 | | RegistryPort: r.RegistryPort, |
210 | 211 | | RegistryHostedPort: r.RegistryHostedPort, |
| 212 | + | NexusUser: r.NexusUser, |
211 | 213 | | NexusPassword: pass, |
212 | 214 | | }, |
213 | 215 | | } |
| skipped 49 lines |
263 | 265 | | return |
264 | 266 | | } |
265 | 267 | | if err := nexus.CheckConn( |
266 | | - | "admin", |
| 268 | + | repo.NexusUser, |
267 | 269 | | pass, |
268 | 270 | | fmt.Sprintf("%s://%s:%d", repo.Protocol, repo.Hostname, repo.RepoPort), |
269 | 271 | | ); err != nil { |
| skipped 17 lines |
287 | 289 | | return nil, err |
288 | 290 | | } |
289 | 291 | | systemRegistry := model.SystemRegistry{ |
290 | | - | ID: creation.ID, |
291 | 292 | | Architecture: creation.Architecture, |
292 | 293 | | Protocol: creation.Protocol, |
293 | 294 | | Hostname: creation.Hostname, |
294 | 295 | | RepoPort: creation.RepoPort, |
295 | 296 | | RegistryPort: creation.RegistryPort, |
296 | 297 | | RegistryHostedPort: creation.RegistryHostedPort, |
| 298 | + | NexusUser: creation.NexusUser, |
297 | 299 | | NexusPassword: password, |
298 | 300 | | } |
299 | 301 | | if err := s.systemRegistryRepo.Save(&systemRegistry); err != nil { |
| skipped 3 lines |
303 | 305 | | } |
304 | 306 | | |
305 | 307 | | func (s systemSettingService) UpdateRegistry(arch string, creation dto.SystemRegistryUpdate) (*dto.SystemRegistry, error) { |
306 | | - | password, err := encrypt.StringEncrypt(creation.NexusPassword) |
307 | | - | if err != nil { |
308 | | - | return nil, err |
309 | | - | } |
310 | 308 | | systemRegistry := model.SystemRegistry{ |
311 | 309 | | ID: creation.ID, |
312 | 310 | | Architecture: arch, |
| skipped 2 lines |
315 | 313 | | RepoPort: creation.RepoPort, |
316 | 314 | | RegistryPort: creation.RegistryPort, |
317 | 315 | | RegistryHostedPort: creation.RegistryHostedPort, |
318 | | - | NexusPassword: password, |
319 | 316 | | } |
320 | | - | if err := s.systemRegistryRepo.Save(&systemRegistry); err != nil { |
| 317 | + | if err := db.DB.Model(&model.SystemRegistry{}).Update(&systemRegistry).Error; err != nil { |
321 | 318 | | return nil, err |
322 | 319 | | } |
323 | 320 | | return &dto.SystemRegistry{SystemRegistry: systemRegistry}, nil |
| skipped 23 lines |
347 | 344 | | return nil |
348 | 345 | | } |
349 | 346 | | |
| 347 | + | func (u *systemSettingService) ChangePassword(ch dto.RepoChangePassword) error { |
| 348 | + | password, err := encrypt.StringEncrypt(ch.NexusPassword) |
| 349 | + | if err != nil { |
| 350 | + | return err |
| 351 | + | } |
| 352 | + | if err := db.DB.Model(&model.SystemRegistry{}).Where("id = ?", ch.ID). |
| 353 | + | Update(map[string]interface{}{"nexus_password": password, "nexus_user": ch.NexusUser}).Error; err != nil { |
| 354 | + | return err |
| 355 | + | } |
| 356 | + | return nil |
| 357 | + | } |
| 358 | + | |