|
1 | 1 | import { ChildProcess, spawn } from "child_process"; |
| 2 | +import * as fs from "fs"; |
2 | 3 | import * as path from "path"; |
3 | 4 |
|
4 | 5 | import * as core from "@actions/core"; |
@@ -29,6 +30,7 @@ type BasicAuthCredentials = { |
29 | 30 |
|
30 | 31 | type ProxyConfig = { |
31 | 32 | all_credentials: Credential[]; |
| 33 | + ca_certificate_file?: string; |
32 | 34 | ca: CertificateAuthority; |
33 | 35 | proxy_auth?: BasicAuthCredentials; |
34 | 36 | }; |
@@ -118,6 +120,22 @@ async function runWrapper() { |
118 | 120 | ca, |
119 | 121 | }; |
120 | 122 |
|
| 123 | + // Try to write the certificate to disk. Some extractors may use this to populate |
| 124 | + // the `SSL_CERT_FILE` environment variable. |
| 125 | + try { |
| 126 | + const certificatePath = path.join( |
| 127 | + actionsUtil.getTemporaryDirectory(), |
| 128 | + "codeql_package_proxy.crt", |
| 129 | + ); |
| 130 | + fs.writeFileSync(certificatePath, ca.cert); |
| 131 | + |
| 132 | + proxyConfig.ca_certificate_file = certificatePath; |
| 133 | + } catch (error) { |
| 134 | + logger.error( |
| 135 | + `Failed to write the proxy certificate to disk: ${util.getErrorMessage(error)}`, |
| 136 | + ); |
| 137 | + } |
| 138 | + |
121 | 139 | // Start the Proxy |
122 | 140 | const proxyBin = await getProxyBinaryPath(); |
123 | 141 | await startProxy(proxyBin, proxyConfig, proxyLogFilePath, logger); |
@@ -171,6 +189,7 @@ async function startProxy( |
171 | 189 | core.setOutput("proxy_host", host); |
172 | 190 | core.setOutput("proxy_port", port.toString()); |
173 | 191 | core.setOutput("proxy_ca_certificate", config.ca.cert); |
| 192 | + core.setOutput("proxy_ca_certificate_file", config.ca_certificate_file); |
174 | 193 |
|
175 | 194 | const registry_urls = config.all_credentials |
176 | 195 | .filter((credential) => credential.url !== undefined) |
|
0 commit comments