@friggframework/core 1.2.1 → 1.2.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # v1.2.2 (Fri Aug 09 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Add support for secrets loading from SECRET_ARN [#327](https://github.com/friggframework/frigg/pull/327) ([@seanspeaks](https://github.com/seanspeaks))
6
+ - Adding support for secrets loading ([@seanspeaks](https://github.com/seanspeaks))
7
+
8
+ #### Authors: 1
9
+
10
+ - Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
11
+
12
+ ---
13
+
1
14
  # v1.2.1 (Thu Aug 08 2024)
2
15
 
3
16
  #### 🐛 Bug Fix
@@ -3,6 +3,7 @@ require('source-map-support').install();
3
3
 
4
4
  const { connectToDatabase } = require('../database/mongo');
5
5
  const { initDebugLog, flushDebugLog } = require('../logs');
6
+ const { secretsToEnv } = require('./secrets-to-env');
6
7
 
7
8
  const createHandler = (optionByName = {}) => {
8
9
  const {
@@ -20,6 +21,15 @@ const createHandler = (optionByName = {}) => {
20
21
  try {
21
22
  initDebugLog(eventName, event);
22
23
 
24
+ const requestMethod = event.httpMethod;
25
+ const requestPath = event.path;
26
+ if (requestMethod && requestPath) {
27
+ console.info(`${requestMethod} ${requestPath}`);
28
+ }
29
+
30
+ // If enabled (i.e. if SECRET_ARN is set in process.env) Fetch secrets from AWS Secrets Manager, and set them as environment variables.
31
+ await secretsToEnv();
32
+
23
33
  // Helps mongoose reuse the connection. Lowers response times.
24
34
  context.callbackWaitsForEmptyEventLoop = false;
25
35
 
@@ -0,0 +1,61 @@
1
+ const getSecretValue = async () => {
2
+ console.log('Fetching secrets...');
3
+
4
+ const httpPort = process.env.PARAMETERS_SECRETS_EXTENSION_HTTP_PORT || 2773;
5
+ const url = `http://localhost:${httpPort}/secretsmanager/get?secretId=${encodeURIComponent(
6
+ process.env.SECRET_ARN
7
+ )}`;
8
+ const options = {
9
+ headers: {
10
+ 'X-Aws-Parameters-Secrets-Token': process.env.AWS_SESSION_TOKEN,
11
+ },
12
+ method: 'GET',
13
+ };
14
+
15
+ const response = await fetch(url, options);
16
+
17
+ if (!response.ok) {
18
+ const json = await response.json().catch((err) => err.message);
19
+ console.error('Invalid response - response:', JSON.stringify(response));
20
+ console.error('Invalid response - json:', json);
21
+ throw new Error(`Invalid ${response.status} response`);
22
+ }
23
+
24
+ const result = await response.json();
25
+
26
+ if (!result) {
27
+ throw new Error('Error getting secret', result);
28
+ }
29
+
30
+ return JSON.parse(result.SecretString);
31
+ };
32
+
33
+ const transformSecrets = (secrets) => {
34
+ Object.keys(secrets).forEach((key) => {
35
+ process.env[key] = secrets[key];
36
+ });
37
+ };
38
+
39
+ /**
40
+ * Middleware that gets the secrets from Lambda layer and transform into environment variables.
41
+ *
42
+ */
43
+ const secretsToEnv = async () => {
44
+ if (!process.env.SECRET_ARN) {
45
+ return;
46
+ }
47
+ console.log('Secrets to env');
48
+
49
+ try {
50
+ const secrets = await getSecretValue();
51
+ transformSecrets(secrets);
52
+
53
+ return secrets;
54
+ } catch (err) {
55
+ throw err;
56
+ }
57
+ };
58
+
59
+ module.exports = {
60
+ secretsToEnv,
61
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "dependencies": {
6
6
  "@hapi/boom": "^10.0.1",
7
7
  "aws-sdk": "^2.1200.0",
@@ -15,9 +15,9 @@
15
15
  "node-fetch": "^2.6.7"
16
16
  },
17
17
  "devDependencies": {
18
- "@friggframework/eslint-config": "^1.2.1",
19
- "@friggframework/prettier-config": "^1.2.1",
20
- "@friggframework/test": "^1.2.1",
18
+ "@friggframework/eslint-config": "^1.2.2",
19
+ "@friggframework/prettier-config": "^1.2.2",
20
+ "@friggframework/test": "^1.2.2",
21
21
  "@types/lodash": "^4.14.191",
22
22
  "@typescript-eslint/eslint-plugin": "^8.0.0",
23
23
  "chai": "^4.3.6",
@@ -48,5 +48,5 @@
48
48
  },
49
49
  "homepage": "https://github.com/friggframework/frigg#readme",
50
50
  "description": "",
51
- "gitHead": "3c2bb949c71be314cf44e326e618b3e16b787e8c"
51
+ "gitHead": "8c33a41d9cf6de867bbb6a308aea32c7e7d05691"
52
52
  }