mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -05:00
CMS - SQL Login (#5989)
* initial SQL Login with save password working * fix switching auth types * remove metadata from package file * allow editing connections for unsaved password connections * review comments * change thenables to async/awaits * review comments * changed thenables to promises * remove authTypeChanged bool * removed unused import * review comments * removed try catches * cr comments * review comments
This commit is contained in:
@@ -18,40 +18,37 @@ const localize = nls.loadMessageBundle();
|
||||
|
||||
export function registerCmsServerCommand(appContext: AppContext, tree: CmsResourceTreeProvider): void {
|
||||
// Create a CMS Server
|
||||
appContext.apiWrapper.registerCommand('cms.resource.registerCmsServer', async (node?: TreeNode) => {
|
||||
appContext.apiWrapper.registerCommand('cms.resource.registerCmsServer', async (node?: TreeNode, connectionProfile?: azdata.IConnectionProfile) => {
|
||||
if (node && !(node instanceof CmsResourceEmptyTreeNode)) {
|
||||
return;
|
||||
}
|
||||
await appContext.cmsUtils.connection.then(async (connection) => {
|
||||
if (connection && connection.options) {
|
||||
let registeredCmsServerName = connection.options.registeredServerName ?
|
||||
connection.options.registeredServerName : connection.options.server;
|
||||
// check if a CMS with the same name is registered or not
|
||||
let cachedServers = appContext.cmsUtils.registeredCmsServers;
|
||||
let serverExists: boolean = false;
|
||||
if (cachedServers) {
|
||||
serverExists = cachedServers.some((server) => {
|
||||
return server.name === registeredCmsServerName;
|
||||
});
|
||||
}
|
||||
if (!serverExists) {
|
||||
// remove any group ID if user selects a connection from
|
||||
// recent connection list
|
||||
connection.options.groupId = null;
|
||||
let registeredCmsServerDescription = connection.options.registeredServerDescription;
|
||||
// remove server description from connection uri
|
||||
connection.options.registeredCmsServerDescription = null;
|
||||
let ownerUri = await azdata.connection.getUriForConnection(connection.connectionId);
|
||||
appContext.cmsUtils.cacheRegisteredCmsServer(registeredCmsServerName, registeredCmsServerDescription, ownerUri, connection);
|
||||
tree.notifyNodeChanged(undefined);
|
||||
} else {
|
||||
// error out for same server name
|
||||
let errorText = localize('cms.errors.sameCmsServerName', 'Central Management Server Group already has a Registered Server with the name {0}', registeredCmsServerName);
|
||||
appContext.apiWrapper.showErrorMessage(errorText);
|
||||
return;
|
||||
}
|
||||
let connection = await appContext.cmsUtils.makeConnection(connectionProfile);
|
||||
if (connection && connection.options) {
|
||||
let registeredCmsServerName = connection.options.registeredServerName ?
|
||||
connection.options.registeredServerName : connection.options.server;
|
||||
// check if a CMS with the same name is registered or not
|
||||
let cachedServers = appContext.cmsUtils.registeredCmsServers;
|
||||
let serverExists: boolean = false;
|
||||
if (cachedServers) {
|
||||
serverExists = cachedServers.some((server) => {
|
||||
return server.name === registeredCmsServerName;
|
||||
});
|
||||
}
|
||||
});
|
||||
if (!serverExists) {
|
||||
// remove any group ID if user selects a connection from
|
||||
// recent connection list
|
||||
connection.options.groupId = null;
|
||||
let registeredCmsServerDescription = connection.options.registeredServerDescription;
|
||||
let ownerUri = await azdata.connection.getUriForConnection(connection.connectionId);
|
||||
appContext.cmsUtils.cacheRegisteredCmsServer(registeredCmsServerName, registeredCmsServerDescription, ownerUri, connection);
|
||||
tree.notifyNodeChanged(undefined);
|
||||
} else {
|
||||
// error out for same server name
|
||||
let errorText = localize('cms.errors.sameCmsServerName', 'Central Management Server Group already has a Registered Server with the name {0}', registeredCmsServerName);
|
||||
appContext.apiWrapper.showErrorMessage(errorText);
|
||||
throw new Error(errorText);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,7 +58,7 @@ export function deleteCmsServerCommand(appContext: AppContext, tree: CmsResource
|
||||
if (!(node instanceof CmsResourceTreeNode)) {
|
||||
return;
|
||||
}
|
||||
await appContext.cmsUtils.deleteCmsServer(node.name);
|
||||
await appContext.cmsUtils.deleteCmsServer(node.name, node.connection);
|
||||
tree.isSystemInitialized = false;
|
||||
tree.notifyNodeChanged(undefined);
|
||||
});
|
||||
@@ -76,16 +73,8 @@ export function addRegisteredServerCommand(appContext: AppContext, tree: CmsReso
|
||||
let relativePath = node instanceof CmsResourceTreeNode ? '' : node.relativePath;
|
||||
let serverName = node instanceof CmsResourceTreeNode ? node.connection.options.registeredServerName === ''
|
||||
? node.connection.options.server : node.connection.options.registeredServerName : null;
|
||||
await appContext.cmsUtils.addRegisteredServer(relativePath, node.ownerUri, serverName).then((result) => {
|
||||
if (result) {
|
||||
tree.notifyNodeChanged(node);
|
||||
}
|
||||
}, (error) => {
|
||||
// error out
|
||||
let errorText = localize('cms.errors.addRegisterServerFail', 'Could not add the Registered Server {0}', error);
|
||||
appContext.apiWrapper.showErrorMessage(errorText);
|
||||
return;
|
||||
});
|
||||
await appContext.cmsUtils.addRegisteredServer(relativePath, node.ownerUri, serverName);
|
||||
tree.notifyNodeChanged(node);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,18 +84,14 @@ export function deleteRegisteredServerCommand(appContext: AppContext, tree: CmsR
|
||||
if (!(node instanceof RegisteredServerTreeNode)) {
|
||||
return;
|
||||
}
|
||||
appContext.apiWrapper.showWarningMessage(
|
||||
let result = await appContext.apiWrapper.showWarningMessage(
|
||||
`${localize('cms.confirmDeleteServer', 'Are you sure you want to delete')} ${node.name}?`,
|
||||
localize('cms.yes', 'Yes'),
|
||||
localize('cms.no', 'No')).then((result) => {
|
||||
if (result && result === localize('cms.yes', 'Yes')) {
|
||||
appContext.cmsUtils.removeRegisteredServer(node.name, node.relativePath, node.ownerUri).then((result) => {
|
||||
if (result) {
|
||||
tree.notifyNodeChanged(node.parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
localize('cms.no', 'No'));
|
||||
if (result && result === localize('cms.yes', 'Yes')) {
|
||||
await appContext.cmsUtils.removeRegisteredServer(node.name, node.relativePath, node.ownerUri);
|
||||
tree.notifyNodeChanged(node.parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -151,22 +136,19 @@ export function addServerGroupCommand(appContext: AppContext, tree: CmsResourceT
|
||||
dialog.content = [mainTab];
|
||||
azdata.window.openDialog(dialog);
|
||||
let groupExists = false;
|
||||
dialog.okButton.onClick(() => {
|
||||
dialog.okButton.onClick(async () => {
|
||||
let path = node instanceof ServerGroupTreeNode ? node.relativePath : '';
|
||||
if (node.serverGroupNodes.some(node => node.name === serverGroupName)) {
|
||||
groupExists = true;
|
||||
}
|
||||
if (!groupExists) {
|
||||
appContext.cmsUtils.addServerGroup(serverGroupName, serverDescription, path, node.ownerUri).then((result) => {
|
||||
if (result) {
|
||||
tree.notifyNodeChanged(node);
|
||||
}
|
||||
});
|
||||
await appContext.cmsUtils.addServerGroup(serverGroupName, serverDescription, path, node.ownerUri);
|
||||
tree.notifyNodeChanged(node);
|
||||
} else {
|
||||
// error out for same server group
|
||||
let errorText = localize('cms.errors.sameServerGroupName', '{0} already has a Server Group with the name {1}', node.name, serverGroupName);
|
||||
const errorText = localize('cms.errors.sameServerGroupName', '{0} already has a Server Group with the name {1}', node.name, serverGroupName);
|
||||
appContext.apiWrapper.showErrorMessage(errorText);
|
||||
return;
|
||||
throw new Error(errorText);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -178,18 +160,14 @@ export function deleteServerGroupCommand(appContext: AppContext, tree: CmsResour
|
||||
if (!(node instanceof ServerGroupTreeNode)) {
|
||||
return;
|
||||
}
|
||||
appContext.apiWrapper.showWarningMessage(
|
||||
let result = await appContext.apiWrapper.showWarningMessage(
|
||||
`${localize('cms.confirmDeleteGroup', 'Are you sure you want to delete')} ${node.name}?`,
|
||||
localize('cms.yes', 'Yes'),
|
||||
localize('cms.no', 'No')).then((result) => {
|
||||
if (result && result === localize('cms.yes', 'Yes')) {
|
||||
appContext.cmsUtils.removeServerGroup(node.name, node.relativePath, node.ownerUri).then((result) => {
|
||||
if (result) {
|
||||
tree.notifyNodeChanged(node.parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
localize('cms.no', 'No'));
|
||||
if (result && result === localize('cms.yes', 'Yes')) {
|
||||
await appContext.cmsUtils.removeServerGroup(node.name, node.relativePath, node.ownerUri);
|
||||
tree.notifyNodeChanged(node.parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
import * as azdata from 'azdata';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { TreeItemCollapsibleState } from 'vscode';
|
||||
import { TreeItemCollapsibleState, TreeItem } from 'vscode';
|
||||
import { AppContext } from '../../appContext';
|
||||
import { TreeNode } from '../treeNode';
|
||||
import { CmsResourceTreeNodeBase } from './baseTreeNodes';
|
||||
@@ -38,48 +38,52 @@ export class CmsResourceTreeNode extends CmsResourceTreeNodeBase {
|
||||
try {
|
||||
let nodes: CmsResourceTreeNodeBase[] = [];
|
||||
if (!this.ownerUri) {
|
||||
this._ownerUri = await this.appContext.cmsUtils.getUriForConnection(this.connection);
|
||||
// Set back password to get ownerUri
|
||||
if (this.connection.options.authenticationType === 'SqlLogin' && this.connection.options.savePassword === true) {
|
||||
this.connection.options.password = await this.appContext.cmsUtils.getPassword(this.connection.options.user);
|
||||
}
|
||||
}
|
||||
return this.appContext.cmsUtils.createCmsServer(this.connection, this.name, this.description).then((result) => {
|
||||
if (result) {
|
||||
if (result.registeredServersList) {
|
||||
result.registeredServersList.forEach((registeredServer) => {
|
||||
nodes.push(new RegisteredServerTreeNode(
|
||||
registeredServer.name,
|
||||
registeredServer.description,
|
||||
registeredServer.serverName,
|
||||
registeredServer.relativePath,
|
||||
this.ownerUri,
|
||||
this.appContext,
|
||||
this.treeChangeHandler, this));
|
||||
});
|
||||
}
|
||||
if (result.registeredServerGroups) {
|
||||
if (result.registeredServerGroups) {
|
||||
this._serverGroupNodes = [];
|
||||
result.registeredServerGroups.forEach((serverGroup) => {
|
||||
let serverGroupNode = new ServerGroupTreeNode(
|
||||
serverGroup.name,
|
||||
serverGroup.description,
|
||||
serverGroup.relativePath,
|
||||
this.ownerUri,
|
||||
this.appContext,
|
||||
this.treeChangeHandler, this);
|
||||
nodes.push(serverGroupNode);
|
||||
this._serverGroupNodes.push(serverGroupNode);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (nodes.length > 0) {
|
||||
return nodes.sort((node1, node2) => node1.name > node2.name ? 1 : -1);
|
||||
} else {
|
||||
return [CmsResourceMessageTreeNode.create(CmsResourceTreeNode.noResourcesLabel, undefined)];
|
||||
}
|
||||
// cache new connection is different from old one
|
||||
if (this.appContext.cmsUtils.didConnectionChange(this._connection, result.connection)) {
|
||||
this._connection = result.connection;
|
||||
this._ownerUri = result.ownerUri;
|
||||
this.appContext.cmsUtils.cacheRegisteredCmsServer(this.name, this.description, this.ownerUri, this.connection);
|
||||
}
|
||||
if (result.listRegisteredServersResult.registeredServersList) {
|
||||
result.listRegisteredServersResult.registeredServersList.forEach((registeredServer) => {
|
||||
nodes.push(new RegisteredServerTreeNode(
|
||||
registeredServer.name,
|
||||
registeredServer.description,
|
||||
registeredServer.serverName,
|
||||
registeredServer.relativePath,
|
||||
this.ownerUri,
|
||||
this.appContext,
|
||||
this.treeChangeHandler, this));
|
||||
});
|
||||
}
|
||||
if (result.listRegisteredServersResult.registeredServerGroups) {
|
||||
this._serverGroupNodes = [];
|
||||
result.listRegisteredServersResult.registeredServerGroups.forEach((serverGroup) => {
|
||||
let serverGroupNode = new ServerGroupTreeNode(
|
||||
serverGroup.name,
|
||||
serverGroup.description,
|
||||
serverGroup.relativePath,
|
||||
this.ownerUri,
|
||||
this.appContext,
|
||||
this.treeChangeHandler, this);
|
||||
nodes.push(serverGroupNode);
|
||||
this._serverGroupNodes.push(serverGroupNode);
|
||||
});
|
||||
}
|
||||
if (nodes.length > 0) {
|
||||
return nodes.sort((node1, node2) => node1.name > node2.name ? 1 : -1);
|
||||
} else {
|
||||
return [CmsResourceMessageTreeNode.create(CmsResourceTreeNode.noResourcesLabel, undefined)];
|
||||
}
|
||||
}, (error) => {
|
||||
let errorText = localize('cms.errors.expandCmsFail', 'The Central Management Server {0} could not be found or is offline', this.name);
|
||||
this.appContext.apiWrapper.showErrorMessage(error ? error : errorText);
|
||||
return [];
|
||||
this.treeChangeHandler.notifyNodeChanged(undefined);
|
||||
throw error;
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
|
||||
@@ -14,6 +14,7 @@ import { CmsResourceEmptyTreeNode } from './cmsResourceEmptyTreeNode';
|
||||
import { ICmsResourceTreeChangeHandler } from './treeChangeHandler';
|
||||
import { CmsResourceMessageTreeNode } from '../messageTreeNode';
|
||||
import { CmsResourceTreeNode } from './cmsResourceTreeNode';
|
||||
import { ICmsResourceNodeInfo } from './baseTreeNodes';
|
||||
|
||||
export class CmsResourceTreeProvider implements TreeDataProvider<TreeNode>, ICmsResourceTreeChangeHandler {
|
||||
|
||||
@@ -27,7 +28,8 @@ export class CmsResourceTreeProvider implements TreeDataProvider<TreeNode>, ICms
|
||||
|
||||
public async getChildren(element?: TreeNode): Promise<TreeNode[]> {
|
||||
if (element) {
|
||||
return element.getChildren(true);
|
||||
let children = await element.getChildren(true);
|
||||
return children;
|
||||
}
|
||||
|
||||
if (!this.isSystemInitialized) {
|
||||
@@ -42,11 +44,11 @@ export class CmsResourceTreeProvider implements TreeDataProvider<TreeNode>, ICms
|
||||
servers.push(new CmsResourceTreeNode(
|
||||
server.name,
|
||||
server.description,
|
||||
undefined,
|
||||
server.ownerUri,
|
||||
server.connection,
|
||||
this._appContext, this, null));
|
||||
this.appContext.cmsUtils.cacheRegisteredCmsServer(server.name, server.description,
|
||||
undefined, server.connection);
|
||||
server.ownerUri, server.connection);
|
||||
});
|
||||
return servers;
|
||||
}
|
||||
@@ -62,13 +64,6 @@ export class CmsResourceTreeProvider implements TreeDataProvider<TreeNode>, ICms
|
||||
let registeredCmsServers = this.appContext.cmsUtils.registeredCmsServers;
|
||||
if (registeredCmsServers && registeredCmsServers.length > 0) {
|
||||
this.isSystemInitialized = true;
|
||||
// save the CMS Servers for future use
|
||||
let toSaveCmsServers = JSON.parse(JSON.stringify(registeredCmsServers));
|
||||
toSaveCmsServers.forEach(server => {
|
||||
server.ownerUri = undefined,
|
||||
server.connection.options.password = '';
|
||||
});
|
||||
await this._appContext.cmsUtils.setConfiguration(toSaveCmsServers);
|
||||
return registeredCmsServers.map((server) => {
|
||||
return new CmsResourceTreeNode(
|
||||
server.name,
|
||||
|
||||
Reference in New Issue
Block a user