-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #737 from snyk/fix/expose-broker-client-config-inf…
…o-in-connection feat: send clientconfig metadata to server [HYB-202]
- Loading branch information
Showing
10 changed files
with
183 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ConfigMetadata } from '../types/client'; | ||
import { Config } from '../types/config'; | ||
import { log as logger } from '../../logs/logger'; | ||
|
||
export const getClientConfigMetadata = ( | ||
clientConfig: Record<string, any>, | ||
): ConfigMetadata => { | ||
const configMetadata: ConfigMetadata = { | ||
haMode: highAvailabilityModeEnabled(clientConfig), | ||
debugMode: clientConfig.logLevel === 'debug' ? true : false, | ||
bodyLogMode: clientConfig.logEnableBody ? true : false, | ||
credPooling: isCredPoolingUsed(clientConfig), | ||
privateCa: clientConfig.nodeExtraCaCert ? true : false, | ||
tlsReject: | ||
parseInt(clientConfig.nodeTlsRejectUnauthorized) === 0 ? true : false, | ||
proxy: clientConfig.httpProxy || clientConfig.httpsProxy ? true : false, | ||
customAccept: clientConfig.accept ? true : false, | ||
insecureDownstream: clientConfig.insecureDownstream ? true : false, | ||
universalBroker: clientConfig.universalBrokerEnabled ? true : false, | ||
}; | ||
return configMetadata; | ||
}; | ||
|
||
const isCredPoolingUsed = (config: Record<string, any>): boolean => { | ||
for (const key in config) { | ||
if (config.hasOwnProperty(key) && key.includes('_POOL')) { | ||
return true; // Found a key containing '_POOL' | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
export function highAvailabilityModeEnabled(config: any): boolean { | ||
// high availability mode is disabled per default | ||
let highAvailabilityModeEnabled = false; | ||
const highAvailabilityModeEnabledValue = (config as Config) | ||
.BROKER_HA_MODE_ENABLED; | ||
|
||
if (typeof highAvailabilityModeEnabledValue !== 'undefined') { | ||
highAvailabilityModeEnabled = | ||
highAvailabilityModeEnabledValue.toLowerCase() === 'true' || | ||
highAvailabilityModeEnabledValue.toLowerCase() === 'yes'; | ||
} | ||
|
||
logger.info({ enabled: highAvailabilityModeEnabled }, 'checking for HA mode'); | ||
|
||
return highAvailabilityModeEnabled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { getClientConfigMetadata } from '../../lib/client/utils/configHelpers'; | ||
import { getConfig, loadBrokerConfig } from '../../lib/common/config/config'; | ||
import { LoadedClientOpts } from '../../lib/common/types/options'; | ||
|
||
describe('config', () => { | ||
beforeAll(() => { | ||
loadBrokerConfig(); | ||
}); | ||
afterEach(() => { | ||
delete process.env.LOG_LEVEL; | ||
delete process.env.LOG_ENABLE_BODY; | ||
delete process.env.GITHUB_TOKEN_POOL; | ||
delete process.env.INSECURE_DOWNSTREAM; | ||
delete process.env.BROKER_HA_MODE_ENABLED; | ||
delete process.env.HTTP_PROXY; | ||
delete process.env.NODE_EXTRA_CA_CERT; | ||
delete process.env.ACCEPT; | ||
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED; | ||
delete process.env.UNIVERSAL_BROKER_ENABLED; | ||
}); | ||
|
||
afterAll(() => { | ||
delete process.env.LOG_LEVEL; | ||
delete process.env.LOG_ENABLE_BODY; | ||
delete process.env.GITHUB_TOKEN_POOL; | ||
delete process.env.INSECURE_DOWNSTREAM; | ||
delete process.env.BROKER_HA_MODE_ENABLED; | ||
delete process.env.HTTP_PROXY; | ||
delete process.env.NODE_EXTRA_CA_CERT; | ||
delete process.env.ACCEPT; | ||
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED; | ||
delete process.env.UNIVERSAL_BROKER_ENABLED; | ||
}); | ||
it('everything is false for empty config', () => { | ||
loadBrokerConfig(); | ||
const config = getConfig(); | ||
expect(getClientConfigMetadata(config as LoadedClientOpts)).toEqual({ | ||
bodyLogMode: false, | ||
credPooling: false, | ||
customAccept: false, | ||
debugMode: false, | ||
haMode: false, | ||
privateCa: false, | ||
proxy: false, | ||
tlsReject: false, | ||
insecureDownstream: false, | ||
universalBroker: false, | ||
}); | ||
}); | ||
|
||
it('everything is true for everything enabled in config', () => { | ||
process.env.LOG_LEVEL = 'debug'; | ||
process.env.LOG_ENABLE_BODY = 'true'; | ||
process.env.GITHUB_TOKEN_POOL = '123,456'; | ||
process.env.INSECURE_DOWNSTREAM = 'true_but_truly_value_does_not_matter'; | ||
process.env.BROKER_HA_MODE_ENABLED = 'true'; | ||
process.env.HTTP_PROXY = 'http://myproxy'; | ||
process.env.NODE_EXTRA_CA_CERT = 'my/path'; | ||
process.env.ACCEPT = 'my/path'; | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
process.env.UNIVERSAL_BROKER_ENABLED = 'true'; | ||
loadBrokerConfig(); | ||
const config = getConfig(); | ||
expect(getClientConfigMetadata(config as LoadedClientOpts)).toEqual({ | ||
bodyLogMode: true, | ||
credPooling: true, | ||
customAccept: true, | ||
debugMode: true, | ||
haMode: true, | ||
privateCa: true, | ||
proxy: true, | ||
tlsReject: true, | ||
insecureDownstream: true, | ||
universalBroker: true, | ||
}); | ||
}); | ||
|
||
it('everything is false for everything disabled in config', () => { | ||
process.env.LOG_LEVEL = 'info'; | ||
process.env.GITHUB_TOKEN = '456'; | ||
process.env.BROKER_HA_MODE_ENABLED = 'false'; | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'; | ||
loadBrokerConfig(); | ||
const config = getConfig(); | ||
expect(getClientConfigMetadata(config as LoadedClientOpts)).toEqual({ | ||
bodyLogMode: false, | ||
credPooling: false, | ||
customAccept: false, | ||
debugMode: false, | ||
haMode: false, | ||
privateCa: false, | ||
proxy: false, | ||
tlsReject: false, | ||
insecureDownstream: false, | ||
universalBroker: false, | ||
}); | ||
}); | ||
}); |