@digitraffic/common 2023.4.28-1 → 2023.5.10-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.
@@ -12,8 +12,6 @@ export interface DbConfiguration {
12
12
  readonly instances: number;
13
13
  readonly customParameterGroup: boolean;
14
14
  readonly securityGroupId: string;
15
- readonly superuserName: string;
16
- readonly superuserPassword: string;
17
15
  readonly proxy: {
18
16
  readonly name?: string;
19
17
  readonly securityGroupId: string;
@@ -4,6 +4,7 @@ exports.DbStack = void 0;
4
4
  const aws_cdk_lib_1 = require("aws-cdk-lib");
5
5
  const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
6
6
  const aws_rds_1 = require("aws-cdk-lib/aws-rds");
7
+ const aws_secretsmanager_1 = require("aws-cdk-lib/aws-secretsmanager");
7
8
  const import_util_1 = require("../import-util");
8
9
  /**
9
10
  * Stack that creates DatabaseCluster.
@@ -43,6 +44,7 @@ class DbStack extends aws_cdk_lib_1.Stack {
43
44
  : aws_rds_1.ParameterGroup.fromParameterGroupName(this, "ParameterGroup", `default.aurora-postgresql${configuration.dbVersion.auroraPostgresMajorVersion}`);
44
45
  }
45
46
  createClusterParameters(configuration, instanceName, vpc, securityGroup, parameterGroup) {
47
+ const secret = aws_secretsmanager_1.Secret.fromSecretCompleteArn(this, "DBSecret", configuration.secretArn);
46
48
  return {
47
49
  engine: aws_rds_1.DatabaseClusterEngine.auroraPostgres({
48
50
  version: configuration.dbVersion,
@@ -71,7 +73,7 @@ class DbStack extends aws_cdk_lib_1.Stack {
71
73
  instanceType: configuration.dbInstanceType,
72
74
  parameterGroup,
73
75
  },
74
- credentials: aws_rds_1.Credentials.fromPassword(configuration.superuserName, aws_cdk_lib_1.SecretValue.unsafePlainText(configuration.superuserPassword)),
76
+ credentials: aws_rds_1.Credentials.fromPassword(secret.secretValueFromJson("db.superuser").unsafeUnwrap(), secret.secretValueFromJson("db.superuser.password")),
75
77
  parameterGroup,
76
78
  };
77
79
  }
@@ -93,7 +95,7 @@ class DbStack extends aws_cdk_lib_1.Stack {
93
95
  throw new Error("Couldn't pull CfnDBInstances from the L1 constructs!");
94
96
  }
95
97
  cfnInstances.forEach((cfnInstance) => delete cfnInstance.engineVersion);
96
- cluster.node.addDependency(parameterGroup, "Create ParameterGroup before DatabaseCluster");
98
+ cluster.node.addDependency(parameterGroup);
97
99
  return cluster;
98
100
  }
99
101
  }
@@ -19,7 +19,9 @@ class NetworkStack extends aws_cdk_lib_1.Stack {
19
19
  createVpc(configuration) {
20
20
  return new aws_ec2_1.Vpc(this, "DigitrafficVPC", {
21
21
  vpcName: configuration.vpcName,
22
- availabilityZones: ["eu-west-1a", "eu-west-1b"],
22
+ availabilityZones: aws_cdk_lib_1.Stack.of(this)
23
+ .availabilityZones.sort()
24
+ .slice(0, 2),
23
25
  enableDnsHostnames: true,
24
26
  enableDnsSupport: true,
25
27
  ipAddresses: aws_ec2_1.IpAddresses.cidr(configuration.cidr),
@@ -1,3 +1,4 @@
1
+ export declare const EPOCH: Date;
1
2
  /**
2
3
  * Counts difference in milliseconds between dates.
3
4
  * @param start
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dateFromIsoString = exports.countDiffInSeconds = exports.countDiffMs = void 0;
3
+ exports.dateFromIsoString = exports.countDiffInSeconds = exports.countDiffMs = exports.EPOCH = void 0;
4
+ exports.EPOCH = new Date(Date.UTC(1970, 0, 1));
4
5
  /**
5
6
  * Counts difference in milliseconds between dates.
6
7
  * @param start
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitraffic/common",
3
- "version": "2023.4.28-1",
3
+ "version": "2023.5.10-1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,13 +17,13 @@
17
17
  "src/**/*.ts"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@aws-cdk/aws-synthetics-alpha": "^2.62.2-alpha.0",
20
+ "@aws-cdk/aws-synthetics-alpha": "^2.78.0-alpha.0",
21
21
  "@types/geojson": "^7946.0.10",
22
- "aws-cdk-lib": "^2.76.0",
23
- "aws-sdk": "^2.1362.0",
22
+ "aws-cdk-lib": "^2.78.0",
23
+ "aws-sdk": "^2.1374.0",
24
24
  "axios": "^1.2.6",
25
25
  "change-case": "^4.1.2",
26
- "constructs": "^10.1.292",
26
+ "constructs": "^10.2.17",
27
27
  "geojson-validation": "^1.0.2",
28
28
  "moment": "^2.29.4",
29
29
  "node-ttl": "^0.2.0",
@@ -31,34 +31,34 @@
31
31
  "pg-promise": "^11.0.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@aws-cdk/aws-synthetics-alpha": "2.70.0-alpha.0",
35
- "@types/aws-lambda": "~8.10.114",
34
+ "@aws-cdk/aws-synthetics-alpha": "2.78.0-alpha.0",
35
+ "@types/aws-lambda": "~8.10.115",
36
36
  "@types/geojson": "^7946.0.10",
37
37
  "@types/jest": "^29.5.1",
38
38
  "@types/lodash": "^4.14.194",
39
39
  "@types/node": "18.15.13",
40
- "@types/ramda": "~0.29.0",
40
+ "@types/ramda": "~0.29.1",
41
41
  "@types/sinon": "10.0.14",
42
- "@typescript-eslint/eslint-plugin": "~5.59.0",
43
- "@typescript-eslint/parser": "^5.59.0",
44
- "aws-cdk-lib": "~2.76.0",
45
- "aws-sdk": "~2.1362.0",
42
+ "@typescript-eslint/eslint-plugin": "~5.59.5",
43
+ "@typescript-eslint/parser": "^5.59.5",
44
+ "aws-cdk-lib": "~2.78.0",
45
+ "aws-sdk": "~2.1374.0",
46
46
  "axios": "^1.3.6",
47
47
  "change-case": "^4.1.2",
48
- "constructs": "10.2.2",
49
- "eslint": "~8.38.0",
48
+ "constructs": "10.2.17",
49
+ "eslint": "~8.40.0",
50
50
  "eslint-config-prettier": "^8.8.0",
51
51
  "eslint-plugin-deprecation": "~1.4.1",
52
52
  "geojson-validation": "^1.0.2",
53
53
  "husky": "^8.0.3",
54
54
  "jest": "^29.5.0",
55
55
  "jest-junit": "^16.0.0",
56
- "lint-staged": "^13.2.1",
56
+ "lint-staged": "^13.2.2",
57
57
  "moment": "^2.29.4",
58
58
  "node-ttl": "^0.2.0",
59
59
  "pg-native": "^3.0.1",
60
60
  "pg-promise": "^11.4.3",
61
- "prettier": "^2.8.7",
61
+ "prettier": "^2.8.8",
62
62
  "ramda": "~0.29.0",
63
63
  "rimraf": "^5.0.0",
64
64
  "sinon": "15.0.4",
@@ -1,4 +1,4 @@
1
- import { Duration, RemovalPolicy, SecretValue, Stack } from "aws-cdk-lib";
1
+ import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib";
2
2
  import {
3
3
  InstanceType,
4
4
  IVpc,
@@ -19,8 +19,9 @@ import {
19
19
  ParameterGroup,
20
20
  } from "aws-cdk-lib/aws-rds";
21
21
  import { Construct } from "constructs";
22
- import { exportValue, importVpc } from "../import-util";
22
+ import { Secret } from "aws-cdk-lib/aws-secretsmanager";
23
23
  import { InfraStackConfiguration } from "./intra-stack-configuration";
24
+ import { exportValue, importVpc } from "../import-util";
24
25
 
25
26
  export interface DbConfiguration {
26
27
  readonly secretArn: string;
@@ -32,9 +33,6 @@ export interface DbConfiguration {
32
33
  readonly customParameterGroup: boolean;
33
34
  readonly securityGroupId: string;
34
35
 
35
- readonly superuserName: string;
36
- readonly superuserPassword: string;
37
-
38
36
  readonly proxy: {
39
37
  readonly name?: string;
40
38
  readonly securityGroupId: string;
@@ -126,6 +124,12 @@ export class DbStack extends Stack {
126
124
  securityGroup: ISecurityGroup,
127
125
  parameterGroup: IParameterGroup
128
126
  ): DatabaseClusterProps {
127
+ const secret = Secret.fromSecretCompleteArn(
128
+ this,
129
+ "DBSecret",
130
+ configuration.secretArn
131
+ );
132
+
129
133
  return {
130
134
  engine: DatabaseClusterEngine.auroraPostgres({
131
135
  version: configuration.dbVersion,
@@ -155,8 +159,8 @@ export class DbStack extends Stack {
155
159
  parameterGroup,
156
160
  },
157
161
  credentials: Credentials.fromPassword(
158
- configuration.superuserName,
159
- SecretValue.unsafePlainText(configuration.superuserPassword)
162
+ secret.secretValueFromJson("db.superuser").unsafeUnwrap(),
163
+ secret.secretValueFromJson("db.superuser.password")
160
164
  ),
161
165
  parameterGroup,
162
166
  };
@@ -200,10 +204,7 @@ export class DbStack extends Stack {
200
204
  }
201
205
  cfnInstances.forEach((cfnInstance) => delete cfnInstance.engineVersion);
202
206
 
203
- cluster.node.addDependency(
204
- parameterGroup,
205
- "Create ParameterGroup before DatabaseCluster"
206
- );
207
+ cluster.node.addDependency(parameterGroup);
207
208
 
208
209
  return cluster;
209
210
  }
@@ -53,7 +53,9 @@ export class NetworkStack extends Stack {
53
53
  createVpc(configuration: NetworkConfiguration): Vpc {
54
54
  return new Vpc(this, "DigitrafficVPC", {
55
55
  vpcName: configuration.vpcName,
56
- availabilityZones: ["eu-west-1a", "eu-west-1b"],
56
+ availabilityZones: Stack.of(this)
57
+ .availabilityZones.sort()
58
+ .slice(0, 2), // take two first azs
57
59
  enableDnsHostnames: true,
58
60
  enableDnsSupport: true,
59
61
  ipAddresses: IpAddresses.cidr(configuration.cidr),
@@ -1,4 +1,4 @@
1
-
1
+ export const EPOCH = new Date(Date.UTC(1970, 0, 1));
2
2
  /**
3
3
  * Counts difference in milliseconds between dates.
4
4
  * @param start
@@ -14,7 +14,7 @@ export function countDiffMs(start: Date, end: Date): number {
14
14
  * @param end
15
15
  */
16
16
  export function countDiffInSeconds(start: Date, end: Date): number {
17
- return countDiffMs(start, end)/1000;
17
+ return countDiffMs(start, end) / 1000;
18
18
  }
19
19
 
20
20
  /**