Skip to content

Commit

Permalink
PTFM-800 don't log user creds (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
amodelbello authored Feb 9, 2021
1 parent 1312914 commit 08a1bfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/AmqpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export class AmqpClient {
private async connect(): Promise<void> {
const brokerUrl = AmqpClient.getBrokerUrl(this.amqpConfig)
this.connection = await connect(brokerUrl)
log.info(`AMQP Successfully connected to ${brokerUrl} `)

const brokerUrlForLogs = AmqpClient.getBrokerUrl(this.amqpConfig, true)
log.info(`AMQP Successfully connected to ${brokerUrlForLogs} `)

this.connection.on('error', (e): void => {
log.error(e)
Expand Down Expand Up @@ -222,11 +224,13 @@ export class AmqpClient {
return reducedConsumers
}

private static getBrokerUrl(config: AmqpConfig): string {
private static getBrokerUrl(config: AmqpConfig, forLogs = false): string {
const { host, port, vhost, tls, username, password } = config

const protocol = tls ? 'amqps' : 'amqp'
const url = `${protocol}://${username}:${password}@${host}:${port}${vhost}`
const url = `${protocol}://${forLogs ? 'XXXXXX' : username}:${
forLogs ? 'XXXXXX' : password
}@${host}:${port}${vhost}`

return url
}
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/AmqpClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('AmqpClient', () => {
it('initializes', async () => {
const initializedAmqp = await amqp.init()
expect(initializedAmqp).toBeTruthy()
expect(log.info).toHaveBeenCalledWith(expect.stringContaining('XXXXXX:XXXXXX'))
})

it('initializes with alternate config', async () => {
Expand Down

0 comments on commit 08a1bfc

Please sign in to comment.