blob: 09db4fc60beed961593d6141af867109f5d84732 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import { readFile, readFileSync } from "fs";
import { pathFromRoot } from "../../ActionUtilities";
import { SecureContextOptions } from "tls";
export namespace GoogleCredentialsLoader {
export interface InstalledCredentials {
client_id: string;
project_id: string;
auth_uri: string;
token_uri: string;
auth_provider_x509_cert_url: string;
client_secret: string;
redirect_uris: string[];
}
export let ProjectCredentials: InstalledCredentials;
export async function loadCredentials() {
ProjectCredentials = await new Promise<InstalledCredentials>(resolve => {
readFile(__dirname + '/google_project_credentials.json', function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
resolve(JSON.parse(content.toString()).installed);
});
});
}
}
export namespace SSLCredentialsLoader {
export let Credentials: SecureContextOptions = {};
export async function loadCredentials() {
const { serverName } = process.env;
const cert = (suffix: string) => readFileSync(pathFromRoot(`./${serverName}${suffix}`)).toString();
Credentials.key = cert(".key");
Credentials.cert = cert(".crt");
Credentials.ca = cert("-ca.crt");
}
}
|