Skip to content

Commit d3938fa

Browse files
feat: Add ability to request codify credentials (#16)
1 parent 1952d09 commit d3938fa

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

package-lock.json

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"ajv": "^8.12.0",
1818
"ajv-formats": "^2.1.1",
19-
"codify-schemas": "1.0.76",
19+
"codify-schemas": "1.0.77",
2020
"@npmcli/promise-spawn": "^7.0.1",
2121
"@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
2222
"uuid": "^10.0.0",

src/messages/sender.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ class CodifyCliSenderImpl {
2121
})
2222
}
2323

24+
async getCodifyCliCredentials(): Promise<string> {
25+
const data = await this.sendAndWaitForResponse(<IpcMessageV2>{
26+
cmd: MessageCmd.CODIFY_CREDENTIALS_REQUEST,
27+
data: {},
28+
})
29+
30+
if (typeof data.data !== 'string') {
31+
throw new Error('Expected string back from credentials request');
32+
}
33+
34+
return data.data;
35+
}
36+
2437
private async sendAndWaitForResponse(message: IpcMessageV2): Promise<IpcMessageV2> {
2538
return new Promise((resolve) => {
2639
const requestId = nanoid(8);

src/resource/resource-controller.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class ResourceController<T extends StringIndexedObject> {
5959
parameters: Partial<T>,
6060
): Promise<ValidateResponseData['resourceValidations'][0]> {
6161
const originalParameters = structuredClone(parameters);
62-
await this.applyTransformParameters(parameters);
62+
await this.applyTransformations(parameters, undefined, true);
6363
this.addDefaultValues(parameters);
6464

6565
if (this.schemaValidator) {
@@ -143,10 +143,10 @@ export class ResourceController<T extends StringIndexedObject> {
143143
const paramsToMatch = structuredClone(resourceToMatch.parameters) as Partial<T>;
144144

145145
this.addDefaultValues(originalParams);
146-
await this.applyTransformParameters(originalParams);
146+
await this.applyTransformations(originalParams);
147147

148148
this.addDefaultValues(paramsToMatch);
149-
await this.applyTransformParameters(paramsToMatch);
149+
await this.applyTransformations(paramsToMatch);
150150

151151
const match = parameterMatcher(originalParams, paramsToMatch);
152152
if (match) {
@@ -170,10 +170,10 @@ export class ResourceController<T extends StringIndexedObject> {
170170
};
171171

172172
this.addDefaultValues(desired);
173-
await this.applyTransformParameters(desired);
173+
await this.applyTransformations(desired);
174174

175175
this.addDefaultValues(state);
176-
await this.applyTransformParameters(state);
176+
await this.applyTransformations(state);
177177

178178
// Parse data from the user supplied config
179179
const parsedConfig = new ConfigParser(desired, state, this.parsedSettings.statefulParameters)
@@ -221,7 +221,7 @@ export class ResourceController<T extends StringIndexedObject> {
221221
parameters: Partial<T>
222222
): Promise<Plan<T>> {
223223
this.addDefaultValues(parameters);
224-
await this.applyTransformParameters(parameters);
224+
await this.applyTransformations(parameters);
225225

226226
// Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
227227
const parametersToRefresh = this.settings.importAndDestroy?.refreshKeys
@@ -298,7 +298,7 @@ export class ResourceController<T extends StringIndexedObject> {
298298
}
299299

300300
this.addDefaultValues(parameters);
301-
await this.applyTransformParameters(parameters);
301+
await this.applyTransformations(parameters);
302302

303303
// Use refresh parameters if specified, otherwise try to refresh as many parameters as possible here
304304
const parametersToRefresh = this.getParametersToRefreshForImport(parameters, context);
@@ -325,7 +325,7 @@ export class ResourceController<T extends StringIndexedObject> {
325325
?.map((r, idx) => ({ ...r, ...statefulCurrentParameters[idx] }))
326326

327327
for (const result of resultParametersArray) {
328-
await this.applyTransformParameters(result, { original: context.originalDesiredConfig });
328+
await this.applyTransformations(result, { original: context.originalDesiredConfig });
329329
this.removeDefaultValues(result, parameters);
330330
}
331331

@@ -408,9 +408,9 @@ ${JSON.stringify(refresh, null, 2)}
408408
}
409409
}
410410

411-
private async applyTransformParameters(config: Partial<T> | null, reverse?: {
411+
private async applyTransformations(config: Partial<T> | null, reverse?: {
412412
original: Partial<T> | null
413-
}): Promise<void> {
413+
}, skipConfigTransformation = false): Promise<void> {
414414
if (!config) {
415415
return;
416416
}
@@ -425,7 +425,7 @@ ${JSON.stringify(refresh, null, 2)}
425425
: await inputTransformation.to(config[key]);
426426
}
427427

428-
if (this.settings.transformation) {
428+
if (this.settings.transformation && !skipConfigTransformation) {
429429
const transformed = reverse
430430
? await this.settings.transformation.from({ ...config }, reverse.original)
431431
: await this.settings.transformation.to({ ...config })

0 commit comments

Comments
 (0)