WriteDefaultConfigFile generates a new default high-level server configuration file at filePath. The default indexer will use SQLite. If filePath already exists, it is overwritten.
(filePath string)
| 1169 | // file at filePath. The default indexer will use SQLite. |
| 1170 | // If filePath already exists, it is overwritten. |
| 1171 | func WriteDefaultConfigFile(filePath string) error { |
| 1172 | conf := defaultBaseConfig |
| 1173 | blobDir, err := osutil.CamliBlobRoot() |
| 1174 | if err != nil { |
| 1175 | return err |
| 1176 | } |
| 1177 | varDir, err := osutil.CamliVarDir() |
| 1178 | if err != nil { |
| 1179 | return err |
| 1180 | } |
| 1181 | if err := wkfs.MkdirAll(blobDir, 0700); err != nil { |
| 1182 | return fmt.Errorf("Could not create default blobs directory: %v", err) |
| 1183 | } |
| 1184 | conf.BlobPath = blobDir |
| 1185 | conf.PackRelated = true |
| 1186 | |
| 1187 | conf.SQLite = filepath.Join(varDir, "index.sqlite") |
| 1188 | |
| 1189 | keyID, secretRing, err := getOrMakeKeyring() |
| 1190 | if err != nil { |
| 1191 | return err |
| 1192 | } |
| 1193 | conf.Identity = keyID |
| 1194 | conf.IdentitySecretRing = secretRing |
| 1195 | |
| 1196 | confData, err := json.MarshalIndent(conf, "", " ") |
| 1197 | if err != nil { |
| 1198 | return fmt.Errorf("Could not json encode config file : %v", err) |
| 1199 | } |
| 1200 | |
| 1201 | if err := wkfs.WriteFile(filePath, confData, 0600); err != nil { |
| 1202 | return fmt.Errorf("Could not create or write default server config: %v", err) |
| 1203 | } |
| 1204 | |
| 1205 | return nil |
| 1206 | } |
| 1207 | |
| 1208 | func getOrMakeKeyring() (keyID, secRing string, err error) { |
| 1209 | secRing = osutil.SecretRingFile() |
no test coverage detected