From dd8b12f8057d0e335e8bdaa234e06ebc5909c6be Mon Sep 17 00:00:00 2001 From: kenvanhyning Date: Mon, 6 Jan 2020 16:53:06 -0800 Subject: [PATCH] Kenvh/noazurecms (#8755) * Disallow Azure SQL DB servers for CMS * removed commented out lines * added check for valid serverInfo --- .../src/cmsResource/cmsResourceCommands.ts | 29 ++++++++++++------- resources/xlf/en/cms.xlf | 5 +++- .../browser/connectionManagementService.ts | 3 ++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/extensions/cms/src/cmsResource/cmsResourceCommands.ts b/extensions/cms/src/cmsResource/cmsResourceCommands.ts index 1ab061ecd4..cebaf627b3 100644 --- a/extensions/cms/src/cmsResource/cmsResourceCommands.ts +++ b/extensions/cms/src/cmsResource/cmsResourceCommands.ts @@ -33,20 +33,27 @@ export function registerCmsServerCommand(appContext: AppContext, tree: CmsResour 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 + + // don't allow duplicate server entries + if (serverExists) { 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); } + + // don't allow azure servers + let isCloud: boolean = connection.options.isCloud; + if (isCloud) { + let errorText = localize('cms.errors.azureNotAllowed', "Azure SQL Servers cannot be used as Central Management Servers"); + throw new Error(errorText); + } + + // 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); } }); } diff --git a/resources/xlf/en/cms.xlf b/resources/xlf/en/cms.xlf index 85f4177a46..66ac3b5f19 100644 --- a/resources/xlf/en/cms.xlf +++ b/resources/xlf/en/cms.xlf @@ -336,6 +336,9 @@ Central Management Server Group already has a Registered Server with the name {0} + + Azure SQL Database Servers cannot be used as Central Management Servers + Are you sure you want to delete @@ -372,4 +375,4 @@ You cannot add a shared registered server with the same name as the Configuration Server - \ No newline at end of file + diff --git a/src/sql/workbench/services/connection/browser/connectionManagementService.ts b/src/sql/workbench/services/connection/browser/connectionManagementService.ts index 0e547c6577..e692575516 100644 --- a/src/sql/workbench/services/connection/browser/connectionManagementService.ts +++ b/src/sql/workbench/services/connection/browser/connectionManagementService.ts @@ -1040,6 +1040,9 @@ export class ConnectionManagementService extends Disposable implements IConnecti this._connectionStatusManager.deleteConnection(uri); resolve({ connected: connectResult, errorMessage: errorMessage, errorCode: errorCode, callStack: callStack, connectionProfile: connection }); } else { + if (connectionMngInfo.serverInfo) { + connection.options.isCloud = connectionMngInfo.serverInfo.isCloud; + } resolve({ connected: connectResult, errorMessage: errorMessage, errorCode: errorCode, callStack: callStack, connectionProfile: connection }); } }