Skip to content

Commit 44c37a0

Browse files
authored
fix(amazonq): make trust chain resolution optional for Q LSP (#5778)
don't block server startup if resolution fails
1 parent 2cfbbb7 commit 44c37a0

File tree

1 file changed

+13
-7
lines changed
  • plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp

1 file changed

+13
-7
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,21 @@ private class AmazonQServerInstance(private val project: Project, private val cs
371371
// make assumption that all requests will resolve to the same CA
372372
// also terrible assumption that default endpoint is reachable
373373
val qUri = URI(QDefaultServiceConfig.ENDPOINT)
374-
val rtsTrustChain = TrustChainUtil.getTrustChain(qUri)
375-
val extraCaCerts = Files.createTempFile("q-extra-ca", ".pem").apply {
376-
writeText(
377-
TrustChainUtil.certsToPem(rtsTrustChain)
378-
)
374+
val extraCaCerts = try {
375+
val rtsTrustChain = TrustChainUtil.getTrustChain(qUri)
376+
377+
Files.createTempFile("q-extra-ca", ".pem").apply {
378+
writeText(
379+
TrustChainUtil.certsToPem(rtsTrustChain)
380+
)
381+
}
382+
} catch (e: Exception) {
383+
LOG.info(e) { "Could not resolve trust chain for $qUri, skipping NODE_EXTRA_CA_CERTS" }
384+
null
379385
}
380386

381387
val node = if (SystemInfo.isWindows) "node.exe" else "node"
382-
var nodePath = getNodeRuntimePath(artifact.resolve(node))
388+
val nodePath = getNodeRuntimePath(artifact.resolve(node))
383389

384390
val cmd = NodeExePatcher.patch(nodePath)
385391
.withParameters(
@@ -388,7 +394,7 @@ private class AmazonQServerInstance(private val project: Project, private val cs
388394
"--set-credentials-encryption-key",
389395
).withEnvironment(
390396
buildMap {
391-
put("NODE_EXTRA_CA_CERTS", extraCaCerts.toAbsolutePath().toString())
397+
extraCaCerts?.let { put("NODE_EXTRA_CA_CERTS", it.toAbsolutePath().toString()) }
392398

393399
val proxy = JdkProxyProvider.getInstance().proxySelector.select(qUri)
394400
// log if only socks proxy available

0 commit comments

Comments
 (0)