@riocrypto/common-server 1.0.1913 → 1.0.1914
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.
|
@@ -54,7 +54,7 @@ class SecretManagerClient {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
getSecretValue(secretId) {
|
|
57
|
-
var _a, _b
|
|
57
|
+
var _a, _b;
|
|
58
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
59
|
let file;
|
|
60
60
|
if (this.env === common_1.RioEnv.Development) {
|
|
@@ -69,21 +69,37 @@ class SecretManagerClient {
|
|
|
69
69
|
else if (this.env === common_1.RioEnv.Production) {
|
|
70
70
|
file = "production-secrets";
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
const maxRetries = 5;
|
|
73
|
+
let attempt = 0;
|
|
74
|
+
while (attempt < maxRetries) {
|
|
75
|
+
try {
|
|
76
|
+
// Access the secret version
|
|
77
|
+
const [version] = yield this.client.accessSecretVersion({
|
|
78
|
+
name: `projects/${this.projectId}/secrets/${file}/versions/latest`,
|
|
79
|
+
});
|
|
80
|
+
if (!((_b = (_a = version.payload) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.toString())) {
|
|
81
|
+
throw new Error("No payload data");
|
|
82
|
+
}
|
|
83
|
+
const secrets = JSON.parse(version.payload.data.toString());
|
|
84
|
+
return secrets[secretId];
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
attempt++;
|
|
88
|
+
// Check if the error code is 13 (INTERNAL) and retry if so
|
|
89
|
+
if (err.code === 13 && attempt < maxRetries) {
|
|
90
|
+
console.warn(`Attempt ${attempt} failed with error code ${err.code}. Retrying in ${Math.pow(2, attempt)} seconds...`);
|
|
91
|
+
// Exponential backoff
|
|
92
|
+
yield new Promise((resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1000));
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
console.error(`Failed to access secret ${secretId}:`, err);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
79
99
|
}
|
|
80
|
-
const secrets = JSON.parse((_d = (_c = version.payload) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.toString());
|
|
81
|
-
return secrets[secretId];
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
console.error(`Failed to access secret ${secretId}: ${err}`);
|
|
85
|
-
return null;
|
|
86
100
|
}
|
|
101
|
+
console.error(`Failed to access secret ${secretId} after ${maxRetries} attempts.`);
|
|
102
|
+
return null;
|
|
87
103
|
});
|
|
88
104
|
}
|
|
89
105
|
}
|