Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish reading deployment profiles from the Windows registry #4251

Merged
merged 3 commits into from
May 12, 2023

Conversation

ericpromislow
Copy link
Contributor

@ericpromislow ericpromislow commented Mar 21, 2023

Fixes #4153
Fixes #4193

@ericpromislow ericpromislow requested a review from mook-as March 21, 2023 23:16
@ericpromislow ericpromislow marked this pull request as draft March 22, 2023 00:06
@ericpromislow ericpromislow marked this pull request as ready for review March 22, 2023 00:16
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is missing tests. Actually, we should have tests in a separate PR, and merge that before this one.

pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from a97fdca to 1691e41 Compare March 23, 2023 23:32
@ericpromislow ericpromislow marked this pull request as draft March 24, 2023 18:33
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 7bca028 to d2f8831 Compare April 27, 2023 21:45
@ericpromislow ericpromislow changed the base branch from main to 4209-handle-bad-linux-deployment-files April 27, 2023 21:59
@ericpromislow ericpromislow force-pushed the 4209-handle-bad-linux-deployment-files branch from 16cb99e to f634529 Compare April 28, 2023 18:50
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 53c0ac5 to ea0a4f1 Compare April 28, 2023 20:33
@ericpromislow ericpromislow changed the base branch from 4209-handle-bad-linux-deployment-files to 4579-load-user-defined-deployment-settings April 28, 2023 20:33
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch 2 times, most recently from 0133e77 to 27bb153 Compare April 28, 2023 23:15
@ericpromislow ericpromislow force-pushed the 4579-load-user-defined-deployment-settings branch from 23a2b17 to ab9f223 Compare April 28, 2023 23:34
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 27bb153 to 2ee51de Compare April 28, 2023 23:34
@ericpromislow ericpromislow requested a review from mook-as April 28, 2023 23:38
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 67dd43a to 72e6f2e Compare April 29, 2023 00:12
@ericpromislow ericpromislow marked this pull request as ready for review May 1, 2023 17:47
@ericpromislow ericpromislow marked this pull request as draft May 1, 2023 18:00
@ericpromislow ericpromislow force-pushed the 4579-load-user-defined-deployment-settings branch from ab9f223 to a6c769d Compare May 1, 2023 21:30
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from bcdfafc to 0f42874 Compare May 2, 2023 19:28
Base automatically changed from 4579-load-user-defined-deployment-settings to main May 2, 2023 20:21
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch 3 times, most recently from 1e97704 to 03bc6a0 Compare May 3, 2023 00:08
@ericpromislow ericpromislow marked this pull request as ready for review May 3, 2023 00:09
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 03bc6a0 to 9c0c48a Compare May 3, 2023 00:22
@ericpromislow ericpromislow marked this pull request as draft May 3, 2023 17:03
@ericpromislow ericpromislow marked this pull request as ready for review May 3, 2023 18:46
@ericpromislow ericpromislow marked this pull request as draft May 3, 2023 18:51
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch 2 times, most recently from 3a79099 to 2e11979 Compare May 3, 2023 19:49
@ericpromislow ericpromislow marked this pull request as ready for review May 3, 2023 19:52
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 2e11979 to fe879d4 Compare May 4, 2023 17:06
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unflagging for review because this keeps being changed

@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch 3 times, most recently from 0c6faec to a9bba89 Compare May 5, 2023 19:18
@ericpromislow ericpromislow requested a review from mook-as May 5, 2023 19:35
@ericpromislow
Copy link
Contributor Author

Keep in mind that the follow-up PR #4612 will display deployment profile type-errors in a dialog box and then shut down.

This PR is about doing a better job of reading deployment profiles, and it also recognizes the "special objects", like WSL.integrations

pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
Comment on lines 223 to 219
registryKeysFixedCase.forEach((key, index) => {
const originalKey = registryKeys[index];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to ever need index again, and registryKeysFixedCase is only used here.
I think the code would be a lot easier to understand as:

Suggested change
registryKeysFixedCase.forEach((key, index) => {
const originalKey = registryKeys[index];
for (const originalKey of Object.keys(schemaObj)) {
const key = fixProfileKeyCase(originalKey, schemaKeys);

Looking at the loop over commonKeys, it's probably better to call these schemaKey and registryKey, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this approach, you're not going to find keys that are in the registry instance but aren't in the schema.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, how about:

    for (const originalKey of nativeReg.enumKeyNames(regKey)) {
      const key = fixProfileKeyCase(originalKey, schemaKeys);

(You'll notice that my original code is wrong anyway, passing a key of schemaObj to fixProfileKeyCase doesn't make sense…)

pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
const registryValueNames = nativeReg.enumValueNames(regKey);
const registryValueNamesFixedCase = registryValueNames.map(k => fixProfileKeyCase(k, schemaKeys));

registryValueNamesFixedCase.forEach((key, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above — for (const originalName of nativeReg.enumValueNames(regKey) { const key = fixProfileKeyCase(originalName, schemaKeys);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And same as above, if we walk the schema instead of the registry we miss undefined entries

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! My suggestion here was correct (enumerating over the result of enumValueNames).

pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch 2 times, most recently from 4b25702 to 2f50bbc Compare May 9, 2023 19:43
@ericpromislow ericpromislow requested a review from mook-as May 9, 2023 21:52
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this type checking makes me think we should just pull in the schema validator we already use for the HTTP API. We may need to massage it to be usable here, though. Also, that can be a follow-up PR.

pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from c7f0b22 to d8b9be9 Compare May 12, 2023 01:01
@ericpromislow ericpromislow requested a review from mook-as May 12, 2023 01:01
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing major left, just some nits. The main changes are just in the test.

// Drop the initial 'defaults' or 'locked' field
const pathPartsWithoutHiveType = pathParts.slice(1);

for (const originalKey of nativeReg.enumKeyNames(regKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const originalKey of nativeReg.enumKeyNames(regKey)) {
for (const registryKey of nativeReg.enumKeyNames(regKey)) {

Since that makes it easier when we push to userDefinedObjectKeys/commonKeys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

pkg/rancher-desktop/main/deploymentProfiles.ts Outdated Show resolved Hide resolved
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from 8d35f55 to cbfd7bf Compare May 12, 2023 18:18
- Don't complain about any entries in the settings schema that aren't in the registry.
- Treat `WSL/integrations`, `extensions`, and `diagnostics/mutedChecks` as hashes
- Registry keys and value names are case-insensitive
- Do type-based parsing of raw registry values.
- There's no need to do post-input validation of registry data. The reader validates as it goes.
- Convert 0s and 1s in user-defined objects into booleans.

Currently if there are certain errors in a deployment profile,
such as unrecognized names or type mismatches, we log them but
they aren't fatal, and aren't shown in a dialog box.

These will be raised into dialog boxes with fatal errors in a subsequent PR.

Signed-off-by: Eric Promislow <[email protected]>
- Use case-sensitive checks for user-defined objects.
  We've already normalized the case of the registry field, so can use === to compare.

- The reg file can be ascii-encoded.

Any non-ascii characters should appear only inside SZ strings and be hex-encoded.
All the names in the schema can be represented in 7-bit ASCII characters so there's
no need to support other encodings.

Signed-off-by: Eric Promislow <[email protected]>
@ericpromislow ericpromislow force-pushed the 4193-registry-profile-improvements branch from cbfd7bf to cf06fdc Compare May 12, 2023 18:20
@ericpromislow ericpromislow requested a review from mook-as May 12, 2023 18:49
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I have a couple comments, they don't block merging.

await fs.promises.rm(testDir, { force: true, recursive: true });
consoleMock.mockReset();
});
// TODO: Add an `afterAll(clearRegistry)` when we're finished developing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean we should do it before the PR merges?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there are still at least two more PRs to come after this one.


return false;
function haveUserDefinedObject(pathParts: string[]): boolean {
return userDefinedKeys.some(userDefinedKey => _.isEqual(userDefinedKey, pathParts));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-lodash way would be

const userDefinedKeys = ['extensions', 'WSL.integrations', 'diagnostics.mutedChecks'];

function haveUserDefinedObject(pathParts: string[]): boolean {
  return userDefinedKeys.includes(pathParts.join('.'));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then you're always joining an array to create a string, and I'm going to assume lodash's way of doing the comparison will be faster, since it will eliminate different-size arrays and fail on the different in the first string right away.

The diff is probably miniscule in the scheme of things anyway.

@ericpromislow ericpromislow merged commit 7a2d611 into main May 12, 2023
@jandubois jandubois deleted the 4193-registry-profile-improvements branch June 12, 2023 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deployment profile behavior on Windows Improve the registry reader
2 participants