Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
santigimeno committed Nov 12, 2024
1 parent 3e8615c commit 0cc48e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/nsolid.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,11 @@ function updateConfig(config = {}) {
nsolidConfig.otlp = null;
}

if (nsolidConfig.grpc) {
// Make sure it's a valid URL otherwise it might crash
if (nsolidConfig.grpc && !nsolidConfig.saas) {
// Make sure it's a valid URL otherwise it might crash in the grpc++
// URLParser implementation
try {
new URL(nsolidConfig.grpc);
new URL(`http://${nsolidConfig.grpc}`);
} catch {
process._rawDebug(`Invalid grpc url: "${nsolidConfig.grpc}"`);
nsolidConfig.grpc = null;
Expand Down Expand Up @@ -776,9 +777,7 @@ function initializeConfig(nsolidConfig) {
if (nsolidConfig.saas) {
if (nsolidConfig.command) {
nsolidConfig.saas = undefined;
} else if (nsolidConfig.grpc) {
nsolidConfig.grpc = parseSaasEnvVar(nsolidConfig.saas, 0);
} else {
} else if (!nsolidConfig.grpc) {
nsolidConfig.command = parseSaasEnvVar(nsolidConfig.saas, 0);
}
}
Expand Down Expand Up @@ -907,7 +906,7 @@ function initializeConfig(nsolidConfig) {
nsolidConfig.bulk = 'localhost:' + nsolidConfig.bulk;
if (nsolidConfig.statsd && +nsolidConfig.statsd)
nsolidConfig.statsd = 'localhost:' + nsolidConfig.statsd;
if (nsolidConfig.grpc && +nsolidConfig.grpc)
if (!nsolidConfig.saas && nsolidConfig.grpc && +nsolidConfig.grpc)
nsolidConfig.grpc = 'localhost:' + nsolidConfig.grpc;

return nsolidConfig;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-nsolid-config-saas.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function execProc7() {
assert.strictEqual(code, 0);
const config = JSON.parse(output);
assert.strictEqual(config.command, undefined);
assert.strictEqual(config.grpc, saasCommand);
assert.strictEqual(config.grpc, `${PORT}`);
assert.strictEqual(config.saas, saasToken);
});
}
Expand Down

0 comments on commit 0cc48e3

Please sign in to comment.