@riocrypto/common 1.0.547 → 1.0.549
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,10 +35,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
35
|
exports.secretManagerClient = void 0;
|
|
13
36
|
const secret_manager_1 = require("@google-cloud/secret-manager");
|
|
14
37
|
const rio_env_1 = require("../types/rio-env");
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
15
39
|
class SecretManagerClient {
|
|
16
40
|
constructor(env) {
|
|
17
41
|
this.env = env;
|
|
18
|
-
|
|
42
|
+
const secretFilePath = "/etc/secrets/secret-manager-service-account-key.json";
|
|
43
|
+
const secretFileContents = fs.readFileSync(secretFilePath, "utf8");
|
|
44
|
+
const secretData = JSON.parse(secretFileContents);
|
|
45
|
+
this.projectId = secretData.project_id;
|
|
46
|
+
const clientEmail = secretData.client_email;
|
|
47
|
+
const privateKey = secretData.private_key;
|
|
48
|
+
this.client = new secret_manager_1.SecretManagerServiceClient({
|
|
49
|
+
projectId: this.projectId,
|
|
50
|
+
credentials: {
|
|
51
|
+
client_email: clientEmail,
|
|
52
|
+
private_key: privateKey,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
19
55
|
}
|
|
20
56
|
getSecretValue(secretId) {
|
|
21
57
|
var _a, _b, _c, _d;
|
|
@@ -36,7 +72,7 @@ class SecretManagerClient {
|
|
|
36
72
|
try {
|
|
37
73
|
// Access the secret version
|
|
38
74
|
const [version] = yield this.client.accessSecretVersion({
|
|
39
|
-
name: `projects/
|
|
75
|
+
name: `projects/${this.projectId}/secrets/${file}/versions/latest`,
|
|
40
76
|
});
|
|
41
77
|
if (!((_b = (_a = version.payload) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.toString())) {
|
|
42
78
|
throw new Error();
|
|
@@ -51,4 +87,4 @@ class SecretManagerClient {
|
|
|
51
87
|
});
|
|
52
88
|
}
|
|
53
89
|
}
|
|
54
|
-
exports.secretManagerClient = new SecretManagerClient(process.env.RIO_ENV);
|
|
90
|
+
exports.secretManagerClient = new SecretManagerClient(process.env.RIO_ENV || process.env.NEXT_PUBLIC_RIO_ENV);
|