This repository was archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support refreshing TLS certs in background (#369)
- Loading branch information
1 parent
2ab950d
commit 3bdf99a
Showing
7 changed files
with
133 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const logger = require('./logger'); | ||
const { | ||
TemporalClient, | ||
WithAuthMetadata, | ||
WithErrorConverter, | ||
} = require('./temporal-client'); | ||
const { getTlsCredentials } = require('./tls'); | ||
const { getTlsConfig } = require('./config'); | ||
|
||
let refreshInterval = Number(process.env.TEMPORAL_TLS_REFRESH_INTERVAL) || 0; | ||
|
||
if (refreshInterval === 0) { | ||
const tls = getTlsConfig(); | ||
if (tls.refreshInterval) { | ||
refreshInterval = Number(tls.refreshInterval); | ||
} | ||
} | ||
|
||
let tlsCache; | ||
let tClient; | ||
|
||
loadClient(); | ||
|
||
if (refreshInterval !== 0) { | ||
setInterval(() => { | ||
try { | ||
const tls = getTlsCredentials(); | ||
if ( | ||
!equal(tls.pk, tlsCache.pk) || | ||
!equal(tls.cert, tlsCache.cert) || | ||
!equal(tls.ca, tlsCache.ca) || | ||
tls.serverName !== tlsCache.serverName || | ||
tls.verifyHost !== tlsCache.verifyHost | ||
) { | ||
loadClient(); | ||
} | ||
} catch (err) { | ||
logger.error(err); | ||
} | ||
}, refreshInterval * 1000); | ||
} | ||
|
||
getTemporalClient = () => tClient; | ||
|
||
function loadClient() { | ||
tlsCache = getTlsCredentials(); | ||
tClient = WithErrorConverter(WithAuthMetadata(new TemporalClient(tlsCache))); | ||
} | ||
|
||
function equal(v1, v2) { | ||
if (Buffer.isBuffer(v1)) { | ||
if (Buffer.isBuffer(v2)) { | ||
return Buffer.compare(v1, v2) === 0; | ||
} | ||
return false; | ||
} else if (Buffer.isBuffer(v2)) { | ||
return false; | ||
} else { | ||
return v1 === v2; | ||
} | ||
} | ||
|
||
module.exports = { getTemporalClient }; |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const { getCredentials } = require('./tls'); | ||
module.exports = { getCredentials }; | ||
const { getTlsCredentials, getGrpcCredentials } = require('./tls'); | ||
module.exports = { getTlsCredentials, getGrpcCredentials }; |
Oops, something went wrong.