Skip to content

Commit

Permalink
fix: read gcreds from env var
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Nov 15, 2022
1 parent d17bd81 commit 7fcc05d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/util/gcp-kms-utils.ts
Expand Up @@ -21,8 +21,19 @@ const EcdsaPubKey = asn1.define("EcdsaPubKey", function (this: any) {
});
/* eslint-enable func-names */

function getClientCredentials() {
return process.env.GOOGLE_APPLICATION_CREDENTIAL_EMAIL && process.env.GOOGLE_APPLICATION_CREDENTIAL_PRIVATE_KEY
? {
credentials: {
client_email: process.env.GOOGLE_APPLICATION_CREDENTIAL_EMAIL,
private_key: process.env.GOOGLE_APPLICATION_CREDENTIAL_PRIVATE_KEY,
},
}
: {};
}

export async function sign(digest: Buffer, kmsCredentials: GcpKmsSignerCredentials) {
const kms = new KeyManagementServiceClient();
const kms = new KeyManagementServiceClient(getClientCredentials());
const versionName = kms.cryptoKeyVersionPath(
kmsCredentials.projectId,
kmsCredentials.locationId,
Expand All @@ -40,7 +51,7 @@ export async function sign(digest: Buffer, kmsCredentials: GcpKmsSignerCredentia
}

export const getPublicKey = async (kmsCredentials: GcpKmsSignerCredentials) => {
const kms = new KeyManagementServiceClient();
const kms = new KeyManagementServiceClient(getClientCredentials());
const versionName = kms.cryptoKeyVersionPath(
kmsCredentials.projectId,
kmsCredentials.locationId,
Expand Down

0 comments on commit 7fcc05d

Please sign in to comment.