@digitraffic/common 2024.1.10-1 → 2024.1.19-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/dist/aws/infra/api/handler-factory.d.ts +2 -2
- package/dist/aws/infra/api/handler-factory.js +4 -9
- package/dist/aws/infra/api/integration.d.ts +1 -1
- package/dist/aws/infra/api/integration.js +9 -13
- package/dist/aws/infra/api/response.d.ts +2 -3
- package/dist/aws/infra/api/response.js +25 -30
- package/dist/aws/infra/api/responses.d.ts +2 -3
- package/dist/aws/infra/api/responses.js +25 -31
- package/dist/aws/infra/api/static-integration.d.ts +1 -1
- package/dist/aws/infra/api/static-integration.js +7 -11
- package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-alarm.js +7 -11
- package/dist/aws/infra/canaries/canary-keys.js +3 -6
- package/dist/aws/infra/canaries/canary-parameters.js +1 -2
- package/dist/aws/infra/canaries/canary-role.js +8 -12
- package/dist/aws/infra/canaries/canary.d.ts +2 -2
- package/dist/aws/infra/canaries/canary.js +9 -13
- package/dist/aws/infra/canaries/database-canary.d.ts +3 -3
- package/dist/aws/infra/canaries/database-canary.js +8 -12
- package/dist/aws/infra/canaries/database-checker.d.ts +1 -1
- package/dist/aws/infra/canaries/database-checker.js +10 -14
- package/dist/aws/infra/canaries/url-canary.d.ts +4 -4
- package/dist/aws/infra/canaries/url-canary.js +8 -12
- package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/url-checker.js +33 -40
- package/dist/aws/infra/documentation.js +8 -16
- package/dist/aws/infra/import-util.js +10 -18
- package/dist/aws/infra/scheduler.js +10 -14
- package/dist/aws/infra/security-rule.js +4 -8
- package/dist/aws/infra/sqs-integration.d.ts +1 -2
- package/dist/aws/infra/sqs-integration.js +11 -15
- package/dist/aws/infra/sqs-queue.d.ts +1 -1
- package/dist/aws/infra/sqs-queue.js +30 -35
- package/dist/aws/infra/stack/lambda-configs.d.ts +2 -2
- package/dist/aws/infra/stack/lambda-configs.js +14 -20
- package/dist/aws/infra/stack/monitoredfunction.d.ts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.js +19 -27
- package/dist/aws/infra/stack/parameters.d.ts +1 -1
- package/dist/aws/infra/stack/parameters.js +5 -10
- package/dist/aws/infra/stack/rest_apis.d.ts +3 -3
- package/dist/aws/infra/stack/rest_apis.js +41 -54
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +1 -1
- package/dist/aws/infra/stack/stack-checking-aspect.js +24 -31
- package/dist/aws/infra/stack/stack.d.ts +3 -4
- package/dist/aws/infra/stack/stack.js +16 -20
- package/dist/aws/infra/stack/subscription.d.ts +2 -2
- package/dist/aws/infra/stack/subscription.js +5 -10
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-dns-stack.js +25 -29
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-proxy-stack.js +23 -27
- package/dist/aws/infra/stacks/db-stack.d.ts +3 -4
- package/dist/aws/infra/stacks/db-stack.js +30 -34
- package/dist/aws/infra/stacks/intra-stack-configuration.js +1 -2
- package/dist/aws/infra/stacks/network-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/network-stack.js +14 -18
- package/dist/aws/infra/usage-plans.js +2 -7
- package/dist/aws/runtime/apikey.js +3 -7
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +1 -1
- package/dist/aws/runtime/digitraffic-integration-response.js +7 -11
- package/dist/aws/runtime/dt-logger-default.d.ts +2 -2
- package/dist/aws/runtime/dt-logger-default.js +2 -5
- package/dist/aws/runtime/dt-logger.d.ts +1 -1
- package/dist/aws/runtime/dt-logger.js +3 -10
- package/dist/aws/runtime/environment.js +3 -7
- package/dist/aws/runtime/messaging.js +1 -5
- package/dist/aws/runtime/s3.js +3 -7
- package/dist/aws/runtime/secrets/dbsecret.d.ts +1 -1
- package/dist/aws/runtime/secrets/dbsecret.js +5 -9
- package/dist/aws/runtime/secrets/proxy-holder.js +12 -16
- package/dist/aws/runtime/secrets/rds-holder.js +12 -16
- package/dist/aws/runtime/secrets/secret-holder.d.ts +1 -1
- package/dist/aws/runtime/secrets/secret-holder.js +9 -13
- package/dist/aws/runtime/secrets/secret.js +7 -11
- package/dist/aws/types/errors.js +5 -9
- package/dist/aws/types/lambda-response.js +3 -10
- package/dist/aws/types/mediatypes.js +2 -5
- package/dist/aws/types/model-with-reference.js +1 -2
- package/dist/aws/types/proxytypes.js +1 -2
- package/dist/aws/types/tags.js +2 -5
- package/dist/database/cached.d.ts +1 -1
- package/dist/database/cached.js +8 -14
- package/dist/database/database.js +14 -21
- package/dist/database/last-updated.d.ts +1 -1
- package/dist/database/last-updated.js +8 -17
- package/dist/database/models.js +1 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.js +3 -9
- package/dist/marine/rtz.js +1 -2
- package/dist/test/asserter.js +1 -5
- package/dist/test/db-testutils.d.ts +1 -1
- package/dist/test/db-testutils.js +8 -13
- package/dist/test/httpserver.js +10 -14
- package/dist/test/secrets-manager.js +9 -35
- package/dist/test/testutils.js +8 -19
- package/dist/types/async-timeout-error.js +1 -5
- package/dist/types/aws-env.js +1 -2
- package/dist/types/either.js +1 -2
- package/dist/types/http-error.js +1 -5
- package/dist/types/input-error.js +1 -5
- package/dist/types/language.js +2 -5
- package/dist/types/nullable.d.ts +1 -1
- package/dist/types/nullable.js +1 -2
- package/dist/types/traffictype.js +2 -5
- package/dist/types/urn.js +1 -2
- package/dist/types/util-types.js +1 -2
- package/dist/types/validator.js +4 -9
- package/dist/utils/api-model.d.ts +1 -1
- package/dist/utils/api-model.js +17 -27
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/base64.js +2 -7
- package/dist/utils/date-utils.js +9 -16
- package/dist/utils/geojson-types.js +2 -7
- package/dist/utils/geometry.js +15 -48
- package/dist/utils/logging.d.ts +1 -1
- package/dist/utils/logging.js +8 -13
- package/dist/utils/retry.js +21 -26
- package/dist/utils/slack.js +7 -14
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +14 -29
- package/package.json +107 -18
- package/src/aws/infra/api/handler-factory.ts +3 -3
- package/src/aws/infra/api/integration.ts +2 -2
- package/src/aws/infra/api/response.ts +3 -3
- package/src/aws/infra/api/responses.ts +4 -4
- package/src/aws/infra/api/static-integration.ts +2 -2
- package/src/aws/infra/canaries/canary-alarm.ts +1 -1
- package/src/aws/infra/canaries/canary.ts +3 -3
- package/src/aws/infra/canaries/database-canary.ts +3 -3
- package/src/aws/infra/canaries/database-checker.ts +6 -6
- package/src/aws/infra/canaries/url-canary.ts +6 -6
- package/src/aws/infra/canaries/url-checker.ts +8 -8
- package/src/aws/infra/sqs-integration.ts +1 -1
- package/src/aws/infra/sqs-queue.ts +2 -2
- package/src/aws/infra/stack/lambda-configs.ts +2 -2
- package/src/aws/infra/stack/monitoredfunction.ts +4 -4
- package/src/aws/infra/stack/parameters.ts +1 -1
- package/src/aws/infra/stack/rest_apis.ts +6 -6
- package/src/aws/infra/stack/stack-checking-aspect.ts +1 -1
- package/src/aws/infra/stack/stack.ts +4 -5
- package/src/aws/infra/stack/subscription.ts +2 -2
- package/src/aws/infra/stacks/db-dns-stack.ts +4 -4
- package/src/aws/infra/stacks/db-proxy-stack.ts +5 -5
- package/src/aws/infra/stacks/db-stack.ts +5 -5
- package/src/aws/infra/stacks/network-stack.ts +3 -3
- package/src/aws/runtime/digitraffic-integration-response.ts +2 -2
- package/src/aws/runtime/dt-logger-default.ts +2 -2
- package/src/aws/runtime/secrets/dbsecret.ts +1 -1
- package/src/aws/runtime/secrets/proxy-holder.ts +4 -4
- package/src/aws/runtime/secrets/rds-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret.ts +2 -2
- package/src/database/cached.ts +1 -1
- package/src/database/database.ts +3 -3
- package/src/database/last-updated.ts +1 -1
- package/src/index.ts +2 -0
- package/src/test/db-testutils.ts +2 -2
- package/src/test/secrets-manager.ts +2 -2
- package/src/types/nullable.ts +1 -1
- package/src/utils/api-model.ts +1 -1
- package/src/utils/geometry.ts +5 -3
- package/src/utils/logging.ts +2 -2
- package/src/utils/retry.ts +3 -3
- package/src/utils/slack.ts +2 -2
- package/src/utils/utils.ts +3 -3
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
const rds_holder_1 = require("../../runtime/secrets/rds-holder");
|
7
|
-
const utils_1 = require("../../../utils/utils");
|
8
|
-
const dt_logger_default_1 = require("../../runtime/dt-logger-default");
|
1
|
+
import { inDatabaseReadonly } from "../../../database/database.js";
|
2
|
+
import { ProxyHolder } from "../../runtime/secrets/proxy-holder.js";
|
3
|
+
import { RdsHolder } from "../../runtime/secrets/rds-holder.js";
|
4
|
+
import { getEnvVariable } from "../../../utils/utils.js";
|
5
|
+
import { logger } from "../../runtime/dt-logger-default.js";
|
9
6
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
10
7
|
const synthetics = require("Synthetics");
|
11
8
|
class DatabaseCheck {
|
@@ -55,7 +52,7 @@ const stepConfig = {
|
|
55
52
|
* Checker for sql that checks the count. Meaning that the
|
56
53
|
* sql must be structured as "select count(*) from <table> where <something>".
|
57
54
|
*/
|
58
|
-
class DatabaseCountChecker {
|
55
|
+
export class DatabaseCountChecker {
|
59
56
|
constructor(credentialsFunction) {
|
60
57
|
this.checks = [];
|
61
58
|
this.credentialsFunction = credentialsFunction;
|
@@ -65,10 +62,10 @@ class DatabaseCountChecker {
|
|
65
62
|
synthetics.getConfiguration().withFailedCanaryMetric(true);
|
66
63
|
}
|
67
64
|
static createForProxy() {
|
68
|
-
return new DatabaseCountChecker(() => new
|
65
|
+
return new DatabaseCountChecker(() => new ProxyHolder(getEnvVariable("SECRET_ID")).setCredentials());
|
69
66
|
}
|
70
67
|
static createForRds() {
|
71
|
-
return new DatabaseCountChecker(() => new
|
68
|
+
return new DatabaseCountChecker(() => new RdsHolder(getEnvVariable("SECRET_ID")).setCredentials());
|
72
69
|
}
|
73
70
|
/**
|
74
71
|
* Expect that the count is 1
|
@@ -96,9 +93,9 @@ class DatabaseCountChecker {
|
|
96
93
|
throw new Error("No checks");
|
97
94
|
}
|
98
95
|
await this.credentialsFunction();
|
99
|
-
await
|
96
|
+
await inDatabaseReadonly(async (db) => {
|
100
97
|
for (const check of this.checks) {
|
101
|
-
|
98
|
+
logger.info({
|
102
99
|
method: "DatabaseCountChecker.expect",
|
103
100
|
message: "Running sql: " + check.sql,
|
104
101
|
});
|
@@ -116,5 +113,4 @@ class DatabaseCountChecker {
|
|
116
113
|
return "OK";
|
117
114
|
}
|
118
115
|
}
|
119
|
-
exports.DatabaseCountChecker = DatabaseCountChecker;
|
120
116
|
//# sourceMappingURL=database-checker.js.map
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Role } from "aws-cdk-lib/aws-iam";
|
2
2
|
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
3
|
-
import { DigitrafficRestApi } from "../stack/rest_apis";
|
4
|
-
import { DigitrafficStack } from "../stack/stack";
|
5
|
-
import { DigitrafficCanary } from "./canary";
|
6
|
-
import { CanaryParameters } from "./canary-parameters";
|
3
|
+
import { DigitrafficRestApi } from "../stack/rest_apis.js";
|
4
|
+
import { DigitrafficStack } from "../stack/stack.js";
|
5
|
+
import { DigitrafficCanary } from "./canary.js";
|
6
|
+
import { CanaryParameters } from "./canary-parameters.js";
|
7
7
|
export interface UrlCanaryParameters extends CanaryParameters {
|
8
8
|
readonly hostname: string;
|
9
9
|
readonly apiKeyId: string;
|
@@ -1,26 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const canary_1 = require("./canary");
|
6
|
-
const canary_keys_1 = require("./canary-keys");
|
7
|
-
class UrlCanary extends canary_1.DigitrafficCanary {
|
1
|
+
import { CfnCanary } from "aws-cdk-lib/aws-synthetics";
|
2
|
+
import { DigitrafficCanary } from "./canary.js";
|
3
|
+
import { ENV_API_KEY, ENV_HOSTNAME, ENV_SECRET } from "./canary-keys.js";
|
4
|
+
export class UrlCanary extends DigitrafficCanary {
|
8
5
|
constructor(stack, role, params, secret) {
|
9
6
|
const canaryName = `${params.name}-url`;
|
10
7
|
const environmentVariables = {};
|
11
|
-
environmentVariables[
|
8
|
+
environmentVariables[ENV_HOSTNAME] = params.hostname;
|
12
9
|
if (params.secret) {
|
13
|
-
environmentVariables[
|
10
|
+
environmentVariables[ENV_SECRET] = params.secret;
|
14
11
|
}
|
15
12
|
if (params.apiKeyId) {
|
16
|
-
environmentVariables[
|
13
|
+
environmentVariables[ENV_API_KEY] = params.apiKeyId;
|
17
14
|
}
|
18
15
|
if (secret) {
|
19
16
|
secret.grantRead(role);
|
20
17
|
}
|
21
18
|
// the handler code is defined at the actual project using this
|
22
19
|
super(stack, canaryName, role, params, environmentVariables);
|
23
|
-
if (params.inVpc && this.node.defaultChild instanceof
|
20
|
+
if (params.inVpc && this.node.defaultChild instanceof CfnCanary) {
|
24
21
|
const subnetIds = stack.vpc === undefined
|
25
22
|
? []
|
26
23
|
: stack.vpc.privateSubnets.map((subnet) => subnet.subnetId);
|
@@ -56,5 +53,4 @@ class UrlCanary extends canary_1.DigitrafficCanary {
|
|
56
53
|
return publicApi.apiKeyIds[0];
|
57
54
|
}
|
58
55
|
}
|
59
|
-
exports.UrlCanary = UrlCanary;
|
60
56
|
//# sourceMappingURL=url-canary.js.map
|
@@ -1,6 +1,6 @@
|
|
1
|
-
/// <reference types="node" />
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
2
2
|
import { IncomingMessage } from "http";
|
3
|
-
import { MediaType } from "../../types/mediatypes";
|
3
|
+
import { MediaType } from "../../types/mediatypes.js";
|
4
4
|
import { FeatureCollection } from "geojson";
|
5
5
|
export declare const API_KEY_HEADER = "x-api-key";
|
6
6
|
type CheckerFunction = (Res: IncomingMessage) => Promise<void>;
|
@@ -1,28 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const asserter_1 = require("../../../test/asserter");
|
1
|
+
import { createRequire as _createRequire } from "module";
|
2
|
+
const __require = _createRequire(import.meta.url);
|
3
|
+
import { Asserter } from "../../../test/asserter.js";
|
5
4
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
6
5
|
const synthetics = require("Synthetics");
|
7
|
-
const zlib =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
const zlib = __require("zlib");
|
7
|
+
import { MediaType } from "../../types/mediatypes.js";
|
8
|
+
import { getApiKeyFromAPIGateway } from "../../runtime/apikey.js";
|
9
|
+
import { isValidGeoJson } from "../../../utils/geometry.js";
|
10
|
+
import { getEnvVariable } from "../../../utils/utils.js";
|
11
|
+
import { ENV_API_KEY, ENV_HOSTNAME } from "./canary-keys.js";
|
12
|
+
import { logger } from "../../runtime/dt-logger-default.js";
|
13
|
+
import { logException } from "../../../utils/logging.js";
|
14
|
+
export const API_KEY_HEADER = "x-api-key";
|
16
15
|
const baseHeaders = {
|
17
16
|
"Digitraffic-User": "internal-digitraffic-canary",
|
18
17
|
"Accept-Encoding": "gzip",
|
19
18
|
Accept: "*/*",
|
20
19
|
};
|
21
|
-
class UrlChecker {
|
20
|
+
export class UrlChecker {
|
22
21
|
constructor(hostname, apiKey) {
|
23
22
|
const headers = { ...baseHeaders };
|
24
23
|
if (apiKey) {
|
25
|
-
headers[
|
24
|
+
headers[API_KEY_HEADER] = apiKey;
|
26
25
|
}
|
27
26
|
this.requestOptions = {
|
28
27
|
hostname,
|
@@ -40,12 +39,12 @@ class UrlChecker {
|
|
40
39
|
.withFailedCanaryMetric(true);
|
41
40
|
}
|
42
41
|
static create(hostname, apiKeyId) {
|
43
|
-
return
|
42
|
+
return getApiKeyFromAPIGateway(apiKeyId).then((apiKey) => {
|
44
43
|
return new UrlChecker(hostname, apiKey.value);
|
45
44
|
});
|
46
45
|
}
|
47
46
|
static createV2() {
|
48
|
-
return this.create(
|
47
|
+
return this.create(getEnvVariable(ENV_HOSTNAME), getEnvVariable(ENV_API_KEY));
|
49
48
|
}
|
50
49
|
expectStatus(statusCode, url, callback) {
|
51
50
|
const requestOptions = {
|
@@ -71,7 +70,7 @@ class UrlChecker {
|
|
71
70
|
},
|
72
71
|
};
|
73
72
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
|
74
|
-
return synthetics.executeHttpStep(`Verify 404 for ${url}`, requestOptions, validateStatusCodeAndContentType(404,
|
73
|
+
return synthetics.executeHttpStep(`Verify 404 for ${url}`, requestOptions, validateStatusCodeAndContentType(404, MediaType.TEXT_PLAIN));
|
75
74
|
}
|
76
75
|
expect400(url) {
|
77
76
|
const requestOptions = {
|
@@ -81,14 +80,14 @@ class UrlChecker {
|
|
81
80
|
},
|
82
81
|
};
|
83
82
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
|
84
|
-
return synthetics.executeHttpStep(`Verify 400 for ${url}`, requestOptions, validateStatusCodeAndContentType(400,
|
83
|
+
return synthetics.executeHttpStep(`Verify 400 for ${url}`, requestOptions, validateStatusCodeAndContentType(400, MediaType.TEXT_PLAIN));
|
85
84
|
}
|
86
85
|
expect403WithoutApiKey(url, mediaType) {
|
87
86
|
if (
|
88
87
|
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
89
88
|
!this.requestOptions.headers ||
|
90
|
-
!this.requestOptions.headers[
|
91
|
-
|
89
|
+
!this.requestOptions.headers[API_KEY_HEADER]) {
|
90
|
+
logger.error({
|
92
91
|
method: "UrlChecker.expect403WithoutApiKey",
|
93
92
|
message: "No Api-key defined",
|
94
93
|
});
|
@@ -101,13 +100,12 @@ class UrlChecker {
|
|
101
100
|
},
|
102
101
|
};
|
103
102
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
|
104
|
-
return synthetics.executeHttpStep(`Verify 403 for ${url}`, requestOptions, validateStatusCodeAndContentType(403, mediaType ??
|
103
|
+
return synthetics.executeHttpStep(`Verify 403 for ${url}`, requestOptions, validateStatusCodeAndContentType(403, mediaType ?? MediaType.APPLICATION_JSON));
|
105
104
|
}
|
106
105
|
done() {
|
107
106
|
return "Canary successful";
|
108
107
|
}
|
109
108
|
}
|
110
|
-
exports.UrlChecker = UrlChecker;
|
111
109
|
async function getResponseBody(response) {
|
112
110
|
const body = await getBodyFromResponse(response);
|
113
111
|
if (response.headers["content-encoding"] === "gzip") {
|
@@ -115,7 +113,7 @@ async function getResponseBody(response) {
|
|
115
113
|
return zlib.gunzipSync(body).toString();
|
116
114
|
}
|
117
115
|
catch (e) {
|
118
|
-
|
116
|
+
logException(logger, e);
|
119
117
|
}
|
120
118
|
}
|
121
119
|
return body.toString();
|
@@ -153,22 +151,22 @@ function validateStatusCodeAndContentType(statusCode, contentType) {
|
|
153
151
|
};
|
154
152
|
}
|
155
153
|
// DEPRECATED
|
156
|
-
class ResponseChecker {
|
154
|
+
export class ResponseChecker {
|
157
155
|
constructor(contentType) {
|
158
156
|
this.checkCors = true;
|
159
157
|
this.contentType = contentType;
|
160
158
|
}
|
161
159
|
static forJson() {
|
162
|
-
return new ResponseChecker(
|
160
|
+
return new ResponseChecker(MediaType.APPLICATION_JSON);
|
163
161
|
}
|
164
162
|
static forCSV() {
|
165
|
-
return new ResponseChecker(
|
163
|
+
return new ResponseChecker(MediaType.TEXT_CSV);
|
166
164
|
}
|
167
165
|
static forGeojson() {
|
168
|
-
return new ResponseChecker(
|
166
|
+
return new ResponseChecker(MediaType.APPLICATION_GEOJSON);
|
169
167
|
}
|
170
168
|
static forJpeg() {
|
171
|
-
return new ResponseChecker(
|
169
|
+
return new ResponseChecker(MediaType.IMAGE_JPEG);
|
172
170
|
}
|
173
171
|
check() {
|
174
172
|
return this.responseChecker(() => {
|
@@ -202,8 +200,7 @@ class ResponseChecker {
|
|
202
200
|
};
|
203
201
|
}
|
204
202
|
}
|
205
|
-
|
206
|
-
class ContentChecker {
|
203
|
+
export class ContentChecker {
|
207
204
|
static checkJson(fn) {
|
208
205
|
return async (res) => {
|
209
206
|
const body = await getResponseBody(res);
|
@@ -217,8 +214,7 @@ class ContentChecker {
|
|
217
214
|
};
|
218
215
|
}
|
219
216
|
}
|
220
|
-
|
221
|
-
class ContentTypeChecker {
|
217
|
+
export class ContentTypeChecker {
|
222
218
|
static checkContentType(contentType) {
|
223
219
|
return (res) => {
|
224
220
|
if (!res.statusCode) {
|
@@ -240,20 +236,18 @@ class ContentTypeChecker {
|
|
240
236
|
};
|
241
237
|
}
|
242
238
|
}
|
243
|
-
|
244
|
-
class GeoJsonChecker {
|
239
|
+
export class GeoJsonChecker {
|
245
240
|
static validFeatureCollection(fn) {
|
246
241
|
return ResponseChecker.forGeojson().checkJson((json) => {
|
247
|
-
|
248
|
-
|
242
|
+
Asserter.assertEquals(json.type, "FeatureCollection");
|
243
|
+
Asserter.assertTrue(isValidGeoJson(json));
|
249
244
|
if (fn) {
|
250
245
|
fn(json);
|
251
246
|
}
|
252
247
|
});
|
253
248
|
}
|
254
249
|
}
|
255
|
-
|
256
|
-
class HeaderChecker {
|
250
|
+
export class HeaderChecker {
|
257
251
|
static checkHeaderExists(headerName) {
|
258
252
|
return (res) => {
|
259
253
|
if (!res.headers[headerName]) {
|
@@ -271,5 +265,4 @@ class HeaderChecker {
|
|
271
265
|
};
|
272
266
|
}
|
273
267
|
}
|
274
|
-
exports.HeaderChecker = HeaderChecker;
|
275
268
|
//# sourceMappingURL=url-checker.js.map
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DocumentationPart = exports.addTagsAndSummary = exports.addTags = exports.addDocumentation = exports.addQueryParameterDescription = void 0;
|
4
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
1
|
+
import { CfnDocumentationPart } from "aws-cdk-lib/aws-apigateway";
|
5
2
|
// Documentation parts are objects that describe an API Gateway API or parts of an API
|
6
3
|
// https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-documenting-api.html
|
7
4
|
/**
|
@@ -13,8 +10,8 @@ const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
|
13
10
|
*
|
14
11
|
* @deprecated Use DigitrafficRestApi.documentResource
|
15
12
|
*/
|
16
|
-
function addQueryParameterDescription(name, description, resource, stack) {
|
17
|
-
new
|
13
|
+
export function addQueryParameterDescription(name, description, resource, stack) {
|
14
|
+
new CfnDocumentationPart(stack, `${name}Documentation`, {
|
18
15
|
restApiId: resource.api.restApiId,
|
19
16
|
location: {
|
20
17
|
type: "QUERY_PARAMETER",
|
@@ -24,7 +21,6 @@ function addQueryParameterDescription(name, description, resource, stack) {
|
|
24
21
|
properties: JSON.stringify({ description }),
|
25
22
|
});
|
26
23
|
}
|
27
|
-
exports.addQueryParameterDescription = addQueryParameterDescription;
|
28
24
|
/**
|
29
25
|
* Add a documentation part to a method
|
30
26
|
* @param methodDescription
|
@@ -32,8 +28,8 @@ exports.addQueryParameterDescription = addQueryParameterDescription;
|
|
32
28
|
* @param resource REST API resource
|
33
29
|
* @param stack CloudFormation stack
|
34
30
|
*/
|
35
|
-
function addDocumentation(methodDescription, documentationProperties, resource, stack) {
|
36
|
-
new
|
31
|
+
export function addDocumentation(methodDescription, documentationProperties, resource, stack) {
|
32
|
+
new CfnDocumentationPart(stack, `${methodDescription}Documentation`, {
|
37
33
|
restApiId: resource.api.restApiId,
|
38
34
|
location: {
|
39
35
|
type: "METHOD",
|
@@ -42,7 +38,6 @@ function addDocumentation(methodDescription, documentationProperties, resource,
|
|
42
38
|
properties: JSON.stringify(documentationProperties),
|
43
39
|
});
|
44
40
|
}
|
45
|
-
exports.addDocumentation = addDocumentation;
|
46
41
|
/**
|
47
42
|
* Adds OpenAPI tags to an API method
|
48
43
|
* @param methodDescription Description of API method
|
@@ -50,10 +45,9 @@ exports.addDocumentation = addDocumentation;
|
|
50
45
|
* @param resource REST API resource
|
51
46
|
* @param stack CloudFormation stack
|
52
47
|
*/
|
53
|
-
function addTags(methodDescription, tags, resource, stack) {
|
48
|
+
export function addTags(methodDescription, tags, resource, stack) {
|
54
49
|
addDocumentation(methodDescription, { tags }, resource, stack);
|
55
50
|
}
|
56
|
-
exports.addTags = addTags;
|
57
51
|
/**
|
58
52
|
* Adds OpenAPI tags and a method summary to an API method
|
59
53
|
*
|
@@ -65,11 +59,10 @@ exports.addTags = addTags;
|
|
65
59
|
* @param resource REST API resource
|
66
60
|
* @param stack CloudFormation stack
|
67
61
|
*/
|
68
|
-
function addTagsAndSummary(methodDescription, tags, summary, resource, stack) {
|
62
|
+
export function addTagsAndSummary(methodDescription, tags, summary, resource, stack) {
|
69
63
|
addDocumentation(methodDescription, { tags, summary }, resource, stack);
|
70
64
|
}
|
71
|
-
|
72
|
-
class DocumentationPart {
|
65
|
+
export class DocumentationPart {
|
73
66
|
constructor(parameterName, documentationProperties, type) {
|
74
67
|
this.parameterName = parameterName;
|
75
68
|
this.documentationProperties = documentationProperties;
|
@@ -91,5 +84,4 @@ class DocumentationPart {
|
|
91
84
|
return new DocumentationPart(name, { tags, summary }, "METHOD");
|
92
85
|
}
|
93
86
|
}
|
94
|
-
exports.DocumentationPart = DocumentationPart;
|
95
87
|
//# sourceMappingURL=documentation.js.map
|
@@ -1,17 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
|
5
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
6
|
-
class OldStackImports {
|
1
|
+
import { Vpc } from "aws-cdk-lib/aws-ec2";
|
2
|
+
import { CfnOutput, Fn } from "aws-cdk-lib";
|
3
|
+
export class OldStackImports {
|
7
4
|
}
|
8
|
-
exports.OldStackImports = OldStackImports;
|
9
5
|
OldStackImports.AURORAINSTANCE_SG_IMPORT_NAME = "AuroraSG";
|
10
6
|
OldStackImports.RDSPROXY_SG_IMPORT_NAME = "RDSProxySG";
|
11
7
|
/**
|
12
8
|
* Import VPC from other stack outputs
|
13
9
|
*/
|
14
|
-
function importVpc(scope, environmentName) {
|
10
|
+
export function importVpc(scope, environmentName) {
|
15
11
|
const vpcId = importValue(environmentName, "VPCID");
|
16
12
|
const privateSubnetIds = [
|
17
13
|
importValue(environmentName, "digitrafficprivateASubnet"),
|
@@ -20,34 +16,30 @@ function importVpc(scope, environmentName) {
|
|
20
16
|
const availabilityZones = ["euw1-az1", "euw1-az2"];
|
21
17
|
// VPC reference construction requires vpcId and availability zones
|
22
18
|
// private subnets are used in Lambda configuration
|
23
|
-
return
|
19
|
+
return Vpc.fromVpcAttributes(scope, "vpc", {
|
24
20
|
vpcId,
|
25
21
|
privateSubnetIds,
|
26
22
|
availabilityZones,
|
27
23
|
});
|
28
24
|
}
|
29
|
-
exports.importVpc = importVpc;
|
30
25
|
/**
|
31
26
|
* Import value from other stack output. Stack outputs are named with
|
32
27
|
* digitraffic-${environmentName}-${name} pattern and this function takes care of it
|
33
28
|
*/
|
34
|
-
function importValue(environmentName, name) {
|
35
|
-
return
|
29
|
+
export function importValue(environmentName, name) {
|
30
|
+
return Fn.importValue(outputName(environmentName, name));
|
36
31
|
}
|
37
|
-
exports.importValue = importValue;
|
38
32
|
/**
|
39
33
|
* Export value as stack output. Use same naming pattern as importValue.
|
40
34
|
*/
|
41
|
-
function exportValue(stack, environmentName, name, value) {
|
35
|
+
export function exportValue(stack, environmentName, name, value) {
|
42
36
|
const exportName = outputName(environmentName, name);
|
43
|
-
new
|
37
|
+
new CfnOutput(stack, exportName, {
|
44
38
|
exportName,
|
45
39
|
value,
|
46
40
|
});
|
47
41
|
}
|
48
|
-
|
49
|
-
function outputName(environmentName, name) {
|
42
|
+
export function outputName(environmentName, name) {
|
50
43
|
return `digitraffic-${environmentName}-${name}`;
|
51
44
|
}
|
52
|
-
exports.outputName = outputName;
|
53
45
|
//# sourceMappingURL=import-util.js.map
|
@@ -1,31 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
6
|
-
const aws_events_targets_1 = require("aws-cdk-lib/aws-events-targets");
|
7
|
-
class Scheduler extends aws_events_1.Rule {
|
1
|
+
import { Rule, Schedule } from "aws-cdk-lib/aws-events";
|
2
|
+
import { Duration } from "aws-cdk-lib";
|
3
|
+
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
|
4
|
+
export class Scheduler extends Rule {
|
8
5
|
constructor(stack, ruleName, schedule, lambda) {
|
9
6
|
super(stack, ruleName, { ruleName, schedule });
|
10
7
|
if (lambda) {
|
11
|
-
this.addTarget(new
|
8
|
+
this.addTarget(new LambdaFunction(lambda));
|
12
9
|
}
|
13
10
|
}
|
14
11
|
static everyMinute(stack, ruleName, lambda) {
|
15
|
-
return Scheduler.every(stack, ruleName,
|
12
|
+
return Scheduler.every(stack, ruleName, Duration.minutes(1), lambda);
|
16
13
|
}
|
17
14
|
static everyMinutes(stack, ruleName, minutes, lambda) {
|
18
|
-
return Scheduler.every(stack, ruleName,
|
15
|
+
return Scheduler.every(stack, ruleName, Duration.minutes(minutes), lambda);
|
19
16
|
}
|
20
17
|
static everyHour(stack, ruleName, lambda) {
|
21
|
-
return Scheduler.every(stack, ruleName,
|
18
|
+
return Scheduler.every(stack, ruleName, Duration.hours(1), lambda);
|
22
19
|
}
|
23
20
|
static everyDay(stack, ruleName, lambda) {
|
24
|
-
return Scheduler.every(stack, ruleName,
|
21
|
+
return Scheduler.every(stack, ruleName, Duration.days(1), lambda);
|
25
22
|
}
|
26
23
|
static every(stack, ruleName, duration, lambda) {
|
27
|
-
return new Scheduler(stack, ruleName,
|
24
|
+
return new Scheduler(stack, ruleName, Schedule.rate(duration), lambda);
|
28
25
|
}
|
29
26
|
}
|
30
|
-
exports.Scheduler = Scheduler;
|
31
27
|
//# sourceMappingURL=scheduler.js.map
|
@@ -1,15 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.DigitrafficSecurityRule = void 0;
|
4
|
-
const aws_events_1 = require("aws-cdk-lib/aws-events");
|
5
|
-
const aws_events_targets_1 = require("aws-cdk-lib/aws-events-targets");
|
1
|
+
import { Rule } from "aws-cdk-lib/aws-events";
|
2
|
+
import { SnsTopic } from "aws-cdk-lib/aws-events-targets";
|
6
3
|
/**
|
7
4
|
* Automatic rule for Security Hub. Send notification to given topic if the following conditions apply:
|
8
5
|
* * There is a finding with a status of NEW
|
9
6
|
* * It has severity of HIGH or CRITICAL
|
10
7
|
* * It is in a FAILED state
|
11
8
|
*/
|
12
|
-
class DigitrafficSecurityRule extends
|
9
|
+
export class DigitrafficSecurityRule extends Rule {
|
13
10
|
constructor(scope, topic) {
|
14
11
|
const ruleName = 'SecurityHubRule';
|
15
12
|
super(scope, ruleName, {
|
@@ -32,8 +29,7 @@ class DigitrafficSecurityRule extends aws_events_1.Rule {
|
|
32
29
|
},
|
33
30
|
},
|
34
31
|
});
|
35
|
-
this.addTarget(new
|
32
|
+
this.addTarget(new SnsTopic(topic));
|
36
33
|
}
|
37
34
|
}
|
38
|
-
exports.DigitrafficSecurityRule = DigitrafficSecurityRule;
|
39
35
|
//# sourceMappingURL=security-rule.js.map
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { RequestValidator, Resource } from "aws-cdk-lib/aws-apigateway";
|
1
|
+
import { RequestValidator, Resource, IModel } from "aws-cdk-lib/aws-apigateway";
|
2
2
|
import { Queue } from "aws-cdk-lib/aws-sqs";
|
3
|
-
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
4
3
|
import { Construct } from "constructs";
|
5
4
|
export declare function attachQueueToApiGatewayResource(stack: Construct, queue: Queue, resource: Resource, requestValidator: RequestValidator, resourceName: string, apiKeyRequired: boolean, requestModels?: Record<string, IModel>): void;
|
@@ -1,21 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
6
|
-
const aws_iam_1 = require("aws-cdk-lib/aws-iam");
|
7
|
-
function attachQueueToApiGatewayResource(stack, queue, resource, requestValidator, resourceName, apiKeyRequired, requestModels) {
|
1
|
+
import { Aws } from "aws-cdk-lib";
|
2
|
+
import { AwsIntegration, PassthroughBehavior } from "aws-cdk-lib/aws-apigateway";
|
3
|
+
import { PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
4
|
+
export function attachQueueToApiGatewayResource(stack, queue, resource, requestValidator, resourceName, apiKeyRequired, requestModels) {
|
8
5
|
// role for API Gateway
|
9
|
-
const apiGwRole = new
|
10
|
-
assumedBy: new
|
6
|
+
const apiGwRole = new Role(stack, `${resourceName}APIGatewayToSQSRole`, {
|
7
|
+
assumedBy: new ServicePrincipal("apigateway.amazonaws.com"),
|
11
8
|
});
|
12
9
|
// grants API Gateway the right to send SQS messages
|
13
|
-
apiGwRole.addToPolicy(new
|
10
|
+
apiGwRole.addToPolicy(new PolicyStatement({
|
14
11
|
resources: [queue.queueArn],
|
15
12
|
actions: ["sqs:SendMessage"],
|
16
13
|
}));
|
17
14
|
// grants API Gateway the right write CloudWatch Logs
|
18
|
-
apiGwRole.addToPolicy(new
|
15
|
+
apiGwRole.addToPolicy(new PolicyStatement({
|
19
16
|
resources: ["*"],
|
20
17
|
actions: [
|
21
18
|
"logs:CreateLogGroup",
|
@@ -31,11 +28,11 @@ function attachQueueToApiGatewayResource(stack, queue, resource, requestValidato
|
|
31
28
|
const fifoMessageGroupId = queue.fifo
|
32
29
|
? "&MessageGroupId=AlwaysSameFifoGroup"
|
33
30
|
: "";
|
34
|
-
const sqsIntegration = new
|
31
|
+
const sqsIntegration = new AwsIntegration({
|
35
32
|
service: "sqs",
|
36
33
|
integrationHttpMethod: "POST",
|
37
34
|
options: {
|
38
|
-
passthroughBehavior:
|
35
|
+
passthroughBehavior: PassthroughBehavior.NEVER,
|
39
36
|
credentialsRole: apiGwRole,
|
40
37
|
requestParameters: {
|
41
38
|
// SQS requires the Content-Type of the HTTP request to be application/x-www-form-urlencoded
|
@@ -63,7 +60,7 @@ function attachQueueToApiGatewayResource(stack, queue, resource, requestValidato
|
|
63
60
|
},
|
64
61
|
],
|
65
62
|
},
|
66
|
-
path: `${
|
63
|
+
path: `${Aws.ACCOUNT_ID}/${queue.queueName}`,
|
67
64
|
});
|
68
65
|
resource.addMethod("POST", sqsIntegration, {
|
69
66
|
requestValidator,
|
@@ -85,5 +82,4 @@ function attachQueueToApiGatewayResource(stack, queue, resource, requestValidato
|
|
85
82
|
],
|
86
83
|
});
|
87
84
|
}
|
88
|
-
exports.attachQueueToApiGatewayResource = attachQueueToApiGatewayResource;
|
89
85
|
//# sourceMappingURL=sqs-integration.js.map
|