codify-plugin-lib 1.0.87 → 1.0.88
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.
|
@@ -76,6 +76,8 @@ export class ResourceController {
|
|
|
76
76
|
this.validatePlanInputs(desiredConfig, stateConfig, statefulMode);
|
|
77
77
|
this.addDefaultValues(desiredConfig);
|
|
78
78
|
await this.applyTransformParameters(desiredConfig);
|
|
79
|
+
this.addDefaultValues(stateConfig);
|
|
80
|
+
await this.applyTransformParameters(stateConfig);
|
|
79
81
|
// Parse data from the user supplied config
|
|
80
82
|
const parsedConfig = new ConfigParser(desiredConfig, stateConfig, this.parsedSettings.statefulParameters);
|
|
81
83
|
const { coreParameters, desiredParameters, stateParameters, allParameters, allNonStatefulParameters, allStatefulParameters, } = parsedConfig;
|
|
@@ -188,30 +190,30 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
188
190
|
`);
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
|
-
async applyTransformParameters(
|
|
192
|
-
if (!
|
|
193
|
+
async applyTransformParameters(config) {
|
|
194
|
+
if (!config) {
|
|
193
195
|
return;
|
|
194
196
|
}
|
|
195
197
|
for (const [key, inputTransformation] of Object.entries(this.parsedSettings.inputTransformations)) {
|
|
196
|
-
if (
|
|
198
|
+
if (config[key] === undefined || !inputTransformation) {
|
|
197
199
|
continue;
|
|
198
200
|
}
|
|
199
|
-
|
|
201
|
+
config[key] = await inputTransformation(config[key]);
|
|
200
202
|
}
|
|
201
203
|
if (this.settings.inputTransformation) {
|
|
202
|
-
const { parameters, coreParameters } = splitUserConfig(
|
|
204
|
+
const { parameters, coreParameters } = splitUserConfig(config);
|
|
203
205
|
const transformed = await this.settings.inputTransformation(parameters);
|
|
204
|
-
Object.keys(
|
|
205
|
-
Object.assign(
|
|
206
|
+
Object.keys(config).forEach((k) => delete config[k]);
|
|
207
|
+
Object.assign(config, transformed, coreParameters);
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
|
-
addDefaultValues(
|
|
209
|
-
if (!
|
|
210
|
+
addDefaultValues(config) {
|
|
211
|
+
if (!config) {
|
|
210
212
|
return;
|
|
211
213
|
}
|
|
212
214
|
for (const [key, defaultValue] of Object.entries(this.parsedSettings.defaultValues)) {
|
|
213
|
-
if (defaultValue !== undefined && (
|
|
214
|
-
|
|
215
|
+
if (defaultValue !== undefined && (config[key] === undefined || config[key] === null)) {
|
|
216
|
+
config[key] = defaultValue;
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
219
|
}
|
package/package.json
CHANGED
|
@@ -112,6 +112,9 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
112
112
|
this.addDefaultValues(desiredConfig);
|
|
113
113
|
await this.applyTransformParameters(desiredConfig);
|
|
114
114
|
|
|
115
|
+
this.addDefaultValues(stateConfig);
|
|
116
|
+
await this.applyTransformParameters(stateConfig);
|
|
117
|
+
|
|
115
118
|
// Parse data from the user supplied config
|
|
116
119
|
const parsedConfig = new ConfigParser(desiredConfig, stateConfig, this.parsedSettings.statefulParameters)
|
|
117
120
|
const {
|
|
@@ -258,36 +261,36 @@ ${JSON.stringify(refresh, null, 2)}
|
|
|
258
261
|
}
|
|
259
262
|
}
|
|
260
263
|
|
|
261
|
-
private async applyTransformParameters(
|
|
262
|
-
if (!
|
|
264
|
+
private async applyTransformParameters(config: Partial<T> & ResourceConfig | null): Promise<void> {
|
|
265
|
+
if (!config) {
|
|
263
266
|
return;
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
for (const [key, inputTransformation] of Object.entries(this.parsedSettings.inputTransformations)) {
|
|
267
|
-
if (
|
|
270
|
+
if (config[key] === undefined || !inputTransformation) {
|
|
268
271
|
continue;
|
|
269
272
|
}
|
|
270
273
|
|
|
271
|
-
(
|
|
274
|
+
(config as Record<string, unknown>)[key] = await inputTransformation(config[key]);
|
|
272
275
|
}
|
|
273
276
|
|
|
274
277
|
if (this.settings.inputTransformation) {
|
|
275
|
-
const { parameters, coreParameters } = splitUserConfig(
|
|
278
|
+
const { parameters, coreParameters } = splitUserConfig(config);
|
|
276
279
|
|
|
277
280
|
const transformed = await this.settings.inputTransformation(parameters)
|
|
278
|
-
Object.keys(
|
|
279
|
-
Object.assign(
|
|
281
|
+
Object.keys(config).forEach((k) => delete config[k])
|
|
282
|
+
Object.assign(config, transformed, coreParameters);
|
|
280
283
|
}
|
|
281
284
|
}
|
|
282
285
|
|
|
283
|
-
private addDefaultValues(
|
|
284
|
-
if (!
|
|
286
|
+
private addDefaultValues(config: Partial<T> | null): void {
|
|
287
|
+
if (!config) {
|
|
285
288
|
return;
|
|
286
289
|
}
|
|
287
290
|
|
|
288
291
|
for (const [key, defaultValue] of Object.entries(this.parsedSettings.defaultValues)) {
|
|
289
|
-
if (defaultValue !== undefined && (
|
|
290
|
-
(
|
|
292
|
+
if (defaultValue !== undefined && (config[key] === undefined || config[key] === null)) {
|
|
293
|
+
(config as Record<string, unknown>)[key] = defaultValue;
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
296
|
}
|
|
@@ -491,4 +491,37 @@ describe('Resource parameter tests', () => {
|
|
|
491
491
|
|
|
492
492
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.NOOP);
|
|
493
493
|
})
|
|
494
|
+
|
|
495
|
+
it('Supports transform parameters for state parameters', async () => {
|
|
496
|
+
const resource = spy(new class extends TestResource {
|
|
497
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
498
|
+
return {
|
|
499
|
+
id: 'resourceType',
|
|
500
|
+
inputTransformation: (desired) => ({
|
|
501
|
+
propA: 'propA',
|
|
502
|
+
propB: 10,
|
|
503
|
+
})
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async refresh(): Promise<Partial<TestConfig> | null> {
|
|
508
|
+
return {
|
|
509
|
+
propA: 'propA',
|
|
510
|
+
propB: 10,
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const controller = new ResourceController(resource);
|
|
516
|
+
const plan = await controller.plan(null, { type: 'resourceType', propC: 'abc' } as any, true);
|
|
517
|
+
|
|
518
|
+
expect(resource.refresh.called).to.be.true;
|
|
519
|
+
expect(resource.refresh.getCall(0).firstArg['propA']).to.exist;
|
|
520
|
+
expect(resource.refresh.getCall(0).firstArg['propB']).to.exist;
|
|
521
|
+
expect(resource.refresh.getCall(0).firstArg['propC']).to.not.exist;
|
|
522
|
+
|
|
523
|
+
expect(plan.currentConfig?.propA).to.eq('propA');
|
|
524
|
+
expect(plan.currentConfig?.propB).to.eq(10);
|
|
525
|
+
expect(plan.currentConfig?.propC).to.be.undefined;
|
|
526
|
+
})
|
|
494
527
|
})
|