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

chore: only load keytar during the migration process VSCODE-450 #572

Merged
merged 1 commit into from
Aug 7, 2023

Conversation

kmruiz
Copy link
Contributor

@kmruiz kmruiz commented Aug 2, 2023

Only load keytar during the migration of stored connections to process to the new SecretStorageAPI, maintained by the VSCode team. This is a requirement specified in VSCODE-450. This is related to #546.

Description

Keytar is removed from the activation of the plugin, and only loaded when the migration process starts.

Checklist

Motivation and Context

Please, see #546 for more information.

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@kmruiz kmruiz self-assigned this Aug 2, 2023
Copy link
Contributor

@himanshusinghs himanshusinghs left a comment

Choose a reason for hiding this comment

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

Looks good! 🎉
I was thinking, we probably won't need to assign the created keytar module to ext but that would also entail a bunch of refactoring in our tests. Maybe we can leave it as you have it right now, since it all will anyways be removed at some point.

@@ -13,7 +13,7 @@ import ConnectionString from 'mongodb-connection-string-url';
import { EventEmitter } from 'events';
import type { MongoClientOptions } from 'mongodb';
import { v4 as uuidv4 } from 'uuid';

import { createKeytar } from './utils/keytar';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we maybe update this model, so it remembers that keytar require failed once, and we don't try to resolve it again for each next connection that goes through the migration? With our webpack configuration, the failed require won't be cached:

vscode/webpack.config.js

Lines 75 to 76 in 711587b

strictModuleErrorHandling: true,
strictModuleExceptionHandling: true,

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way to handle it is to move the createKeytar call to the loadSavedConnections function, where can see if there are connections without secretStorageLocation and then try to require it once for the whole migration attempt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which of these solutions you think would be more valuable? From what I've understood, keytar is a deprecated feature, so all the code related to it will be removed at some point. IMO, I would just do whatever is cheaper and doesn't impact the user negatively.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would require it once in loadSavedConnections, but you can decide what works better implementation-wise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving it to loadSavedConnections needs some changes in the tests, as some of them fail.

I'll keep the current version and merge.

Thanks a lot!

Copy link
Contributor

@alenakhineika alenakhineika Aug 7, 2023

Choose a reason for hiding this comment

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

What will happen when vscode team removes keytar from vscode and there are migrations that require a migration? Are we ok with resolving the keytar module for each connection? Will this make the launch of the extension slower than it could be?

Copy link
Contributor

@alenakhineika alenakhineika Aug 7, 2023

Choose a reason for hiding this comment

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

Moving createKeytar to loadSavedConnections should note brake tests. Have you tried something like this?

async loadSavedConnections(): Promise<void> {
    const globalAndWorkspaceConnections = Object.entries({
      ...this._storageController.get(
        StorageVariables.GLOBAL_SAVED_CONNECTIONS,
        StorageLocation.GLOBAL
      ),
      ...this._storageController.get(
        StorageVariables.WORKSPACE_SAVED_CONNECTIONS,
        StorageLocation.WORKSPACE
      ),
    });

    const hasConnectionsThatDidNotMigrateEarlier =
      !!globalAndWorkspaceConnections.some(([, connectionInfo]) => !connectionInfo.storageLocation);

    if (hasConnectionsThatDidNotMigrateEarlier) {
      try {
        ext.keytarModule =
          ext.keytarModule === undefined ? createKeytar() : ext.keytarModule;
      } catch (err) {
        // Couldn't load keytar, proceed without storing & loading connections.
      }
    }

    ...
}

@kmruiz kmruiz merged commit 095a20b into main Aug 7, 2023
@kmruiz kmruiz deleted the chore/VSCODE-450 branch August 7, 2023 18:15
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.

3 participants