mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 01:25:36 -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user