@riocrypto/common-server 1.0.2762 → 1.0.2765
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) {
|
|
@@ -11,13 +34,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
35
|
exports.buildGCloudStorageClient = exports.GCloudStorageClient = void 0;
|
|
13
36
|
const storage_1 = require("@google-cloud/storage");
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
14
38
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
39
|
+
const KEY_PATH = "/etc/secrets/cloud-storage/cloud-storage-service-account-key.json";
|
|
40
|
+
function buildStorage() {
|
|
41
|
+
if (fs.existsSync(KEY_PATH)) {
|
|
42
|
+
return new storage_1.Storage({ keyFilename: KEY_PATH });
|
|
43
|
+
}
|
|
44
|
+
return new storage_1.Storage();
|
|
45
|
+
}
|
|
15
46
|
class GCloudStorageClient {
|
|
16
47
|
constructor(bucket) {
|
|
17
|
-
|
|
18
|
-
keyFilename: "/etc/secrets/cloud-storage/cloud-storage-service-account-key.json",
|
|
19
|
-
});
|
|
20
|
-
this._bucket = storage.bucket(bucket);
|
|
48
|
+
this._bucket = buildStorage().bucket(bucket);
|
|
21
49
|
}
|
|
22
50
|
get bucket() {
|
|
23
51
|
return this._bucket;
|
|
@@ -26,9 +54,7 @@ class GCloudStorageClient {
|
|
|
26
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
55
|
const bucketName = gcsUri.split("/")[2];
|
|
28
56
|
const folderPath = gcsUri.split("/").slice(4).join("/"); // Extract the folder path from the URI
|
|
29
|
-
const storage =
|
|
30
|
-
keyFilename: "/etc/secrets/cloud-storage/cloud-storage-service-account-key.json",
|
|
31
|
-
});
|
|
57
|
+
const storage = buildStorage();
|
|
32
58
|
const [files] = yield storage
|
|
33
59
|
.bucket(bucketName)
|
|
34
60
|
.getFiles({ prefix: folderPath });
|
|
@@ -40,6 +40,7 @@ class SecretManagerClient {
|
|
|
40
40
|
constructor(env) {
|
|
41
41
|
this.env = env;
|
|
42
42
|
this.secretCache = null;
|
|
43
|
+
this.envMismatch = false;
|
|
43
44
|
this.POLL_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
|
|
44
45
|
const secretFilePath = "/etc/secrets/secret-manager/secret-manager-service-account-key.json";
|
|
45
46
|
if (fs.existsSync(secretFilePath)) {
|
|
@@ -67,20 +68,19 @@ class SecretManagerClient {
|
|
|
67
68
|
*/
|
|
68
69
|
getSecretValue(secretId) {
|
|
69
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
|
|
71
|
+
if (this.envMismatch) {
|
|
72
|
+
throw new Error("Secret access blocked: RIO_ENV mismatch between service and secret file");
|
|
73
|
+
}
|
|
71
74
|
if (this.secretCache && this.secretCache.secrets[secretId]) {
|
|
72
75
|
return this.secretCache.secrets[secretId];
|
|
73
76
|
}
|
|
74
|
-
// If not in cache or cache doesn't exist, fetch entire secret file
|
|
75
77
|
const success = yield this.refreshSecretCache();
|
|
76
78
|
if (!success) {
|
|
77
79
|
return null;
|
|
78
80
|
}
|
|
79
|
-
// Check again after refresh
|
|
80
81
|
if (this.secretCache && this.secretCache.secrets[secretId]) {
|
|
81
82
|
return this.secretCache.secrets[secretId];
|
|
82
83
|
}
|
|
83
|
-
// Secret not found even after refresh
|
|
84
84
|
console.error(`Secret ${secretId} not found in secret file`);
|
|
85
85
|
return null;
|
|
86
86
|
});
|
|
@@ -122,11 +122,14 @@ class SecretManagerClient {
|
|
|
122
122
|
throw new Error("No payload data");
|
|
123
123
|
}
|
|
124
124
|
const secrets = JSON.parse(version.payload.data.toString());
|
|
125
|
-
|
|
125
|
+
if (secrets.RIO_ENV && secrets.RIO_ENV !== this.env) {
|
|
126
|
+
console.error(`FATAL: Environment mismatch! Service expects "${this.env}" but secret file "${file}" contains RIO_ENV="${secrets.RIO_ENV}"`);
|
|
127
|
+
this.envMismatch = true;
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
126
130
|
if ((_c = this.secretCache) === null || _c === void 0 ? void 0 : _c.pollingInterval) {
|
|
127
131
|
clearInterval(this.secretCache.pollingInterval);
|
|
128
132
|
}
|
|
129
|
-
// Set up new cache with polling
|
|
130
133
|
this.setupCacheWithPolling(secrets);
|
|
131
134
|
console.info(`Refreshed ${Object.keys(secrets).length} secrets from ${file}`);
|
|
132
135
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2765",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@google-cloud/secret-manager": "^5.6.0",
|
|
25
25
|
"@google-cloud/storage": "^7.19.0",
|
|
26
26
|
"@hyperdx/node-opentelemetry": "^0.10.3",
|
|
27
|
-
"@riocrypto/common": "1.0.
|
|
27
|
+
"@riocrypto/common": "1.0.2560",
|
|
28
28
|
"@slack/web-api": "^7.15.0",
|
|
29
29
|
"@types/express": "^4.17.25",
|
|
30
30
|
"axios": "1.13.6",
|