quidproquo-deploy-awscdk 0.0.74 → 0.0.76

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.
@@ -49,6 +49,11 @@ class Function extends QpqConstructBlock_1.QpqConstructBlock {
49
49
  actions: ['cloudformation:ListExports'],
50
50
  resources: ['*'],
51
51
  }));
52
+ // Let lambdas read from api keys in api gateway
53
+ this.lambdaFunction.addToRolePolicy(new aws_cdk_lib_1.aws_iam.PolicyStatement({
54
+ actions: ['apigateway:GET'],
55
+ resources: ['*'],
56
+ }));
52
57
  }
53
58
  }
54
59
  exports.Function = Function;
@@ -60,7 +60,7 @@ class QpqCoreQueueConstruct extends QpqCoreQueueConstructBase {
60
60
  visibilityTimeout: cdk.Duration.seconds(props.queueConfig.ttRetryInSeconds),
61
61
  removalPolicy: cdk.RemovalPolicy.DESTROY,
62
62
  deadLetterQueue: {
63
- maxReceiveCount: props.queueConfig.maxRetry,
63
+ maxReceiveCount: props.queueConfig.maxTries,
64
64
  queue: new aws_cdk_lib_1.aws_sqs.Queue(this, 'DeadLetterQueue', {
65
65
  queueName: this.resourceName(`${props.queueConfig.name}-dead`),
66
66
  removalPolicy: cdk.RemovalPolicy.DESTROY,
@@ -58,6 +58,10 @@ class QpqWebserverApiConstruct extends QpqConstructBlock_1.QpqConstructBlock {
58
58
  grantables.forEach((g) => {
59
59
  g.grantAll(func.lambdaFunction);
60
60
  });
61
+ // const routes = qpqWebServerUtils.getAllRoutesForApi(props.apiConfig.apiName, props.qpqConfig);
62
+ // const apiKeys = routes.reduce((acc, r) => {
63
+ // return [...acc, ...(r.options.routeAuthSettings?.apiKeys || [])];
64
+ // }, [] as ApiKey[]);
61
65
  // Create a rest api
62
66
  const api = new aws_cdk_lib_1.aws_apigateway.LambdaRestApi(this, 'lambda-rest-api', {
63
67
  restApiName: this.resourceName(`${props.apiConfig.apiName}-rest-api`),
@@ -68,7 +72,27 @@ class QpqWebserverApiConstruct extends QpqConstructBlock_1.QpqConstructBlock {
68
72
  },
69
73
  binaryMediaTypes: ['*/*'],
70
74
  proxy: true,
75
+ // defaultMethodOptions: {
76
+ // apiKeyRequired: apiKeys.length > 0,
77
+ // },
71
78
  });
79
+ // const usagePlan = api.addUsagePlan(this.qpqResourceName(props.apiConfig.apiName, 'usagePlan'), {
80
+ // apiStages: [
81
+ // {
82
+ // api,
83
+ // stage: api.deploymentStage,
84
+ // },
85
+ // ],
86
+ // });
87
+ // apiKeys.forEach((apiKey) => {
88
+ // const name = `${props.apiConfig.apiName}-${apiKey.name}`;
89
+ // const newApiKey = api.addApiKey(this.qpqResourceName(name, 'apiKey'), {
90
+ // description: apiKey.description,
91
+ // apiKeyName: this.resourceName(name),
92
+ // value: apiKey.value,
93
+ // });
94
+ // // usagePlan.addApiKey(newApiKey);
95
+ // });
72
96
  // Map all requests to this service to /serviceName/*
73
97
  new aws_cdk_lib_1.aws_apigateway.BasePathMapping(this, 'rest-bpm', {
74
98
  domainName: subdomain.domainName,
@@ -0,0 +1,11 @@
1
+ import { aws_lambda } from 'aws-cdk-lib';
2
+ import { Construct } from 'constructs';
3
+ import { ApiKeyQPQWebServerConfigSetting } from 'quidproquo-webserver';
4
+ import { QpqConstructBlock, QpqConstructBlockProps } from '../../../base/QpqConstructBlock';
5
+ export interface QpqWebserverApiKeyConstructProps extends QpqConstructBlockProps {
6
+ apiKeyConfig: ApiKeyQPQWebServerConfigSetting;
7
+ apiLayerVersions?: aws_lambda.ILayerVersion[];
8
+ }
9
+ export declare class QpqWebserverApiKeyConstruct extends QpqConstructBlock {
10
+ constructor(scope: Construct, id: string, props: QpqWebserverApiKeyConstructProps);
11
+ }
@@ -0,0 +1,44 @@
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
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.QpqWebserverApiKeyConstruct = void 0;
27
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
28
+ const QpqConstructBlock_1 = require("../../../base/QpqConstructBlock");
29
+ const qpqDeployAwsCdkUtils = __importStar(require("../../../../utils"));
30
+ const quidproquo_actionprocessor_awslambda_1 = require("quidproquo-actionprocessor-awslambda");
31
+ class QpqWebserverApiKeyConstruct extends QpqConstructBlock_1.QpqConstructBlock {
32
+ constructor(scope, id, props) {
33
+ super(scope, id, props);
34
+ const apiKeyConfig = props.apiKeyConfig.apiKey;
35
+ const apiKey = new aws_cdk_lib_1.aws_apigateway.ApiKey(this, apiKeyConfig.name, {
36
+ description: apiKeyConfig.description,
37
+ apiKeyName: this.resourceName(apiKeyConfig.name),
38
+ value: apiKeyConfig.value,
39
+ enabled: true,
40
+ });
41
+ qpqDeployAwsCdkUtils.exportStackValue(this, quidproquo_actionprocessor_awslambda_1.awsNamingUtils.getCFExportNameApiKeyIdFromConfig(apiKeyConfig.name, props.qpqConfig), apiKey.keyId);
42
+ }
43
+ }
44
+ exports.QpqWebserverApiKeyConstruct = QpqWebserverApiKeyConstruct;
@@ -0,0 +1 @@
1
+ export * from './QpqWebserverApiKeyConstruct';
@@ -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("./QpqWebserverApiKeyConstruct"), exports);
@@ -1,4 +1,5 @@
1
1
  export * from './api';
2
+ export * from './apiKey';
2
3
  export * from './domain';
3
4
  export * from './redirect';
4
5
  export * from './webEntry';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
+ __exportStar(require("./apiKey"), exports);
18
19
  __exportStar(require("./domain"), exports);
19
20
  __exportStar(require("./redirect"), exports);
20
21
  __exportStar(require("./webEntry"), exports);
@@ -44,6 +44,12 @@ class InfQpqServiceStack extends QpqServiceStack_1.QpqServiceStack {
44
44
  qpqConfig: props.qpqConfig,
45
45
  userDirectoryConfig: setting,
46
46
  }));
47
+ // Api Keys
48
+ const apiKeys = quidproquo_webserver_1.qpqWebServerUtils.getAllApiKeyConfigs(props.qpqConfig).map((setting) => new constructs_1.QpqWebserverApiKeyConstruct(this, quidproquo_core_1.qpqCoreUtils.getUniqueKeyForSetting(setting), {
49
+ awsAccountId: props.awsAccountId,
50
+ qpqConfig: props.qpqConfig,
51
+ apiKeyConfig: setting,
52
+ }));
47
53
  }
48
54
  }
49
55
  exports.InfQpqServiceStack = InfQpqServiceStack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-deploy-awscdk",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -49,5 +49,13 @@ export class Function extends QpqConstructBlock {
49
49
  resources: ['*'],
50
50
  }),
