Skip to content

Commit 7fcc05d

Browse files
committed
fix: read gcreds from env var
1 parent d17bd81 commit 7fcc05d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/util/gcp-kms-utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,19 @@ const EcdsaPubKey = asn1.define("EcdsaPubKey", function (this: any) {
2121
});
2222
/* eslint-enable func-names */
2323

24+
function getClientCredentials() {
25+
return process.env.GOOGLE_APPLICATION_CREDENTIAL_EMAIL && process.env.GOOGLE_APPLICATION_CREDENTIAL_PRIVATE_KEY
26+
? {
27+
credentials: {
28+
client_email: process.env.GOOGLE_APPLICATION_CREDENTIAL_EMAIL,
29+
private_key: process.env.GOOGLE_APPLICATION_CREDENTIAL_PRIVATE_KEY,
30+
},
31+
}
32+
: {};
33+
}
34+
2435
export async function sign(digest: Buffer, kmsCredentials: GcpKmsSignerCredentials) {
25-
const kms = new KeyManagementServiceClient();
36+
const kms = new KeyManagementServiceClient(getClientCredentials());
2637
const versionName = kms.cryptoKeyVersionPath(
2738
kmsCredentials.projectId,
2839
kmsCredentials.locationId,
@@ -40,7 +51,7 @@ export async function sign(digest: Buffer, kmsCredentials: GcpKmsSignerCredentia
4051
}
4152

4253
export const getPublicKey = async (kmsCredentials: GcpKmsSignerCredentials) => {
43-
const kms = new KeyManagementServiceClient();
54+
const kms = new KeyManagementServiceClient(getClientCredentials());
4455
const versionName = kms.cryptoKeyVersionPath(
4556
kmsCredentials.projectId,
4657
kmsCredentials.locationId,

0 commit comments

Comments
 (0)