@aws-mdaa/dataops-job-l3-construct 1.5.0 → 1.6.0

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.
Files changed (90) hide show
  1. package/.jsii +38 -28
  2. package/README.md +5 -0
  3. package/lib/dataops-job-l3-construct.d.ts +8 -1
  4. package/lib/dataops-job-l3-construct.js +40 -13
  5. package/node_modules/@aws-mdaa/config/README.md +3 -0
  6. package/node_modules/@aws-mdaa/config/lib/blueprint-value-transformer.d.ts +20 -0
  7. package/node_modules/@aws-mdaa/config/lib/blueprint-value-transformer.js +70 -0
  8. package/node_modules/@aws-mdaa/config/lib/blueprint-value-transformer.ts +88 -0
  9. package/node_modules/@aws-mdaa/config/lib/config.d.ts +87 -0
  10. package/node_modules/@aws-mdaa/config/lib/config.js +7 -0
  11. package/node_modules/@aws-mdaa/config/lib/config.ts +92 -0
  12. package/node_modules/@aws-mdaa/config/lib/index.d.ts +11 -0
  13. package/node_modules/@aws-mdaa/config/lib/index.js +28 -0
  14. package/node_modules/@aws-mdaa/config/lib/index.ts +12 -0
  15. package/node_modules/@aws-mdaa/config/lib/param-transformer.d.ts +49 -0
  16. package/node_modules/@aws-mdaa/config/lib/param-transformer.js +160 -0
  17. package/node_modules/@aws-mdaa/config/lib/param-transformer.ts +159 -0
  18. package/node_modules/@aws-mdaa/config/lib/path-value-transformer.d.ts +10 -0
  19. package/node_modules/@aws-mdaa/config/lib/path-value-transformer.js +30 -0
  20. package/node_modules/@aws-mdaa/config/lib/path-value-transformer.ts +27 -0
  21. package/node_modules/@aws-mdaa/config/lib/ref-value-transformer.d.ts +44 -0
  22. package/node_modules/@aws-mdaa/config/lib/ref-value-transformer.js +243 -0
  23. package/node_modules/@aws-mdaa/config/lib/ref-value-transformer.ts +302 -0
  24. package/node_modules/@aws-mdaa/config/lib/ssm-ref-transformer.d.ts +8 -0
  25. package/node_modules/@aws-mdaa/config/lib/ssm-ref-transformer.js +22 -0
  26. package/node_modules/@aws-mdaa/config/lib/ssm-ref-transformer.ts +21 -0
  27. package/node_modules/@aws-mdaa/config/lib/transformer.d.ts +35 -0
  28. package/node_modules/@aws-mdaa/config/lib/transformer.js +66 -0
  29. package/node_modules/@aws-mdaa/config/lib/transformer.ts +74 -0
  30. package/node_modules/@aws-mdaa/config/package.json +42 -0
  31. package/node_modules/@aws-mdaa/config/test/blueprint-value-transformer.test.js +224 -0
  32. package/node_modules/@aws-mdaa/config/test/blueprint-value-transformer.test.ts +259 -0
  33. package/node_modules/@aws-mdaa/config/test/config-nt.test.d.ts +5 -0
  34. package/node_modules/@aws-mdaa/config/test/config-nt.test.js +129 -0
  35. package/node_modules/@aws-mdaa/config/test/config-nt.test.ts +163 -0
  36. package/node_modules/@aws-mdaa/config/test/config.test.d.ts +5 -0
  37. package/node_modules/@aws-mdaa/config/test/config.test.js +409 -0
  38. package/node_modules/@aws-mdaa/config/test/config.test.ts +517 -0
  39. package/node_modules/@aws-mdaa/config/test/param-transformer.test.d.ts +5 -0
  40. package/node_modules/@aws-mdaa/config/test/param-transformer.test.js +216 -0
  41. package/node_modules/@aws-mdaa/config/test/param-transformer.test.ts +234 -0
  42. package/node_modules/@aws-mdaa/config/test/path-value-transformer.test.d.ts +5 -0
  43. package/node_modules/@aws-mdaa/config/test/path-value-transformer.test.js +59 -0
  44. package/node_modules/@aws-mdaa/config/test/path-value-transformer.test.ts +68 -0
  45. package/node_modules/@aws-mdaa/config/test/ref-value-transformer.test.d.ts +5 -0
  46. package/node_modules/@aws-mdaa/config/test/ref-value-transformer.test.js +254 -0
  47. package/node_modules/@aws-mdaa/config/test/ref-value-transformer.test.ts +304 -0
  48. package/node_modules/@aws-mdaa/config/test/ssm-ref-transformer.test.d.ts +5 -0
  49. package/node_modules/@aws-mdaa/config/test/ssm-ref-transformer.test.js +66 -0
  50. package/node_modules/@aws-mdaa/config/test/ssm-ref-transformer.test.ts +79 -0
  51. package/node_modules/@aws-mdaa/config/tsconfig.tsbuildinfo +1 -0
  52. package/node_modules/lodash/README.md +2 -2
  53. package/node_modules/lodash/_baseOrderBy.js +1 -1
  54. package/node_modules/lodash/_baseUnset.js +7 -20
  55. package/node_modules/lodash/_setCacheHas.js +1 -1
  56. package/node_modules/lodash/compact.js +1 -1
  57. package/node_modules/lodash/core.js +3 -3
  58. package/node_modules/lodash/core.min.js +26 -25
  59. package/node_modules/lodash/fromPairs.js +3 -1
  60. package/node_modules/lodash/lodash.js +38 -27
  61. package/node_modules/lodash/lodash.min.js +125 -129
  62. package/node_modules/lodash/package.json +4 -2
  63. package/node_modules/lodash/random.js +9 -0
  64. package/node_modules/lodash/template.js +16 -4
  65. package/node_modules/lodash/templateSettings.js +4 -0
  66. package/package.json +27 -32
  67. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/README.md +0 -185
  68. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/lib/index.d.ts +0 -57
  69. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/lib/index.js +0 -198
  70. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/lib/index.ts +0 -241
  71. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/package.json +0 -44
  72. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/test/bucketpolicy-helper.test.js +0 -200
  73. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/test/bucketpolicy-helper.test.ts +0 -215
  74. package/node_modules/@aws-mdaa/s3-bucketpolicy-helper/tsconfig.tsbuildinfo +0 -1
  75. package/node_modules/@aws-mdaa/s3-inventory-helper/.npmignore +0 -34
  76. package/node_modules/@aws-mdaa/s3-inventory-helper/README.md +0 -3
  77. package/node_modules/@aws-mdaa/s3-inventory-helper/jest.config.js +0 -5
  78. package/node_modules/@aws-mdaa/s3-inventory-helper/lib/index.d.ts +0 -48
  79. package/node_modules/@aws-mdaa/s3-inventory-helper/lib/index.js +0 -213
  80. package/node_modules/@aws-mdaa/s3-inventory-helper/lib/index.ts +0 -241
  81. package/node_modules/@aws-mdaa/s3-inventory-helper/package.json +0 -44
  82. package/node_modules/@aws-mdaa/s3-inventory-helper/test/TODO +0 -0
  83. package/node_modules/@aws-mdaa/s3-inventory-helper/tsconfig.json +0 -40
  84. package/node_modules/@aws-mdaa/s3-inventory-helper/tsconfig.tsbuildinfo +0 -1
  85. package/node_modules/@aws-mdaa/s3-inventory-helper/typedoc.json +0 -7
  86. /package/node_modules/@aws-mdaa/{s3-bucketpolicy-helper → config}/.npmignore +0 -0
  87. /package/node_modules/@aws-mdaa/{s3-bucketpolicy-helper → config}/jest.config.js +0 -0
  88. /package/node_modules/@aws-mdaa/{s3-bucketpolicy-helper/test/bucketpolicy-helper.test.d.ts → config/test/blueprint-value-transformer.test.d.ts} +0 -0
  89. /package/node_modules/@aws-mdaa/{s3-bucketpolicy-helper → config}/tsconfig.json +0 -0
  90. /package/node_modules/@aws-mdaa/{s3-bucketpolicy-helper → config}/typedoc.json +0 -0
