codify-plugin-lib 1.0.128 → 1.0.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plan/plan.d.ts +14 -14
- package/dist/plan/plan.js +60 -66
- package/dist/plugin/plugin.d.ts +2 -2
- package/dist/plugin/plugin.js +17 -14
- package/dist/resource/config-parser.d.ts +2 -5
- package/dist/resource/config-parser.js +1 -28
- package/dist/resource/resource-controller.d.ts +4 -4
- package/dist/resource/resource-controller.js +47 -49
- package/package.json +2 -2
- package/src/common/errors.test.ts +1 -1
- package/src/messages/handlers.test.ts +9 -3
- package/src/plan/plan.test.ts +21 -20
- package/src/plan/plan.ts +99 -105
- package/src/plugin/plugin.test.ts +8 -9
- package/src/plugin/plugin.ts +24 -16
- package/src/resource/config-parser.ts +6 -41
- package/src/resource/resource-controller-stateful-mode.test.ts +4 -4
- package/src/resource/resource-controller.test.ts +47 -32
- package/src/resource/resource-controller.ts +58 -58
- package/src/resource/resource-settings.test.ts +113 -83
- package/src/stateful-parameter/stateful-parameter-controller.test.ts +19 -10
- package/src/utils/test-utils.test.ts +6 -6
|
@@ -38,16 +38,19 @@ describe('Resource parameter tests', () => {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const controller = new ResourceController(resource);
|
|
41
|
-
const plan = await controller.plan(
|
|
42
|
-
type: 'type',
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const plan = await controller.plan(
|
|
42
|
+
{ type: 'type' },
|
|
43
|
+
{
|
|
44
|
+
propA: 'a',
|
|
45
|
+
propB: 10
|
|
46
|
+
},
|
|
47
|
+
null,
|
|
48
|
+
false
|
|
49
|
+
)
|
|
46
50
|
|
|
47
51
|
expect(statefulParameter.refresh.notCalled).to.be.true;
|
|
48
52
|
expect(plan.currentConfig).to.be.null;
|
|
49
53
|
expect(plan.desiredConfig).toMatchObject({
|
|
50
|
-
type: 'type',
|
|
51
54
|
propA: 'a',
|
|
52
55
|
propB: 10
|
|
53
56
|
})
|
|
@@ -116,7 +119,12 @@ describe('Resource parameter tests', () => {
|
|
|
116
119
|
|
|
117
120
|
const controller = new ResourceController(resource);
|
|
118
121
|
|
|
119
|
-
const plan = await controller.plan(
|
|
122
|
+
const plan = await controller.plan(
|
|
123
|
+
{ type: 'type' },
|
|
124
|
+
{ propA: 'a', propB: 0, propC: 'b' },
|
|
125
|
+
null,
|
|
126
|
+
false
|
|
127
|
+
)
|
|
120
128
|
|
|
121
129
|
const resourceSpy = spy(resource);
|
|
122
130
|
await controller.apply(plan);
|
|
@@ -156,12 +164,11 @@ describe('Resource parameter tests', () => {
|
|
|
156
164
|
const controller = new ResourceController(resource);
|
|
157
165
|
const plan = await controller.plan({
|
|
158
166
|
type: 'type',
|
|
159
|
-
})
|
|
167
|
+
}, {}, null, false)
|
|
160
168
|
|
|
161
169
|
expect(statefulParameter.refresh.notCalled).to.be.true;
|
|
162
170
|
expect(plan.currentConfig).to.be.null;
|
|
163
171
|
expect(plan.desiredConfig).toMatchObject({
|
|
164
|
-
type: 'type',
|
|
165
172
|
propA: 'abc',
|
|
166
173
|
})
|
|
167
174
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.CREATE);
|
|
@@ -196,7 +203,7 @@ describe('Resource parameter tests', () => {
|
|
|
196
203
|
}
|
|
197
204
|
|
|
198
205
|
const controller = new ResourceController(resource);
|
|
199
|
-
const plan = await controller.plan({ type: 'type', propA: ['a', 'b'] } as any)
|
|
206
|
+
const plan = await controller.plan({ type: 'type' }, { propA: ['a', 'b'] } as any, null, false)
|
|
200
207
|
|
|
201
208
|
expect(plan).toMatchObject({
|
|
202
209
|
changeSet: {
|
|
@@ -230,7 +237,7 @@ describe('Resource parameter tests', () => {
|
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
const controller = new ResourceController(resource);
|
|
233
|
-
const plan = await controller.plan({ type: 'type', propA: ['a', 'b', 'c', 'd'] } as any)
|
|
240
|
+
const plan = await controller.plan({ type: 'type' }, { propA: ['a', 'b', 'c', 'd'] } as any, null, false)
|
|
234
241
|
|
|
235
242
|
expect(plan).toMatchObject({
|
|
236
243
|
changeSet: {
|
|
@@ -277,21 +284,25 @@ describe('Resource parameter tests', () => {
|
|
|
277
284
|
}
|
|
278
285
|
|
|
279
286
|
const controller = new ResourceController(resource);
|
|
280
|
-
const plan = await controller.plan(
|
|
281
|
-
type: 'type',
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
287
|
+
const plan = await controller.plan(
|
|
288
|
+
{ type: 'type' },
|
|
289
|
+
{
|
|
290
|
+
hosts: [
|
|
291
|
+
{
|
|
292
|
+
Host: 'new.com',
|
|
293
|
+
AddKeysToAgent: 'yes',
|
|
294
|
+
IdentityFile: '~/.ssh/id_ed25519'
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
Host: 'github.com',
|
|
298
|
+
AddKeysToAgent: 'yes',
|
|
299
|
+
UseKeychain: 'yes',
|
|
300
|
+
}
|
|
301
|
+
]
|
|
302
|
+
},
|
|
303
|
+
null,
|
|
304
|
+
false
|
|
305
|
+
);
|
|
295
306
|
|
|
296
307
|
expect(plan).toMatchObject({
|
|
297
308
|
'changeSet': {
|
|
@@ -361,7 +372,7 @@ describe('Resource parameter tests', () => {
|
|
|
361
372
|
}
|
|
362
373
|
|
|
363
374
|
const controller = new ResourceController(resource);
|
|
364
|
-
const plan = await controller.plan({ type: 'type', propA: ['3.11'] } as any)
|
|
375
|
+
const plan = await controller.plan({ type: 'type' }, { propA: ['3.11'] } as any, null, false)
|
|
365
376
|
|
|
366
377
|
expect(plan).toMatchObject({
|
|
367
378
|
changeSet: {
|
|
@@ -421,14 +432,17 @@ describe('Resource parameter tests', () => {
|
|
|
421
432
|
});
|
|
422
433
|
|
|
423
434
|
const controller = new ResourceController(resource)
|
|
424
|
-
const plan = await controller.plan(
|
|
425
|
-
type: 'resourceType',
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
435
|
+
const plan = await controller.plan(
|
|
436
|
+
{ type: 'resourceType' },
|
|
437
|
+
{
|
|
438
|
+
propA: 'propA',
|
|
439
|
+
propB: 10,
|
|
440
|
+
propC: 'propC',
|
|
441
|
+
propD: 'propD',
|
|
442
|
+
propE: 'propE',
|
|
443
|
+
}, null,
|
|
444
|
+
false
|
|
445
|
+
);
|
|
432
446
|
|
|
433
447
|
expect(plan.currentConfig?.propB).to.be.lessThan(plan.currentConfig?.propC as any);
|
|
434
448
|
expect(plan.currentConfig?.propC).to.be.lessThan(plan.currentConfig?.propA as any);
|
|
@@ -500,7 +514,7 @@ describe('Resource parameter tests', () => {
|
|
|
500
514
|
{ name: 'propB', operation: ParameterOperation.ADD, previousValue: null, newValue: null },
|
|
501
515
|
{ name: 'propC', operation: ParameterOperation.ADD, previousValue: null, newValue: null },
|
|
502
516
|
],
|
|
503
|
-
|
|
517
|
+
isStateful: false,
|
|
504
518
|
}, {}) as any
|
|
505
519
|
);
|
|
506
520
|
|
|
@@ -523,7 +537,7 @@ describe('Resource parameter tests', () => {
|
|
|
523
537
|
{ name: 'propB', operation: ParameterOperation.MODIFY, previousValue: null, newValue: null },
|
|
524
538
|
{ name: 'propC', operation: ParameterOperation.MODIFY, previousValue: null, newValue: null },
|
|
525
539
|
],
|
|
526
|
-
|
|
540
|
+
isStateful: false,
|
|
527
541
|
}, {}) as any
|
|
528
542
|
);
|
|
529
543
|
|
|
@@ -542,7 +556,7 @@ describe('Resource parameter tests', () => {
|
|
|
542
556
|
{ name: 'propB', operation: ParameterOperation.REMOVE, previousValue: null, newValue: null },
|
|
543
557
|
{ name: 'propC', operation: ParameterOperation.REMOVE, previousValue: null, newValue: null },
|
|
544
558
|
],
|
|
545
|
-
|
|
559
|
+
isStateful: false,
|
|
546
560
|
}, {}) as any
|
|
547
561
|
);
|
|
548
562
|
|
|
@@ -571,7 +585,7 @@ describe('Resource parameter tests', () => {
|
|
|
571
585
|
});
|
|
572
586
|
|
|
573
587
|
const controller = new ResourceController(resource);
|
|
574
|
-
const plan = await controller.plan({ type: 'resourceType', propC: 'abc' } as any);
|
|
588
|
+
const plan = await controller.plan({ type: 'resourceType' }, { propC: 'abc' } as any, null, false);
|
|
575
589
|
|
|
576
590
|
expect(resource.refresh.called).to.be.true;
|
|
577
591
|
expect(resource.refresh.getCall(0).firstArg['propA']).to.exist;
|
|
@@ -606,7 +620,7 @@ describe('Resource parameter tests', () => {
|
|
|
606
620
|
});
|
|
607
621
|
|
|
608
622
|
const controller = new ResourceController(resource);
|
|
609
|
-
const plan = await controller.plan(
|
|
623
|
+
const plan = await controller.plan({ type: 'resourceType' }, null, { propC: 'abc' }, true);
|
|
610
624
|
|
|
611
625
|
expect(resource.refresh.called).to.be.true;
|
|
612
626
|
expect(resource.refresh.getCall(0).firstArg['propA']).to.exist;
|
|
@@ -654,7 +668,7 @@ describe('Resource parameter tests', () => {
|
|
|
654
668
|
};
|
|
655
669
|
|
|
656
670
|
const controller = new ResourceController(resource);
|
|
657
|
-
const plan = await controller.plan({ type: 'resourceType', propA: '~/test/folder' } as any);
|
|
671
|
+
const plan = await controller.plan({ type: 'resourceType' }, { propA: '~/test/folder' } as any, null, false);
|
|
658
672
|
|
|
659
673
|
expect(plan.changeSet.parameterChanges[0]).toMatchObject({
|
|
660
674
|
operation: ParameterOperation.NOOP,
|
|
@@ -682,7 +696,7 @@ describe('Resource parameter tests', () => {
|
|
|
682
696
|
};
|
|
683
697
|
|
|
684
698
|
const controller = new ResourceController(resource);
|
|
685
|
-
const plan = await controller.plan({ type: 'resourceType', propA: 'setting', propB: 64 } as any);
|
|
699
|
+
const plan = await controller.plan({ type: 'resourceType' }, { propA: 'setting', propB: 64 } as any, null, false);
|
|
686
700
|
|
|
687
701
|
expect(plan.changeSet.parameterChanges).toMatchObject(
|
|
688
702
|
expect.arrayContaining([
|
|
@@ -741,7 +755,7 @@ describe('Resource parameter tests', () => {
|
|
|
741
755
|
|
|
742
756
|
const controller = new ResourceController(resource);
|
|
743
757
|
|
|
744
|
-
const result = await controller.plan({ type: 'resourceType', propA: '10.0' });
|
|
758
|
+
const result = await controller.plan({ type: 'resourceType' }, { propA: '10.0' }, null, false);
|
|
745
759
|
expect(result.changeSet).toMatchObject({
|
|
746
760
|
operation: ResourceOperation.NOOP,
|
|
747
761
|
})
|
|
@@ -771,14 +785,18 @@ describe('Resource parameter tests', () => {
|
|
|
771
785
|
|
|
772
786
|
const controller = new ResourceController(resource);
|
|
773
787
|
|
|
774
|
-
const result = await controller.plan(
|
|
775
|
-
type: 'resourceType',
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
788
|
+
const result = await controller.plan(
|
|
789
|
+
{ type: 'resourceType' },
|
|
790
|
+
{
|
|
791
|
+
propD: {
|
|
792
|
+
testC: 10,
|
|
793
|
+
testA: 'a',
|
|
794
|
+
testB: 'b',
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
null,
|
|
798
|
+
false
|
|
799
|
+
);
|
|
782
800
|
|
|
783
801
|
expect(result.changeSet).toMatchObject({
|
|
784
802
|
operation: ResourceOperation.NOOP,
|
|
@@ -808,14 +826,18 @@ describe('Resource parameter tests', () => {
|
|
|
808
826
|
|
|
809
827
|
const controller = new ResourceController(resource);
|
|
810
828
|
|
|
811
|
-
const result = await controller.plan(
|
|
812
|
-
type: 'resourceType',
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
829
|
+
const result = await controller.plan(
|
|
830
|
+
{ type: 'resourceType' },
|
|
831
|
+
{
|
|
832
|
+
propD: {
|
|
833
|
+
testC: 10,
|
|
834
|
+
testA: 'a',
|
|
835
|
+
testB: 'b',
|
|
836
|
+
}
|
|
837
|
+
},
|
|
838
|
+
null,
|
|
839
|
+
false
|
|
840
|
+
);
|
|
819
841
|
|
|
820
842
|
expect(result.changeSet).toMatchObject({
|
|
821
843
|
operation: ResourceOperation.RECREATE,
|
|
@@ -856,8 +878,9 @@ describe('Resource parameter tests', () => {
|
|
|
856
878
|
}
|
|
857
879
|
|
|
858
880
|
const controller = new ResourceController(resource);
|
|
859
|
-
await controller.plan(
|
|
860
|
-
type: 'resourceType',
|
|
881
|
+
await controller.plan(
|
|
882
|
+
{ type: 'resourceType' },
|
|
883
|
+
{
|
|
861
884
|
propD: [
|
|
862
885
|
{
|
|
863
886
|
Host: 'new.com',
|
|
@@ -874,13 +897,16 @@ describe('Resource parameter tests', () => {
|
|
|
874
897
|
PasswordAuthentication: true,
|
|
875
898
|
}
|
|
876
899
|
]
|
|
877
|
-
|
|
900
|
+
},
|
|
901
|
+
null,
|
|
902
|
+
false
|
|
903
|
+
);
|
|
878
904
|
|
|
879
905
|
})
|
|
880
906
|
|
|
881
907
|
it('Transforms input parameters for stateful parameters', async () => {
|
|
882
908
|
const sp = new class extends TestStatefulParameter {
|
|
883
|
-
getSettings():
|
|
909
|
+
getSettings(): any {
|
|
884
910
|
return {
|
|
885
911
|
type: 'array',
|
|
886
912
|
inputTransformation: (hosts: Record<string, unknown>[]) => hosts.map((h) => Object.fromEntries(
|
|
@@ -896,7 +922,7 @@ describe('Resource parameter tests', () => {
|
|
|
896
922
|
}
|
|
897
923
|
}
|
|
898
924
|
|
|
899
|
-
async refresh(desired: any): Promise<
|
|
925
|
+
async refresh(desired: any): Promise<any | null> {
|
|
900
926
|
expect(desired[0].AddKeysToAgent).to.eq('yes')
|
|
901
927
|
expect(desired[1].AddKeysToAgent).to.eq('yes')
|
|
902
928
|
expect(desired[1].UseKeychain).to.eq('yes')
|
|
@@ -918,25 +944,29 @@ describe('Resource parameter tests', () => {
|
|
|
918
944
|
}
|
|
919
945
|
|
|
920
946
|
const controller = new ResourceController(resource);
|
|
921
|
-
await controller.plan(
|
|
922
|
-
type: 'resourceType',
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
947
|
+
await controller.plan(
|
|
948
|
+
{ type: 'resourceType' },
|
|
949
|
+
{
|
|
950
|
+
propD: [
|
|
951
|
+
{
|
|
952
|
+
Host: 'new.com',
|
|
953
|
+
AddKeysToAgent: true,
|
|
954
|
+
IdentityFile: 'id_ed25519'
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
Host: 'github.com',
|
|
958
|
+
AddKeysToAgent: true,
|
|
959
|
+
UseKeychain: true,
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
Match: 'User bob,joe,phil',
|
|
963
|
+
PasswordAuthentication: true,
|
|
964
|
+
}
|
|
965
|
+
]
|
|
966
|
+
},
|
|
967
|
+
null,
|
|
968
|
+
false
|
|
969
|
+
);
|
|
940
970
|
|
|
941
971
|
})
|
|
942
972
|
})
|
|
@@ -34,7 +34,7 @@ describe('Stateful parameter tests', () => {
|
|
|
34
34
|
desired: null,
|
|
35
35
|
current: [{ propZ: ['a', 'b', 'c'] }],
|
|
36
36
|
state: { propZ: ['a', 'b', 'c'] },
|
|
37
|
-
|
|
37
|
+
isStateful: true,
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.DESTROY);
|
|
@@ -153,9 +153,12 @@ describe('Stateful parameter tests', () => {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
const controller = new ResourceController(resource);
|
|
156
|
-
const plan = await controller.plan(
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
const plan = await controller.plan(
|
|
157
|
+
{ type: 'type' },
|
|
158
|
+
{ nodeVersions: ['20.15'] } as any,
|
|
159
|
+
null,
|
|
160
|
+
false
|
|
161
|
+
)
|
|
159
162
|
|
|
160
163
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.NOOP);
|
|
161
164
|
})
|
|
@@ -188,9 +191,12 @@ describe('Stateful parameter tests', () => {
|
|
|
188
191
|
}
|
|
189
192
|
|
|
190
193
|
const controller = new ResourceController(resource);
|
|
191
|
-
const plan = await controller.plan(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
const plan = await controller.plan(
|
|
195
|
+
{ type: 'type' },
|
|
196
|
+
{ propA: '20.15', } as any,
|
|
197
|
+
null,
|
|
198
|
+
false
|
|
199
|
+
)
|
|
194
200
|
|
|
195
201
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.NOOP);
|
|
196
202
|
})
|
|
@@ -226,9 +232,12 @@ describe('Stateful parameter tests', () => {
|
|
|
226
232
|
}
|
|
227
233
|
|
|
228
234
|
const controller = new ResourceController(resource);
|
|
229
|
-
const plan = await controller.plan(
|
|
230
|
-
|
|
231
|
-
|
|
235
|
+
const plan = await controller.plan(
|
|
236
|
+
{ type: 'type' },
|
|
237
|
+
{ propA: ['20.15', '20.18'] } as any,
|
|
238
|
+
null,
|
|
239
|
+
false
|
|
240
|
+
)
|
|
232
241
|
|
|
233
242
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.NOOP);
|
|
234
243
|
})
|
|
@@ -12,17 +12,17 @@ export function testPlan<T extends StringIndexedObject>(params: {
|
|
|
12
12
|
state?: Partial<T> | null;
|
|
13
13
|
core?: ResourceConfig;
|
|
14
14
|
settings?: ResourceSettings<T>;
|
|
15
|
-
|
|
15
|
+
isStateful?: boolean;
|
|
16
16
|
}) {
|
|
17
17
|
return Plan.calculate({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
desired: params.desired ?? null,
|
|
19
|
+
currentArray: params.current ?? null,
|
|
20
|
+
state: params.state ?? null,
|
|
21
|
+
core: params.core ?? { type: 'type' },
|
|
22
22
|
settings: params.settings ?
|
|
23
23
|
new ParsedResourceSettings<T>(params.settings)
|
|
24
24
|
: new ParsedResourceSettings<T>({ id: 'type' }),
|
|
25
|
-
|
|
25
|
+
isStateful: params.isStateful ?? false,
|
|
26
26
|
})
|
|
27
27
|
}
|
|
28
28
|
|