cloudcms-server 3.2.320 → 3.2.322
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/middleware/virtual-config/virtual-config.js +127 -124
- package/package.json +1 -1
- package/server/index.js +11 -10
|
@@ -165,169 +165,172 @@ exports = module.exports = function()
|
|
|
165
165
|
// so that only N number of virtual configs are loaded at a time
|
|
166
166
|
enqueueLoadVirtualConfig(function(host, rootStore, logMethod, callback) {
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// check cache to see if we already tried to load this in the past few minutes and were sorely disappointed
|
|
173
|
-
process.cache.read(VCSENTINEL_CACHE_KEY, function (err, doesNotExist) {
|
|
168
|
+
return function()
|
|
169
|
+
{
|
|
170
|
+
rootStore.existsFile("gitana.json", function(exists) {
|
|
174
171
|
|
|
175
|
-
|
|
176
|
-
return finishedLoading({
|
|
177
|
-
"message": "No virtual config found for host (from previous attempt)"
|
|
178
|
-
}, null, true);
|
|
179
|
-
}
|
|
172
|
+
var loadFromRemote = function(finishedLoading) {
|
|
180
173
|
|
|
181
|
-
// load the
|
|
182
|
-
|
|
174
|
+
// check cache to see if we already tried to load this in the past few minutes and were sorely disappointed
|
|
175
|
+
process.cache.read(VCSENTINEL_CACHE_KEY, function (err, doesNotExist) {
|
|
183
176
|
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return finishedLoading(err);
|
|
177
|
+
if (doesNotExist) {
|
|
178
|
+
return finishedLoading({
|
|
179
|
+
"message": "No virtual config found for host (from previous attempt)"
|
|
180
|
+
}, null, true);
|
|
189
181
|
}
|
|
190
182
|
|
|
191
|
-
|
|
192
|
-
{
|
|
193
|
-
// mark that it failed (30 minute TTL)
|
|
194
|
-
return process.cache.write(VCSENTINEL_CACHE_KEY, true, BLACKLIST_TTL_SECONDS, function() {
|
|
195
|
-
finishedLoading({
|
|
196
|
-
"message": "No virtual config found for host: " + host
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
}
|
|
183
|
+
// load the gitana.json file from Cloud CMS
|
|
184
|
+
loadConfigForVirtualHost(host, logMethod, function (err, virtualConfig) {
|
|
200
185
|
|
|
201
|
-
// populate gitana.json
|
|
202
|
-
var gitanaJson = {
|
|
203
|
-
"clientKey": virtualConfig.clientKey
|
|
204
|
-
};
|
|
205
|
-
if (virtualConfig.clientSecret) {
|
|
206
|
-
gitanaJson.clientSecret = virtualConfig.clientSecret;
|
|
207
|
-
}
|
|
208
|
-
if (virtualConfig.username) {
|
|
209
|
-
gitanaJson.username = virtualConfig.username;
|
|
210
|
-
}
|
|
211
|
-
if (virtualConfig.password) {
|
|
212
|
-
gitanaJson.password = virtualConfig.password;
|
|
213
|
-
}
|
|
214
|
-
if (virtualConfig.application) {
|
|
215
|
-
gitanaJson.application = virtualConfig.application;
|
|
216
|
-
}
|
|
217
|
-
if (virtualConfig.baseURL) {
|
|
218
|
-
gitanaJson.baseURL = virtualConfig.baseURL;
|
|
219
|
-
}
|
|
220
|
-
if (!gitanaJson.baseURL)
|
|
221
|
-
{
|
|
222
|
-
gitanaJson.baseURL = util.cleanupURL(util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH));
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// mark as retrieved from virtual driver
|
|
226
|
-
gitanaJson._virtual = true;
|
|
227
|
-
|
|
228
|
-
// write the gitana.json file
|
|
229
|
-
rootStore.writeFile("gitana.json", JSON.stringify(gitanaJson, null, " "), function (err) {
|
|
230
|
-
|
|
231
|
-
// if we failed to write the file, then delete and call back with error
|
|
232
186
|
if (err)
|
|
233
187
|
{
|
|
234
|
-
|
|
235
|
-
|
|
188
|
+
// something failed, perhaps a network issue
|
|
189
|
+
// don't store anything
|
|
190
|
+
return finishedLoading(err);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!virtualConfig)
|
|
194
|
+
{
|
|
195
|
+
// mark that it failed (30 minute TTL)
|
|
196
|
+
return process.cache.write(VCSENTINEL_CACHE_KEY, true, BLACKLIST_TTL_SECONDS, function() {
|
|
197
|
+
finishedLoading({
|
|
198
|
+
"message": "No virtual config found for host: " + host
|
|
199
|
+
});
|
|
236
200
|
});
|
|
237
201
|
}
|
|
238
202
|
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
|
|
203
|
+
// populate gitana.json
|
|
204
|
+
var gitanaJson = {
|
|
205
|
+
"clientKey": virtualConfig.clientKey
|
|
206
|
+
};
|
|
207
|
+
if (virtualConfig.clientSecret) {
|
|
208
|
+
gitanaJson.clientSecret = virtualConfig.clientSecret;
|
|
209
|
+
}
|
|
210
|
+
if (virtualConfig.username) {
|
|
211
|
+
gitanaJson.username = virtualConfig.username;
|
|
212
|
+
}
|
|
213
|
+
if (virtualConfig.password) {
|
|
214
|
+
gitanaJson.password = virtualConfig.password;
|
|
215
|
+
}
|
|
216
|
+
if (virtualConfig.application) {
|
|
217
|
+
gitanaJson.application = virtualConfig.application;
|
|
218
|
+
}
|
|
219
|
+
if (virtualConfig.baseURL) {
|
|
220
|
+
gitanaJson.baseURL = virtualConfig.baseURL;
|
|
221
|
+
}
|
|
222
|
+
if (!gitanaJson.baseURL)
|
|
223
|
+
{
|
|
224
|
+
gitanaJson.baseURL = util.cleanupURL(util.asURL(process.env.GITANA_PROXY_SCHEME, process.env.GITANA_PROXY_HOST, process.env.GITANA_PROXY_PORT, process.env.GITANA_PROXY_PATH));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// mark as retrieved from virtual driver
|
|
228
|
+
gitanaJson._virtual = true;
|
|
229
|
+
|
|
230
|
+
// write the gitana.json file
|
|
231
|
+
rootStore.writeFile("gitana.json", JSON.stringify(gitanaJson, null, " "), function (err) {
|
|
242
232
|
|
|
243
|
-
// if we failed to
|
|
244
|
-
if (err
|
|
233
|
+
// if we failed to write the file, then delete and call back with error
|
|
234
|
+
if (err)
|
|
245
235
|
{
|
|
246
236
|
return rootStore.deleteFile("gitana.json", function() {
|
|
247
|
-
finishedLoading(
|
|
248
|
-
"message": "There was a problem writing the driver configuration file. Please reload."
|
|
249
|
-
});
|
|
237
|
+
finishedLoading(err);
|
|
250
238
|
});
|
|
251
239
|
}
|
|
252
240
|
|
|
253
|
-
|
|
241
|
+
// make sure the file wrote successfully
|
|
242
|
+
// check stats, ensure non-error and file size > 0
|
|
243
|
+
rootStore.fileStats("gitana.json", function(err, stats) {
|
|
244
|
+
|
|
245
|
+
// if we failed to read stats, then delete and call back with error
|
|
246
|
+
if (err || stats.size === 0)
|
|
247
|
+
{
|
|
248
|
+
return rootStore.deleteFile("gitana.json", function() {
|
|
249
|
+
finishedLoading({
|
|
250
|
+
"message": "There was a problem writing the driver configuration file. Please reload."
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
finishedLoading(null, gitanaJson);
|
|
256
|
+
});
|
|
254
257
|
});
|
|
255
258
|
});
|
|
256
259
|
});
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
if (exists)
|
|
261
|
-
{
|
|
262
|
-
// read gitana json and send back
|
|
263
|
-
rootStore.readFile("gitana.json", function(err, data) {
|
|
260
|
+
};
|
|
264
261
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (!data)
|
|
271
|
-
{
|
|
272
|
-
return callback({
|
|
273
|
-
"message": "The gitana.json data read from disk was null or empty"
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// make sure not size 0
|
|
278
|
-
rootStore.fileStats("gitana.json", function(err, stats) {
|
|
262
|
+
if (exists)
|
|
263
|
+
{
|
|
264
|
+
// read gitana json and send back
|
|
265
|
+
rootStore.readFile("gitana.json", function(err, data) {
|
|
279
266
|
|
|
280
267
|
if (err)
|
|
281
268
|
{
|
|
282
269
|
return callback(err);
|
|
283
270
|
}
|
|
284
271
|
|
|
285
|
-
|
|
286
|
-
if (err || stats.size === 0)
|
|
272
|
+
if (!data)
|
|
287
273
|
{
|
|
288
|
-
return
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
});
|
|
292
|
-
});
|
|
274
|
+
return callback({
|
|
275
|
+
"message": "The gitana.json data read from disk was null or empty"
|
|
276
|
+
})
|
|
293
277
|
}
|
|
294
278
|
|
|
295
|
-
//
|
|
296
|
-
|
|
279
|
+
// make sure not size 0
|
|
280
|
+
rootStore.fileStats("gitana.json", function(err, stats) {
|
|
297
281
|
|
|
298
|
-
|
|
282
|
+
if (err)
|
|
283
|
+
{
|
|
284
|
+
return callback(err);
|
|
285
|
+
}
|
|
299
286
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
{
|
|
303
|
-
var newBaseURL = util.cleanupURL(gitanaJson.baseURL);
|
|
304
|
-
if (newBaseURL !== gitanaJson.baseURL)
|
|
287
|
+
// if we failed to read stats or file size 0, then delete and call back with error
|
|
288
|
+
if (err || stats.size === 0)
|
|
305
289
|
{
|
|
306
|
-
|
|
290
|
+
return rootStore.deleteFile("gitana.json", function() {
|
|
291
|
+
callback({
|
|
292
|
+
"message": "There was a problem writing the driver configuration file. Please reload."
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
}
|
|
307
296
|
|
|
308
|
-
|
|
297
|
+
// remove vcSentinel if it exists
|
|
298
|
+
process.cache.remove(VCSENTINEL_CACHE_KEY);
|
|
309
299
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
300
|
+
var gitanaJson = JSON.parse("" + data);
|
|
301
|
+
|
|
302
|
+
// auto-upgrade the host?
|
|
303
|
+
if (gitanaJson.baseURL)
|
|
304
|
+
{
|
|
305
|
+
var newBaseURL = util.cleanupURL(gitanaJson.baseURL);
|
|
306
|
+
if (newBaseURL !== gitanaJson.baseURL)
|
|
307
|
+
{
|
|
308
|
+
console.log("Auto-upgrade gitana.json from: " + gitanaJson.baseURL + ", to: " + newBaseURL);
|
|
309
|
+
|
|
310
|
+
gitanaJson.baseURL = newBaseURL;
|
|
311
|
+
|
|
312
|
+
// write the gitana.json file
|
|
313
|
+
rootStore.writeFile("gitana.json", JSON.stringify(gitanaJson, null, " "), function (err) {
|
|
314
|
+
// nada
|
|
315
|
+
});
|
|
316
|
+
}
|
|
314
317
|
}
|
|
315
|
-
}
|
|
316
318
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
+
// otherwise, fine!
|
|
320
|
+
callback(null, gitanaJson);
|
|
321
|
+
});
|
|
319
322
|
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
323
|
+
}
|
|
324
|
+
else
|
|
325
|
+
{
|
|
326
|
+
loadFromRemote(function(err, gitanaJson, doesNotExist) {
|
|
327
|
+
callback(err, gitanaJson, doesNotExist);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
329
332
|
|
|
330
|
-
});
|
|
333
|
+
}(host, rootStore, logMethod, callback));
|
|
331
334
|
};
|
|
332
335
|
|
|
333
336
|
r.interceptor = function()
|
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -1004,16 +1004,17 @@ var startServer = function(config, startServerFinishedFn)
|
|
|
1004
1004
|
|
|
1005
1005
|
if (kill)
|
|
1006
1006
|
{
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1007
|
+
var text = "KILL, method: " + req.method + ", url: " + req.url;
|
|
1008
|
+
if (req.headers)
|
|
1009
|
+
{
|
|
1010
|
+
text += ", headers: " + JSON.stringify(req.headers);
|
|
1011
|
+
}
|
|
1012
|
+
if (req.query)
|
|
1013
|
+
{
|
|
1014
|
+
text += ", query: " + JSON.stringify(req.query);
|
|
1015
|
+
}
|
|
1016
|
+
console.log(text);
|
|
1017
|
+
|
|
1017
1018
|
// are we being spoofed? kill the connection
|
|
1018
1019
|
res.blocked = true;
|
|
1019
1020
|
res.writeHead(503, { 'Content-Type': 'application/json' });
|