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

VSCODE-311: new data service and connection model #377

Merged

Conversation

alenakhineika
Copy link
Contributor

@alenakhineika alenakhineika commented Dec 16, 2021

Description

Switch to a new connection info format. The new data service is using a new connection info object that should be adopted by the extension and used to connect and save connections.

VSCode should start using a new connection info object for the saved connections including migration of previously saved connections to a new format and using the connection-secrets module from Compass to protect all secrets.

  • VSCODE-312 - Switch to a new data service and connection model
  • VSCODE-313 - Use the connection-secrets module to protect all secrets
  • VSCODE-314 - Transform previously saved connections to a new format

I also removed LSP inspector since the webview extension is buggy and doesn't work almost all the time.

It also fixes #383.

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Dependents

Dependent on mongodb-js/compass#2650

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)

@alenakhineika alenakhineika added WIP and removed WIP labels Dec 16, 2021
@alenakhineika alenakhineika removed the WIP label Dec 17, 2021
Copy link
Contributor

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Nice work! Took a first look at everything, but I think I’ll need to spend a bit more time before I can say that I fully follow the data flow everywhere :)

src/commands/launchMongoShell.ts Outdated Show resolved Hide resolved
src/commands/launchMongoShell.ts Outdated Show resolved Hide resolved
src/commands/launchMongoShell.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/explorer/indexListTreeItem.ts Outdated Show resolved Hide resolved
src/language/languageServerController.ts Outdated Show resolved Hide resolved
src/language/mongoDBService.ts Outdated Show resolved Hide resolved
@alenakhineika alenakhineika removed the WIP label Dec 20, 2021
Copy link
Contributor

@addaleax addaleax 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 left a few more comments, but they are mostly non-blocking, and in any case, nothing larger.

One thing I’m curious about: Is there a specfic reason for keeping the connections in memory in ConnectionController._connections, instead of always accessing them through the storage API? I’m not saying we should change this, I’m just wondering 🙂

src/storage/storageController.ts Outdated Show resolved Hide resolved
src/storage/storageController.ts Outdated Show resolved Hide resolved
src/storage/storageController.ts Show resolved Hide resolved
src/storage/storageController.ts Outdated Show resolved Hide resolved
src/telemetry/connectionTelemetry.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
newConnectionModel
);
parseNewConnection(rawConnectionModel: RawConnectionModel): ConnectionInfo {
const connectionModel = new ConnectionModel(rawConnectionModel);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is the part where we’re not sure about whether it’s alright to keep going with ConnectionModel? I would think it’s okay, yeah. We should probably just leave a ticket about eventually removing it. (But it might be nice if @Anemy could confirm this 🙂)

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine yup. It's probably not worth adding all the logic to build the connectionInfo from the connection configuration object the form in the webview creates. Would be nice to remove this usage of connection-model eventually, and this would definitely be something that sharing the connect form would help make go away as well.

src/views/webviewController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
src/connectionController.ts Outdated Show resolved Hide resolved
return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"';
try {
// eslint-disable-next-line no-new
new ConnectionString(uri);
Copy link
Member

Choose a reason for hiding this comment

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

I like this change, but I'm wondering if the old one, although not as good of a validation check, might give a user unsure what to enter in something more information to help their case.
Mostly if they input something like a url but is invalid they'd get an Invalid connection string error message which doesn't hint at what might go there. https://github.com/mongodb-js/mongodb-connection-string-url/blob/main/src/index.ts#L106
Maybe something for that package instead of here. We do have a placeholder here that should give those users something to go off of so this may be a non-issue.

Copy link
Contributor Author

@alenakhineika alenakhineika Dec 21, 2021

Choose a reason for hiding this comment

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

@addaleax what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can definitely see the concern here – if you want to keep the previous check additionally (i.e. add

          if (!uri.startsWith('mongodb://') && !uri.startsWith('mongodb+srv://')) {
            return 'MongoDB connection strings begin with "mongodb://" or "mongodb+srv://"';

before the new ConnectionString check), I think that’s okay and won’t make anything worse, but I also honestly think that this isn’t something we need to worry about a ton, and I do agree with @Anemy that it would be a bit nicer to improve the error message inside the connection string url package as a long-term solution 🙂

@alenakhineika
Copy link
Contributor Author

alenakhineika commented Dec 20, 2021

@addaleax Answering your question why we keep connections in memory: first of all, I didn't change this logic in this pr, this worked like this before. But was thinking about it while refactoring and kept like this because of two reasons:

  • to fetch all connections at once with secrets to migrate them to a new format and then use them to seamlessly switch between connections without accessing a keychain, and allow users to copy URLs for connections on the sidebar also without accessing the keychain.
  • In the scope, we defined a goal that Compass and VSCodeshould use a single shared entry in the OS keychain for all saved connections. It means that the password to the keychain will be requested only once and then used for all saved connections. So in the future, we also will fetch everything at once and I believe store it in memory to not reenter the password for the keychain, therefore it felt like a good idea to keep them in memory for now as well.

We also discusses it with Maurizio and as I remember he was also up to pulling them all together. I am open here for a discussion if you have a strong opinion to do it differently!

@alenakhineika alenakhineika requested a review from Anemy December 21, 2021 16:30
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

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

nice work - big changes that touch almost all the extension. Solid cleanup on the language server.

@@ -106,44 +80,18 @@ export default class ConnectionTreeItem extends vscode.TreeItem
return element;
}

async listDatabasesUserHasAccessTo(
Copy link
Member

Choose a reason for hiding this comment

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

Cool that we're sharing this with compass now 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I was very excited to see this change in compass and know the fact that we can reuse it in vscode!

@alenakhineika alenakhineika merged commit ff15215 into main Jan 7, 2022
@alenakhineika alenakhineika deleted the VSCODE-312-switch-to-new-data-service-and-model-v2 branch January 7, 2022 19:53
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.

Improperly encoded URI does not give an error
4 participants