add the ability to read in cert

This commit is contained in:
Jonathan Tamsut
2023-05-01 14:51:54 -07:00
parent c6cde72b37
commit 57a5994e12
+24 -4
View File
@@ -1,8 +1,28 @@
import {Octokit} from "@octokit/rest";
import { Agent } from "node:https";
import { readFileSync } from "fs";
export function getClient(token: string, userAgent?: string): Octokit {
return new Octokit({
auth: token,
userAgent: userAgent || `GitHub Actions Language Server`
});
const selfSignedCertPath = process.env.NODE_EXTRA_CA_CERTS;
// if NODE_EXTRA_CA_CERTS is set then use the self-signed cert to make the request
if (selfSignedCertPath) {
const httpsAgent = new Agent({
ca: readFileSync(selfSignedCertPath)
});
return new Octokit({
auth: token,
userAgent: userAgent || `GitHub Actions Language Server`,
request: {
agent: httpsAgent
},
});
} else {
return new Octokit({
auth: token,
userAgent: userAgent || `GitHub Actions Language Server`
});
}
}