@apolitical/server 4.1.0-pla-305.0 → 4.1.0-pla-305.1
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.
- package/package.json +2 -6
- package/src/services/secrets.service.js +3 -26
- package/src/secrets.js +0 -10
package/package.json
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apolitical/server",
|
|
3
|
-
"version": "4.1.0-pla-305.
|
|
3
|
+
"version": "4.1.0-pla-305.1",
|
|
4
4
|
"description": "Node.js module to encapsulate Apolitical's express server setup",
|
|
5
5
|
"author": "Apolitical Group Limited <engineering@apolitical.co>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.js",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": "./src/index.js",
|
|
10
|
-
"./secrets": "./src/secrets.js"
|
|
11
|
-
},
|
|
12
8
|
"files": [
|
|
13
9
|
"src"
|
|
14
10
|
],
|
|
@@ -29,7 +25,7 @@
|
|
|
29
25
|
"dependencies": {
|
|
30
26
|
"@apolitical/logger": "2.1.0",
|
|
31
27
|
"@cloudnative/health-connect": "2.1.0",
|
|
32
|
-
"@google-cloud/secret-manager": "
|
|
28
|
+
"@google-cloud/secret-manager": "6.1.1",
|
|
33
29
|
"@opentelemetry/api": "1.9.0",
|
|
34
30
|
"@opentelemetry/auto-instrumentations-node": "0.57.1",
|
|
35
31
|
"@opentelemetry/exporter-trace-otlp-grpc": "0.200.0",
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = ({ secretManager, config, logger }) => {
|
|
4
|
-
const DEV_DEFAULTS = {
|
|
5
|
-
impersonateAccount: 'development-platform@hazel-tea-194609.iam.gserviceaccount.com',
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const cache = {};
|
|
9
4
|
let client = null;
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
// calls to isImpersonationEnabled() reflect the dev default without
|
|
13
|
-
// re-reading process.env.
|
|
14
|
-
let resolvedImpersonationTarget = config.GOOGLE_IMPERSONATE_SERVICE_ACCOUNT?.trim() || null;
|
|
6
|
+
const resolvedImpersonationTarget = config.GOOGLE_IMPERSONATE_SERVICE_ACCOUNT?.trim() || null;
|
|
15
7
|
|
|
16
8
|
function isImpersonationEnabled() {
|
|
17
9
|
return resolvedImpersonationTarget !== null;
|
|
@@ -23,15 +15,6 @@ module.exports = ({ secretManager, config, logger }) => {
|
|
|
23
15
|
|
|
24
16
|
function getClient() {
|
|
25
17
|
if (!client) {
|
|
26
|
-
if (config.NODE_ENV !== 'production' && !isImpersonationEnabled()) {
|
|
27
|
-
resolvedImpersonationTarget = DEV_DEFAULTS.impersonateAccount;
|
|
28
|
-
// Set on process.env so the Google Cloud SDK picks it up via ADC
|
|
29
|
-
process.env['GOOGLE_IMPERSONATE_SERVICE_ACCOUNT'] = resolvedImpersonationTarget;
|
|
30
|
-
logger.info('[secrets] set default impersonation for development', {
|
|
31
|
-
targetServiceAccount: resolvedImpersonationTarget,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
18
|
if (isImpersonationEnabled()) {
|
|
36
19
|
logger.info('[secrets] using impersonation', impersonationLogContext());
|
|
37
20
|
}
|
|
@@ -66,18 +49,12 @@ module.exports = ({ secretManager, config, logger }) => {
|
|
|
66
49
|
throw new Error(`Empty payload for secret ${spec.name}`);
|
|
67
50
|
}
|
|
68
51
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (spec.exportToEnv) {
|
|
72
|
-
process.env[spec.envVar] = payload;
|
|
73
|
-
}
|
|
52
|
+
process.env[spec.envVar] = payload;
|
|
74
53
|
|
|
75
54
|
logger.info('[secrets] loaded', {
|
|
76
55
|
name: spec.name,
|
|
77
56
|
envVar: spec.envVar,
|
|
78
57
|
version,
|
|
79
|
-
cached: true,
|
|
80
|
-
exportedToEnv: !!spec.exportToEnv,
|
|
81
58
|
});
|
|
82
59
|
} catch (err) {
|
|
83
60
|
throw new Error(`Failed to load secret "${spec.name}": ${err.message}`);
|
|
@@ -86,7 +63,7 @@ module.exports = ({ secretManager, config, logger }) => {
|
|
|
86
63
|
}
|
|
87
64
|
|
|
88
65
|
function getSecret(envVar) {
|
|
89
|
-
const val =
|
|
66
|
+
const val = process.env[envVar];
|
|
90
67
|
if (!val) {
|
|
91
68
|
throw new Error(`Secret "${envVar}" not loaded`);
|
|
92
69
|
}
|
package/src/secrets.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const secretManager = require('@google-cloud/secret-manager');
|
|
4
|
-
const secretsServiceFactory = require('./services/secrets.service');
|
|
5
|
-
|
|
6
|
-
module.exports = secretsServiceFactory({
|
|
7
|
-
secretManager,
|
|
8
|
-
config: process.env,
|
|
9
|
-
logger: console,
|
|
10
|
-
});
|