-
Notifications
You must be signed in to change notification settings - Fork 8
/
auth.ts
40 lines (34 loc) · 1000 Bytes
/
auth.ts
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
import { writeFileSync } from "fs";
import {
getInput,
info,
exportVariable,
startGroup,
endGroup,
} from "@actions/core";
export const login = async () => {
startGroup("Firebase Authentication");
let key = getInput("gcp_sa_key");
const token = getInput("firebase_token");
if (!key && !token) {
throw new Error(
"Either firebase_token or gcp_sa_key are required to authenticate firebase-tools"
);
}
if (token) {
info("Setting firebase token for use by CLI");
await exportVariable("FIREBASE_TOKEN", token);
}
if (key) {
const pattern =
/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
if (pattern.test(key)) {
const buffer = Buffer.from(key, "base64");
key = buffer.toString("ascii");
}
info("Storing service account key into /opt/gcp_key.json");
writeFileSync("/opt/gcp_key.json", key);
await exportVariable("GOOGLE_APPLICATION_CREDENTIALS", "/opt/gcp_key.json");
}
endGroup();
};