@resistdesign/voltra 3.0.0-alpha.3 → 3.0.0-alpha.4
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/README.md +75 -0
- package/SearchTypes-DjN6YQzE.d.ts +577 -0
- package/Types-C7XjUjoF.d.ts +240 -0
- package/Validation-CFP59oIP.d.ts +226 -0
- package/api/index.d.ts +6 -0
- package/api/index.js +7968 -0
- package/app/index.d.ts +5 -0
- package/app/index.js +810 -0
- package/common/Testing/CLI.js +432 -0
- package/common/index.d.ts +4 -0
- package/common/index.js +1760 -0
- package/iac/index.d.ts +2 -0
- package/iac/index.js +1661 -0
- package/iac/packs/index.d.ts +1 -0
- package/iac/packs/index.js +1620 -0
- package/index-BkFZlfit.d.ts +112 -0
- package/index-C3-iD9Mh.d.ts +690 -0
- package/index-DZ2BB4iX.d.ts +5357 -0
- package/{src/iac/types/IaCTypes.d.ts → index-DcvJOZ_c.d.ts} +1018 -23
- package/index-IokxSNxm.d.ts +745 -0
- package/index.d.ts +13 -0
- package/index.js +10973 -0
- package/package.json +40 -41
- package/src/api/DataAccessControl.d.ts +0 -85
- package/src/api/DataAccessControl.js +0 -159
- package/src/api/ORM/DACUtils.d.ts +0 -60
- package/src/api/ORM/DACUtils.js +0 -197
- package/src/api/ORM/ListItemUtils.d.ts +0 -7
- package/src/api/ORM/ListItemUtils.js +0 -22
- package/src/api/ORM/ORMRouteMap.d.ts +0 -19
- package/src/api/ORM/ORMRouteMap.js +0 -82
- package/src/api/ORM/TypeInfoORMService.d.ts +0 -103
- package/src/api/ORM/TypeInfoORMService.js +0 -581
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver/ConfigTypes.d.ts +0 -63
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver/ConfigTypes.js +0 -2
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver.d.ts +0 -36
- package/src/api/ORM/drivers/DynamoDBDataItemDBDriver.js +0 -282
- package/src/api/ORM/drivers/S3FileItemDBDriver/ConfigTypes.d.ts +0 -90
- package/src/api/ORM/drivers/S3FileItemDBDriver/ConfigTypes.js +0 -2
- package/src/api/ORM/drivers/S3FileItemDBDriver/S3FileDriver.d.ts +0 -45
- package/src/api/ORM/drivers/S3FileItemDBDriver/S3FileDriver.js +0 -127
- package/src/api/ORM/drivers/S3FileItemDBDriver.d.ts +0 -44
- package/src/api/ORM/drivers/S3FileItemDBDriver.js +0 -182
- package/src/api/ORM/drivers/common/SupportedTypeInfoORMDBDrivers.d.ts +0 -12
- package/src/api/ORM/drivers/common/SupportedTypeInfoORMDBDrivers.js +0 -20
- package/src/api/ORM/drivers/common/Types.d.ts +0 -77
- package/src/api/ORM/drivers/common/Types.js +0 -14
- package/src/api/ORM/drivers/common/index.d.ts +0 -2
- package/src/api/ORM/drivers/common/index.js +0 -18
- package/src/api/ORM/drivers/index.d.ts +0 -3
- package/src/api/ORM/drivers/index.js +0 -19
- package/src/api/ORM/index.d.ts +0 -4
- package/src/api/ORM/index.js +0 -43
- package/src/api/Router/AWS.d.ts +0 -26
- package/src/api/Router/AWS.js +0 -76
- package/src/api/Router/Auth.d.ts +0 -2
- package/src/api/Router/Auth.js +0 -9
- package/src/api/Router/CORS.d.ts +0 -6
- package/src/api/Router/CORS.js +0 -27
- package/src/api/Router/Types.d.ts +0 -71
- package/src/api/Router/Types.js +0 -2
- package/src/api/Router/index.d.ts +0 -18
- package/src/api/Router/index.js +0 -145
- package/src/api/index.d.ts +0 -3
- package/src/api/index.js +0 -39
- package/src/app/index.d.ts +0 -1
- package/src/app/index.js +0 -37
- package/src/app/utils/ApplicationState.d.ts +0 -52
- package/src/app/utils/ApplicationState.js +0 -86
- package/src/app/utils/ApplicationStateLoader.d.ts +0 -46
- package/src/app/utils/ApplicationStateLoader.js +0 -57
- package/src/app/utils/Controller.d.ts +0 -4
- package/src/app/utils/Controller.js +0 -47
- package/src/app/utils/Debug.d.ts +0 -4
- package/src/app/utils/Debug.js +0 -30
- package/src/app/utils/EasyLayout.d.ts +0 -49
- package/src/app/utils/EasyLayout.js +0 -122
- package/src/app/utils/Route.d.ts +0 -28
- package/src/app/utils/Route.js +0 -102
- package/src/app/utils/Service.d.ts +0 -12
- package/src/app/utils/Service.js +0 -34
- package/src/app/utils/TypeInfoORMAPIUtils.d.ts +0 -20
- package/src/app/utils/TypeInfoORMAPIUtils.js +0 -62
- package/src/app/utils/TypeInfoORMClient.d.ts +0 -24
- package/src/app/utils/TypeInfoORMClient.js +0 -69
- package/src/app/utils/index.d.ts +0 -8
- package/src/app/utils/index.js +0 -24
- package/src/common/CommandLine/collectRequiredEnvironmentVariables.d.ts +0 -1
- package/src/common/CommandLine/collectRequiredEnvironmentVariables.js +0 -16
- package/src/common/HelperTypes.d.ts +0 -3
- package/src/common/HelperTypes.js +0 -2
- package/src/common/IdGeneration/getSimpleId.d.ts +0 -4
- package/src/common/IdGeneration/getSimpleId.js +0 -16
- package/src/common/IdGeneration/index.d.ts +0 -1
- package/src/common/IdGeneration/index.js +0 -17
- package/src/common/ItemRelationshipInfoTypes.d.ts +0 -46
- package/src/common/ItemRelationshipInfoTypes.js +0 -20
- package/src/common/ItemRelationships/ItemRelationshipValidation.d.ts +0 -10
- package/src/common/ItemRelationships/ItemRelationshipValidation.js +0 -43
- package/src/common/ItemRelationships/index.d.ts +0 -1
- package/src/common/ItemRelationships/index.js +0 -17
- package/src/common/Logging/Utils.d.ts +0 -10
- package/src/common/Logging/Utils.js +0 -33
- package/src/common/Logging/index.d.ts +0 -1
- package/src/common/Logging/index.js +0 -17
- package/src/common/Routing.d.ts +0 -25
- package/src/common/Routing.js +0 -102
- package/src/common/SearchTypes.d.ts +0 -98
- package/src/common/SearchTypes.js +0 -39
- package/src/common/SearchUtils.d.ts +0 -22
- package/src/common/SearchUtils.js +0 -134
- package/src/common/SearchValidation.d.ts +0 -17
- package/src/common/SearchValidation.js +0 -90
- package/src/common/Storyboarding/Types.d.ts +0 -25
- package/src/common/Storyboarding/Types.js +0 -2
- package/src/common/StringTransformers.d.ts +0 -17
- package/src/common/StringTransformers.js +0 -36
- package/src/common/Testing/CLI.d.ts +0 -2
- package/src/common/Testing/CLI.js +0 -56
- package/src/common/Testing/Types.d.ts +0 -117
- package/src/common/Testing/Types.js +0 -19
- package/src/common/Testing/Utils.d.ts +0 -48
- package/src/common/Testing/Utils.js +0 -334
- package/src/common/Testing/index.d.ts +0 -2
- package/src/common/Testing/index.js +0 -18
- package/src/common/TypeInfoDataItemUtils.d.ts +0 -10
- package/src/common/TypeInfoDataItemUtils.js +0 -55
- package/src/common/TypeInfoORM/Types.d.ts +0 -76
- package/src/common/TypeInfoORM/Types.js +0 -55
- package/src/common/TypeInfoORM/index.d.ts +0 -1
- package/src/common/TypeInfoORM/index.js +0 -17
- package/src/common/TypeParsing/Constants.d.ts +0 -1
- package/src/common/TypeParsing/Constants.js +0 -4
- package/src/common/TypeParsing/ParsingUtils/Constants.d.ts +0 -5
- package/src/common/TypeParsing/ParsingUtils/Constants.js +0 -8
- package/src/common/TypeParsing/ParsingUtils/checkType.d.ts +0 -8
- package/src/common/TypeParsing/ParsingUtils/checkType.js +0 -46
- package/src/common/TypeParsing/ParsingUtils/checkUnionType.d.ts +0 -6
- package/src/common/TypeParsing/ParsingUtils/checkUnionType.js +0 -15
- package/src/common/TypeParsing/ParsingUtils/extractCommentTags.d.ts +0 -2
- package/src/common/TypeParsing/ParsingUtils/extractCommentTags.js +0 -105
- package/src/common/TypeParsing/ParsingUtils/extractLiteralValues.d.ts +0 -6
- package/src/common/TypeParsing/ParsingUtils/extractLiteralValues.js +0 -42
- package/src/common/TypeParsing/ParsingUtils/extractTypeDetails.d.ts +0 -8
- package/src/common/TypeParsing/ParsingUtils/extractTypeDetails.js +0 -14
- package/src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.d.ts +0 -5
- package/src/common/TypeParsing/ParsingUtils/getPrimaryFieldForTypeInfo.js +0 -27
- package/src/common/TypeParsing/ParsingUtils/getTypeInfo.d.ts +0 -3
- package/src/common/TypeParsing/ParsingUtils/getTypeInfo.js +0 -27
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoField.d.ts +0 -3
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoField.js +0 -44
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromAliasType.js +0 -28
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromFieldFilter.js +0 -105
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getTypeInfoFromTypeAlias.js +0 -20
- package/src/common/TypeParsing/ParsingUtils/getTypeKeyword.d.ts +0 -3
- package/src/common/TypeParsing/ParsingUtils/getTypeKeyword.js +0 -17
- package/src/common/TypeParsing/ParsingUtils/getUnionOrIntersectionTypeInfo.d.ts +0 -4
- package/src/common/TypeParsing/ParsingUtils/getUnionOrIntersectionTypeInfo.js +0 -49
- package/src/common/TypeParsing/ParsingUtils/getUnionOrLiteralStringValues.d.ts +0 -2
- package/src/common/TypeParsing/ParsingUtils/getUnionOrLiteralStringValues.js +0 -24
- package/src/common/TypeParsing/TypeInfo.d.ts +0 -142
- package/src/common/TypeParsing/TypeInfo.js +0 -13
- package/src/common/TypeParsing/TypeMapping.d.ts +0 -9
- package/src/common/TypeParsing/TypeMapping.js +0 -32
- package/src/common/TypeParsing/TypeParsing.d.ts +0 -5
- package/src/common/TypeParsing/TypeParsing.js +0 -39
- package/src/common/TypeParsing/Utils.d.ts +0 -21
- package/src/common/TypeParsing/Utils.js +0 -94
- package/src/common/TypeParsing/Validation.d.ts +0 -92
- package/src/common/TypeParsing/Validation.js +0 -340
- package/src/common/TypeParsing/index.d.ts +0 -5
- package/src/common/TypeParsing/index.js +0 -44
- package/src/common/index.d.ts +0 -11
- package/src/common/index.js +0 -47
- package/src/iac/SimpleCFT.d.ts +0 -48
- package/src/iac/SimpleCFT.js +0 -82
- package/src/iac/index.d.ts +0 -9
- package/src/iac/index.js +0 -48
- package/src/iac/packs/auth/user-management.d.ts +0 -14
- package/src/iac/packs/auth/user-management.js +0 -302
- package/src/iac/packs/auth.d.ts +0 -19
- package/src/iac/packs/auth.js +0 -47
- package/src/iac/packs/build/utils.d.ts +0 -100
- package/src/iac/packs/build/utils.js +0 -23
- package/src/iac/packs/build.d.ts +0 -29
- package/src/iac/packs/build.js +0 -217
- package/src/iac/packs/cdn.d.ts +0 -12
- package/src/iac/packs/cdn.js +0 -126
- package/src/iac/packs/cloud-function.d.ts +0 -17
- package/src/iac/packs/cloud-function.js +0 -69
- package/src/iac/packs/database.d.ts +0 -29
- package/src/iac/packs/database.js +0 -27
- package/src/iac/packs/dns.d.ts +0 -13
- package/src/iac/packs/dns.js +0 -26
- package/src/iac/packs/file-storage.d.ts +0 -14
- package/src/iac/packs/file-storage.js +0 -71
- package/src/iac/packs/gateway.d.ts +0 -27
- package/src/iac/packs/gateway.js +0 -342
- package/src/iac/packs/index.d.ts +0 -11
- package/src/iac/packs/index.js +0 -27
- package/src/iac/packs/repo.d.ts +0 -10
- package/src/iac/packs/repo.js +0 -34
- package/src/iac/packs/ssl-certificate.d.ts +0 -10
- package/src/iac/packs/ssl-certificate.js +0 -36
- package/src/iac/types/CloudFormationResourceSpecification.d.ts +0 -2
- package/src/iac/types/Constants.d.ts +0 -9
- package/src/iac/types/Constants.js +0 -20
- package/src/iac/types/IaCTypes.js +0 -14
- package/src/iac/types/Renderers.d.ts +0 -12
- package/src/iac/types/Renderers.js +0 -112
- package/src/iac/types/Types.d.ts +0 -37
- package/src/iac/types/Types.js +0 -2
- package/src/iac/types/Utils.d.ts +0 -2
- package/src/iac/types/Utils.js +0 -60
- package/src/iac/types/generate.d.ts +0 -1
- package/src/iac/types/generate.js +0 -31
- package/src/iac/utils/index.d.ts +0 -36
- package/src/iac/utils/index.js +0 -105
- package/src/iac/utils/patch-utils.d.ts +0 -15
- package/src/iac/utils/patch-utils.js +0 -62
- package/src/index.d.ts +0 -178
- package/src/index.js +0 -214
package/iac/index.js
ADDED
|
@@ -0,0 +1,1661 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/iac/packs/index.ts
|
|
10
|
+
var packs_exports = {};
|
|
11
|
+
__export(packs_exports, {
|
|
12
|
+
COMMAND_HELPERS: () => COMMAND_HELPERS,
|
|
13
|
+
DEFAULT_AUTH_TYPE: () => DEFAULT_AUTH_TYPE,
|
|
14
|
+
DEFAULT_BUILD_PIPELINE_REPO_PROVIDER: () => DEFAULT_BUILD_PIPELINE_REPO_PROVIDER,
|
|
15
|
+
PLACEHOLDER_FUNCTION_CODE: () => PLACEHOLDER_FUNCTION_CODE,
|
|
16
|
+
addAuth: () => addAuth,
|
|
17
|
+
addBuildPipeline: () => addBuildPipeline,
|
|
18
|
+
addCDN: () => addCDN,
|
|
19
|
+
addCloudFunction: () => addCloudFunction,
|
|
20
|
+
addDNS: () => addDNS,
|
|
21
|
+
addDatabase: () => addDatabase,
|
|
22
|
+
addGateway: () => addGateway,
|
|
23
|
+
addRepo: () => addRepo,
|
|
24
|
+
addSSLCertificate: () => addSSLCertificate,
|
|
25
|
+
addSecureFileStorage: () => addSecureFileStorage,
|
|
26
|
+
createBuildSpec: () => createBuildSpec
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// src/iac/utils/index.ts
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
32
|
+
DEFAULT_MERGE_STRATEGY: () => DEFAULT_MERGE_STRATEGY,
|
|
33
|
+
addParameter: () => addParameter,
|
|
34
|
+
addParameters: () => addParameters,
|
|
35
|
+
createResourcePack: () => createResourcePack,
|
|
36
|
+
getValuePathArray: () => getValuePathArray,
|
|
37
|
+
getValuePathString: () => getValuePathString,
|
|
38
|
+
isConstructedFrom: () => isConstructedFrom,
|
|
39
|
+
mergeValues: () => mergeValues,
|
|
40
|
+
patchTemplate: () => patchTemplate
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// src/iac/utils/patch-utils.ts
|
|
44
|
+
var DEFAULT_MERGE_STRATEGY = "transpose";
|
|
45
|
+
var getValuePathString = (valuePathArray = []) => valuePathArray.map((p) => encodeURIComponent(p)).join("/");
|
|
46
|
+
var getValuePathArray = (valuePathString = "") => valuePathString.split("/").map((p) => decodeURIComponent(p));
|
|
47
|
+
var isConstructedFrom = (value, constructorReference) => value !== null && typeof value === "object" && "constructor" in value && value.constructor === constructorReference;
|
|
48
|
+
var mergeValues = (valuePathArray = [], existingValue, newValue, mergeStrategyMap = {}) => {
|
|
49
|
+
const valuePathString = getValuePathString(valuePathArray);
|
|
50
|
+
const arrayIndexWildcardValuePathString = getValuePathString(
|
|
51
|
+
valuePathArray.map((p) => typeof p === "number" ? "#" : p)
|
|
52
|
+
);
|
|
53
|
+
const {
|
|
54
|
+
[valuePathString]: {
|
|
55
|
+
strategy: specificKeyMergeStrategy = DEFAULT_MERGE_STRATEGY,
|
|
56
|
+
data: specificKeyMergeStrategyData = void 0
|
|
57
|
+
} = {},
|
|
58
|
+
[arrayIndexWildcardValuePathString]: {
|
|
59
|
+
strategy: arrayIndexWildcardMergeStrategy = DEFAULT_MERGE_STRATEGY,
|
|
60
|
+
data: arrayIndexWildcardMergeStrategyData = void 0
|
|
61
|
+
} = {}
|
|
62
|
+
} = mergeStrategyMap;
|
|
63
|
+
const mergeStrategy = valuePathString in mergeStrategyMap ? specificKeyMergeStrategy : arrayIndexWildcardMergeStrategy;
|
|
64
|
+
const mergeStrategyData = valuePathString in mergeStrategyMap ? specificKeyMergeStrategyData : arrayIndexWildcardMergeStrategyData;
|
|
65
|
+
let mergedValue = typeof newValue !== "undefined" ? newValue : existingValue;
|
|
66
|
+
if (mergeStrategy !== "replace") {
|
|
67
|
+
if (isConstructedFrom(existingValue, Array) && isConstructedFrom(newValue, Array)) {
|
|
68
|
+
if (mergeStrategy === "accumulate") {
|
|
69
|
+
mergedValue = [...existingValue, ...newValue];
|
|
70
|
+
} else if (mergeStrategy === "accumulate-unique") {
|
|
71
|
+
mergedValue = [
|
|
72
|
+
...existingValue,
|
|
73
|
+
...newValue.filter(
|
|
74
|
+
(item) => existingValue.indexOf(item) === -1
|
|
75
|
+
)
|
|
76
|
+
];
|
|
77
|
+
} else if (mergeStrategy === "accumulate-unique-by") {
|
|
78
|
+
const existingItemMap = {};
|
|
79
|
+
const newItemMap = {};
|
|
80
|
+
for (let i = 0; i < existingValue.length; i++) {
|
|
81
|
+
const existingItem = existingValue[i];
|
|
82
|
+
if (existingItem && typeof existingItem === "object") {
|
|
83
|
+
const identifier = mergeStrategyData instanceof Function ? mergeStrategyData(existingItem) : existingItem[mergeStrategyData];
|
|
84
|
+
existingItemMap[identifier] = existingItem;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (let j = 0; j < newValue.length; j++) {
|
|
88
|
+
const newItem = newValue[j];
|
|
89
|
+
if (newItem && typeof newItem === "object") {
|
|
90
|
+
const identifier = mergeStrategyData instanceof Function ? mergeStrategyData(newItem) : newItem[mergeStrategyData];
|
|
91
|
+
newItemMap[identifier] = newItem;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
mergedValue = Object.keys({
|
|
95
|
+
...existingItemMap,
|
|
96
|
+
...newItemMap
|
|
97
|
+
}).map(
|
|
98
|
+
(id, index) => mergeValues(
|
|
99
|
+
[...valuePathArray, index],
|
|
100
|
+
existingItemMap[id],
|
|
101
|
+
newItemMap[id],
|
|
102
|
+
mergeStrategyMap
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
} else if (mergeStrategy === "transpose") {
|
|
106
|
+
const fullLength = Math.max(existingValue.length, newValue.length);
|
|
107
|
+
mergedValue = [...new Array(fullLength)].map(
|
|
108
|
+
(_empty, index) => mergeValues(
|
|
109
|
+
[...valuePathArray, index],
|
|
110
|
+
existingValue[index],
|
|
111
|
+
newValue[index],
|
|
112
|
+
mergeStrategyMap
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
} else if (isConstructedFrom(existingValue, Object) && isConstructedFrom(newValue, Object)) {
|
|
117
|
+
mergedValue = Object.keys({ ...existingValue, ...newValue }).reduce(
|
|
118
|
+
(acc, k) => ({
|
|
119
|
+
...acc,
|
|
120
|
+
[k]: mergeValues(
|
|
121
|
+
[...valuePathArray, k],
|
|
122
|
+
existingValue[k],
|
|
123
|
+
newValue[k],
|
|
124
|
+
mergeStrategyMap
|
|
125
|
+
)
|
|
126
|
+
}),
|
|
127
|
+
{}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return mergedValue;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/iac/utils/index.ts
|
|
135
|
+
var addParameter = (parameterInfo, template) => {
|
|
136
|
+
const { ParameterId, Parameter, Label, Group } = parameterInfo;
|
|
137
|
+
const {
|
|
138
|
+
Parameters,
|
|
139
|
+
Metadata: {
|
|
140
|
+
"AWS::CloudFormation::Interface": {
|
|
141
|
+
ParameterGroups = [],
|
|
142
|
+
ParameterLabels = {}
|
|
143
|
+
} = {}
|
|
144
|
+
} = {}
|
|
145
|
+
} = template;
|
|
146
|
+
let NewParameterGroups = ParameterGroups;
|
|
147
|
+
if (Group) {
|
|
148
|
+
const GroupObject = ParameterGroups.filter(
|
|
149
|
+
(g) => g.Label?.default === Group
|
|
150
|
+
)[0];
|
|
151
|
+
NewParameterGroups = GroupObject ? ParameterGroups.map(
|
|
152
|
+
(g) => g.Label?.default === Group ? {
|
|
153
|
+
...g,
|
|
154
|
+
Parameters: [...g.Parameters || [], ParameterId]
|
|
155
|
+
} : g
|
|
156
|
+
) : [
|
|
157
|
+
...ParameterGroups,
|
|
158
|
+
{
|
|
159
|
+
Label: {
|
|
160
|
+
default: Group
|
|
161
|
+
},
|
|
162
|
+
Parameters: [ParameterId]
|
|
163
|
+
}
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...template,
|
|
168
|
+
Parameters: {
|
|
169
|
+
...Parameters,
|
|
170
|
+
[ParameterId]: Parameter
|
|
171
|
+
},
|
|
172
|
+
Metadata: {
|
|
173
|
+
...template.Metadata,
|
|
174
|
+
"AWS::CloudFormation::Interface": {
|
|
175
|
+
...template?.Metadata?.["AWS::CloudFormation::Interface"],
|
|
176
|
+
ParameterGroups: NewParameterGroups,
|
|
177
|
+
ParameterLabels: {
|
|
178
|
+
...ParameterLabels,
|
|
179
|
+
[ParameterId]: {
|
|
180
|
+
default: Label
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
var addParameters = (parameters, template) => parameters.reduce((acc, p) => addParameter(p, acc), template);
|
|
188
|
+
var patchTemplate = (patch, template) => mergeValues([], template, patch, {
|
|
189
|
+
[getValuePathString([
|
|
190
|
+
// Parameter Groups
|
|
191
|
+
"Metadata",
|
|
192
|
+
"AWS::CloudFormation::Interface",
|
|
193
|
+
"ParameterGroups"
|
|
194
|
+
])]: {
|
|
195
|
+
strategy: "accumulate-unique-by",
|
|
196
|
+
data: (pG) => pG?.Label?.default
|
|
197
|
+
},
|
|
198
|
+
[getValuePathString([
|
|
199
|
+
// Parameter Group Parameter Ids
|
|
200
|
+
"Metadata",
|
|
201
|
+
"AWS::CloudFormation::Interface",
|
|
202
|
+
"ParameterGroups",
|
|
203
|
+
"#",
|
|
204
|
+
"Parameters"
|
|
205
|
+
])]: {
|
|
206
|
+
strategy: "accumulate-unique"
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
var createResourcePack = (creator) => (params, template) => {
|
|
210
|
+
const patch = creator(params);
|
|
211
|
+
return patchTemplate(patch, template);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/iac/packs/auth/user-management.ts
|
|
215
|
+
var addUserManagement = createResourcePack(
|
|
216
|
+
({
|
|
217
|
+
id,
|
|
218
|
+
authRoleName,
|
|
219
|
+
unauthRoleName,
|
|
220
|
+
domainName,
|
|
221
|
+
hostedZoneId,
|
|
222
|
+
sslCertificateArn,
|
|
223
|
+
callbackUrls,
|
|
224
|
+
logoutUrls,
|
|
225
|
+
baseDomainRecordAliasTargetDNSName,
|
|
226
|
+
apiGatewayRESTAPIId,
|
|
227
|
+
apiStageName
|
|
228
|
+
}) => {
|
|
229
|
+
const apiRoleConfig = apiGatewayRESTAPIId && apiStageName ? {
|
|
230
|
+
[`${id}IdentityPoolRoles`]: {
|
|
231
|
+
Type: "AWS::Cognito::IdentityPoolRoleAttachment",
|
|
232
|
+
Properties: {
|
|
233
|
+
IdentityPoolId: {
|
|
234
|
+
Ref: `${id}IdentityPool`
|
|
235
|
+
},
|
|
236
|
+
Roles: {
|
|
237
|
+
authenticated: {
|
|
238
|
+
"Fn::GetAtt": [`${id}AuthRole`, "Arn"]
|
|
239
|
+
},
|
|
240
|
+
unauthenticated: {
|
|
241
|
+
"Fn::GetAtt": [`${id}UnauthRole`, "Arn"]
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
[`${id}AuthRole`]: {
|
|
247
|
+
Type: "AWS::IAM::Role",
|
|
248
|
+
Properties: {
|
|
249
|
+
RoleName: authRoleName,
|
|
250
|
+
Path: "/",
|
|
251
|
+
AssumeRolePolicyDocument: {
|
|
252
|
+
Version: "2012-10-17",
|
|
253
|
+
Statement: [
|
|
254
|
+
{
|
|
255
|
+
Effect: "Allow",
|
|
256
|
+
Principal: {
|
|
257
|
+
Federated: "cognito-identity.amazonaws.com"
|
|
258
|
+
},
|
|
259
|
+
Action: ["sts:AssumeRoleWithWebIdentity"],
|
|
260
|
+
Condition: {
|
|
261
|
+
StringEquals: {
|
|
262
|
+
"cognito-identity.amazonaws.com:aud": {
|
|
263
|
+
Ref: `${id}IdentityPool`
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
"ForAnyValue:StringLike": {
|
|
267
|
+
"cognito-identity.amazonaws.com:amr": "authenticated"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
},
|
|
273
|
+
Policies: [
|
|
274
|
+
{
|
|
275
|
+
PolicyName: "CognitoAuthorizedPolicy",
|
|
276
|
+
PolicyDocument: {
|
|
277
|
+
Version: "2012-10-17",
|
|
278
|
+
Statement: [
|
|
279
|
+
{
|
|
280
|
+
Effect: "Allow",
|
|
281
|
+
Action: [
|
|
282
|
+
"mobileanalytics:PutEvents",
|
|
283
|
+
"cognito-sync:*",
|
|
284
|
+
"cognito-identity:*"
|
|
285
|
+
],
|
|
286
|
+
Resource: "*"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
Effect: "Allow",
|
|
290
|
+
Action: ["execute-api:Invoke"],
|
|
291
|
+
Resource: {
|
|
292
|
+
"Fn::Sub": [
|
|
293
|
+
"arn:aws:execute-api:${Region}:${AccountId}:${APIID}/${StageName}/${HTTPVerb}/api/*",
|
|
294
|
+
{
|
|
295
|
+
Region: {
|
|
296
|
+
Ref: "AWS::Region"
|
|
297
|
+
},
|
|
298
|
+
AccountId: {
|
|
299
|
+
Ref: "AWS::AccountId"
|
|
300
|
+
},
|
|
301
|
+
APIID: apiGatewayRESTAPIId,
|
|
302
|
+
StageName: apiStageName,
|
|
303
|
+
HTTPVerb: "*"
|
|
304
|
+
}
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
[`${id}UnauthRole`]: {
|
|
315
|
+
Type: "AWS::IAM::Role",
|
|
316
|
+
Properties: {
|
|
317
|
+
RoleName: unauthRoleName,
|
|
318
|
+
Path: "/",
|
|
319
|
+
AssumeRolePolicyDocument: {
|
|
320
|
+
Version: "2012-10-17",
|
|
321
|
+
Statement: [
|
|
322
|
+
{
|
|
323
|
+
Effect: "Allow",
|
|
324
|
+
Principal: {
|
|
325
|
+
Federated: "cognito-identity.amazonaws.com"
|
|
326
|
+
},
|
|
327
|
+
Action: ["sts:AssumeRoleWithWebIdentity"],
|
|
328
|
+
Condition: {
|
|
329
|
+
StringEquals: {
|
|
330
|
+
"cognito-identity.amazonaws.com:aud": {
|
|
331
|
+
Ref: `${id}IdentityPool`
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
"ForAnyValue:StringLike": {
|
|
335
|
+
"cognito-identity.amazonaws.com:amr": "unauthenticated"
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
},
|
|
341
|
+
Policies: [
|
|
342
|
+
{
|
|
343
|
+
PolicyName: "CognitoUnauthorizedPolicy",
|
|
344
|
+
PolicyDocument: {
|
|
345
|
+
Version: "2012-10-17",
|
|
346
|
+
Statement: [
|
|
347
|
+
{
|
|
348
|
+
Effect: "Allow",
|
|
349
|
+
Action: [
|
|
350
|
+
"mobileanalytics:PutEvents",
|
|
351
|
+
"cognito-sync:*",
|
|
352
|
+
"cognito-identity:*"
|
|
353
|
+
],
|
|
354
|
+
Resource: "*"
|
|
355
|
+
}
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
} : {};
|
|
363
|
+
return {
|
|
364
|
+
Resources: {
|
|
365
|
+
[id]: {
|
|
366
|
+
Type: "AWS::Cognito::UserPool",
|
|
367
|
+
Properties: {
|
|
368
|
+
UserPoolName: {
|
|
369
|
+
"Fn::Sub": [`\${AWS::StackName}${id}`, {}]
|
|
370
|
+
},
|
|
371
|
+
AccountRecoverySetting: {
|
|
372
|
+
RecoveryMechanisms: [
|
|
373
|
+
{
|
|
374
|
+
Name: "verified_email",
|
|
375
|
+
Priority: 1
|
|
376
|
+
}
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
AdminCreateUserConfig: {
|
|
380
|
+
AllowAdminCreateUserOnly: false,
|
|
381
|
+
UnusedAccountValidityDays: 365
|
|
382
|
+
},
|
|
383
|
+
AutoVerifiedAttributes: ["email"],
|
|
384
|
+
AliasAttributes: ["phone_number", "email", "preferred_username"],
|
|
385
|
+
Schema: [
|
|
386
|
+
{
|
|
387
|
+
Name: "email",
|
|
388
|
+
Required: true,
|
|
389
|
+
Mutable: true
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
Name: "given_name",
|
|
393
|
+
Required: true,
|
|
394
|
+
Mutable: true
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
Name: "family_name",
|
|
398
|
+
Required: true,
|
|
399
|
+
Mutable: true
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
Name: "phone_number",
|
|
403
|
+
Required: true,
|
|
404
|
+
Mutable: true
|
|
405
|
+
}
|
|
406
|
+
],
|
|
407
|
+
DeviceConfiguration: {
|
|
408
|
+
ChallengeRequiredOnNewDevice: true,
|
|
409
|
+
DeviceOnlyRememberedOnUserPrompt: false
|
|
410
|
+
},
|
|
411
|
+
UsernameConfiguration: {
|
|
412
|
+
CaseSensitive: false
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
[`${id}BaseDomainRecord`]: !!baseDomainRecordAliasTargetDNSName ? {
|
|
417
|
+
Type: "AWS::Route53::RecordSet",
|
|
418
|
+
DeletionPolicy: "Delete",
|
|
419
|
+
Properties: {
|
|
420
|
+
HostedZoneId: hostedZoneId,
|
|
421
|
+
Type: "A",
|
|
422
|
+
Name: domainName,
|
|
423
|
+
AliasTarget: {
|
|
424
|
+
HostedZoneId: "Z2FDTNDATAQYW2",
|
|
425
|
+
DNSName: baseDomainRecordAliasTargetDNSName
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
} : void 0,
|
|
429
|
+
[`${id}DomainRecord`]: {
|
|
430
|
+
Type: "AWS::Route53::RecordSet",
|
|
431
|
+
DeletionPolicy: "Delete",
|
|
432
|
+
Properties: {
|
|
433
|
+
HostedZoneId: hostedZoneId,
|
|
434
|
+
Type: "A",
|
|
435
|
+
Name: {
|
|
436
|
+
"Fn::Sub": [
|
|
437
|
+
"auth.${BaseDomainName}",
|
|
438
|
+
{
|
|
439
|
+
BaseDomainName: domainName
|
|
440
|
+
}
|
|
441
|
+
]
|
|
442
|
+
},
|
|
443
|
+
AliasTarget: {
|
|
444
|
+
HostedZoneId: "Z2FDTNDATAQYW2",
|
|
445
|
+
DNSName: {
|
|
446
|
+
"Fn::GetAtt": [`${id}Domain`, "CloudFrontDistribution"]
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
[`${id}Domain`]: {
|
|
452
|
+
Type: "AWS::Cognito::UserPoolDomain",
|
|
453
|
+
DependsOn: !!baseDomainRecordAliasTargetDNSName ? `${id}BaseDomainRecord` : void 0,
|
|
454
|
+
Properties: {
|
|
455
|
+
Domain: {
|
|
456
|
+
"Fn::Sub": [
|
|
457
|
+
"auth.${BaseDomainName}",
|
|
458
|
+
{
|
|
459
|
+
BaseDomainName: domainName
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
},
|
|
463
|
+
UserPoolId: {
|
|
464
|
+
Ref: id
|
|
465
|
+
},
|
|
466
|
+
CustomDomainConfig: {
|
|
467
|
+
CertificateArn: sslCertificateArn
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
[`${id}Client`]: {
|
|
472
|
+
Type: "AWS::Cognito::UserPoolClient",
|
|
473
|
+
Properties: {
|
|
474
|
+
ClientName: {
|
|
475
|
+
"Fn::Sub": [`\${AWS::StackName}${id}Client`, {}]
|
|
476
|
+
},
|
|
477
|
+
UserPoolId: {
|
|
478
|
+
Ref: id
|
|
479
|
+
},
|
|
480
|
+
AllowedOAuthFlowsUserPoolClient: true,
|
|
481
|
+
AllowedOAuthFlows: ["code", "implicit"],
|
|
482
|
+
AllowedOAuthScopes: [
|
|
483
|
+
"openid",
|
|
484
|
+
"email",
|
|
485
|
+
"phone",
|
|
486
|
+
"profile",
|
|
487
|
+
"aws.cognito.signin.user.admin"
|
|
488
|
+
],
|
|
489
|
+
CallbackURLs: callbackUrls,
|
|
490
|
+
LogoutURLs: logoutUrls,
|
|
491
|
+
EnableTokenRevocation: true,
|
|
492
|
+
PreventUserExistenceErrors: "ENABLED",
|
|
493
|
+
SupportedIdentityProviders: ["COGNITO"]
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
[`${id}IdentityPool`]: {
|
|
497
|
+
Type: "AWS::Cognito::IdentityPool",
|
|
498
|
+
Properties: {
|
|
499
|
+
IdentityPoolName: {
|
|
500
|
+
"Fn::Sub": [`\${AWS::StackName}${id}IdentityPool`, {}]
|
|
501
|
+
},
|
|
502
|
+
AllowUnauthenticatedIdentities: false,
|
|
503
|
+
CognitoIdentityProviders: [
|
|
504
|
+
{
|
|
505
|
+
ClientId: {
|
|
506
|
+
Ref: `${id}Client`
|
|
507
|
+
},
|
|
508
|
+
ProviderName: {
|
|
509
|
+
"Fn::GetAtt": [id, "ProviderName"]
|
|
510
|
+
},
|
|
511
|
+
ServerSideTokenCheck: true
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
...apiRoleConfig
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
);
|
|
521
|
+
var SimpleCFT = class {
|
|
522
|
+
/**
|
|
523
|
+
* Create a SimpleCFT template wrapper.
|
|
524
|
+
*
|
|
525
|
+
* @param template - Initial CloudFormation template.
|
|
526
|
+
*/
|
|
527
|
+
constructor(template = {
|
|
528
|
+
AWSTemplateFormatVersion: "2010-09-09"
|
|
529
|
+
}) {
|
|
530
|
+
this.template = template;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Apply a pack with configuration to the stack template.
|
|
534
|
+
* @see {@link IaC} for an example.
|
|
535
|
+
* */
|
|
536
|
+
applyPack = (pack, params) => {
|
|
537
|
+
this.template = pack(params, this.template);
|
|
538
|
+
return this;
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Apply a patch to the stack template.
|
|
542
|
+
*
|
|
543
|
+
* @param patch - Template patch to merge.
|
|
544
|
+
* */
|
|
545
|
+
patch = (patch) => {
|
|
546
|
+
this.template = patchTemplate(patch, this.template);
|
|
547
|
+
return this;
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* Add a stack parameter including its descriptive info and an optional parameter group.
|
|
551
|
+
*
|
|
552
|
+
* @param parameter - Parameter definition and metadata.
|
|
553
|
+
* */
|
|
554
|
+
addParameter = (parameter) => {
|
|
555
|
+
this.template = addParameter(parameter, this.template);
|
|
556
|
+
return this;
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* Add a group of stack parameters including their descriptive info and an optional parameter group.
|
|
560
|
+
*
|
|
561
|
+
* @param group - Parameter group definition.
|
|
562
|
+
* */
|
|
563
|
+
addParameterGroup = ({ Label: Group, Parameters }) => {
|
|
564
|
+
const parameterIds = Object.keys(Parameters);
|
|
565
|
+
const parameterList = parameterIds.map((ParameterId) => {
|
|
566
|
+
const { Label, ...Parameter } = Parameters[ParameterId];
|
|
567
|
+
return {
|
|
568
|
+
Group,
|
|
569
|
+
ParameterId,
|
|
570
|
+
Label,
|
|
571
|
+
Parameter
|
|
572
|
+
};
|
|
573
|
+
});
|
|
574
|
+
this.template = addParameters(parameterList, this.template);
|
|
575
|
+
return this;
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* Use a modification to dynamically apply various changes at once.
|
|
579
|
+
*
|
|
580
|
+
* @param modification - Modification callback to apply.
|
|
581
|
+
* */
|
|
582
|
+
modify = (modification) => {
|
|
583
|
+
modification(this);
|
|
584
|
+
return this;
|
|
585
|
+
};
|
|
586
|
+
/**
|
|
587
|
+
* Convert the stack template to a string.
|
|
588
|
+
*
|
|
589
|
+
* @returns JSON string representation of the template.
|
|
590
|
+
* */
|
|
591
|
+
toString = () => JSON.stringify(this.template, null, 2);
|
|
592
|
+
/**
|
|
593
|
+
* Convert the stack template to a JSON object.
|
|
594
|
+
*
|
|
595
|
+
* @returns Template JSON object.
|
|
596
|
+
* */
|
|
597
|
+
toJSON = () => this.template;
|
|
598
|
+
/**
|
|
599
|
+
* Convert the stack template to a YAML string.
|
|
600
|
+
*
|
|
601
|
+
* @returns YAML string representation of the template.
|
|
602
|
+
* */
|
|
603
|
+
toYAML = () => YAML.stringify(this.template, {
|
|
604
|
+
aliasDuplicateObjects: false
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
// src/iac/packs/auth.ts
|
|
609
|
+
var addAuth = createResourcePack(
|
|
610
|
+
({
|
|
611
|
+
userManagementId,
|
|
612
|
+
authRoleName,
|
|
613
|
+
unauthRoleName,
|
|
614
|
+
hostedZoneIdParameterName,
|
|
615
|
+
domainNameParameterName,
|
|
616
|
+
sslCertificateId,
|
|
617
|
+
callbackUrls,
|
|
618
|
+
logoutUrls,
|
|
619
|
+
mainCDNCloudFrontId,
|
|
620
|
+
apiCloudFunctionGatewayId,
|
|
621
|
+
apiStageName,
|
|
622
|
+
adminGroupId,
|
|
623
|
+
userManagementAdminGroupName
|
|
624
|
+
}) => new SimpleCFT().applyPack(addUserManagement, {
|
|
625
|
+
id: userManagementId,
|
|
626
|
+
authRoleName,
|
|
627
|
+
unauthRoleName,
|
|
628
|
+
domainName: {
|
|
629
|
+
Ref: domainNameParameterName
|
|
630
|
+
},
|
|
631
|
+
hostedZoneId: {
|
|
632
|
+
Ref: hostedZoneIdParameterName
|
|
633
|
+
},
|
|
634
|
+
sslCertificateArn: {
|
|
635
|
+
Ref: sslCertificateId
|
|
636
|
+
},
|
|
637
|
+
callbackUrls,
|
|
638
|
+
logoutUrls,
|
|
639
|
+
baseDomainRecordAliasTargetDNSName: {
|
|
640
|
+
"Fn::GetAtt": [mainCDNCloudFrontId, "DomainName"]
|
|
641
|
+
},
|
|
642
|
+
apiGatewayRESTAPIId: {
|
|
643
|
+
Ref: apiCloudFunctionGatewayId
|
|
644
|
+
},
|
|
645
|
+
apiStageName
|
|
646
|
+
}).patch({
|
|
647
|
+
Resources: {
|
|
648
|
+
[adminGroupId]: {
|
|
649
|
+
Type: "AWS::Cognito::UserPoolGroup",
|
|
650
|
+
Properties: {
|
|
651
|
+
GroupName: userManagementAdminGroupName,
|
|
652
|
+
UserPoolId: {
|
|
653
|
+
Ref: userManagementId
|
|
654
|
+
},
|
|
655
|
+
Description: "Application admin group."
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}).template
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
// src/iac/packs/build.ts
|
|
663
|
+
var DEFAULT_BUILD_PIPELINE_REPO_PROVIDER = "GitHub";
|
|
664
|
+
var addBuildPipeline = createResourcePack(
|
|
665
|
+
({
|
|
666
|
+
id,
|
|
667
|
+
buildSpec,
|
|
668
|
+
dependsOn,
|
|
669
|
+
environmentVariables,
|
|
670
|
+
timeoutInMinutes = 10,
|
|
671
|
+
environmentType = "LINUX_CONTAINER",
|
|
672
|
+
environmentComputeType = "BUILD_GENERAL1_SMALL",
|
|
673
|
+
environmentImage = "aws/codebuild/nodejs:10.14.1",
|
|
674
|
+
repoConfig: {
|
|
675
|
+
provider = DEFAULT_BUILD_PIPELINE_REPO_PROVIDER,
|
|
676
|
+
owner,
|
|
677
|
+
repo,
|
|
678
|
+
branch,
|
|
679
|
+
oauthToken
|
|
680
|
+
}
|
|
681
|
+
}) => ({
|
|
682
|
+
Resources: {
|
|
683
|
+
[`${id}CodeBuildRole`]: {
|
|
684
|
+
Type: "AWS::IAM::Role",
|
|
685
|
+
Properties: {
|
|
686
|
+
AssumeRolePolicyDocument: {
|
|
687
|
+
Statement: [
|
|
688
|
+
{
|
|
689
|
+
Effect: "Allow",
|
|
690
|
+
Principal: {
|
|
691
|
+
Service: ["codebuild.amazonaws.com"]
|
|
692
|
+
},
|
|
693
|
+
Action: ["sts:AssumeRole"]
|
|
694
|
+
}
|
|
695
|
+
]
|
|
696
|
+
},
|
|
697
|
+
Path: "/",
|
|
698
|
+
Policies: [
|
|
699
|
+
{
|
|
700
|
+
PolicyName: "codebuild-service",
|
|
701
|
+
PolicyDocument: {
|
|
702
|
+
Statement: [
|
|
703
|
+
{
|
|
704
|
+
Effect: "Allow",
|
|
705
|
+
Action: "*",
|
|
706
|
+
Resource: "*"
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
Version: "2012-10-17"
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
]
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
[`${id}CodePipelineRole`]: {
|
|
716
|
+
Type: "AWS::IAM::Role",
|
|
717
|
+
Properties: {
|
|
718
|
+
AssumeRolePolicyDocument: {
|
|
719
|
+
Statement: [
|
|
720
|
+
{
|
|
721
|
+
Effect: "Allow",
|
|
722
|
+
Principal: {
|
|
723
|
+
Service: ["codepipeline.amazonaws.com"]
|
|
724
|
+
},
|
|
725
|
+
Action: ["sts:AssumeRole"]
|
|
726
|
+
}
|
|
727
|
+
]
|
|
728
|
+
},
|
|
729
|
+
Path: "/",
|
|
730
|
+
Policies: [
|
|
731
|
+
{
|
|
732
|
+
PolicyName: "codepipeline-service",
|
|
733
|
+
PolicyDocument: {
|
|
734
|
+
Statement: [
|
|
735
|
+
{
|
|
736
|
+
Action: ["codebuild:*"],
|
|
737
|
+
Resource: "*",
|
|
738
|
+
Effect: "Allow"
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
Action: [
|
|
742
|
+
"s3:GetObject",
|
|
743
|
+
"s3:GetObjectVersion",
|
|
744
|
+
"s3:GetBucketVersioning"
|
|
745
|
+
],
|
|
746
|
+
Resource: "*",
|
|
747
|
+
Effect: "Allow"
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
Action: ["s3:PutObject"],
|
|
751
|
+
Resource: ["arn:aws:s3:::codepipeline*"],
|
|
752
|
+
Effect: "Allow"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
Action: ["s3:*", "cloudformation:*", "iam:PassRole"],
|
|
756
|
+
Resource: "*",
|
|
757
|
+
Effect: "Allow"
|
|
758
|
+
}
|
|
759
|
+
],
|
|
760
|
+
Version: "2012-10-17"
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
]
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
[`${id}PipelineBucket`]: {
|
|
767
|
+
Type: "AWS::S3::Bucket",
|
|
768
|
+
DeletionPolicy: "Delete",
|
|
769
|
+
Properties: {
|
|
770
|
+
BucketEncryption: {
|
|
771
|
+
ServerSideEncryptionConfiguration: [
|
|
772
|
+
{
|
|
773
|
+
ServerSideEncryptionByDefault: {
|
|
774
|
+
SSEAlgorithm: "AES256"
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
]
|
|
778
|
+
},
|
|
779
|
+
PublicAccessBlockConfiguration: {
|
|
780
|
+
BlockPublicAcls: true,
|
|
781
|
+
BlockPublicPolicy: true,
|
|
782
|
+
IgnorePublicAcls: true,
|
|
783
|
+
RestrictPublicBuckets: true
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
[`${id}CodeBuildAndDeploy`]: {
|
|
788
|
+
Type: "AWS::CodeBuild::Project",
|
|
789
|
+
DependsOn: dependsOn,
|
|
790
|
+
Properties: {
|
|
791
|
+
Name: {
|
|
792
|
+
"Fn::Sub": `\${AWS::StackName}-${id}CodeBuildAndDeploy`
|
|
793
|
+
},
|
|
794
|
+
Description: "Deploy site to S3",
|
|
795
|
+
ServiceRole: {
|
|
796
|
+
"Fn::GetAtt": [`${id}CodeBuildRole`, "Arn"]
|
|
797
|
+
},
|
|
798
|
+
Artifacts: {
|
|
799
|
+
Type: "CODEPIPELINE"
|
|
800
|
+
},
|
|
801
|
+
Environment: {
|
|
802
|
+
Type: environmentType,
|
|
803
|
+
ComputeType: environmentComputeType,
|
|
804
|
+
Image: environmentImage,
|
|
805
|
+
EnvironmentVariables: environmentVariables
|
|
806
|
+
},
|
|
807
|
+
Source: {
|
|
808
|
+
Type: "CODEPIPELINE",
|
|
809
|
+
BuildSpec: buildSpec
|
|
810
|
+
},
|
|
811
|
+
TimeoutInMinutes: timeoutInMinutes
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
[`${id}Pipeline`]: {
|
|
815
|
+
Type: "AWS::CodePipeline::Pipeline",
|
|
816
|
+
DependsOn: `${id}CodeBuildAndDeploy`,
|
|
817
|
+
Properties: {
|
|
818
|
+
RoleArn: {
|
|
819
|
+
"Fn::GetAtt": [`${id}CodePipelineRole`, "Arn"]
|
|
820
|
+
},
|
|
821
|
+
Stages: [
|
|
822
|
+
{
|
|
823
|
+
Name: "Acquire-Source",
|
|
824
|
+
Actions: [
|
|
825
|
+
{
|
|
826
|
+
InputArtifacts: [],
|
|
827
|
+
Name: "Source",
|
|
828
|
+
ActionTypeId: {
|
|
829
|
+
Category: "Source",
|
|
830
|
+
Owner: "ThirdParty",
|
|
831
|
+
Version: "1",
|
|
832
|
+
Provider: provider
|
|
833
|
+
},
|
|
834
|
+
OutputArtifacts: [
|
|
835
|
+
{
|
|
836
|
+
Name: "SourceOutput"
|
|
837
|
+
}
|
|
838
|
+
],
|
|
839
|
+
Configuration: {
|
|
840
|
+
Owner: owner,
|
|
841
|
+
Repo: repo,
|
|
842
|
+
Branch: branch,
|
|
843
|
+
OAuthToken: oauthToken
|
|
844
|
+
},
|
|
845
|
+
RunOrder: 1
|
|
846
|
+
}
|
|
847
|
+
]
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
Name: "Build-And-Deploy",
|
|
851
|
+
Actions: [
|
|
852
|
+
{
|
|
853
|
+
Name: "Artifact",
|
|
854
|
+
ActionTypeId: {
|
|
855
|
+
Category: "Build",
|
|
856
|
+
Owner: "AWS",
|
|
857
|
+
Version: "1",
|
|
858
|
+
Provider: "CodeBuild"
|
|
859
|
+
},
|
|
860
|
+
InputArtifacts: [
|
|
861
|
+
{
|
|
862
|
+
Name: "SourceOutput"
|
|
863
|
+
}
|
|
864
|
+
],
|
|
865
|
+
OutputArtifacts: [
|
|
866
|
+
{
|
|
867
|
+
Name: "DeployOutput"
|
|
868
|
+
}
|
|
869
|
+
],
|
|
870
|
+
Configuration: {
|
|
871
|
+
ProjectName: {
|
|
872
|
+
Ref: `${id}CodeBuildAndDeploy`
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
RunOrder: 1
|
|
876
|
+
}
|
|
877
|
+
]
|
|
878
|
+
}
|
|
879
|
+
],
|
|
880
|
+
ArtifactStore: {
|
|
881
|
+
Type: "S3",
|
|
882
|
+
Location: {
|
|
883
|
+
Ref: `${id}PipelineBucket`
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
})
|
|
890
|
+
);
|
|
891
|
+
var COMMAND_HELPERS = {
|
|
892
|
+
updateFunction: ({
|
|
893
|
+
cloudFunctionArn,
|
|
894
|
+
codeZipFilePath
|
|
895
|
+
}) => `aws lambda update-function-code --function-name "${cloudFunctionArn}" --zip-file "fileb://${codeZipFilePath}"`,
|
|
896
|
+
copyDirectoryToS3: ({
|
|
897
|
+
s3Domain,
|
|
898
|
+
directoryPath
|
|
899
|
+
}) => `aws s3 cp --recursive --acl public-read ${directoryPath} s3://${s3Domain}/`,
|
|
900
|
+
cloudFrontInvalidation: ({
|
|
901
|
+
cloudFrontDistributionId,
|
|
902
|
+
pathsToInvalidate = ["/*"]
|
|
903
|
+
}) => `aws cloudfront create-invalidation --distribution-id "${cloudFrontDistributionId}" --paths "${pathsToInvalidate.join('" "')}"`,
|
|
904
|
+
addNPMTokenWithNPMRC: ({ npmToken }) => `echo '//registry.npmjs.org/:_authToken=${npmToken}' > .npmrc`
|
|
905
|
+
};
|
|
906
|
+
var createBuildSpec = ({ version = 0.2, phases }) => YAML.stringify(
|
|
907
|
+
// TRICKY: Removed all keys with a value of `undefined`.
|
|
908
|
+
JSON.parse(
|
|
909
|
+
JSON.stringify({
|
|
910
|
+
version,
|
|
911
|
+
phases
|
|
912
|
+
})
|
|
913
|
+
)
|
|
914
|
+
);
|
|
915
|
+
|
|
916
|
+
// src/iac/packs/cdn.ts
|
|
917
|
+
var addCDN = createResourcePack(
|
|
918
|
+
({
|
|
919
|
+
id,
|
|
920
|
+
hostedZoneId,
|
|
921
|
+
domainName,
|
|
922
|
+
certificateArn,
|
|
923
|
+
fileStorageId
|
|
924
|
+
}) => {
|
|
925
|
+
const oacId = `${id}OriginAccessControl`;
|
|
926
|
+
return {
|
|
927
|
+
Resources: {
|
|
928
|
+
[oacId]: {
|
|
929
|
+
Type: "AWS::CloudFront::OriginAccessControl",
|
|
930
|
+
Properties: {
|
|
931
|
+
OriginAccessControlConfig: {
|
|
932
|
+
Name: oacId,
|
|
933
|
+
OriginAccessControlOriginType: "s3",
|
|
934
|
+
SigningBehavior: "always",
|
|
935
|
+
SigningProtocol: "sigv4"
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
[id]: {
|
|
940
|
+
Type: "AWS::CloudFront::Distribution",
|
|
941
|
+
DependsOn: fileStorageId,
|
|
942
|
+
Properties: {
|
|
943
|
+
DistributionConfig: {
|
|
944
|
+
Aliases: [domainName],
|
|
945
|
+
ViewerCertificate: {
|
|
946
|
+
AcmCertificateArn: certificateArn,
|
|
947
|
+
SslSupportMethod: "sni-only",
|
|
948
|
+
MinimumProtocolVersion: "TLSv1.1_2016"
|
|
949
|
+
},
|
|
950
|
+
DefaultCacheBehavior: {
|
|
951
|
+
ForwardedValues: {
|
|
952
|
+
QueryString: false
|
|
953
|
+
},
|
|
954
|
+
TargetOriginId: {
|
|
955
|
+
"Fn::Sub": [
|
|
956
|
+
"S3-${S3BucketName}",
|
|
957
|
+
{
|
|
958
|
+
S3BucketName: domainName
|
|
959
|
+
}
|
|
960
|
+
]
|
|
961
|
+
},
|
|
962
|
+
ViewerProtocolPolicy: "redirect-to-https"
|
|
963
|
+
},
|
|
964
|
+
DefaultRootObject: "index.html",
|
|
965
|
+
Enabled: true,
|
|
966
|
+
IPV6Enabled: false,
|
|
967
|
+
HttpVersion: "http2",
|
|
968
|
+
Origins: [
|
|
969
|
+
{
|
|
970
|
+
DomainName: {
|
|
971
|
+
"Fn::Sub": [
|
|
972
|
+
"${S3BucketName}.s3.amazonaws.com",
|
|
973
|
+
{
|
|
974
|
+
S3BucketName: domainName
|
|
975
|
+
}
|
|
976
|
+
]
|
|
977
|
+
},
|
|
978
|
+
Id: {
|
|
979
|
+
"Fn::Sub": [
|
|
980
|
+
"S3-${S3BucketName}",
|
|
981
|
+
{
|
|
982
|
+
S3BucketName: domainName
|
|
983
|
+
}
|
|
984
|
+
]
|
|
985
|
+
},
|
|
986
|
+
OriginAccessControlId: { Ref: oacId },
|
|
987
|
+
S3OriginConfig: {
|
|
988
|
+
OriginAccessIdentity: ""
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
],
|
|
992
|
+
CustomErrorResponses: [
|
|
993
|
+
{
|
|
994
|
+
ErrorCachingMinTTL: 300,
|
|
995
|
+
ErrorCode: 404,
|
|
996
|
+
ResponseCode: 200,
|
|
997
|
+
ResponsePagePath: "/index.html"
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1000
|
+
ErrorCachingMinTTL: 300,
|
|
1001
|
+
ErrorCode: 403,
|
|
1002
|
+
ResponseCode: 200,
|
|
1003
|
+
ResponsePagePath: "/index.html"
|
|
1004
|
+
}
|
|
1005
|
+
],
|
|
1006
|
+
PriceClass: "PriceClass_All"
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
},
|
|
1010
|
+
[`${id}Route53Record`]: {
|
|
1011
|
+
Type: "AWS::Route53::RecordSet",
|
|
1012
|
+
DependsOn: [id],
|
|
1013
|
+
Properties: {
|
|
1014
|
+
HostedZoneId: hostedZoneId,
|
|
1015
|
+
Type: "A",
|
|
1016
|
+
Name: {
|
|
1017
|
+
"Fn::Sub": [
|
|
1018
|
+
"${DomainName}.",
|
|
1019
|
+
{
|
|
1020
|
+
DomainName: domainName
|
|
1021
|
+
}
|
|
1022
|
+
]
|
|
1023
|
+
},
|
|
1024
|
+
AliasTarget: {
|
|
1025
|
+
HostedZoneId: "Z2FDTNDATAQYW2",
|
|
1026
|
+
DNSName: {
|
|
1027
|
+
"Fn::Sub": [
|
|
1028
|
+
"${DomainName}.",
|
|
1029
|
+
{
|
|
1030
|
+
DomainName: {
|
|
1031
|
+
"Fn::GetAtt": [id, "DomainName"]
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
);
|
|
1043
|
+
|
|
1044
|
+
// src/iac/packs/cloud-function.ts
|
|
1045
|
+
var PLACEHOLDER_FUNCTION_CODE = {
|
|
1046
|
+
ZipFile: `module.exports = {handler: async () => ({
|
|
1047
|
+
statusCode: 200,
|
|
1048
|
+
headers: {'Content-Type': 'application/json'},
|
|
1049
|
+
body: '"You did it!"'
|
|
1050
|
+
})};
|
|
1051
|
+
`
|
|
1052
|
+
};
|
|
1053
|
+
var addCloudFunction = createResourcePack(
|
|
1054
|
+
({
|
|
1055
|
+
id,
|
|
1056
|
+
code = PLACEHOLDER_FUNCTION_CODE,
|
|
1057
|
+
environment = {
|
|
1058
|
+
Variables: {
|
|
1059
|
+
NODE_ENV: "production"
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
handler = "index.handler",
|
|
1063
|
+
runtime = "nodejs26.x",
|
|
1064
|
+
timeout = 30,
|
|
1065
|
+
policies = [
|
|
1066
|
+
{
|
|
1067
|
+
PolicyName: "lambda-parameter-store",
|
|
1068
|
+
PolicyDocument: {
|
|
1069
|
+
Version: "2012-10-17",
|
|
1070
|
+
Statement: [
|
|
1071
|
+
{
|
|
1072
|
+
Effect: "Allow",
|
|
1073
|
+
Action: ["*"],
|
|
1074
|
+
Resource: "*"
|
|
1075
|
+
}
|
|
1076
|
+
]
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
]
|
|
1080
|
+
}) => {
|
|
1081
|
+
return {
|
|
1082
|
+
Resources: {
|
|
1083
|
+
[`${id}Role`]: {
|
|
1084
|
+
Type: "AWS::IAM::Role",
|
|
1085
|
+
Properties: {
|
|
1086
|
+
ManagedPolicyArns: [
|
|
1087
|
+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
|
|
1088
|
+
],
|
|
1089
|
+
AssumeRolePolicyDocument: {
|
|
1090
|
+
Version: "2012-10-17",
|
|
1091
|
+
Statement: [
|
|
1092
|
+
{
|
|
1093
|
+
Action: ["sts:AssumeRole"],
|
|
1094
|
+
Effect: "Allow",
|
|
1095
|
+
Principal: {
|
|
1096
|
+
Service: ["lambda.amazonaws.com"]
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
]
|
|
1100
|
+
},
|
|
1101
|
+
Policies: policies
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
[id]: {
|
|
1105
|
+
Type: "AWS::Lambda::Function",
|
|
1106
|
+
Properties: {
|
|
1107
|
+
Timeout: timeout,
|
|
1108
|
+
Code: code,
|
|
1109
|
+
Environment: environment,
|
|
1110
|
+
Handler: handler,
|
|
1111
|
+
Role: {
|
|
1112
|
+
"Fn::GetAtt": [`${id}Role`, "Arn"]
|
|
1113
|
+
},
|
|
1114
|
+
Runtime: runtime
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
);
|
|
1121
|
+
|
|
1122
|
+
// src/iac/packs/database.ts
|
|
1123
|
+
var addDatabase = createResourcePack(
|
|
1124
|
+
({
|
|
1125
|
+
tableId,
|
|
1126
|
+
tableName,
|
|
1127
|
+
keys,
|
|
1128
|
+
attributes,
|
|
1129
|
+
billingMode = "PAY_PER_REQUEST"
|
|
1130
|
+
}) => new SimpleCFT().patch({
|
|
1131
|
+
Resources: {
|
|
1132
|
+
[tableId]: {
|
|
1133
|
+
Type: "AWS::DynamoDB::Table",
|
|
1134
|
+
Properties: {
|
|
1135
|
+
TableName: tableName,
|
|
1136
|
+
AttributeDefinitions: Object.keys(attributes).map(
|
|
1137
|
+
(attributeName) => ({
|
|
1138
|
+
AttributeName: attributeName,
|
|
1139
|
+
AttributeType: attributes[attributeName]
|
|
1140
|
+
})
|
|
1141
|
+
),
|
|
1142
|
+
KeySchema: Object.keys(keys).map((keyName) => ({
|
|
1143
|
+
AttributeName: keyName,
|
|
1144
|
+
KeyType: keys[keyName]
|
|
1145
|
+
})),
|
|
1146
|
+
BillingMode: billingMode
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}).template
|
|
1151
|
+
);
|
|
1152
|
+
|
|
1153
|
+
// src/iac/packs/dns.ts
|
|
1154
|
+
var addDNS = createResourcePack(
|
|
1155
|
+
({
|
|
1156
|
+
id,
|
|
1157
|
+
hostedZoneId,
|
|
1158
|
+
domainName,
|
|
1159
|
+
resourceRecords,
|
|
1160
|
+
recordType = "A"
|
|
1161
|
+
}) => {
|
|
1162
|
+
let cft = new SimpleCFT().patch({
|
|
1163
|
+
Resources: {
|
|
1164
|
+
[id]: {
|
|
1165
|
+
Type: "AWS::Route53::RecordSet",
|
|
1166
|
+
Properties: {
|
|
1167
|
+
HostedZoneId: hostedZoneId,
|
|
1168
|
+
Type: recordType,
|
|
1169
|
+
Name: domainName,
|
|
1170
|
+
ResourceRecords: resourceRecords,
|
|
1171
|
+
TTL: "300"
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
return cft.template;
|
|
1177
|
+
}
|
|
1178
|
+
);
|
|
1179
|
+
|
|
1180
|
+
// src/iac/packs/file-storage.ts
|
|
1181
|
+
var addSecureFileStorage = createResourcePack(
|
|
1182
|
+
({
|
|
1183
|
+
id,
|
|
1184
|
+
bucketName,
|
|
1185
|
+
shouldDelete = true,
|
|
1186
|
+
blockPublicAccess = true,
|
|
1187
|
+
cors = false,
|
|
1188
|
+
accessControl = void 0,
|
|
1189
|
+
allowACLs = false
|
|
1190
|
+
}) => {
|
|
1191
|
+
return {
|
|
1192
|
+
Resources: {
|
|
1193
|
+
[id]: {
|
|
1194
|
+
Type: "AWS::S3::Bucket",
|
|
1195
|
+
DeletionPolicy: shouldDelete ? "Delete" : "Retain",
|
|
1196
|
+
Properties: {
|
|
1197
|
+
BucketName: bucketName,
|
|
1198
|
+
AccessControl: accessControl,
|
|
1199
|
+
OwnershipControls: allowACLs ? {
|
|
1200
|
+
Rules: [
|
|
1201
|
+
{
|
|
1202
|
+
ObjectOwnership: "ObjectWriter"
|
|
1203
|
+
}
|
|
1204
|
+
]
|
|
1205
|
+
} : void 0,
|
|
1206
|
+
CorsConfiguration: typeof cors === "object" ? cors : cors === true ? {
|
|
1207
|
+
CorsRules: [
|
|
1208
|
+
{
|
|
1209
|
+
AllowedHeaders: ["*"],
|
|
1210
|
+
AllowedMethods: [
|
|
1211
|
+
"GET",
|
|
1212
|
+
"PUT",
|
|
1213
|
+
"POST",
|
|
1214
|
+
"DELETE",
|
|
1215
|
+
"HEAD"
|
|
1216
|
+
],
|
|
1217
|
+
AllowedOrigins: ["*"]
|
|
1218
|
+
}
|
|
1219
|
+
]
|
|
1220
|
+
} : void 0,
|
|
1221
|
+
BucketEncryption: {
|
|
1222
|
+
ServerSideEncryptionConfiguration: [
|
|
1223
|
+
{
|
|
1224
|
+
ServerSideEncryptionByDefault: {
|
|
1225
|
+
SSEAlgorithm: "AES256"
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
]
|
|
1229
|
+
},
|
|
1230
|
+
PublicAccessBlockConfiguration: blockPublicAccess ? {
|
|
1231
|
+
BlockPublicAcls: true,
|
|
1232
|
+
BlockPublicPolicy: true,
|
|
1233
|
+
IgnorePublicAcls: true,
|
|
1234
|
+
RestrictPublicBuckets: true
|
|
1235
|
+
} : {
|
|
1236
|
+
BlockPublicAcls: false,
|
|
1237
|
+
BlockPublicPolicy: false,
|
|
1238
|
+
IgnorePublicAcls: false,
|
|
1239
|
+
RestrictPublicBuckets: false
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
);
|
|
1247
|
+
|
|
1248
|
+
// src/iac/packs/gateway.ts
|
|
1249
|
+
var DEFAULT_AUTH_TYPE = "COGNITO_USER_POOLS";
|
|
1250
|
+
var addGateway = createResourcePack(
|
|
1251
|
+
({
|
|
1252
|
+
id,
|
|
1253
|
+
hostedZoneId,
|
|
1254
|
+
domainName,
|
|
1255
|
+
certificateArn,
|
|
1256
|
+
cloudFunction: {
|
|
1257
|
+
id: cloudFunctionId,
|
|
1258
|
+
region: cloudFunctionRegion = "${AWS::Region}"
|
|
1259
|
+
},
|
|
1260
|
+
stageName = "production",
|
|
1261
|
+
authorizer,
|
|
1262
|
+
deploymentSuffix = ""
|
|
1263
|
+
}) => {
|
|
1264
|
+
const cloudFunctionUri = {
|
|
1265
|
+
"Fn::Sub": `arn:aws:apigateway:${cloudFunctionRegion}:lambda:path/2015-03-31/functions/\${${cloudFunctionId}.Arn}/invocations`
|
|
1266
|
+
};
|
|
1267
|
+
const {
|
|
1268
|
+
scopes: authScopes = ["phone", "email", "openid", "profile"],
|
|
1269
|
+
type: authType = "COGNITO_USER_POOLS",
|
|
1270
|
+
providerARNs,
|
|
1271
|
+
identitySource = "method.request.header.authorization"
|
|
1272
|
+
} = !!authorizer && typeof authorizer === "object" ? authorizer : {};
|
|
1273
|
+
const authorizerId = `${id}CustomAuthorizer`;
|
|
1274
|
+
const authProps = !!authorizer ? {
|
|
1275
|
+
AuthorizationScopes: authScopes,
|
|
1276
|
+
AuthorizationType: authType === DEFAULT_AUTH_TYPE ? DEFAULT_AUTH_TYPE : "CUSTOM",
|
|
1277
|
+
AuthorizerId: {
|
|
1278
|
+
Ref: authorizerId
|
|
1279
|
+
}
|
|
1280
|
+
} : {
|
|
1281
|
+
AuthorizationType: "NONE"
|
|
1282
|
+
};
|
|
1283
|
+
const fullDeploymentId = `${id}GatewayRESTAPIDeployment${deploymentSuffix}`;
|
|
1284
|
+
return new SimpleCFT().patch({
|
|
1285
|
+
Resources: {
|
|
1286
|
+
// REST API
|
|
1287
|
+
[id]: {
|
|
1288
|
+
Type: "AWS::ApiGateway::RestApi",
|
|
1289
|
+
Properties: {
|
|
1290
|
+
Name: {
|
|
1291
|
+
"Fn::Sub": `\${AWS::StackName}-${id}GatewayRESTAPI`
|
|
1292
|
+
},
|
|
1293
|
+
EndpointConfiguration: {
|
|
1294
|
+
Types: ["EDGE"]
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
},
|
|
1298
|
+
[`${id}GatewayRESTAPIResource`]: {
|
|
1299
|
+
Type: "AWS::ApiGateway::Resource",
|
|
1300
|
+
DependsOn: id,
|
|
1301
|
+
Properties: {
|
|
1302
|
+
ParentId: {
|
|
1303
|
+
"Fn::GetAtt": [id, "RootResourceId"]
|
|
1304
|
+
},
|
|
1305
|
+
PathPart: "{proxy+}",
|
|
1306
|
+
RestApiId: {
|
|
1307
|
+
Ref: id
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
},
|
|
1311
|
+
[`${id}GatewayRESTAPIMethod`]: {
|
|
1312
|
+
Type: "AWS::ApiGateway::Method",
|
|
1313
|
+
DependsOn: `${id}GatewayRESTAPIResource`,
|
|
1314
|
+
Properties: {
|
|
1315
|
+
...authProps,
|
|
1316
|
+
HttpMethod: "ANY",
|
|
1317
|
+
ResourceId: {
|
|
1318
|
+
Ref: `${id}GatewayRESTAPIResource`
|
|
1319
|
+
},
|
|
1320
|
+
RestApiId: {
|
|
1321
|
+
Ref: id
|
|
1322
|
+
},
|
|
1323
|
+
Integration: {
|
|
1324
|
+
Type: "AWS_PROXY",
|
|
1325
|
+
IntegrationHttpMethod: "POST",
|
|
1326
|
+
Uri: cloudFunctionUri
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
},
|
|
1330
|
+
[`${id}GatewayRESTAPIRootMethod`]: {
|
|
1331
|
+
Type: "AWS::ApiGateway::Method",
|
|
1332
|
+
DependsOn: `${id}GatewayRESTAPIResource`,
|
|
1333
|
+
Properties: {
|
|
1334
|
+
...authProps,
|
|
1335
|
+
HttpMethod: "ANY",
|
|
1336
|
+
ResourceId: {
|
|
1337
|
+
"Fn::GetAtt": [id, "RootResourceId"]
|
|
1338
|
+
},
|
|
1339
|
+
RestApiId: {
|
|
1340
|
+
Ref: id
|
|
1341
|
+
},
|
|
1342
|
+
Integration: {
|
|
1343
|
+
Type: "AWS_PROXY",
|
|
1344
|
+
IntegrationHttpMethod: "POST",
|
|
1345
|
+
Uri: cloudFunctionUri
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}).patch({
|
|
1351
|
+
Resources: {
|
|
1352
|
+
// CORS
|
|
1353
|
+
[`${id}GatewayRESTAPIOPTIONSMethod`]: {
|
|
1354
|
+
Type: "AWS::ApiGateway::Method",
|
|
1355
|
+
DependsOn: `${id}GatewayRESTAPIResource`,
|
|
1356
|
+
Properties: {
|
|
1357
|
+
AuthorizationType: "NONE",
|
|
1358
|
+
HttpMethod: "OPTIONS",
|
|
1359
|
+
ResourceId: {
|
|
1360
|
+
Ref: `${id}GatewayRESTAPIResource`
|
|
1361
|
+
},
|
|
1362
|
+
RestApiId: {
|
|
1363
|
+
Ref: id
|
|
1364
|
+
},
|
|
1365
|
+
Integration: {
|
|
1366
|
+
Type: "AWS_PROXY",
|
|
1367
|
+
IntegrationHttpMethod: "POST",
|
|
1368
|
+
Uri: cloudFunctionUri
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
},
|
|
1372
|
+
[`${id}GatewayRESTAPIRootOPTIONSMethod`]: {
|
|
1373
|
+
Type: "AWS::ApiGateway::Method",
|
|
1374
|
+
DependsOn: `${id}GatewayRESTAPIResource`,
|
|
1375
|
+
Properties: {
|
|
1376
|
+
AuthorizationType: "NONE",
|
|
1377
|
+
HttpMethod: "OPTIONS",
|
|
1378
|
+
ResourceId: {
|
|
1379
|
+
"Fn::GetAtt": [id, "RootResourceId"]
|
|
1380
|
+
},
|
|
1381
|
+
RestApiId: {
|
|
1382
|
+
Ref: id
|
|
1383
|
+
},
|
|
1384
|
+
Integration: {
|
|
1385
|
+
Type: "AWS_PROXY",
|
|
1386
|
+
IntegrationHttpMethod: "POST",
|
|
1387
|
+
Uri: cloudFunctionUri
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
},
|
|
1391
|
+
[`${id}GatewayResponseDefault4XX`]: {
|
|
1392
|
+
Type: "AWS::ApiGateway::GatewayResponse",
|
|
1393
|
+
Properties: {
|
|
1394
|
+
ResponseParameters: {
|
|
1395
|
+
// Not authorized, so just allow the current origin by mapping it into the header.
|
|
1396
|
+
"gatewayresponse.header.Access-Control-Allow-Origin": "method.request.header.origin",
|
|
1397
|
+
"gatewayresponse.header.Access-Control-Allow-Credentials": "'true'",
|
|
1398
|
+
"gatewayresponse.header.Access-Control-Allow-Headers": "'*'"
|
|
1399
|
+
},
|
|
1400
|
+
ResponseType: "DEFAULT_4XX",
|
|
1401
|
+
RestApiId: {
|
|
1402
|
+
Ref: id
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}).patch({
|
|
1408
|
+
Resources: {
|
|
1409
|
+
// SUPPORTING RESOURCES
|
|
1410
|
+
[fullDeploymentId]: {
|
|
1411
|
+
Type: "AWS::ApiGateway::Deployment",
|
|
1412
|
+
DependsOn: [
|
|
1413
|
+
`${id}GatewayRESTAPIResource`,
|
|
1414
|
+
`${id}GatewayRESTAPIMethod`,
|
|
1415
|
+
`${id}GatewayRESTAPIRootMethod`,
|
|
1416
|
+
id,
|
|
1417
|
+
cloudFunctionId
|
|
1418
|
+
],
|
|
1419
|
+
Properties: {
|
|
1420
|
+
RestApiId: {
|
|
1421
|
+
Ref: id
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
},
|
|
1425
|
+
[`${id}CloudWatch`]: {
|
|
1426
|
+
Type: "AWS::Logs::LogGroup",
|
|
1427
|
+
Properties: {
|
|
1428
|
+
LogGroupName: {
|
|
1429
|
+
"Fn::Sub": `\${AWS::StackName}-${id}GatewayLogs`
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
[`${id}CloudWatchRole`]: {
|
|
1434
|
+
Type: "AWS::IAM::Role",
|
|
1435
|
+
Properties: {
|
|
1436
|
+
AssumeRolePolicyDocument: {
|
|
1437
|
+
Version: "2012-10-17",
|
|
1438
|
+
Statement: [
|
|
1439
|
+
{
|
|
1440
|
+
Effect: "Allow",
|
|
1441
|
+
Principal: {
|
|
1442
|
+
Service: ["apigateway.amazonaws.com"]
|
|
1443
|
+
},
|
|
1444
|
+
Action: "sts:AssumeRole"
|
|
1445
|
+
}
|
|
1446
|
+
]
|
|
1447
|
+
},
|
|
1448
|
+
Path: "/",
|
|
1449
|
+
ManagedPolicyArns: [
|
|
1450
|
+
"arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
|
|
1451
|
+
]
|
|
1452
|
+
}
|
|
1453
|
+
},
|
|
1454
|
+
[`${id}CloudWatchAccount`]: {
|
|
1455
|
+
Type: "AWS::ApiGateway::Account",
|
|
1456
|
+
Properties: {
|
|
1457
|
+
CloudWatchRoleArn: {
|
|
1458
|
+
"Fn::GetAtt": [`${id}CloudWatchRole`, "Arn"]
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
},
|
|
1462
|
+
[`${id}GatewayRESTAPIEnvironment`]: {
|
|
1463
|
+
Type: "AWS::ApiGateway::Stage",
|
|
1464
|
+
DependsOn: [`${id}CloudWatchAccount`, fullDeploymentId],
|
|
1465
|
+
Properties: {
|
|
1466
|
+
AccessLogSetting: {
|
|
1467
|
+
DestinationArn: {
|
|
1468
|
+
"Fn::GetAtt": [`${id}CloudWatch`, "Arn"]
|
|
1469
|
+
},
|
|
1470
|
+
Format: '{"requestId":"$context.requestId","ip":"$context.identity.sourceIp","caller":"$context.identity.caller","user":"$context.identity.user","requestTime":"$context.requestTime","httpMethod":"$context.httpMethod","resourcePath":"$context.resourcePath","status":"$context.status","protocol":"$context.protocol","responseLength":"$context.responseLength","apiGatewayErrorMessage":"$context.error.message"}'
|
|
1471
|
+
},
|
|
1472
|
+
DeploymentId: {
|
|
1473
|
+
Ref: fullDeploymentId
|
|
1474
|
+
},
|
|
1475
|
+
RestApiId: {
|
|
1476
|
+
Ref: id
|
|
1477
|
+
},
|
|
1478
|
+
StageName: stageName
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}).patch({
|
|
1483
|
+
Resources: {
|
|
1484
|
+
// DNS
|
|
1485
|
+
[`${id}DomainName`]: {
|
|
1486
|
+
Type: "AWS::ApiGateway::DomainName",
|
|
1487
|
+
Properties: {
|
|
1488
|
+
CertificateArn: certificateArn,
|
|
1489
|
+
DomainName: domainName,
|
|
1490
|
+
EndpointConfiguration: {
|
|
1491
|
+
Types: ["EDGE"]
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
},
|
|
1495
|
+
[`${id}DomainNameBasePathMapping`]: {
|
|
1496
|
+
Type: "AWS::ApiGateway::BasePathMapping",
|
|
1497
|
+
DependsOn: [
|
|
1498
|
+
id,
|
|
1499
|
+
`${id}GatewayRESTAPIEnvironment`,
|
|
1500
|
+
`${id}DomainName`
|
|
1501
|
+
],
|
|
1502
|
+
Properties: {
|
|
1503
|
+
DomainName: domainName,
|
|
1504
|
+
RestApiId: {
|
|
1505
|
+
Ref: id
|
|
1506
|
+
},
|
|
1507
|
+
Stage: stageName
|
|
1508
|
+
}
|
|
1509
|
+
},
|
|
1510
|
+
[`${id}Route53Record`]: {
|
|
1511
|
+
Type: "AWS::Route53::RecordSet",
|
|
1512
|
+
DependsOn: `${id}DomainName`,
|
|
1513
|
+
Properties: {
|
|
1514
|
+
HostedZoneId: hostedZoneId,
|
|
1515
|
+
Type: "A",
|
|
1516
|
+
Name: {
|
|
1517
|
+
"Fn::Sub": [
|
|
1518
|
+
"${DomainName}.",
|
|
1519
|
+
{
|
|
1520
|
+
DomainName: domainName
|
|
1521
|
+
}
|
|
1522
|
+
]
|
|
1523
|
+
},
|
|
1524
|
+
AliasTarget: {
|
|
1525
|
+
HostedZoneId: "Z2FDTNDATAQYW2",
|
|
1526
|
+
DNSName: {
|
|
1527
|
+
"Fn::Sub": [
|
|
1528
|
+
"${DomainName}.",
|
|
1529
|
+
{
|
|
1530
|
+
DomainName: {
|
|
1531
|
+
"Fn::GetAtt": [
|
|
1532
|
+
`${id}DomainName`,
|
|
1533
|
+
"DistributionDomainName"
|
|
1534
|
+
]
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
]
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
}).patch({
|
|
1544
|
+
Resources: {
|
|
1545
|
+
// PERMISSIONS
|
|
1546
|
+
[`${id}CloudFunctionANYResourcePermission`]: {
|
|
1547
|
+
Type: "AWS::Lambda::Permission",
|
|
1548
|
+
Properties: {
|
|
1549
|
+
Action: "lambda:InvokeFunction",
|
|
1550
|
+
Principal: "apigateway.amazonaws.com",
|
|
1551
|
+
FunctionName: {
|
|
1552
|
+
"Fn::GetAtt": [cloudFunctionId, "Arn"]
|
|
1553
|
+
},
|
|
1554
|
+
SourceArn: {
|
|
1555
|
+
"Fn::Sub": [
|
|
1556
|
+
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*",
|
|
1557
|
+
{
|
|
1558
|
+
__Stage__: stageName,
|
|
1559
|
+
__ApiId__: {
|
|
1560
|
+
Ref: id
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
]
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}).patch(
|
|
1569
|
+
!!authorizer ? {
|
|
1570
|
+
Resources: {
|
|
1571
|
+
// AUTHORIZER
|
|
1572
|
+
[`${id}CustomAuthorizer`]: {
|
|
1573
|
+
Type: "AWS::ApiGateway::Authorizer",
|
|
1574
|
+
Properties: {
|
|
1575
|
+
IdentitySource: identitySource,
|
|
1576
|
+
Name: `${id}CustomAuthorizer`,
|
|
1577
|
+
ProviderARNs: providerARNs,
|
|
1578
|
+
RestApiId: {
|
|
1579
|
+
Ref: id
|
|
1580
|
+
},
|
|
1581
|
+
Type: "COGNITO_USER_POOLS"
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
} : {}
|
|
1586
|
+
).template;
|
|
1587
|
+
}
|
|
1588
|
+
);
|
|
1589
|
+
|
|
1590
|
+
// src/iac/packs/repo.ts
|
|
1591
|
+
var addRepo = createResourcePack(
|
|
1592
|
+
({
|
|
1593
|
+
repoOwnerParameterName,
|
|
1594
|
+
repoNameParameterName,
|
|
1595
|
+
repoBranchParameterName,
|
|
1596
|
+
repoTokenParameterName
|
|
1597
|
+
}) => new SimpleCFT().addParameterGroup({
|
|
1598
|
+
Label: "Repository",
|
|
1599
|
+
Parameters: {
|
|
1600
|
+
[repoOwnerParameterName]: {
|
|
1601
|
+
Label: "RepoOwner",
|
|
1602
|
+
Type: "String",
|
|
1603
|
+
Description: "The owner of the repository"
|
|
1604
|
+
},
|
|
1605
|
+
[repoNameParameterName]: {
|
|
1606
|
+
Label: "RepoName",
|
|
1607
|
+
Type: "String",
|
|
1608
|
+
Description: "The name of the repository"
|
|
1609
|
+
},
|
|
1610
|
+
[repoBranchParameterName]: {
|
|
1611
|
+
Label: "RepoBranch",
|
|
1612
|
+
Type: "String",
|
|
1613
|
+
Description: "The branch of the repository"
|
|
1614
|
+
},
|
|
1615
|
+
[repoTokenParameterName]: {
|
|
1616
|
+
Label: "RepoToken",
|
|
1617
|
+
Type: "String",
|
|
1618
|
+
Description: "The token of the repository",
|
|
1619
|
+
NoEcho: true
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
}).template
|
|
1623
|
+
);
|
|
1624
|
+
|
|
1625
|
+
// src/iac/packs/ssl-certificate.ts
|
|
1626
|
+
var addSSLCertificate = createResourcePack(
|
|
1627
|
+
({
|
|
1628
|
+
id,
|
|
1629
|
+
domainName,
|
|
1630
|
+
hostedZoneId,
|
|
1631
|
+
includeWildCard = true
|
|
1632
|
+
}) => ({
|
|
1633
|
+
Resources: {
|
|
1634
|
+
[id]: {
|
|
1635
|
+
Type: "AWS::CertificateManager::Certificate",
|
|
1636
|
+
Properties: {
|
|
1637
|
+
DomainName: domainName,
|
|
1638
|
+
ValidationMethod: "DNS",
|
|
1639
|
+
DomainValidationOptions: [
|
|
1640
|
+
{
|
|
1641
|
+
DomainName: domainName,
|
|
1642
|
+
HostedZoneId: hostedZoneId
|
|
1643
|
+
}
|
|
1644
|
+
],
|
|
1645
|
+
SubjectAlternativeNames: includeWildCard ? [
|
|
1646
|
+
{
|
|
1647
|
+
"Fn::Sub": [
|
|
1648
|
+
"*.${BaseDomainName}",
|
|
1649
|
+
{
|
|
1650
|
+
BaseDomainName: domainName
|
|
1651
|
+
}
|
|
1652
|
+
]
|
|
1653
|
+
}
|
|
1654
|
+
] : void 0
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
})
|
|
1659
|
+
);
|
|
1660
|
+
|
|
1661
|
+
export { packs_exports as Packs, SimpleCFT, utils_exports as Utils };
|