codify-plugin-lib 1.0.98 → 1.0.99
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/resource/parsed-resource-settings.js +20 -4
- package/dist/resource/resource-controller.js +4 -2
- package/dist/resource/resource-settings.d.ts +2 -1
- package/package.json +1 -1
- package/src/resource/parsed-resource-settings.test.ts +73 -5
- package/src/resource/parsed-resource-settings.ts +31 -5
- package/src/resource/resource-controller.ts +9 -7
- package/src/resource/resource-settings.test.ts +17 -0
- package/src/resource/resource-settings.ts +3 -1
|
@@ -115,10 +115,26 @@ export class ParsedResourceSettings {
|
|
|
115
115
|
'determine the prompt to ask users during imports. It can\'t parse which parameters are needed when ' +
|
|
116
116
|
'required is declared conditionally.');
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
if (this.settings.import) {
|
|
119
|
+
const { requiredParameters, refreshKeys, defaultRefreshValues } = this.settings.import;
|
|
120
|
+
const requiredParametersNotInSchema = requiredParameters
|
|
121
|
+
?.filter((p) => schema && !(schema.properties[p]));
|
|
122
|
+
if (schema && requiredParametersNotInSchema && requiredParametersNotInSchema.length > 0) {
|
|
123
|
+
throw new Error(`The following properties were declared in settings.import.requiredParameters but were not found in the schema:
|
|
124
|
+
${JSON.stringify(requiredParametersNotInSchema, null, 2)}`);
|
|
125
|
+
}
|
|
126
|
+
const refreshKeyNotInSchema = refreshKeys
|
|
127
|
+
?.filter((k) => schema && !(schema.properties[k]));
|
|
128
|
+
if (schema && refreshKeyNotInSchema && refreshKeyNotInSchema.length > 0) {
|
|
129
|
+
throw new Error(`The following properties were declared in settings.import.refreshKeys but were not found in the schema:
|
|
130
|
+
${JSON.stringify(requiredParametersNotInSchema, null, 2)}`);
|
|
131
|
+
}
|
|
132
|
+
const refreshValueNotInRefreshKey = Object.entries(defaultRefreshValues ?? {})
|
|
133
|
+
.filter(([k]) => schema && !(schema.properties[k])).map(([k]) => k);
|
|
134
|
+
if (schema && refreshValueNotInRefreshKey.length > 0) {
|
|
135
|
+
throw new Error(`Properties declared in defaultRefreshValues must already be declared in refreshKeys:
|
|
136
|
+
${JSON.stringify(refreshValueNotInRefreshKey, null, 2)}`);
|
|
137
|
+
}
|
|
122
138
|
}
|
|
123
139
|
}
|
|
124
140
|
validateParameterEqualsFn(parameter, key) {
|
|
@@ -134,13 +134,15 @@ export class ResourceController {
|
|
|
134
134
|
this.addDefaultValues(config);
|
|
135
135
|
await this.applyTransformParameters(config);
|
|
136
136
|
// Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
|
|
137
|
-
const parametersToRefresh = this.settings.import?.
|
|
137
|
+
const parametersToRefresh = this.settings.import?.refreshKeys
|
|
138
138
|
? {
|
|
139
|
-
...Object.fromEntries(this.settings.import?.
|
|
139
|
+
...Object.fromEntries(this.settings.import?.refreshKeys.map((k) => [k, null])),
|
|
140
|
+
...this.settings.import?.defaultRefreshValues,
|
|
140
141
|
...config,
|
|
141
142
|
}
|
|
142
143
|
: {
|
|
143
144
|
...Object.fromEntries(this.getAllParameterKeys().map((k) => [k, null])),
|
|
145
|
+
...this.settings.import?.defaultRefreshValues,
|
|
144
146
|
...config,
|
|
145
147
|
};
|
|
146
148
|
// Parse data from the user supplied config
|
|
@@ -54,7 +54,8 @@ export interface ResourceSettings<T extends StringIndexedObject> {
|
|
|
54
54
|
inputTransformation?: (desired: Partial<T>) => Promise<unknown> | unknown;
|
|
55
55
|
import?: {
|
|
56
56
|
requiredParameters?: Array<Partial<keyof T>>;
|
|
57
|
-
|
|
57
|
+
refreshKeys?: Array<Partial<keyof T>>;
|
|
58
|
+
defaultRefreshValues?: Partial<T>;
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
/**
|
package/package.json
CHANGED
|
@@ -63,19 +63,16 @@ describe('Resource options parser tests', () => {
|
|
|
63
63
|
schema,
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
expect(() => new ParsedResourceSettings(option)).
|
|
66
|
+
expect(() => new ParsedResourceSettings(option)).toThrowError();
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
it('Throws an error when an import.requiredParameters is declared improperly', () => {
|
|
70
70
|
const schema = {
|
|
71
71
|
'$schema': 'http://json-schema.org/draft-07/schema',
|
|
72
|
-
'$id': 'https://www.codifycli.com/git-clone.json',
|
|
73
|
-
'title': 'Git-clone resource',
|
|
74
72
|
'type': 'object',
|
|
75
73
|
'properties': {
|
|
76
74
|
'remote': {
|
|
77
75
|
'type': 'string',
|
|
78
|
-
'description': 'Remote tracking url to clone repo from. Equivalent to repository and only one should be specified'
|
|
79
76
|
},
|
|
80
77
|
},
|
|
81
78
|
'additionalProperties': false,
|
|
@@ -89,6 +86,77 @@ describe('Resource options parser tests', () => {
|
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
|
|
92
|
-
expect(() => new ParsedResourceSettings(option)).
|
|
89
|
+
expect(() => new ParsedResourceSettings(option)).toThrowError();
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('Throws an error when an import.refreshKeys is declared improperly', () => {
|
|
93
|
+
const schema = {
|
|
94
|
+
'$schema': 'http://json-schema.org/draft-07/schema',
|
|
95
|
+
'type': 'object',
|
|
96
|
+
'properties': {
|
|
97
|
+
'remote': {
|
|
98
|
+
'type': 'string',
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
'additionalProperties': false,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const option: ResourceSettings<TestConfig> = {
|
|
105
|
+
id: 'typeId',
|
|
106
|
+
schema,
|
|
107
|
+
import: {
|
|
108
|
+
refreshKeys: ['import-error']
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
expect(() => new ParsedResourceSettings(option)).toThrowError();
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('Doesn\'t throw an error when an import.refreshValues is declared properly', () => {
|
|
116
|
+
const schema = {
|
|
117
|
+
'$schema': 'http://json-schema.org/draft-07/schema',
|
|
118
|
+
'type': 'object',
|
|
119
|
+
'properties': {
|
|
120
|
+
'remote': {
|
|
121
|
+
'type': 'string',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
'additionalProperties': false,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const option: ResourceSettings<TestConfig> = {
|
|
128
|
+
id: 'typeId',
|
|
129
|
+
schema,
|
|
130
|
+
import: {
|
|
131
|
+
refreshKeys: ['remote'],
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
expect(() => new ParsedResourceSettings(option)).not.toThrowError()
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('Throws an error if defaultRefreshValue is not found in refreshKeys', () => {
|
|
139
|
+
const schema = {
|
|
140
|
+
'$schema': 'http://json-schema.org/draft-07/schema',
|
|
141
|
+
'type': 'object',
|
|
142
|
+
'properties': {
|
|
143
|
+
'remote': {
|
|
144
|
+
'type': 'string',
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
'additionalProperties': false,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const option: ResourceSettings<TestConfig> = {
|
|
151
|
+
id: 'typeId',
|
|
152
|
+
schema,
|
|
153
|
+
import: {
|
|
154
|
+
defaultRefreshValues: {
|
|
155
|
+
repository: 'abc'
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
expect(() => new ParsedResourceSettings(option)).toThrowError()
|
|
93
161
|
})
|
|
94
162
|
})
|
|
@@ -167,11 +167,37 @@ export class ParsedResourceSettings<T extends StringIndexedObject> implements Re
|
|
|
167
167
|
)
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
this.settings.import
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
if (this.settings.import) {
|
|
171
|
+
const { requiredParameters, refreshKeys, defaultRefreshValues } = this.settings.import;
|
|
172
|
+
|
|
173
|
+
const requiredParametersNotInSchema = requiredParameters
|
|
174
|
+
?.filter(
|
|
175
|
+
(p) => schema && !(schema.properties[p])
|
|
176
|
+
)
|
|
177
|
+
if (schema && requiredParametersNotInSchema && requiredParametersNotInSchema.length > 0) {
|
|
178
|
+
throw new Error(`The following properties were declared in settings.import.requiredParameters but were not found in the schema:
|
|
179
|
+
${JSON.stringify(requiredParametersNotInSchema, null, 2)}`)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const refreshKeyNotInSchema = refreshKeys
|
|
183
|
+
?.filter(
|
|
184
|
+
(k) => schema && !(schema.properties[k])
|
|
185
|
+
)
|
|
186
|
+
if (schema && refreshKeyNotInSchema && refreshKeyNotInSchema.length > 0) {
|
|
187
|
+
throw new Error(`The following properties were declared in settings.import.refreshKeys but were not found in the schema:
|
|
188
|
+
${JSON.stringify(requiredParametersNotInSchema, null, 2)}`)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const refreshValueNotInRefreshKey =
|
|
192
|
+
Object.entries(defaultRefreshValues ?? {})
|
|
193
|
+
.filter(
|
|
194
|
+
([k]) => schema && !(schema.properties[k])
|
|
195
|
+
).map(([k]) => k)
|
|
196
|
+
|
|
197
|
+
if (schema && refreshValueNotInRefreshKey.length > 0) {
|
|
198
|
+
throw new Error(`Properties declared in defaultRefreshValues must already be declared in refreshKeys:
|
|
199
|
+
${JSON.stringify(refreshValueNotInRefreshKey, null, 2)}`)
|
|
200
|
+
}
|
|
175
201
|
}
|
|
176
202
|
}
|
|
177
203
|
|
|
@@ -190,19 +190,21 @@ export class ResourceController<T extends StringIndexedObject> {
|
|
|
190
190
|
await this.applyTransformParameters(config);
|
|
191
191
|
|
|
192
192
|
// Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
|
|
193
|
-
const parametersToRefresh = this.settings.import?.
|
|
193
|
+
const parametersToRefresh = this.settings.import?.refreshKeys
|
|
194
194
|
? {
|
|
195
195
|
...Object.fromEntries(
|
|
196
|
-
this.settings.import?.
|
|
196
|
+
this.settings.import?.refreshKeys.map((k) => [k, null])
|
|
197
197
|
),
|
|
198
|
+
...this.settings.import?.defaultRefreshValues,
|
|
198
199
|
...config,
|
|
199
200
|
}
|
|
200
201
|
: {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
...Object.fromEntries(
|
|
203
|
+
this.getAllParameterKeys().map((k) => [k, null])
|
|
204
|
+
),
|
|
205
|
+
...this.settings.import?.defaultRefreshValues,
|
|
206
|
+
...config,
|
|
207
|
+
};
|
|
206
208
|
|
|
207
209
|
// Parse data from the user supplied config
|
|
208
210
|
const parsedConfig = new ConfigParser(parametersToRefresh, null, this.parsedSettings.statefulParameters)
|
|
@@ -612,4 +612,21 @@ describe('Resource parameter tests', () => {
|
|
|
612
612
|
|
|
613
613
|
expect(plan.changeSet.operation).to.eq(ResourceOperation.NOOP);
|
|
614
614
|
})
|
|
615
|
+
|
|
616
|
+
it('Accepts an input parameters for imports', () => {
|
|
617
|
+
const resource = new class extends TestResource {
|
|
618
|
+
getSettings(): ResourceSettings<TestConfig> {
|
|
619
|
+
return {
|
|
620
|
+
id: 'resourceType',
|
|
621
|
+
import: {
|
|
622
|
+
requiredParameters: ['propA'],
|
|
623
|
+
refreshKeys: ['propB', 'propA'],
|
|
624
|
+
defaultRefreshValues: {
|
|
625
|
+
propB: 6,
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
})
|
|
615
632
|
})
|
|
@@ -68,7 +68,9 @@ export interface ResourceSettings<T extends StringIndexedObject> {
|
|
|
68
68
|
import?: {
|
|
69
69
|
requiredParameters?: Array<Partial<keyof T>>;
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
refreshKeys?: Array<Partial<keyof T>>;
|
|
72
|
+
|
|
73
|
+
defaultRefreshValues?: Partial<T>
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|