@aikidosec/broker-client 0.0.4 → 0.0.6
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/app/client.js +16 -8
- package/package.json +1 -1
package/app/client.js
CHANGED
|
@@ -288,7 +288,8 @@ const socket = io(SERVER_URL, {
|
|
|
288
288
|
reconnectionAttempts: Infinity,
|
|
289
289
|
reconnectionDelay: 1000,
|
|
290
290
|
reconnectionDelayMax: 30000,
|
|
291
|
-
randomizationFactor: 0.5
|
|
291
|
+
randomizationFactor: 0.5,
|
|
292
|
+
autoConnect: false // Don't connect until after registration
|
|
292
293
|
});
|
|
293
294
|
|
|
294
295
|
// Socket.IO event handlers
|
|
@@ -397,12 +398,6 @@ socket.on('forward_request', async (data, callback) => {
|
|
|
397
398
|
* Register this client with the broker server
|
|
398
399
|
*/
|
|
399
400
|
async function registerWithServer() {
|
|
400
|
-
// Check if already registered
|
|
401
|
-
if (getClientId() !== null) {
|
|
402
|
-
log.info("✓ Client already registered (client_id file exists)");
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
401
|
const serverUrl = `${SERVER_URL}/broker-reserved/register`;
|
|
407
402
|
|
|
408
403
|
log.info(`Attempting to register with server at ${serverUrl}`);
|
|
@@ -431,6 +426,9 @@ async function registerWithServer() {
|
|
|
431
426
|
} catch (e) {
|
|
432
427
|
log.warn(`Could not save client_id file: ${e.message}`);
|
|
433
428
|
}
|
|
429
|
+
|
|
430
|
+
log.info("Waiting for server to propagate configuration...");
|
|
431
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
434
432
|
return;
|
|
435
433
|
} else if (response.status === 409) {
|
|
436
434
|
log.info("✓ Client already registered with server (this is OK)");
|
|
@@ -452,6 +450,12 @@ async function registerWithServer() {
|
|
|
452
450
|
}
|
|
453
451
|
} catch (error) {
|
|
454
452
|
log.warn(`Registration attempt ${attempt + 1} failed: ${error.name}: ${error.message}`);
|
|
453
|
+
if (getClientId() !== null) {
|
|
454
|
+
// If we have a client_id already, don't retry
|
|
455
|
+
// we should try once to deal with secret rotation
|
|
456
|
+
log.info("✓ Client already registered (this is OK)");
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
455
459
|
}
|
|
456
460
|
|
|
457
461
|
if (attempt < maxRetries - 1) {
|
|
@@ -500,7 +504,7 @@ async function main() {
|
|
|
500
504
|
log.info("HTTP Proxy: Not configured");
|
|
501
505
|
}
|
|
502
506
|
|
|
503
|
-
// Register with server (creates client_id file)
|
|
507
|
+
// Register with server (creates client_id file, waits for propagation)
|
|
504
508
|
await registerWithServer();
|
|
505
509
|
|
|
506
510
|
// Get client_id after registration
|
|
@@ -514,6 +518,10 @@ async function main() {
|
|
|
514
518
|
log.warn("No client_id available after registration");
|
|
515
519
|
}
|
|
516
520
|
|
|
521
|
+
// Now connect to broker server via Socket.IO
|
|
522
|
+
log.info("Connecting to broker server...");
|
|
523
|
+
socket.connect();
|
|
524
|
+
|
|
517
525
|
// Start background task to sync resources every 3 minutes
|
|
518
526
|
resourceSyncTask().catch(err => log.error(`Resource sync task error: ${err.message}`));
|
|
519
527
|
log.info("Started resource sync background task");
|
package/package.json
CHANGED