-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-secret-json.js
62 lines (59 loc) · 1.86 KB
/
generate-secret-json.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs');
const dotenv = require('dotenv');
dotenv.config({ path: '.env.local' });
const keyFile = process.env.GOOGLE_APPLICATION_KEY_FILE;
if (!keyFile) {
throw new Error(
'GOOGLE_APPLICATION_KEY_FILE environment variable is not defined.'
);
}
const project_id = process.env.GOOGLE_APPLICATION_PROJECT_ID;
if (!project_id) {
throw new Error(
'GOOGLE_APPLICATION_PROJECT_ID environment variable is not defined.'
);
}
const private_key_id = process.env.GOOGLE_APPLICATION_PRIVATE_KEY_ID;
if (!private_key_id) {
throw new Error(
'GOOGLE_APPLICATION_PRIVATE_KEY_ID environment variable is not defined.'
);
}
const private_key = process.env.GOOGLE_APPLICATION_PRIVATE_KEY;
if (!private_key) {
throw new Error(
'GOOGLE_APPLICATION_PRIVATE_KEY environment variable is not defined.'
);
}
const client_email = process.env.GOOGLE_APPLICATION_CLIENT_EMAIL;
if (!client_email) {
throw new Error(
'GOOGLE_APPLICATION_CLIENT_EMAIL environment variable is not defined.'
);
}
const client_id = process.env.GOOGLE_APPLICATION_CLIENT_ID;
if (!client_id) {
throw new Error(
'GOOGLE_APPLICATION_CLIENT_ID environment variable is not defined.'
);
}
const client_x509_cert_url =
process.env.GOOGLE_APPLICATION_CLIENT_X509_CERT_URL;
if (!client_x509_cert_url) {
throw new Error(
'GOOGLE_APPLICATION_CLIENT_X509_CERT_URL environment variable is not defined.'
);
}
const secretData = {
type: 'service_account',
project_id: project_id,
private_key_id: private_key_id,
private_key: private_key,
client_email: client_email,
client_id: client_id,
auth_uri: 'https://accounts.google.com/o/oauth2/auth',
token_uri: 'https://oauth2.googleapis.com/token',
auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
client_x509_cert_url: client_x509_cert_url,
};
fs.writeFileSync(`./${keyFile}`, JSON.stringify(secretData));