Skip to content

Commit d8fe4b8

Browse files
committed
fix(env): privateKey - convert \n to new line
solves issue only found when loaded using kubernetes secrets
1 parent dc4b742 commit d8fe4b8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/helpers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,16 @@ export async function downloadPackage(pkg: IPackageParams, directory: string) {
2525
dir: directory
2626
});
2727
}
28+
29+
export function jsonEscape(str: string) {
30+
return str.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
31+
}
32+
33+
/**
34+
* Converts all \n to new lines and returns key.
35+
* (solves issue only found when loaded using kubernetes secrets)
36+
*/
37+
export function getGCloudPrivateKey() {
38+
const obj = JSON.parse(jsonEscape('{"k": "' + process.env.GOOGLE_CLOUD_PRIVATE_KEY.trim() + '"}'));
39+
return obj.k;
40+
}

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as compression from 'compression';
55
import * as helmet from 'helmet';
66
import {CloudflareChallenge} from '@interactivetraining/le-challenge-cloudflare';
77
import {IPackageParams} from './interfaces';
8-
import {downloadPackage} from './helpers';
8+
import {downloadPackage, getGCloudPrivateKey} from './helpers';
99
import {GCloudStoreCreate} from '@interactivetraining/le-store-gcloud-storage'
1010
import * as http from 'http';
1111

@@ -71,7 +71,7 @@ if (process.env.ENABLE_SSL === "1") {
7171
bucketName: process.env.GOOGLE_CLOUD_BUCKET_NAME,
7272
projectId: process.env.GOOGLE_CLOUD_PROJECT_ID,
7373
dbFileName: process.env.GOOGLE_CLOUD_CERT_DB_FILE,
74-
privateKey: process.env.GOOGLE_CLOUD_PRIVATE_KEY.trim(),
74+
privateKey: getGCloudPrivateKey(),
7575
clientEmail: process.env.GOOGLE_CLOUD_CLIENT_EMAIL
7676
}),
7777
challengeType: 'dns-01',

0 commit comments

Comments
 (0)