| 499 | } |
| 500 | |
| 501 | func (a *AppInstallService) GetServices(key string) ([]response.AppService, error) { |
| 502 | var res []response.AppService |
| 503 | if DatabaseKeys[key] > 0 { |
| 504 | types := []string{key} |
| 505 | if key == constant.AppPostgres { |
| 506 | key = constant.AppPostgresql |
| 507 | } |
| 508 | switch key { |
| 509 | case constant.AppMysql: |
| 510 | types = []string{constant.AppMysql, constant.AppMysqlCluster} |
| 511 | case constant.AppPostgresql: |
| 512 | types = []string{constant.AppPostgresql, constant.AppPostgresqlCluster} |
| 513 | case constant.AppRedis: |
| 514 | types = []string{constant.AppRedis, constant.AppRedisCluster} |
| 515 | } |
| 516 | |
| 517 | dbs, _ := databaseRepo.GetList(repo.WithTypes(types)) |
| 518 | if len(dbs) == 0 { |
| 519 | return res, nil |
| 520 | } |
| 521 | for _, db := range dbs { |
| 522 | service := response.AppService{ |
| 523 | Label: db.Name, |
| 524 | Value: db.Name, |
| 525 | } |
| 526 | if db.AppInstallID > 0 { |
| 527 | install, err := appInstallRepo.GetFirst(repo.WithByID(db.AppInstallID)) |
| 528 | if err != nil { |
| 529 | return nil, err |
| 530 | } |
| 531 | paramMap := make(map[string]string) |
| 532 | if install.Param != "" { |
| 533 | _ = json.Unmarshal([]byte(install.Param), ¶mMap) |
| 534 | } |
| 535 | service.Config = paramMap |
| 536 | service.From = constant.AppResourceLocal |
| 537 | service.Status = install.Status |
| 538 | } else { |
| 539 | service.From = constant.AppResourceRemote |
| 540 | service.Status = constant.StatusRunning |
| 541 | service.Config = map[string]string{"PANEL_DB_ROOT_PASSWORD": db.Password, "PANEL_DB_ROOT_USER": db.Username} |
| 542 | } |
| 543 | res = append(res, service) |
| 544 | } |
| 545 | } else { |
| 546 | app, err := appRepo.GetFirst(appRepo.WithKey(key)) |
| 547 | if err != nil { |
| 548 | return nil, err |
| 549 | } |
| 550 | installs, err := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(app.ID), appInstallRepo.WithStatus(constant.StatusRunning)) |
| 551 | if err != nil { |
| 552 | return nil, err |
| 553 | } |
| 554 | for _, install := range installs { |
| 555 | paramMap := make(map[string]string) |
| 556 | if install.Param != "" { |
| 557 | _ = json.Unmarshal([]byte(install.Param), ¶mMap) |
| 558 | } |