@@ -0,0 +1,302 @@
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { MdaaStringParameter } from '@aws-mdaa/construct';
7
+ import { Fn, Names, Stack } from 'aws-cdk-lib';
8
+ import { Construct } from 'constructs';
9
+ // nosemgrep
10
+ import { IMdaaResourceNaming } from '@aws-mdaa/naming';
11
+ import * as XRegExp from 'xregexp';
12
+ import { ConfigurationElement } from './config';
13
+ import { IMdaaConfigValueTransformer, TransformResult } from './transformer';
14
+ import { IStringParameter } from 'aws-cdk-lib/aws-ssm';
15
+
16
+ export interface AwsEnvironment {
17
+ readonly partition?: string;
18
+ readonly region?: string;
19
+ readonly account?: string;
20
+ }
21
+
22
+ export interface MdaaConfigRefValueTransformerProps {
23
+ readonly naming?: IMdaaResourceNaming;
24
+ readonly org: string;
25
+ readonly domain: string;
26
+ readonly env: string;
27
+ readonly module_name: string;
28
+ readonly scope?: Construct;
29
+ readonly context?: ConfigurationElement;
30
+ readonly awsEnvironment?: AwsEnvironment;
31
+ }
32
+
33
+ export class MdaaConfigRefValueTransformer implements IMdaaConfigValueTransformer {
34
+ protected props: MdaaConfigRefValueTransformerProps;
35
+
36
+ constructor(props: MdaaConfigRefValueTransformerProps) {
37
+ this.props = props;
38
+ }
39
+
40
+ public transformValue(value: string): TransformResult {
41
+ const refMatch = XRegExp.matchRecursive(value, '{{', '}}', 'g', {
42
+ unbalanced: 'skip',
43
+ });
44
+ if (refMatch.length > 0) {
45
+ return this.parseRef(value, refMatch) as TransformResult;
46
+ } else {
47
+ return value;
48
+ }
49
+ }
50
+
51
+ protected parseRef(value: string, refMatch: string[]): string | number | object {
52
+ const isNakedReference = this.isNakedReference(value, refMatch);
53
+
54
+ // Handle naked references that might return objects/arrays
55
+ if (isNakedReference) {
56
+ const nakedResult = this.handleNakedReference(refMatch[0]);
57
+ if (nakedResult !== undefined) {
58
+ return nakedResult;
59
+ }
60
+ }
61
+ // Substitute all references in the string
62
+ return this.substituteReferences(value, refMatch, isNakedReference);
63
+ }
64
+
65
+ private isNakedReference(value: string, refMatch: string[]): boolean {
66
+ return refMatch.length === 1 && value === `{{${refMatch[0]}}}`;
67
+ }
68
+
69
+ private handleNakedReference(ref: string) {
70
+ const refInner = this.transformValue(ref).toString();
71
+
72
+ if (refInner.startsWith('context:')) {
73
+ const resolvedValue = this.parseContext(refInner);
74
+ // If it's an object or array, return it directly
75
+ if (typeof resolvedValue === 'object' && resolvedValue !== null) {
76
+ return resolvedValue;
77
+ }
78
+ }
79
+
80
+ // For env_var refs, attempt to parse JSON arrays/objects so that
81
+ // env vars containing '["a","b"]' resolve to actual arrays rather than strings.
82
+ if (refInner.startsWith('env_var:')) {
83
+ const envValue = this.resolveEnvVar(refInner);
84
+ if (envValue && (envValue.startsWith('[') || envValue.startsWith('{'))) {
85
+ try {
86
+ const parsed = JSON.parse(envValue);
87
+ if (typeof parsed === 'object' && parsed !== null) {
88
+ return parsed;
89
+ }
90
+ } catch {
91
+ // Not valid JSON — fall through to string substitution
92
+ }
93
+ }
94
+ }
95
+
96
+ return undefined;
97
+ }
98
+
99
+ private substituteReferences(value: string, refMatch: string[], isNakedReference: boolean): string {
100
+ return refMatch.reduce((result, ref) => {
101
+ const refInner = this.transformValue(ref).toString();
102
+ const resolvedValue = this.resolveReference(refInner, isNakedReference);
103
+
104
+ if (resolvedValue === undefined) {
105
+ return result;
106
+ }
107
+
108
+ const stringValue = this.convertToString(resolvedValue);
109
+ return result.replace(`{{${ref}}}`, stringValue);
110
+ }, value);
111
+ }
112
+
113
+ private convertToString(value: unknown): string {
114
+ if (typeof value === 'string') {
115
+ return value;
116
+ }
117
+ if (typeof value === 'number' || typeof value === 'boolean') {
118
+ return String(value);
119
+ }
120
+ // For objects, use JSON.stringify as a safe fallback
121
+ return JSON.stringify(value);
122
+ }
123
+
124
+ private resolveReference(refInner: string, isNakedReference: boolean) {
125
+ const simpleRefMap = this.getSimpleRefMap();
126
+
127
+ if (simpleRefMap[refInner]) {
128
+ return simpleRefMap[refInner];
129
+ }
130
+
131
+ if (refInner.startsWith('context:')) {
132
+ return this.resolveContextReference(refInner, isNakedReference);
133
+ }
134
+
135
+ if (refInner.startsWith('env_var:')) {
136
+ return this.resolveEnvVar(refInner);
137
+ }
138
+
139
+ if (refInner.startsWith('ssm-org:')) {
140
+ return this.resolveSsmPartialPathReference(refInner);
141
+ }
142
+
143
+ if (refInner.startsWith('ssm-domain:')) {
144
+ return this.resolveSsmPartialPathReference(refInner);
145
+ }
146
+
147
+ if (refInner.startsWith('ssm-env:')) {
148
+ return this.resolveSsmPartialPathReference(refInner);
149
+ }
150
+
151
+ if (refInner.startsWith('resolve:ssm:')) {
152
+ return this.resolveDirectSsm(refInner);
153
+ }
154
+
155
+ if (refInner.startsWith('ref:')) {
156
+ return this.resolveRef(refInner);
157
+ }
158
+
159
+ return undefined;
160
+ }
161
+
162
+ private resolveRef(refInner: string): string {
163
+ const dummyStack = new Stack(undefined);
164
+ const withoutPrefix = refInner.replace(/^ref:/, '');
165
+ const parts = withoutPrefix.split(':');
166
+
167
+ // Remove leading slash if present from the path
168
+ const pathWithSlash = parts[0];
169
+ const path = pathWithSlash.startsWith('/') ? pathWithSlash.slice(1) : pathWithSlash;
170
+ const attr = parts[1]; // Will be undefined if no attribute specified
171
+
172
+ const logicalId = this.generateLogicalId(dummyStack, path);
173
+
174
+ if (attr) {
175
+ return Fn.getAtt(logicalId, attr).toString();
176
+ } else {
177
+ return Fn.ref(logicalId).toString();
178
+ }
179
+ }
180
+
181
+ private generateLogicalId(parentScope: Construct, path: string): string {
182
+ const pathComponents = path.split('/');
183
+ const construct = new Construct(parentScope, pathComponents[0]);
184
+ if (pathComponents.length == 1) {
185
+ return Names.nodeUniqueId(construct.node);
186
+ } else {
187
+ return this.generateLogicalId(construct, pathComponents.slice(1).join('/'));
188
+ }
189
+ }
190
+
191
+ private getSimpleRefMap(): { [key: string]: string | undefined } {
192
+ const scopeStack = this.props.scope ? Stack.of(this.props.scope) : undefined;
193
+ return {
194
+ org: this.props.org,
195
+ env: this.props.env,
196
+ domain: this.props.domain,
197
+ module_name: this.props.module_name,
198
+ partition: this.props.awsEnvironment?.partition ?? scopeStack?.partition,
199
+ region: this.props.awsEnvironment?.region ?? scopeStack?.region,
200
+ account: this.props.awsEnvironment?.account ?? scopeStack?.account,
201
+ };
202
+ }
203
+
204
+ private resolveContextReference(refInner: string, isNakedReference: boolean) {
205
+ const resolvedValue = this.parseContext(refInner);
206
+
207
+ // If the resolved value is an object or array, and we're not in a naked reference
208
+ if (typeof resolvedValue === 'object' && resolvedValue !== null && !isNakedReference) {
209
+ throw new Error('Cannot embed array or object context value in string');
210
+ }
211
+
212
+ return resolvedValue;
213
+ }
214
+
215
+ private resolveEnvVar(refInner: string): string | undefined {
216
+ const envVar = refInner.replace(/^env_var:/, '');
217
+ return process.env[envVar];
218
+ }
219
+
220
+ private extractSsmValue(refInner: string, prefix: string): string {
221
+ const extracted = refInner.replace(new RegExp(String.raw`^${prefix}:\s*`), '');
222
+ // Remove leading slash to prevent double slashes in the path
223
+ return extracted.startsWith('/') ? extracted.slice(1) : extracted;
224
+ }
225
+
226
+ private resolveSsmPartialPathReference(refInner: string): string {
227
+ if (!this.props.naming) {
228
+ throw new Error(`Unable to resolve ${refInner} ssm param outside of a naming context`);
229
+ }
230
+
231
+ if (refInner.startsWith('ssm-org:')) {
232
+ const ssmPath = this.props.naming.ssmOrgPath(this.extractSsmValue(refInner, 'ssm-org'));
233
+ return `{{resolve:ssm:${ssmPath}}}`;
234
+ }
235
+
236
+ if (refInner.startsWith('ssm-domain:')) {
237
+ const ssmPath = this.props.naming.ssmDomainPath(this.extractSsmValue(refInner, 'ssm-domain'));
238
+ return `{{resolve:ssm:${ssmPath}}}`;
239
+ }
240
+
241
+ if (refInner.startsWith('ssm-env:')) {
242
+ const ssmPath = this.props.naming.ssmEnvPath(this.extractSsmValue(refInner, 'ssm-env'));
243
+ return `{{resolve:ssm:${ssmPath}}}`;
244
+ }
245
+
246
+ return refInner;
247
+ }
248
+
249
+ private resolveDirectSsm(refInner: string): string {
250
+ if (!this.props.scope) {
251
+ throw new Error('Unable to resolve ssm param outside of a Construct');
252
+ }
253
+
254
+ const ssmPath = refInner.replace(/^resolve:ssm:/, '');
255
+ console.log(`Resolving SSM: ${ssmPath}`);
256
+ return this.getSsmValue(ssmPath);
257
+ }
258
+
259
+ private getSsmValue(ssmPath: string): string {
260
+ if (!this.props.scope) {
261
+ throw new Error('Unable to resolve ssm param outside of a Construct');
262
+ }
263
+ //Handle full arn-based SSM paths (for referencing RAM shared SSM params from other accounts)
264
+ if (ssmPath.startsWith('arn:')) {
265
+ const stack = Stack.of(this.props.scope);
266
+ const exists = stack.node.tryFindChild(ssmPath) as IStringParameter;
267
+ if (exists) {
268
+ return exists.stringValue;
269
+ }
270
+ return MdaaStringParameter.fromStringParameterArn(Stack.of(this.props.scope), ssmPath, ssmPath).stringValue;
271
+ }
272
+ return this.props.scope.node.tryGetContext('@mdaaLookupSSMValues')
273
+ ? MdaaStringParameter.valueFromLookup(Stack.of(this.props.scope), ssmPath)
274
+ : MdaaStringParameter.valueForStringParameter(Stack.of(this.props.scope), ssmPath);
275
+ }
276
+
277
+ private parseContext(refInner: string) {
278
+ const refInnerContext = refInner.replace(/^context:/, '');
279
+ const scopeContextValue = this.props.scope?.node.tryGetContext(refInnerContext);
280
+ const scopeInnerContextValue = this.props.context ? this.props.context[refInnerContext] : undefined;
281
+ const contextValue = scopeContextValue ?? scopeInnerContextValue;
282
+ if (!contextValue) {
283
+ throw new Error(`Failed to resolve context: ${refInnerContext}`);
284
+ }
285
+ if (typeof contextValue === 'string') {
286
+ // Check if the value is encoded with quotes (from CLI encoding)
287
+ if (contextValue.startsWith('"') && contextValue.endsWith('"')) {
288
+ // Remove outer quotes
289
+ const unquoted = contextValue.slice(1, -1);
290
+
291
+ if (unquoted.startsWith('obj:')) {
292
+ // Parse object: "obj:{...}" -> {...}
293
+ return JSON.parse(unquoted.replace(/^obj:/, '')) as ConfigurationElement;
294
+ } else if (unquoted.startsWith('list:')) {
295
+ // Parse array: "list:[...]" -> [...]
296
+ return JSON.parse(unquoted.replace(/^list:/, '')) as unknown[];
297
+ }
298
+ }
299
+ }
300
+ return contextValue;
301
+ }
302
+ }
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { IMdaaConfigValueTransformer } from '.';
6
+ export declare class MdaaConfigSSMValueTransformer implements IMdaaConfigValueTransformer {
7
+ transformValue(value: string, contextPath: string): string;
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.MdaaConfigSSMValueTransformer = void 0;
8
+ class MdaaConfigSSMValueTransformer {
9
+ transformValue(value, contextPath) {
10
+ const ignorePaths = ['policyDocument/Statement/Action'];
11
+ if (value.startsWith('ssm:') &&
12
+ ignorePaths.every(ignorePath => !contextPath.toLowerCase().endsWith(ignorePath.toLowerCase()))) {
13
+ const paramName = value.replace(/^ssm:\s*/, '');
14
+ return `{{resolve:ssm:${paramName}}}`;
15
+ }
16
+ else {
17
+ return value;
18
+ }
19
+ }
20
+ }
21
+ exports.MdaaConfigSSMValueTransformer = MdaaConfigSSMValueTransformer;
22
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3NtLXJlZi10cmFuc2Zvcm1lci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInNzbS1yZWYtdHJhbnNmb3JtZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7R0FHRzs7O0FBSUgsTUFBYSw2QkFBNkI7SUFDakMsY0FBYyxDQUFDLEtBQWEsRUFBRSxXQUFtQjtRQUN0RCxNQUFNLFdBQVcsR0FBRyxDQUFDLGlDQUFpQyxDQUFDLENBQUM7UUFDeEQsSUFDRSxLQUFLLENBQUMsVUFBVSxDQUFDLE1BQU0sQ0FBQztZQUN4QixXQUFXLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxFQUFFLENBQUMsQ0FBQyxXQUFXLENBQUMsV0FBVyxFQUFFLENBQUMsUUFBUSxDQUFDLFVBQVUsQ0FBQyxXQUFXLEVBQUUsQ0FBQyxDQUFDLEVBQzlGLENBQUM7WUFDRCxNQUFNLFNBQVMsR0FBRyxLQUFLLENBQUMsT0FBTyxDQUFDLFVBQVUsRUFBRSxFQUFFLENBQUMsQ0FBQztZQUNoRCxPQUFPLGlCQUFpQixTQUFTLElBQUksQ0FBQztRQUN4QyxDQUFDO2FBQU0sQ0FBQztZQUNOLE9BQU8sS0FBSyxDQUFDO1FBQ2YsQ0FBQztJQUNILENBQUM7Q0FDRjtBQWJELHNFQWFDIiwic291cmNlc0NvbnRlbnQiOlsiLyohXG4gKiBDb3B5cmlnaHQgQW1hem9uLmNvbSwgSW5jLiBvciBpdHMgYWZmaWxpYXRlcy4gQWxsIFJpZ2h0cyBSZXNlcnZlZC5cbiAqIFNQRFgtTGljZW5zZS1JZGVudGlmaWVyOiBBcGFjaGUtMi4wXG4gKi9cblxuaW1wb3J0IHsgSU1kYWFDb25maWdWYWx1ZVRyYW5zZm9ybWVyIH0gZnJvbSAnLic7XG5cbmV4cG9ydCBjbGFzcyBNZGFhQ29uZmlnU1NNVmFsdWVUcmFuc2Zvcm1lciBpbXBsZW1lbnRzIElNZGFhQ29uZmlnVmFsdWVUcmFuc2Zvcm1lciB7XG4gIHB1YmxpYyB0cmFuc2Zvcm1WYWx1ZSh2YWx1ZTogc3RyaW5nLCBjb250ZXh0UGF0aDogc3RyaW5nKTogc3RyaW5nIHtcbiAgICBjb25zdCBpZ25vcmVQYXRocyA9IFsncG9saWN5RG9jdW1lbnQvU3RhdGVtZW50L0FjdGlvbiddO1xuICAgIGlmIChcbiAgICAgIHZhbHVlLnN0YXJ0c1dpdGgoJ3NzbTonKSAmJlxuICAgICAgaWdub3JlUGF0aHMuZXZlcnkoaWdub3JlUGF0aCA9PiAhY29udGV4dFBhdGgudG9Mb3dlckNhc2UoKS5lbmRzV2l0aChpZ25vcmVQYXRoLnRvTG93ZXJDYXNlKCkpKVxuICAgICkge1xuICAgICAgY29uc3QgcGFyYW1OYW1lID0gdmFsdWUucmVwbGFjZSgvXnNzbTpcXHMqLywgJycpO1xuICAgICAgcmV0dXJuIGB7e3Jlc29sdmU6c3NtOiR7cGFyYW1OYW1lfX19YDtcbiAgICB9IGVsc2Uge1xuICAgICAgcmV0dXJuIHZhbHVlO1xuICAgIH1cbiAgfVxufVxuIl19
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { IMdaaConfigValueTransformer } from '.';
7
+
8
+ export class MdaaConfigSSMValueTransformer implements IMdaaConfigValueTransformer {
9
+ public transformValue(value: string, contextPath: string): string {
10
+ const ignorePaths = ['policyDocument/Statement/Action'];
11
+ if (
12
+ value.startsWith('ssm:') &&
13
+ ignorePaths.every(ignorePath => !contextPath.toLowerCase().endsWith(ignorePath.toLowerCase()))
14
+ ) {
15
+ const paramName = value.replace(/^ssm:\s*/, '');
16
+ return `{{resolve:ssm:${paramName}}}`;
17
+ } else {
18
+ return value;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,35 @@
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { ConfigurationElement } from './config';
6
+ export type TransformResult = string | number;
7
+ export interface IMdaaConfigValueTransformer {
8
+ transformValue(value: string, contextPath?: string): TransformResult;
9
+ }
10
+ export interface IMdaaConfigTransformer {
11
+ transformConfig(config: ConfigurationElement): ConfigurationElement;
12
+ }
13
+ /**
14
+ * A utility class which executs transformer functions against MDAA Configs.
15
+ */
16
+ export declare class MdaaConfigTransformer implements IMdaaConfigTransformer {
17
+ private readonly valueTransformer;
18
+ private readonly keyTransformer?;
19
+ constructor(valueTransformer: IMdaaConfigValueTransformer, keyTransformer?: IMdaaConfigValueTransformer);
20
+ transformConfig(config: ConfigurationElement): ConfigurationElement;
21
+ /**
22
+ * A recursive function which applies a transformation function to all config values.
23
+ * @param contextPath
24
+ * @param resolvedConfig The config object being transformed
25
+ * @returns A config object with the transformation function applied to all config values.
26
+ */
27
+ transformConfigObject(contextPath: string, resolvedConfig: ConfigurationElement): ConfigurationElement;
28
+ /**
29
+ * A helper function for transformConfigObject for use with Arrays.
30
+ * @param contextPath
31
+ * @param resolvedConfig (Required) - The config object being transformed
32
+ * @returns A config object with the transformation function applied to all config values.
33
+ */
34
+ transformConfigArray(contextPath: string, resolvedConfig: unknown[]): unknown[];
35
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.MdaaConfigTransformer = void 0;
8
+ /**
9
+ * A utility class which executs transformer functions against MDAA Configs.
10
+ */
11
+ class MdaaConfigTransformer {
12
+ constructor(valueTransformer, keyTransformer) {
13
+ this.valueTransformer = valueTransformer;
14
+ this.keyTransformer = keyTransformer;
15
+ }
16
+ transformConfig(config) {
17
+ return this.transformConfigObject('/', config);
18
+ }
19
+ /**
20
+ * A recursive function which applies a transformation function to all config values.
21
+ * @param contextPath
22
+ * @param resolvedConfig The config object being transformed
23
+ * @returns A config object with the transformation function applied to all config values.
24
+ */
25
+ transformConfigObject(contextPath, resolvedConfig) {
26
+ const transformedConfig = {};
27
+ for (const key in resolvedConfig) {
28
+ const value = resolvedConfig[key];
29
+ const transformedKey = this.keyTransformer
30
+ ? this.keyTransformer.transformValue(key, contextPath + '/' + key)
31
+ : key;
32
+ if (typeof value === 'string')
33
+ transformedConfig[transformedKey] = this.valueTransformer.transformValue(value, contextPath + '/' + key);
34
+ else if (Array.isArray(value))
35
+ transformedConfig[transformedKey] = this.transformConfigArray(contextPath + '/' + key, value);
36
+ else if (typeof value === 'object' && value !== null) {
37
+ transformedConfig[transformedKey] = this.transformConfigObject(contextPath + '/' + key, value);
38
+ }
39
+ else
40
+ transformedConfig[transformedKey] = value;
41
+ }
42
+ return transformedConfig;
43
+ }
44
+ /**
45
+ * A helper function for transformConfigObject for use with Arrays.
46
+ * @param contextPath
47
+ * @param resolvedConfig (Required) - The config object being transformed
48
+ * @returns A config object with the transformation function applied to all config values.
49
+ */
50
+ transformConfigArray(contextPath, resolvedConfig) {
51
+ const transformedConfig = [];
52
+ resolvedConfig.forEach(value => {
53
+ if (typeof value === 'string')
54
+ transformedConfig.push(this.valueTransformer.transformValue(value, contextPath));
55
+ else if (Array.isArray(value))
56
+ transformedConfig.push(this.transformConfigArray(contextPath, value));
57
+ else if (typeof value === 'object' && value !== null)
58
+ transformedConfig.push(this.transformConfigObject(contextPath, value));
59
+ else
60
+ transformedConfig.push(value);
61
+ });
62
+ return transformedConfig;
63
+ }
64
+ }
65
+ exports.MdaaConfigTransformer = MdaaConfigTransformer;
66
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNmb3JtZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0cmFuc2Zvcm1lci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7OztHQUdHOzs7QUFjSDs7R0FFRztBQUNILE1BQWEscUJBQXFCO0lBR2hDLFlBQVksZ0JBQTZDLEVBQUUsY0FBNEM7UUFDckcsSUFBSSxDQUFDLGdCQUFnQixHQUFHLGdCQUFnQixDQUFDO1FBQ3pDLElBQUksQ0FBQyxjQUFjLEdBQUcsY0FBYyxDQUFDO0lBQ3ZDLENBQUM7SUFDTSxlQUFlLENBQUMsTUFBNEI7UUFDakQsT0FBTyxJQUFJLENBQUMscUJBQXFCLENBQUMsR0FBRyxFQUFFLE1BQU0sQ0FBQyxDQUFDO0lBQ2pELENBQUM7SUFDRDs7Ozs7T0FLRztJQUNJLHFCQUFxQixDQUFDLFdBQW1CLEVBQUUsY0FBb0M7UUFDcEYsTUFBTSxpQkFBaUIsR0FBeUIsRUFBRSxDQUFDO1FBQ25ELEtBQUssTUFBTSxHQUFHLElBQUksY0FBYyxFQUFFLENBQUM7WUFDakMsTUFBTSxLQUFLLEdBQUcsY0FBYyxDQUFDLEdBQUcsQ0FBQyxDQUFDO1lBQ2xDLE1BQU0sY0FBYyxHQUFHLElBQUksQ0FBQyxjQUFjO2dCQUN4QyxDQUFDLENBQUMsSUFBSSxDQUFDLGNBQWMsQ0FBQyxjQUFjLENBQUMsR0FBRyxFQUFFLFdBQVcsR0FBRyxHQUFHLEdBQUcsR0FBRyxDQUFDO2dC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HRyYW5zZm9ybWVkQ29uZmlnOiBDb25maWd1cmF0aW9uRWxlbWVudCB8IHVua25vd25bXSA9IFtdO1xuICAgIHJlc29sdmVkQ29uZmlnLmZvckVhY2godmFsdWUgPT4ge1xuICAgICAgaWYgKHR5cGVvZiB2YWx1ZSA9PT0gJ3N0cmluZycpIHRyYW5zZm9ybWVkQ29uZmlnLnB1c2godGhpcy52YWx1ZVRyYW5zZm9ybWVyLnRyYW5zZm9ybVZhbHVlKHZhbHVlLCBjb250ZXh0UGF0aCkpO1xuICAgICAgZWxzZSBpZiAoQXJyYXkuaXNBcnJheSh2YWx1ZSkpIHRyYW5zZm9ybWVkQ29uZmlnLnB1c2godGhpcy50cmFuc2Zvcm1Db25maWdBcnJheShjb250ZXh0UGF0aCwgdmFsdWUgYXMgdW5rbm93bltdKSk7XG4gICAgICBlbHNlIGlmICh0eXBlb2YgdmFsdWUgPT09ICdvYmplY3QnICYmIHZhbHVlICE9PSBudWxsKVxuICAgICAgICB0cmFuc2Zvcm1lZENvbmZpZy5wdXNoKHRoaXMudHJhbnNmb3JtQ29uZmlnT2JqZWN0KGNvbnRleHRQYXRoLCB2YWx1ZSBhcyBDb25maWd1cmF0aW9uRWxlbWVudCkpO1xuICAgICAgZWxzZSB0cmFuc2Zvcm1lZENvbmZpZy5wdXNoKHZhbHVlKTtcbiAgICB9KTtcbiAgICByZXR1cm4gdHJhbnNmb3JtZWRDb25maWc7XG4gIH1cbn1cbiJdfQ==
@@ -0,0 +1,74 @@
1
+ /*!
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ import { ConfigurationElement } from './config';
7
+
8
+ export type TransformResult = string | number;
9
+
10
+ export interface IMdaaConfigValueTransformer {
11
+ transformValue(value: string, contextPath?: string): TransformResult;
12
+ }
13
+
14
+ export interface IMdaaConfigTransformer {
15
+ transformConfig(config: ConfigurationElement): ConfigurationElement;
16
+ }
17
+
18
+ /**
19
+ * A utility class which executs transformer functions against MDAA Configs.
20
+ */
21
+ export class MdaaConfigTransformer implements IMdaaConfigTransformer {
22
+ private readonly valueTransformer: IMdaaConfigValueTransformer;
23
+ private readonly keyTransformer?: IMdaaConfigValueTransformer;
24
+ constructor(valueTransformer: IMdaaConfigValueTransformer, keyTransformer?: IMdaaConfigValueTransformer) {
25
+ this.valueTransformer = valueTransformer;
26
+ this.keyTransformer = keyTransformer;
27
+ }
28
+ public transformConfig(config: ConfigurationElement): ConfigurationElement {
29
+ return this.transformConfigObject('/', config);
30
+ }
31
+ /**
32
+ * A recursive function which applies a transformation function to all config values.
33
+ * @param contextPath
34
+ * @param resolvedConfig The config object being transformed
35
+ * @returns A config object with the transformation function applied to all config values.
36
+ */
37
+ public transformConfigObject(contextPath: string, resolvedConfig: ConfigurationElement): ConfigurationElement {
38
+ const transformedConfig: ConfigurationElement = {};
39
+ for (const key in resolvedConfig) {
40
+ const value = resolvedConfig[key];
41
+ const transformedKey = this.keyTransformer
42
+ ? this.keyTransformer.transformValue(key, contextPath + '/' + key)
43
+ : key;
44
+ if (typeof value === 'string')
45
+ transformedConfig[transformedKey] = this.valueTransformer.transformValue(value, contextPath + '/' + key);
46
+ else if (Array.isArray(value))
47
+ transformedConfig[transformedKey] = this.transformConfigArray(contextPath + '/' + key, value);
48
+ else if (typeof value === 'object' && value !== null) {
49
+ transformedConfig[transformedKey] = this.transformConfigObject(
50
+ contextPath + '/' + key,
51
+ value as ConfigurationElement,
52
+ );
53
+ } else transformedConfig[transformedKey] = value;
54
+ }
55
+ return transformedConfig;
56
+ }
57
+ /**
58
+ * A helper function for transformConfigObject for use with Arrays.
59
+ * @param contextPath
60
+ * @param resolvedConfig (Required) - The config object being transformed
61
+ * @returns A config object with the transformation function applied to all config values.
62
+ */
63
+ public transformConfigArray(contextPath: string, resolvedConfig: unknown[]): unknown[] {
64
+ const transformedConfig: ConfigurationElement | unknown[] = [];
65
+ resolvedConfig.forEach(value => {
66
+ if (typeof value === 'string') transformedConfig.push(this.valueTransformer.transformValue(value, contextPath));
67
+ else if (Array.isArray(value)) transformedConfig.push(this.transformConfigArray(contextPath, value as unknown[]));
68
+ else if (typeof value === 'object' && value !== null)
69
+ transformedConfig.push(this.transformConfigObject(contextPath, value as ConfigurationElement));
70
+ else transformedConfig.push(value);
71
+ });
72
+ return transformedConfig;
73
+ }
74
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@aws-mdaa/config",
3
+ "description": "MDAA config utility",
4
+ "author": {
5
+ "name": "Amazon Web Services",
6
+ "url": "https://aws.amazon.com/solutions"
7
+ },
8
+ "version": "1.6.0",
9
+ "license": "Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/aws/modern-data-architecture-accelerator"
13
+ },
14
+ "main": "lib/index.js",
15
+ "types": "lib/index.d.ts",
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "watch": "tsc -w",
19
+ "test": "jest --passWithNoTests --coverage",
20
+ "lint": "eslint --max-warnings 0 -c ../../../eslint.config.mjs",
21
+ "test:package-docs": "../../../scripts/generate_docs/test_package_docs.sh"
22
+ },
23
+ "devDependencies": {
24
+ "@types/jest": "29.5.14",
25
+ "@types/node": "22.9.0",
26
+ "@types/prettier": "2.6.0",
27
+ "constructs": "10.0.96",
28
+ "jest": "29.7.0",
29
+ "ts-jest": "29.4.9",
30
+ "ts-node": "10.9.2",
31
+ "typescript": "5.9.3",
32
+ "typescript-json-schema": "0.67.4"
33
+ },
34
+ "dependencies": {
35
+ "@aws-mdaa/construct": "1.6.0",
36
+ "@aws-mdaa/naming": "1.6.0",
37
+ "aws-cdk-lib": "2.220.0",
38
+ "constructs": "10.0.96",
39
+ "xregexp": "5.1.1"
40
+ },
41
+ "gitHead": "8b49a2b371014baec046605ffdbfe38951099c31"
42
+ }