quidproquo-actionprocessor-awslambda 0.0.143 → 0.0.145

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.
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
13
  const getSecret_1 = require("../../../logic/secretsManager/getSecret");
14
+ const utils_1 = require("./utils");
15
15
  const getProcessConfigActionType = (qpqConfig) => {
16
16
  return ({ secretName }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const awsSecretKey = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveSecretKey)(secretName, qpqConfig);
17
+ const awsSecretKey = (0, utils_1.resolveSecretResourceName)(secretName, qpqConfig);
18
18
  const secretValue = yield (0, getSecret_1.getSecret)(awsSecretKey, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig));
19
19
  return (0, quidproquo_core_1.actionResult)(secretValue);
20
20
  });
@@ -0,0 +1 @@
1
+ export * from './resolveSecretResourceName';
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./resolveSecretResourceName"), exports);
@@ -0,0 +1,2 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ export declare const resolveSecretResourceName: (secretName: string, qpqConfig: QPQConfig) => string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSecretResourceName = void 0;
4
+ const quidproquo_core_1 = require("quidproquo-core");
5
+ const awsNamingUtils_1 = require("../../../../awsNamingUtils");
6
+ const resolveSecretResourceName = (secretName, qpqConfig) => {
7
+ var _a, _b;
8
+ const secretConfig = quidproquo_core_1.qpqCoreUtils.getSecretByName(secretName, qpqConfig);
9
+ return (0, awsNamingUtils_1.getConfigRuntimeResourceNameFromConfigWithServiceOverride)(((_a = secretConfig.owner) === null || _a === void 0 ? void 0 : _a.resourceNameOverride) || secretName, qpqConfig, (_b = secretConfig.owner) === null || _b === void 0 ? void 0 : _b.module);
10
+ };
11
+ exports.resolveSecretResourceName = resolveSecretResourceName;
@@ -0,0 +1,12 @@
1
+ import { QPQConfig, MatchStoryResult, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
2
+ import { CloudflareDnsDeployEvent } from 'quidproquo-webserver';
3
+ import { CloudFormationCustomResourceEvent, Context } from 'aws-lambda';
4
+ type EventInput = [CloudFormationCustomResourceEvent, Context];
5
+ type MatchResult = MatchStoryResult<any, any>;
6
+ declare const _default: (qpqConfig: QPQConfig) => {
7
+ "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<EventInput, CloudflareDnsDeployEvent>;
8
+ "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<void, CloudflareDnsDeployEvent, void>;
9
+ "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<CloudflareDnsDeployEvent, MatchResult, boolean>;
10
+ "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<CloudflareDnsDeployEvent, MatchResult>;
11
+ };
12
+ export default _default;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const quidproquo_core_1 = require("quidproquo-core");
13
+ const quidproquo_webserver_1 = require("quidproquo-webserver");
14
+ const getDomainValidationOptions_1 = require("../../../logic/acm/getDomainValidationOptions");
15
+ const findMatchingCertificates_1 = require("../../../logic/acm/findMatchingCertificates");
16
+ // // TODO: Don't use Globals like this
17
+ const GLOBAL_CERT_ARN = process.env.certificateArn;
18
+ const GLOBAL_CERT_DOMAIN = process.env.certificateDomain;
19
+ const GLOBAL_CERT_REGION = process.env.certificateRegion;
20
+ const awsToQpqEventTypeMap = {
21
+ Create: quidproquo_webserver_1.CloudflareDnsDeployEventEnum.Create,
22
+ Update: quidproquo_webserver_1.CloudflareDnsDeployEventEnum.Update,
23
+ Delete: quidproquo_webserver_1.CloudflareDnsDeployEventEnum.Delete,
24
+ };
25
+ const getProcessTransformEventParams = (siteDnsBase) => {
26
+ return ({ eventParams: [event, context] }) => __awaiter(void 0, void 0, void 0, function* () {
27
+ var _a;
28
+ // Get all the certs that need to be added to the cloud flare
29
+ const certArns = [
30
+ ...(yield (0, findMatchingCertificates_1.findMatchingCertificates)(GLOBAL_CERT_DOMAIN, GLOBAL_CERT_REGION)),
31
+ GLOBAL_CERT_ARN,
32
+ ].filter(Boolean);
33
+ const certDomains = yield Promise.all(certArns.map((arn) => (0, getDomainValidationOptions_1.getDomainValidationOptions)(arn, GLOBAL_CERT_REGION)));
34
+ // Remove trailing dot from keys
35
+ const dnsEntriesWithTrimmedKeys = Object.entries(Object.assign(Object.assign({}, event.ResourceProperties.dnsEntries), certDomains.reduce((acc, certDomain) => (Object.assign(Object.assign({}, acc), certDomain)), {}))).reduce((acc, [key, value]) => {
36
+ const trimmedKey = key.endsWith('.') ? key.slice(0, -1) : key;
37
+ acc[trimmedKey] = value;
38
+ return acc;
39
+ }, {});
40
+ const transformedEventParams = {
41
+ siteDns: siteDnsBase,
42
+ RequestType: awsToQpqEventTypeMap[event.RequestType],
43
+ apiSecretName: event.ResourceProperties.apiSecretName,
44
+ dnsEntries: dnsEntriesWithTrimmedKeys,
45
+ oldDnsEntries: (_a = event === null || event === void 0 ? void 0 : event.OldResourceProperties) === null || _a === void 0 ? void 0 : _a.dnsEntries,
46
+ };
47
+ console.log('transformedEventParams', JSON.stringify(transformedEventParams, null, 2));
48
+ return (0, quidproquo_core_1.actionResult)(transformedEventParams);
49
+ });
50
+ };
51
+ const getProcessTransformResponseResult = (qpqConfig) => {
52
+ // We might need to JSON.stringify the body.
53
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
54
+ // always success
55
+ return (0, quidproquo_core_1.actionResult)(void 0);
56
+ });
57
+ };
58
+ const getProcessAutoRespond = (qpqConfig) => {
59
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
60
+ // always allow
61
+ return (0, quidproquo_core_1.actionResult)(false);
62
+ });
63
+ };
64
+ const getProcessMatchStory = (qpqConfig) => {
65
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
66
+ return (0, quidproquo_core_1.actionResult)({
67
+ src: (0, quidproquo_core_1.getServiceEntry)('cloudflare', 'cloudflare', 'onDeploy'),
68
+ runtime: 'onDeploy',
69
+ });
70
+ });
71
+ };
72
+ exports.default = (qpqConfig) => {
73
+ const [siteDnsConfig] = quidproquo_webserver_1.qpqWebServerUtils.getDnsConfigs(qpqConfig);
74
+ return {
75
+ [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(siteDnsConfig.dnsBase),
76
+ [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(qpqConfig),
77
+ [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(qpqConfig),
78
+ [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(qpqConfig),
79
+ };
80
+ };
@@ -12,6 +12,7 @@ export { default as getEventBridgeEventActionProcessor } from './event/getEventB
12
12
  export { default as getLambdaCognitoCustomMessage } from './event/getLambdaCognitoCustomMessage';
13
13
  export { default as getWebsocketAPIGatewayEventActionProcessor } from './event/getWebsocketAPIGatewayEventActionProcessor';
14
14
  export { default as getS3FileEventActionProcessor } from './event/getS3FileEventActionProcessor';
15
+ export { default as getCustomResourceCloudflareDnsEventActionProcessor } from './event/getCustomResourceCloudflareDnsEventActionProcessor';
15
16
  export { default as getSystemActionProcessor } from './system';
16
17
  export { default as getFileActionProcessor } from './file';
17
18
  export { default as getKeyValueStoreActionProcessor } from './keyValueStore';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getEventBusActionProcessor = exports.getUserDirectoryActionProcessor = exports.getQueueActionProcessor = exports.getKeyValueStoreActionProcessor = exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getS3FileEventActionProcessor = exports.getWebsocketAPIGatewayEventActionProcessor = exports.getLambdaCognitoCustomMessage = exports.getEventBridgeEventActionProcessor = exports.getEventBridgeEventStackDeployActionProcessor = exports.getServiceFunctionExecuteEventActionProcessor = exports.getSQSEventRecordActionProcessor = exports.getCloudFrontOriginRequestEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigSetParameterActionProcessor = exports.getConfigGetGlobalActionProcessor = exports.getConfigGetParametersActionProcessor = exports.getConfigGetParameterActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
6
+ exports.getEventBusActionProcessor = exports.getUserDirectoryActionProcessor = exports.getQueueActionProcessor = exports.getKeyValueStoreActionProcessor = exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getCustomResourceCloudflareDnsEventActionProcessor = exports.getS3FileEventActionProcessor = exports.getWebsocketAPIGatewayEventActionProcessor = exports.getLambdaCognitoCustomMessage = exports.getEventBridgeEventActionProcessor = exports.getEventBridgeEventStackDeployActionProcessor = exports.getServiceFunctionExecuteEventActionProcessor = exports.getSQSEventRecordActionProcessor = exports.getCloudFrontOriginRequestEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigSetParameterActionProcessor = exports.getConfigGetGlobalActionProcessor = exports.getConfigGetParametersActionProcessor = exports.getConfigGetParameterActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
7
7
  var getConfigGetSecretActionProcessor_1 = require("./config/getConfigGetSecretActionProcessor");
8
8
  Object.defineProperty(exports, "getConfigGetSecretActionProcessor", { enumerable: true, get: function () { return __importDefault(getConfigGetSecretActionProcessor_1).default; } });
9
9
  var getConfigGetParameterActionProcessor_1 = require("./config/getConfigGetParameterActionProcessor");
@@ -32,6 +32,8 @@ var getWebsocketAPIGatewayEventActionProcessor_1 = require("./event/getWebsocket
32
32
  Object.defineProperty(exports, "getWebsocketAPIGatewayEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getWebsocketAPIGatewayEventActionProcessor_1).default; } });
33
33
  var getS3FileEventActionProcessor_1 = require("./event/getS3FileEventActionProcessor");
34
34
  Object.defineProperty(exports, "getS3FileEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getS3FileEventActionProcessor_1).default; } });
35
+ var getCustomResourceCloudflareDnsEventActionProcessor_1 = require("./event/getCustomResourceCloudflareDnsEventActionProcessor");
36
+ Object.defineProperty(exports, "getCustomResourceCloudflareDnsEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getCustomResourceCloudflareDnsEventActionProcessor_1).default; } });
35
37
  var system_1 = require("./system");
36
38
  Object.defineProperty(exports, "getSystemActionProcessor", { enumerable: true, get: function () { return __importDefault(system_1).default; } });
37
39
  var file_1 = require("./file");
@@ -0,0 +1 @@
1
+ export declare const findMatchingCertificates: (domainName: string, region: string, retryCount?: number, delayMs?: number) => Promise<string[]>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.findMatchingCertificates = void 0;
13
+ const client_acm_1 = require("@aws-sdk/client-acm");
14
+ const createAwsClient_1 = require("../createAwsClient");
15
+ const findMatchingCertificates = (domainName, region, retryCount = 3, delayMs = 5000) => __awaiter(void 0, void 0, void 0, function* () {
16
+ var _a;
17
+ const lowerCaseDomainName = domainName.toLowerCase();
18
+ const acmClient = (0, createAwsClient_1.createAwsClient)(client_acm_1.ACMClient, {
19
+ region,
20
+ });
21
+ let remainingRetries = retryCount;
22
+ while (remainingRetries > 0) {
23
+ let certificateArns = [];
24
+ let NextToken;
25
+ do {
26
+ const listCommand = new client_acm_1.ListCertificatesCommand({
27
+ NextToken,
28
+ });
29
+ const listResult = yield acmClient.send(listCommand);
30
+ for (const certificate of listResult.CertificateSummaryList || []) {
31
+ if (certificate.CertificateArn &&
32
+ ((_a = certificate.DomainName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === lowerCaseDomainName) {
33
+ certificateArns.push(certificate.CertificateArn);
34
+ }
35
+ }
36
+ NextToken = listResult.NextToken;
37
+ } while (NextToken);
38
+ if (certificateArns.length > 0) {
39
+ return certificateArns;
40
+ }
41
+ remainingRetries--;
42
+ if (remainingRetries != 0) {
43
+ // Don't wait after the last try
44
+ yield new Promise((res) => setTimeout(res, delayMs));
45
+ }
46
+ }
47
+ return []; // Return an empty array after max retries
48
+ });
49
+ exports.findMatchingCertificates = findMatchingCertificates;
50
+ // (async () => {
51
+ // const matchingCerts = await findMatchingCertificates('example.com', 'us-east-1');
52
+ // console.log('Matching certificates:', matchingCerts);
53
+ // })();
@@ -0,0 +1,2 @@
1
+ import { CloudflareDnsEntries } from 'quidproquo-webserver';
2
+ export declare const getDomainValidationOptions: (certificateArn: string, region: string) => Promise<CloudflareDnsEntries>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getDomainValidationOptions = void 0;
13
+ const client_acm_1 = require("@aws-sdk/client-acm");
14
+ const createAwsClient_1 = require("../createAwsClient");
15
+ const getDomainValidationOptions = (certificateArn, region) => __awaiter(void 0, void 0, void 0, function* () {
16
+ var _a, _b;
17
+ const acmClient = (0, createAwsClient_1.createAwsClient)(client_acm_1.ACMClient, {
18
+ region,
19
+ });
20
+ const command = new client_acm_1.DescribeCertificateCommand({
21
+ CertificateArn: certificateArn,
22
+ });
23
+ const result = yield acmClient.send(command);
24
+ const entries = {};
25
+ console.log('DescribeCertificateCommand: ', JSON.stringify(result, null, 2));
26
+ // Extract the DomainValidationOptions and populate the entries
27
+ if (result.Certificate && result.Certificate.DomainValidationOptions) {
28
+ for (const option of result.Certificate.DomainValidationOptions) {
29
+ if (((_a = option.ResourceRecord) === null || _a === void 0 ? void 0 : _a.Name) && ((_b = option.ResourceRecord) === null || _b === void 0 ? void 0 : _b.Value)) {
30
+ entries[option.ResourceRecord.Name] = {
31
+ proxied: false,
32
+ type: 'CNAME',
33
+ value: option.ResourceRecord.Value,
34
+ };
35
+ }
36
+ }
37
+ }
38
+ return entries;
39
+ });
40
+ exports.getDomainValidationOptions = getDomainValidationOptions;
@@ -18,5 +18,9 @@ exports.getSecret = (0, memoFuncAsync_1.memoFuncAsync)((secretName, region) => _
18
18
  const response = yield secretsManagerClient.send(new client_secrets_manager_1.GetSecretValueCommand({
19
19
  SecretId: secretName,
20
20
  }));
21
- return response.SecretString || '';
21
+ const secretValue = response.SecretString || '';
22
+ if (!secretValue) {
23
+ throw new Error(`Failed to get secret value for secret name: [${secretName}]`);
24
+ }
25
+ return secretValue;
22
26
  }), 60);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.143",
3
+ "version": "0.0.145",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "types": "./lib/commonjs/index.d.js",
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "homepage": "https://github.com/joe-coady/quidproquo#readme",
27
27
  "dependencies": {
28
+ "@aws-sdk/client-acm": "^3.379.1",
28
29
  "@aws-sdk/client-api-gateway": "^3.379.1",
29
30
  "@aws-sdk/client-apigatewaymanagementapi": "^3.379.1",
30
31
  "@aws-sdk/client-cloudformation": "^3.379.1",