CreateConfig creates a config file with random passwords at configPath
(insecure, forceOverwrite, diff bool, configPath, adminPassword string, quiet bool)
| 23 | |
| 24 | // CreateConfig creates a config file with random passwords at configPath |
| 25 | func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword string, quiet bool) error { |
| 26 | if diff && forceOverwrite { |
| 27 | return fmt.Errorf("diff and force-overwrite flags are mutually exclusive") |
| 28 | } |
| 29 | if diff && adminPassword != "" { |
| 30 | return fmt.Errorf("diff and admin-password flags are mutually exclusive") |
| 31 | } |
| 32 | |
| 33 | if configExists(configPath) && !forceOverwrite && !diff { |
| 34 | return fmt.Errorf("config file already exists, use --force-overwrite to overwrite or --diff to show diff") |
| 35 | } |
| 36 | |
| 37 | err := checkConfigPath(configPath) |
| 38 | if err != nil && (!forceOverwrite && !diff) { |
| 39 | fmt.Println("off") |
| 40 | return err |
| 41 | } |
| 42 | targetBackupConfig := "" |
| 43 | if err != nil { |
| 44 | targetBackupConfig, err = backupOpenCloudConfigFile(configPath) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | } |
| 49 | err = os.MkdirAll(configPath, 0700) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | |
| 54 | // Load old config |
| 55 | var oldCfg OpenCloudConfig |
| 56 | if diff { |
| 57 | fp, err := os.ReadFile(path.Join(configPath, configFilename)) |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | err = yaml.Unmarshal(fp, &oldCfg) |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | var ( |
| 68 | systemUserID, adminUserID, graphApplicationID, storageUsersMountID, serviceAccountID string |
| 69 | idmServicePassword, idpServicePassword, ocAdminServicePassword, revaServicePassword string |
| 70 | tokenManagerJwtSecret, collaborationWOPISecret, machineAuthAPIKey, systemUserAPIKey string |
| 71 | revaTransferSecret, thumbnailsTransferSecret, serviceAccountSecret, urlSigningSecret string |
| 72 | adminPasswdwordGenerated bool |
| 73 | ) |
| 74 | |
| 75 | if diff { |
| 76 | systemUserID = oldCfg.SystemUserID |
| 77 | adminUserID = oldCfg.AdminUserID |
| 78 | graphApplicationID = oldCfg.Graph.Application.ID |
| 79 | storageUsersMountID = oldCfg.Gateway.StorageRegistry.StorageUsersMountID |
| 80 | serviceAccountID = oldCfg.Graph.ServiceAccount.ServiceAccountID |
| 81 | |
| 82 | idmServicePassword = oldCfg.Idm.ServiceUserPasswords.IdmPassword |
nothing calls this directly
no test coverage detected