Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"codify-schemas": "1.0.76",
"codify-schemas": "1.0.77",
"@npmcli/promise-spawn": "^7.0.1",
"@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
"uuid": "^10.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/messages/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ class CodifyCliSenderImpl {
})
}

async getCodifyCliCredentials(): Promise<string> {
const data = await this.sendAndWaitForResponse(<IpcMessageV2>{
cmd: MessageCmd.CODIFY_CREDENTIALS_REQUEST,
data: {},
})

if (typeof data.data !== 'string') {
throw new Error('Expected string back from credentials request');
}

return data.data;
}

private async sendAndWaitForResponse(message: IpcMessageV2): Promise<IpcMessageV2> {
return new Promise((resolve) => {
const requestId = nanoid(8);
Expand Down
22 changes: 11 additions & 11 deletions src/resource/resource-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class ResourceController<T extends StringIndexedObject> {
parameters: Partial<T>,
): Promise<ValidateResponseData['resourceValidations'][0]> {
const originalParameters = structuredClone(parameters);
await this.applyTransformParameters(parameters);
await this.applyTransformations(parameters, undefined, true);
this.addDefaultValues(parameters);

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

this.addDefaultValues(originalParams);
await this.applyTransformParameters(originalParams);
await this.applyTransformations(originalParams);

this.addDefaultValues(paramsToMatch);
await this.applyTransformParameters(paramsToMatch);
await this.applyTransformations(paramsToMatch);

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

this.addDefaultValues(desired);
await this.applyTransformParameters(desired);
await this.applyTransformations(desired);

this.addDefaultValues(state);
await this.applyTransformParameters(state);
await this.applyTransformations(state);

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

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

this.addDefaultValues(parameters);
await this.applyTransformParameters(parameters);
await this.applyTransformations(parameters);

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

for (const result of resultParametersArray) {
await this.applyTransformParameters(result, { original: context.originalDesiredConfig });
await this.applyTransformations(result, { original: context.originalDesiredConfig });
this.removeDefaultValues(result, parameters);
}

Expand Down Expand Up @@ -408,9 +408,9 @@ ${JSON.stringify(refresh, null, 2)}
}
}

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

if (this.settings.transformation) {
if (this.settings.transformation && !skipConfigTransformation) {
const transformed = reverse
? await this.settings.transformation.from({ ...config }, reverse.original)
: await this.settings.transformation.to({ ...config })
Expand Down