-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert-config.js
More file actions
235 lines (198 loc) · 5.72 KB
/
convert-config.js
File metadata and controls
235 lines (198 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env node
/**
* @license
* Copyright (C) Pryv https://pryv.com
* This file is part of Pryv.io and released under BSD-Clause-3 License
* Refer to LICENSE file
*/
/**
* V1.x → V2 Config Converter
*
* Reads a v1.x api.yml config and produces a v2-compatible config file.
*
* Usage:
* node convert-config.js <v1-config.yml> [output.yml]
*
* If output is omitted, prints to stdout.
*/
const fs = require('fs');
const path = require('path');
const YAML = require('yaml');
const args = process.argv.slice(2);
if (args.length < 1) {
console.error('Usage: node convert-config.js <v1-config.yml> [output.yml]');
process.exit(1);
}
const configPath = path.resolve(args[0]);
const outputPath = args[1] ? path.resolve(args[1]) : null;
// ---------------------------------------------------------------------------
// Load v1 config
// ---------------------------------------------------------------------------
const raw = fs.readFileSync(configPath, 'utf8');
const v1 = YAML.parse(raw);
// ---------------------------------------------------------------------------
// Build v2 config
// ---------------------------------------------------------------------------
const v2 = {};
// dnsLess — keep as-is
if (v1.dnsLess) {
v2.dnsLess = { ...v1.dnsLess };
}
// reporting
if (v1.reporting) {
v2.reporting = { ...v1.reporting };
}
// http — keep port/ip, add new v2 ports
v2.http = {
ip: v1.http?.ip || '127.0.0.1',
port: v1.http?.port || 3000,
hfsPort: 4000,
previewsPort: 3001
};
// --- Storages (v2 structure) ---
v2.storages = {
base: { engine: 'mongodb' },
platform: { engine: 'sqlite' },
series: { engine: 'influxdb' },
file: { engine: 'filesystem' },
audit: { engine: 'sqlite' },
engines: {
mongodb: {
authUser: v1.database?.authUser || '',
authPassword: v1.database?.authPassword || '',
host: v1.database?.host || '127.0.0.1',
port: v1.database?.port || 27017,
name: v1.database?.name || 'pryv-node',
connectTimeoutMS: v1.database?.connectTimeoutMS || 60000,
socketTimeoutMS: v1.database?.socketTimeoutMS || 60000
},
sqlite: {
path: v1.userFiles?.path || 'REPLACE ME'
},
filesystem: {
attachmentsDirPath: v1.eventFiles?.attachmentsDirPath || v1.userFiles?.path || 'REPLACE ME',
previewsDirPath: v1.eventFiles?.previewsDirPath || 'REPLACE ME'
},
influxdb: {
host: v1.influxdb?.host || '127.0.0.1',
port: v1.influxdb?.port || 8086
}
}
};
// If v1 had SQLite events engine, note it (v2 doesn't have SQLite for base)
if (v1.database?.engine === 'sqlite') {
v2._migration_notes = v2._migration_notes || [];
v2._migration_notes.push('v1 used SQLite for events — v2 uses MongoDB or PostgreSQL. Data was exported to backup format.');
}
// eventFiles
if (v1.eventFiles) {
v2.eventFiles = {};
if (v1.eventFiles.previewsCacheMaxAge) v2.eventFiles.previewsCacheMaxAge = v1.eventFiles.previewsCacheMaxAge;
if (v1.eventFiles.previewsCacheCleanUpCronTime) v2.eventFiles.previewsCacheCleanUpCronTime = v1.eventFiles.previewsCacheCleanUpCronTime;
}
// auth — keep as-is
if (v1.auth) {
v2.auth = { ...v1.auth };
}
// customExtensions
if (v1.customExtensions) {
v2.customExtensions = { ...v1.customExtensions };
}
// updates
if (v1.updates) {
v2.updates = { ...v1.updates };
}
// webhooks
if (v1.webhooks) {
v2.webhooks = { ...v1.webhooks };
}
// versioning
if (v1.versioning) {
v2.versioning = { ...v1.versioning };
}
// user-account
if (v1['user-account']) {
v2['user-account'] = { ...v1['user-account'] };
}
// custom.systemStreams → same location in v2
if (v1.custom) {
v2.custom = { ...v1.custom };
}
// caching
if (v1.caching) {
v2.caching = { ...v1.caching };
}
// logs
if (v1.logs) {
v2.logs = { ...v1.logs };
}
// uploads
if (v1.uploads) {
v2.uploads = { ...v1.uploads };
}
// trace
if (v1.trace) {
v2.trace = { ...v1.trace };
}
// integrity
if (v1.integrity) {
v2.integrity = { ...v1.integrity };
}
// accessTracking
if (v1.accessTracking) {
v2.accessTracking = { ...v1.accessTracking };
}
// --- New v2 settings (defaults) ---
// Cluster config (new in v2)
v2.cluster = {
apiWorkers: 2,
hfsWorkers: 1,
previewsWorker: true,
runMigrations: true
};
// Core identity (new in v2 — single core default)
v2.core = {
id: 'single',
available: true
};
// Audit (new in v2)
v2.audit = {
active: true,
storage: {
filter: {
methods: { include: ['all'], exclude: [] }
}
}
};
// --- Strip v1-only settings ---
// These don't exist in v2:
// - openSource, backwardCompatibility, axonMessaging
// We simply don't include them.
// ---------------------------------------------------------------------------
// Remove settings that are v1-only (not copied above)
// ---------------------------------------------------------------------------
// backwardCompatibility.systemStreams.prefix, backwardCompatibility.tags
// axonMessaging — replaced by cluster + tcpBroker
// openSource — removed in v2
// ---------------------------------------------------------------------------
// Output
// ---------------------------------------------------------------------------
// Add header comment
const header = `# V2 configuration — converted from v1.x config
# Source: ${configPath}
# Converted: ${new Date().toISOString()}
#
# REVIEW BEFORE USE:
# - Verify all 'REPLACE ME' values
# - Adjust cluster.apiWorkers / hfsWorkers for your hardware
# - storages.engines.sqlite.path must point to the user data directory
# - storages.engines.filesystem paths must be set
`;
const yamlStr = YAML.stringify(v2, { lineWidth: 120 });
const output = header + '\n' + yamlStr;
if (outputPath) {
fs.writeFileSync(outputPath, output);
console.log('V2 config written to:', outputPath);
} else {
process.stdout.write(output);
}