51
51
  );
52
+
53
+ // Let lambdas read from api keys in api gateway
54
+ this.lambdaFunction.addToRolePolicy(
55
+ new aws_iam.PolicyStatement({
56
+ actions: ['apigateway:GET'],
57
+ resources: ['*'],
58
+ }),
59
+ );
52
60
  }
53
61
  }
@@ -65,7 +65,7 @@ export class QpqCoreQueueConstruct extends QpqCoreQueueConstructBase {
65
65
  removalPolicy: cdk.RemovalPolicy.DESTROY,
66
66
 
67
67
  deadLetterQueue: {
68
- maxReceiveCount: props.queueConfig.maxRetry,
68
+ maxReceiveCount: props.queueConfig.maxTries,
69
69
  queue: new aws_sqs.Queue(this, 'DeadLetterQueue', {
70
70
  queueName: this.resourceName(`${props.queueConfig.name}-dead`),
71
71
  removalPolicy: cdk.RemovalPolicy.DESTROY,
@@ -59,6 +59,11 @@ export class QpqWebserverApiConstruct extends QpqConstructBlock {
59
59
  g.grantAll(func.lambdaFunction);
60
60
  });
61
61
 
62
+ // const routes = qpqWebServerUtils.getAllRoutesForApi(props.apiConfig.apiName, props.qpqConfig);
63
+ // const apiKeys = routes.reduce((acc, r) => {
64
+ // return [...acc, ...(r.options.routeAuthSettings?.apiKeys || [])];
65
+ // }, [] as ApiKey[]);
66
+
62
67
  // Create a rest api
63
68
  const api = new aws_apigateway.LambdaRestApi(this, 'lambda-rest-api', {
64
69
  restApiName: this.resourceName(`${props.apiConfig.apiName}-rest-api`),
@@ -69,8 +74,31 @@ export class QpqWebserverApiConstruct extends QpqConstructBlock {
69
74
  },
70
75
  binaryMediaTypes: ['*/*'],
71
76
  proxy: true,
77
+ // defaultMethodOptions: {
78
+ // apiKeyRequired: apiKeys.length > 0,
79
+ // },
72
80
  });
73
81
 
82
+ // const usagePlan = api.addUsagePlan(this.qpqResourceName(props.apiConfig.apiName, 'usagePlan'), {
83
+ // apiStages: [
84
+ // {
85
+ // api,
86
+ // stage: api.deploymentStage,
87
+ // },
88
+ // ],
89
+ // });
90
+
91
+ // apiKeys.forEach((apiKey) => {
92
+ // const name = `${props.apiConfig.apiName}-${apiKey.name}`;
93
+ // const newApiKey = api.addApiKey(this.qpqResourceName(name, 'apiKey'), {
94
+ // description: apiKey.description,
95
+ // apiKeyName: this.resourceName(name),
96
+ // value: apiKey.value,
97
+ // });
98
+
99
+ // // usagePlan.addApiKey(newApiKey);
100
+ // });
101
+
74
102
  // Map all requests to this service to /serviceName/*
75
103
  new aws_apigateway.BasePathMapping(this, 'rest-bpm', {
76
104
  domainName: subdomain.domainName,
@@ -0,0 +1,35 @@
1
+ import { aws_apigateway, aws_lambda } from 'aws-cdk-lib';
2
+ import { Construct } from 'constructs';
3
+
4
+ import { ApiKeyQPQWebServerConfigSetting, qpqWebServerUtils } from 'quidproquo-webserver';
5
+
6
+ import { QpqConstructBlock, QpqConstructBlockProps } from '../../../base/QpqConstructBlock';
7
+
8
+ import * as qpqDeployAwsCdkUtils from '../../../../utils';
9
+ import { awsNamingUtils } from 'quidproquo-actionprocessor-awslambda';
10
+
11
+ export interface QpqWebserverApiKeyConstructProps extends QpqConstructBlockProps {
12
+ apiKeyConfig: ApiKeyQPQWebServerConfigSetting;
13
+ apiLayerVersions?: aws_lambda.ILayerVersion[];
14
+ }
15
+
16
+ export class QpqWebserverApiKeyConstruct extends QpqConstructBlock {
17
+ constructor(scope: Construct, id: string, props: QpqWebserverApiKeyConstructProps) {
18
+ super(scope, id, props);
19
+
20
+ const apiKeyConfig = props.apiKeyConfig.apiKey;
21
+
22
+ const apiKey = new aws_apigateway.ApiKey(this, apiKeyConfig.name, {
23
+ description: apiKeyConfig.description,
24
+ apiKeyName: this.resourceName(apiKeyConfig.name),
25
+ value: apiKeyConfig.value,
26
+ enabled: true,
27
+ });
28
+
29
+ qpqDeployAwsCdkUtils.exportStackValue(
30
+ this,
31
+ awsNamingUtils.getCFExportNameApiKeyIdFromConfig(apiKeyConfig.name, props.qpqConfig),
32
+ apiKey.keyId,
33
+ );
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ export * from './QpqWebserverApiKeyConstruct';
@@ -1,4 +1,5 @@
1
1
  export * from './api';
2
+ export * from './apiKey';
2
3
  export * from './domain';
3
4
  export * from './redirect';
4
5
  export * from './webEntry';
@@ -11,6 +11,7 @@ import {
11
11
  QpqCoreSecretConstruct,
12
12
  QpqWebserverDomainConstruct,
13
13
  QpqCoreUserDirectoryConstruct,
14
+ QpqWebserverApiKeyConstruct,
14
15
  } from '../constructs';
15
16
 
16
17
  export interface InfQpqServiceStackProps extends QpqServiceStackProps {}
@@ -84,5 +85,16 @@ export class InfQpqServiceStack extends QpqServiceStack {
84
85
  userDirectoryConfig: setting,
85
86
  }),
86
87
  );
88
+
89
+ // Api Keys
90
+ const apiKeys = qpqWebServerUtils.getAllApiKeyConfigs(props.qpqConfig).map(
91
+ (setting) =>
92
+ new QpqWebserverApiKeyConstruct(this, qpqCoreUtils.getUniqueKeyForSetting(setting), {
93
+ awsAccountId: props.awsAccountId,
94
+ qpqConfig: props.qpqConfig,
95
+
96
+ apiKeyConfig: setting,
97
+ }),
98
+ );
87
99
  }
88
100
  }