diff --git a/extensions/mssql/src/mssql.d.ts b/extensions/mssql/src/mssql.d.ts index 4bedc2d715..075972f3f5 100644 --- a/extensions/mssql/src/mssql.d.ts +++ b/extensions/mssql/src/mssql.d.ts @@ -916,13 +916,6 @@ declare module 'mssql' { name: string; } - /** - * Base interface for all the security principal objects. e.g. Login, Server Role, Database Role... - */ - export interface SecurityPrincipalObject extends SqlObject { - securablePermissions: SecurablePermissions[]; - } - /** * Base interface for the object view information. */ @@ -933,419 +926,6 @@ declare module 'mssql' { objectInfo: T; } - /** - * Securable type metadata. - */ - export interface SecurableTypeMetadata { - /** - * Name of the securable type. - */ - name: string; - /** - * Display name of the securable type. - */ - displayName: string; - /** - * Permissions supported by the securable type. - */ - permissions: PermissionMetadata[]; - } - - /** - * Permission metadata. - */ - export interface PermissionMetadata { - /** - * Name of the permission. - */ - name: string; - /** - * Display name of the permission. - */ - displayName: string; - } - - /** - * Base interface for security principal object's view information. - */ - export interface SecurityPrincipalViewInfo extends ObjectViewInfo { - /** - * The securable types that the security principal object can be granted permissions on. - */ - supportedSecurableTypes: SecurableTypeMetadata[]; - } - - /** - * Base interface for database level security principal object's view information. - */ - export interface DatabaseLevelPrincipalViewInfo extends SecurityPrincipalViewInfo { - /** - * The schemas in the database. - */ - schemas: string[]; - } - - /** - * Server level login. - */ - export interface Login extends SecurityPrincipalObject { - /** - * Authentication type. - */ - authenticationType: AuthenticationType; - /** - * Password for the login. - * Only applicable when the authentication type is 'Sql'. - */ - password: string | undefined; - /** - * Old password of the login. - * Only applicable when the authentication type is 'Sql'. - * The old password is required when updating the login's own password and it doesn't have the 'ALTER ANY LOGIN' permission. - */ - oldPassword: string | undefined; - /** - * Whether the password complexity policy is enforced. - * Only applicable when the authentication type is 'Sql'. - */ - enforcePasswordPolicy: boolean | undefined; - /** - * Whether the password expiration policy is enforced. - * Only applicable when the authentication type is 'Sql'. - */ - enforcePasswordExpiration: boolean | undefined; - /** - * Whether SQL Server should prompt for an updated password when the next the login is used. - * Only applicable when the authentication type is 'Sql'. - */ - mustChangePassword: boolean | undefined; - /** - * Whether the login is locked out due to password policy violation. - * Only applicable when the authentication type is 'Sql'. - */ - isLockedOut: boolean; - /** - * The default database for the login. - */ - defaultDatabase: string; - /** - * The default language for the login. - */ - defaultLanguage: string; - /** - * The server roles of the login. - */ - serverRoles: string[]; - /** - * The database users the login is mapped to. - */ - userMapping: ServerLoginUserInfo[]; - /** - * Whether the login is enabled. - */ - isEnabled: boolean; - /** - * Whether the connect permission is granted to the login. - */ - connectPermission: boolean; - } - - /** - * The authentication types. - */ - export const enum AuthenticationType { - Windows = 'Windows', - Sql = 'Sql', - AzureActiveDirectory = 'AAD' - } - - /** - * The user mapping information for login. - */ - export interface ServerLoginUserInfo { - /** - * Target database name. - */ - database: string; - /** - * User name. - */ - user: string; - /** - * Default schema of the user. - */ - defaultSchema: string; - /** - * Databases roles of the user. - */ - databaseRoles: string[]; - } - - /** - * The information required to render the login view. - */ - export interface LoginViewInfo extends SecurityPrincipalViewInfo { - /** - * The authentication types supported by the server. - */ - authenticationTypes: AuthenticationType[]; - /** - * Whether the locked out state can be changed. - */ - canEditLockedOutState: boolean; - /** - * Name of the databases in the server. - */ - databases: string[]; - /** - * Available languages in the server. - */ - languages: string[]; - /** - * All server roles in the server. - */ - serverRoles: string[]; - /** - * Whether advanced password options are supported. - * Advanced password options: check policy, check expiration, must change, unlock. - * Notes: 2 options to control the advanced options because Analytics Platform supports advanced options but does not support advanced options. - */ - supportAdvancedPasswordOptions: boolean; - /** - * Whether advanced options are supported. - * Advanced options: default database, default language and connect permission. - */ - supportAdvancedOptions: boolean; - } - - /** - * The permission information a principal has on a securable. - */ - export interface SecurablePermissionItem { - /** - * name of the permission. - */ - permission: string; - /** - * Name of the grantor. - */ - grantor: string; - /** - * Whether the permission is granted or denied. Undefined means not specified. - */ - grant?: boolean; - /** - * Whether the pincipal can grant this permission to other principals. - * The value will be ignored if the grant property is set to false. - */ - withGrant?: boolean; - } - - /** - * The permissions a principal has over a securable. - */ - export interface SecurablePermissions { - /** - * The securable name. - */ - name: string; - /** - * The securable type. - */ - type: string; - /** - * The schema name of the object if applicable. - */ - schema?: string; - /** - * The permissions. - */ - permissions: SecurablePermissionItem[]; - /** - * The effective permissions. Includes all permissions granted to the principal, including those granted through role memberships. - */ - effectivePermissions: string[]; - } - - /** - * Extend property for objects. - */ - export interface ExtendedProperty { - /** - * Name of the property. - */ - name: string; - /** - * Value of the property. - */ - value: string; - } - - /** - * User types. - */ - export const enum UserType { - /** - * Mapped to a server login. - */ - LoginMapped = 'LoginMapped', - /** - * Mapped to a Windows user or group. - */ - WindowsUser = 'WindowsUser', - /** - * Authenticate with password. - */ - SqlAuthentication = 'SqlAuthentication', - /** - * Authenticate with Azure Active Directory. - */ - AADAuthentication = 'AADAuthentication', - /** - * User that cannot authenticate. - */ - NoLoginAccess = 'NoLoginAccess' - } - - /** - * Database user. - */ - export interface User extends SecurityPrincipalObject { - /** - * Type of the user. - */ - type: UserType; - /** - * Default schema of the user. - */ - defaultSchema: string | undefined; - /** - * Schemas owned by the user. - */ - ownedSchemas: string[]; - /** - * Database roles that the user belongs to. - */ - databaseRoles: string[]; - /** - * The name of the server login associated with the user. - * Only applicable when the user type is 'WithLogin'. - */ - loginName: string | undefined; - /** - * The default language of the user. - * Only applicable when the user type is 'Contained'. - */ - defaultLanguage: string | undefined; - /** - * Password of the user. - * Only applicable when the user type is 'Contained' and the authentication type is 'Sql'. - */ - password: string | undefined; - } - - /** - * The information required to render the user view. - */ - export interface UserViewInfo extends DatabaseLevelPrincipalViewInfo { - /** - * All user types supported by the database. - */ - userTypes: UserType[]; - /** - * All languages supported by the database. - */ - languages: string[]; - /** - * Name of all the logins in the server. - */ - logins: string[]; - /** - * Name of all the database roles. - */ - databaseRoles: string[]; - } - - /** - * Interface representing the server role object. - */ - export interface ServerRoleInfo extends SecurityPrincipalObject { - /** - * Name of the server principal that owns the server role. - */ - owner: string; - /** - * Name of the server principals that are members of the server role. - */ - members: string[]; - /** - * Server roles that the server role is a member of. - */ - memberships: string[]; - } - - /** - * Interface representing the information required to render the server role view. - */ - export interface ServerRoleViewInfo extends SecurityPrincipalViewInfo { - /** - * Whether the server role is a fixed role. - */ - isFixedRole: boolean; - /** - * List of all the server roles. - */ - serverRoles: string[]; - } - - /** - * Interface representing the application role object. - */ - export interface ApplicationRoleInfo extends SecurityPrincipalObject { - /** - * Default schema of the application role. - */ - defaultSchema: string; - /** - * Schemas owned by the application role. - */ - ownedSchemas: string[]; - /** - * Password of the application role. - */ - password: string; - } - - /** - * Interface representing the information required to render the application role view. - */ - export interface ApplicationRoleViewInfo extends DatabaseLevelPrincipalViewInfo { - } - - /** - * Interface representing the database role object. - */ - export interface DatabaseRoleInfo extends SecurityPrincipalObject { - /** - * Name of the database principal that owns the database role. - */ - owner: string; - /** - * Schemas owned by the database role. - */ - ownedSchemas: string[]; - /** - * Name of the user or database role that are members of the database role. - */ - members: string[]; - } - - /** - * Interface representing the information required to render the database role view. - */ - export interface DatabaseRoleViewInfo extends DatabaseLevelPrincipalViewInfo { - } - /** * Interface representing an item in the search result. */ @@ -1363,22 +943,6 @@ declare module 'mssql' { */ schema: string | undefined; } - - export interface Database extends SqlObject { - owner?: string; - collationName?: string; - recoveryModel?: string; - compatibilityLevel?: string; - containmentType?: string; - } - - export interface DatabaseViewInfo extends ObjectViewInfo { - loginNames: string[]; - collationNames: string[]; - compatibilityLevels: string[]; - containmentTypes: string[]; - recoveryModels: string[]; - } } export interface IObjectManagementService { diff --git a/extensions/mssql/src/objectManagement/interfaces.ts b/extensions/mssql/src/objectManagement/interfaces.ts new file mode 100644 index 0000000000..c449ade64f --- /dev/null +++ b/extensions/mssql/src/objectManagement/interfaces.ts @@ -0,0 +1,441 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +import { ObjectManagement } from 'mssql'; + +/** + * Base interface for all the security principal objects. e.g. Login, Server Role, Database Role... + */ +export interface SecurityPrincipalObject extends ObjectManagement.SqlObject { + securablePermissions: SecurablePermissions[]; +} + +/** + * Securable type metadata. + */ +export interface SecurableTypeMetadata { + /** + * Name of the securable type. + */ + name: string; + /** + * Display name of the securable type. + */ + displayName: string; + /** + * Permissions supported by the securable type. + */ + permissions: PermissionMetadata[]; +} + +/** + * Permission metadata. + */ +export interface PermissionMetadata { + /** + * Name of the permission. + */ + name: string; + /** + * Display name of the permission. + */ + displayName: string; +} + +/** + * Base interface for security principal object's view information. + */ +export interface SecurityPrincipalViewInfo extends ObjectManagement.ObjectViewInfo { + /** + * The securable types that the security principal object can be granted permissions on. + */ + supportedSecurableTypes: SecurableTypeMetadata[]; +} + +/** + * Base interface for database level security principal object's view information. + */ +export interface DatabaseLevelPrincipalViewInfo extends SecurityPrincipalViewInfo { + /** + * The schemas in the database. + */ + schemas: string[]; +} + +/** + * Server level login. + */ +export interface Login extends SecurityPrincipalObject { + /** + * Authentication type. + */ + authenticationType: AuthenticationType; + /** + * Password for the login. + * Only applicable when the authentication type is 'Sql'. + */ + password: string | undefined; + /** + * Old password of the login. + * Only applicable when the authentication type is 'Sql'. + * The old password is required when updating the login's own password and it doesn't have the 'ALTER ANY LOGIN' permission. + */ + oldPassword: string | undefined; + /** + * Whether the password complexity policy is enforced. + * Only applicable when the authentication type is 'Sql'. + */ + enforcePasswordPolicy: boolean | undefined; + /** + * Whether the password expiration policy is enforced. + * Only applicable when the authentication type is 'Sql'. + */ + enforcePasswordExpiration: boolean | undefined; + /** + * Whether SQL Server should prompt for an updated password when the next the login is used. + * Only applicable when the authentication type is 'Sql'. + */ + mustChangePassword: boolean | undefined; + /** + * Whether the login is locked out due to password policy violation. + * Only applicable when the authentication type is 'Sql'. + */ + isLockedOut: boolean; + /** + * The default database for the login. + */ + defaultDatabase: string; + /** + * The default language for the login. + */ + defaultLanguage: string; + /** + * The server roles of the login. + */ + serverRoles: string[]; + /** + * The database users the login is mapped to. + */ + userMapping: ServerLoginUserInfo[]; + /** + * Whether the login is enabled. + */ + isEnabled: boolean; + /** + * Whether the connect permission is granted to the login. + */ + connectPermission: boolean; +} + +/** + * The authentication types. + */ +export const enum AuthenticationType { + Windows = 'Windows', + Sql = 'Sql', + AzureActiveDirectory = 'AAD' +} + +/** + * The user mapping information for login. + */ +export interface ServerLoginUserInfo { + /** + * Target database name. + */ + database: string; + /** + * User name. + */ + user: string; + /** + * Default schema of the user. + */ + defaultSchema: string; + /** + * Databases roles of the user. + */ + databaseRoles: string[]; +} + +/** + * The information required to render the login view. + */ +export interface LoginViewInfo extends SecurityPrincipalViewInfo { + /** + * The authentication types supported by the server. + */ + authenticationTypes: AuthenticationType[]; + /** + * Whether the locked out state can be changed. + */ + canEditLockedOutState: boolean; + /** + * Name of the databases in the server. + */ + databases: string[]; + /** + * Available languages in the server. + */ + languages: string[]; + /** + * All server roles in the server. + */ + serverRoles: string[]; + /** + * Whether advanced password options are supported. + * Advanced password options: check policy, check expiration, must change, unlock. + * Notes: 2 options to control the advanced options because Analytics Platform supports advanced options but does not support advanced options. + */ + supportAdvancedPasswordOptions: boolean; + /** + * Whether advanced options are supported. + * Advanced options: default database, default language and connect permission. + */ + supportAdvancedOptions: boolean; +} + +/** + * The permission information a principal has on a securable. + */ +export interface SecurablePermissionItem { + /** + * name of the permission. + */ + permission: string; + /** + * Name of the grantor. + */ + grantor: string; + /** + * Whether the permission is granted or denied. Undefined means not specified. + */ + grant?: boolean; + /** + * Whether the pincipal can grant this permission to other principals. + * The value will be ignored if the grant property is set to false. + */ + withGrant?: boolean; +} + +/** + * The permissions a principal has over a securable. + */ +export interface SecurablePermissions { + /** + * The securable name. + */ + name: string; + /** + * The securable type. + */ + type: string; + /** + * The schema name of the object if applicable. + */ + schema?: string; + /** + * The permissions. + */ + permissions: SecurablePermissionItem[]; + /** + * The effective permissions. Includes all permissions granted to the principal, including those granted through role memberships. + */ + effectivePermissions: string[]; +} + +/** + * Extend property for objects. + */ +export interface ExtendedProperty { + /** + * Name of the property. + */ + name: string; + /** + * Value of the property. + */ + value: string; +} + +/** + * User types. + */ +export const enum UserType { + /** + * Mapped to a server login. + */ + LoginMapped = 'LoginMapped', + /** + * Mapped to a Windows user or group. + */ + WindowsUser = 'WindowsUser', + /** + * Authenticate with password. + */ + SqlAuthentication = 'SqlAuthentication', + /** + * Authenticate with Azure Active Directory. + */ + AADAuthentication = 'AADAuthentication', + /** + * User that cannot authenticate. + */ + NoLoginAccess = 'NoLoginAccess' +} + +/** + * Database user. + */ +export interface User extends SecurityPrincipalObject { + /** + * Type of the user. + */ + type: UserType; + /** + * Default schema of the user. + */ + defaultSchema: string | undefined; + /** + * Schemas owned by the user. + */ + ownedSchemas: string[]; + /** + * Database roles that the user belongs to. + */ + databaseRoles: string[]; + /** + * The name of the server login associated with the user. + * Only applicable when the user type is 'WithLogin'. + */ + loginName: string | undefined; + /** + * The default language of the user. + * Only applicable when the user type is 'Contained'. + */ + defaultLanguage: string | undefined; + /** + * Password of the user. + * Only applicable when the user type is 'Contained' and the authentication type is 'Sql'. + */ + password: string | undefined; +} + +/** + * The information required to render the user view. + */ +export interface UserViewInfo extends DatabaseLevelPrincipalViewInfo { + /** + * All user types supported by the database. + */ + userTypes: UserType[]; + /** + * All languages supported by the database. + */ + languages: string[]; + /** + * Name of all the logins in the server. + */ + logins: string[]; + /** + * Name of all the database roles. + */ + databaseRoles: string[]; +} + +/** + * Interface representing the server role object. + */ +export interface ServerRoleInfo extends SecurityPrincipalObject { + /** + * Name of the server principal that owns the server role. + */ + owner: string; + /** + * Name of the server principals that are members of the server role. + */ + members: string[]; + /** + * Server roles that the server role is a member of. + */ + memberships: string[]; +} + +/** + * Interface representing the information required to render the server role view. + */ +export interface ServerRoleViewInfo extends SecurityPrincipalViewInfo { + /** + * Whether the server role is a fixed role. + */ + isFixedRole: boolean; + /** + * List of all the server roles. + */ + serverRoles: string[]; +} + +/** + * Interface representing the application role object. + */ +export interface ApplicationRoleInfo extends SecurityPrincipalObject { + /** + * Default schema of the application role. + */ + defaultSchema: string; + /** + * Schemas owned by the application role. + */ + ownedSchemas: string[]; + /** + * Password of the application role. + */ + password: string; +} + +/** + * Interface representing the information required to render the application role view. + */ +export interface ApplicationRoleViewInfo extends DatabaseLevelPrincipalViewInfo { +} + +/** + * Interface representing the database role object. + */ +export interface DatabaseRoleInfo extends SecurityPrincipalObject { + /** + * Name of the database principal that owns the database role. + */ + owner: string; + /** + * Schemas owned by the database role. + */ + ownedSchemas: string[]; + /** + * Name of the user or database role that are members of the database role. + */ + members: string[]; +} + +/** + * Interface representing the information required to render the database role view. + */ +export interface DatabaseRoleViewInfo extends DatabaseLevelPrincipalViewInfo { +} + +export interface Database extends ObjectManagement.SqlObject { + owner?: string; + collationName?: string; + recoveryModel?: string; + compatibilityLevel?: string; + containmentType?: string; +} + +export interface DatabaseViewInfo extends ObjectManagement.ObjectViewInfo { + loginNames: string[]; + collationNames: string[]; + compatibilityLevels: string[]; + containmentTypes: string[]; + recoveryModels: string[]; +} diff --git a/extensions/mssql/src/objectManagement/localizedConstants.ts b/extensions/mssql/src/objectManagement/localizedConstants.ts index 1a7e551577..1dddcc3e1b 100644 --- a/extensions/mssql/src/objectManagement/localizedConstants.ts +++ b/extensions/mssql/src/objectManagement/localizedConstants.ts @@ -6,6 +6,7 @@ import * as nls from 'vscode-nls'; import { ObjectManagement } from 'mssql'; import { ObjectTypeInfo } from './ui/findObjectDialog'; +import { AuthenticationType, UserType } from './interfaces'; const localize = nls.loadMessageBundle(); // Object Types @@ -242,19 +243,19 @@ export function getNodeTypeDisplayName(type: string, inTitle: boolean = false): } } -const AuthencationTypeDisplayNameMap = new Map(); -AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.Windows, WindowsAuthenticationTypeDisplayText); -AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.Sql, SQLAuthenticationTypeDisplayText); -AuthencationTypeDisplayNameMap.set(ObjectManagement.AuthenticationType.AzureActiveDirectory, AADAuthenticationTypeDisplayText); +const AuthencationTypeDisplayNameMap = new Map(); +AuthencationTypeDisplayNameMap.set(AuthenticationType.Windows, WindowsAuthenticationTypeDisplayText); +AuthencationTypeDisplayNameMap.set(AuthenticationType.Sql, SQLAuthenticationTypeDisplayText); +AuthencationTypeDisplayNameMap.set(AuthenticationType.AzureActiveDirectory, AADAuthenticationTypeDisplayText); -export function getAuthenticationTypeDisplayName(authType: ObjectManagement.AuthenticationType): string { +export function getAuthenticationTypeDisplayName(authType: AuthenticationType): string { if (AuthencationTypeDisplayNameMap.has(authType)) { return AuthencationTypeDisplayNameMap.get(authType); } throw new Error(`Unknown authentication type: ${authType}`); } -export function getAuthenticationTypeByDisplayName(displayName: string): ObjectManagement.AuthenticationType { +export function getAuthenticationTypeByDisplayName(displayName: string): AuthenticationType { for (let [key, value] of AuthencationTypeDisplayNameMap.entries()) { if (value === displayName) return key; @@ -262,21 +263,21 @@ export function getAuthenticationTypeByDisplayName(displayName: string): ObjectM throw new Error(`Unknown authentication type display name: ${displayName}`); } -const UserTypeDisplayNameMap = new Map(); -UserTypeDisplayNameMap.set(ObjectManagement.UserType.LoginMapped, UserType_LoginMapped); -UserTypeDisplayNameMap.set(ObjectManagement.UserType.WindowsUser, UserType_WindowsUser); -UserTypeDisplayNameMap.set(ObjectManagement.UserType.SqlAuthentication, UserType_SqlAuthentication); -UserTypeDisplayNameMap.set(ObjectManagement.UserType.AADAuthentication, UserType_AADAuthentication); -UserTypeDisplayNameMap.set(ObjectManagement.UserType.NoLoginAccess, UserType_NoLoginAccess); +const UserTypeDisplayNameMap = new Map(); +UserTypeDisplayNameMap.set(UserType.LoginMapped, UserType_LoginMapped); +UserTypeDisplayNameMap.set(UserType.WindowsUser, UserType_WindowsUser); +UserTypeDisplayNameMap.set(UserType.SqlAuthentication, UserType_SqlAuthentication); +UserTypeDisplayNameMap.set(UserType.AADAuthentication, UserType_AADAuthentication); +UserTypeDisplayNameMap.set(UserType.NoLoginAccess, UserType_NoLoginAccess); -export function getUserTypeDisplayName(userType: ObjectManagement.UserType): string { +export function getUserTypeDisplayName(userType: UserType): string { if (UserTypeDisplayNameMap.has(userType)) { return UserTypeDisplayNameMap.get(userType); } throw new Error(`Unknown user type: ${userType}`); } -export function getUserTypeByDisplayName(displayName: string): ObjectManagement.UserType { +export function getUserTypeByDisplayName(displayName: string): UserType { for (let [key, value] of UserTypeDisplayNameMap.entries()) { if (value === displayName) return key; diff --git a/extensions/mssql/src/objectManagement/objectManagementService.ts b/extensions/mssql/src/objectManagement/objectManagementService.ts index 989567a605..6872c37831 100644 --- a/extensions/mssql/src/objectManagement/objectManagementService.ts +++ b/extensions/mssql/src/objectManagement/objectManagementService.ts @@ -2,7 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ - +import { ApplicationRoleViewInfo, AuthenticationType, DatabaseRoleViewInfo, LoginViewInfo, SecurablePermissions, SecurableTypeMetadata, ServerRoleViewInfo, User, UserType, UserViewInfo } from './interfaces'; import * as Utils from '../utils'; import * as constants from '../constants'; import * as contracts from '../contracts'; @@ -67,7 +67,7 @@ export class ObjectManagementService extends BaseService implements IObjectManag } } -const ServerLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [ +const ServerLevelSecurableTypes: SecurableTypeMetadata[] = [ { name: 'Server', displayName: 'Server', @@ -94,7 +94,7 @@ const ServerLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [ } ]; -const DatabaseLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [ +const DatabaseLevelSecurableTypes: SecurableTypeMetadata[] = [ { name: 'AggregateFunction', displayName: 'Aggregate Function', @@ -137,7 +137,7 @@ const DatabaseLevelSecurableTypes: ObjectManagement.SecurableTypeMetadata[] = [ } ] -const ServerLevelPermissions: ObjectManagement.SecurablePermissions[] = [ +const ServerLevelPermissions: SecurablePermissions[] = [ { name: 'Server', type: 'Server', @@ -158,7 +158,7 @@ const ServerLevelPermissions: ObjectManagement.SecurablePermissions[] = [ } ]; -const DatabaseLevelPermissions: ObjectManagement.SecurablePermissions[] = [ +const DatabaseLevelPermissions: SecurablePermissions[] = [ { name: 'table1', type: 'Table', @@ -238,16 +238,16 @@ export class TestObjectManagementService implements IObjectManagementService { return items; } - private getLoginView(isNewObject: boolean, name: string): ObjectManagement.LoginViewInfo { + private getLoginView(isNewObject: boolean, name: string): LoginViewInfo { const serverRoles = ['sysadmin', 'public', 'bulkadmin', 'dbcreator', 'diskadmin', 'processadmin', 'securityadmin', 'serveradmin']; const languages = ['', 'English']; const databases = ['master', 'db1', 'db2']; - let login: ObjectManagement.LoginViewInfo; + let login: LoginViewInfo; if (isNewObject) { - login = { + login = { objectInfo: { name: '', - authenticationType: ObjectManagement.AuthenticationType.Sql, + authenticationType: AuthenticationType.Sql, enforcePasswordPolicy: true, enforcePasswordExpiration: true, mustChangePassword: true, @@ -259,7 +259,7 @@ export class TestObjectManagementService implements IObjectManagementService { isLockedOut: false, securablePermissions: [] }, - authenticationTypes: [ObjectManagement.AuthenticationType.Sql, ObjectManagement.AuthenticationType.Windows], + authenticationTypes: [AuthenticationType.Sql, AuthenticationType.Windows], supportAdvancedOptions: true, supportAdvancedPasswordOptions: true, canEditLockedOutState: false, @@ -269,10 +269,10 @@ export class TestObjectManagementService implements IObjectManagementService { supportedSecurableTypes: ServerLevelSecurableTypes }; } else { - login = { + login = { objectInfo: { name: name, - authenticationType: ObjectManagement.AuthenticationType.Sql, + authenticationType: AuthenticationType.Sql, enforcePasswordPolicy: true, enforcePasswordExpiration: true, mustChangePassword: true, @@ -285,7 +285,7 @@ export class TestObjectManagementService implements IObjectManagementService { password: '******************', securablePermissions: ServerLevelPermissions }, - authenticationTypes: [ObjectManagement.AuthenticationType.Sql, ObjectManagement.AuthenticationType.Windows], + authenticationTypes: [AuthenticationType.Sql, AuthenticationType.Windows], supportAdvancedOptions: true, supportAdvancedPasswordOptions: true, canEditLockedOutState: false, @@ -298,8 +298,8 @@ export class TestObjectManagementService implements IObjectManagementService { return login; } - private getUserView(isNewObject: boolean, name: string): ObjectManagement.UserViewInfo { - let viewInfo: ObjectManagement.UserViewInfo; + private getUserView(isNewObject: boolean, name: string): UserViewInfo { + let viewInfo: UserViewInfo; const languages = ['', 'English']; const schemas = ['dbo', 'sys', 'alanren']; const logins = ['sa', 'alanren', 'alanren@microsoft.com']; @@ -307,12 +307,12 @@ export class TestObjectManagementService implements IObjectManagementService { if (isNewObject) { viewInfo = { - objectInfo: { + objectInfo: { name: '', - type: ObjectManagement.UserType.LoginMapped, + type: UserType.LoginMapped, defaultSchema: 'dbo', defaultLanguage: '', - authenticationType: ObjectManagement.AuthenticationType.Sql, + authenticationType: AuthenticationType.Sql, loginName: 'sa', ownedSchemas: [], databaseRoles: [], @@ -324,18 +324,18 @@ export class TestObjectManagementService implements IObjectManagementService { logins: logins, databaseRoles: databaseRoles, userTypes: [ - ObjectManagement.UserType.LoginMapped, - ObjectManagement.UserType.AADAuthentication, - ObjectManagement.UserType.SqlAuthentication, - ObjectManagement.UserType.NoLoginAccess + UserType.LoginMapped, + UserType.AADAuthentication, + UserType.SqlAuthentication, + UserType.NoLoginAccess ], supportedSecurableTypes: DatabaseLevelSecurableTypes }; } else { viewInfo = { - objectInfo: { + objectInfo: { name: name, - type: ObjectManagement.UserType.LoginMapped, + type: UserType.LoginMapped, defaultSchema: 'dbo', defaultLanguage: '', loginName: 'sa', @@ -348,10 +348,10 @@ export class TestObjectManagementService implements IObjectManagementService { logins: logins, databaseRoles: databaseRoles, userTypes: [ - ObjectManagement.UserType.LoginMapped, - ObjectManagement.UserType.AADAuthentication, - ObjectManagement.UserType.SqlAuthentication, - ObjectManagement.UserType.NoLoginAccess + UserType.LoginMapped, + UserType.AADAuthentication, + UserType.SqlAuthentication, + UserType.NoLoginAccess ], supportedSecurableTypes: DatabaseLevelSecurableTypes }; @@ -359,8 +359,8 @@ export class TestObjectManagementService implements IObjectManagementService { return viewInfo; } - private getServerRoleView(isNewObject: boolean, name: string): ObjectManagement.ServerRoleViewInfo { - return isNewObject ? { + private getServerRoleView(isNewObject: boolean, name: string): ServerRoleViewInfo { + return isNewObject ? { objectInfo: { name: '', members: [], @@ -371,7 +371,7 @@ export class TestObjectManagementService implements IObjectManagementService { isFixedRole: false, serverRoles: ['ServerLevelServerRole 1', 'ServerLevelServerRole 2', 'ServerLevelServerRole 3', 'ServerLevelServerRole 4'], supportedSecurableTypes: ServerLevelSecurableTypes - } : { + } : { objectInfo: { name: 'ServerLevelServerRole 1', members: ['ServerLevelLogin 1', 'ServerLevelServerRole 2'], @@ -385,8 +385,8 @@ export class TestObjectManagementService implements IObjectManagementService { }; } - private getApplicationRoleView(isNewObject: boolean, name: string): ObjectManagement.ApplicationRoleViewInfo { - return isNewObject ? { + private getApplicationRoleView(isNewObject: boolean, name: string): ApplicationRoleViewInfo { + return isNewObject ? { objectInfo: { name: '', defaultSchema: 'dbo', @@ -395,7 +395,7 @@ export class TestObjectManagementService implements IObjectManagementService { }, schemas: ['dbo', 'sys', 'admin'], supportedSecurableTypes: [] - } : { + } : { objectInfo: { name: 'app role1', password: '******************', @@ -408,8 +408,8 @@ export class TestObjectManagementService implements IObjectManagementService { }; } - private getDatabaseRoleView(isNewObject: boolean, name: string): ObjectManagement.DatabaseRoleViewInfo { - return isNewObject ? { + private getDatabaseRoleView(isNewObject: boolean, name: string): DatabaseRoleViewInfo { + return isNewObject ? { objectInfo: { name: '', owner: '', @@ -419,7 +419,7 @@ export class TestObjectManagementService implements IObjectManagementService { }, schemas: ['dbo', 'sys', 'admin'], supportedSecurableTypes: DatabaseLevelSecurableTypes - } : { + } : { objectInfo: { name: 'db role1', owner: '', diff --git a/extensions/mssql/src/objectManagement/ui/applicationRoleDialog.ts b/extensions/mssql/src/objectManagement/ui/applicationRoleDialog.ts index b7eff521e3..1d0bf46061 100644 --- a/extensions/mssql/src/objectManagement/ui/applicationRoleDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/applicationRoleDialog.ts @@ -4,14 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import * as azdata from 'azdata'; import { ObjectManagementDialogOptions } from './objectManagementDialogBase'; -import { IObjectManagementService, ObjectManagement } from 'mssql'; +import { IObjectManagementService } from 'mssql'; import * as localizedConstants from '../localizedConstants'; import { AlterApplicationRoleDocUrl, CreateApplicationRoleDocUrl } from '../constants'; import { isValidSQLPassword } from '../utils'; import { DefaultMaxTableRowCount } from '../../ui/dialogBase'; import { PrincipalDialogBase } from './principalDialogBase'; +import { ApplicationRoleInfo, ApplicationRoleViewInfo } from '../interfaces'; -export class ApplicationRoleDialog extends PrincipalDialogBase { +export class ApplicationRoleDialog extends PrincipalDialogBase { // Sections private generalSection: azdata.GroupContainer; private ownedSchemasSection: azdata.GroupContainer; diff --git a/extensions/mssql/src/objectManagement/ui/databaseDialog.ts b/extensions/mssql/src/objectManagement/ui/databaseDialog.ts index 4ee60857ed..37a4327d50 100644 --- a/extensions/mssql/src/objectManagement/ui/databaseDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/databaseDialog.ts @@ -5,11 +5,12 @@ import * as azdata from 'azdata'; import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase'; -import { IObjectManagementService, ObjectManagement } from 'mssql'; +import { IObjectManagementService } from 'mssql'; import * as localizedConstants from '../localizedConstants'; import { CreateDatabaseDocUrl } from '../constants'; +import { Database, DatabaseViewInfo } from '../interfaces'; -export class DatabaseDialog extends ObjectManagementDialogBase { +export class DatabaseDialog extends ObjectManagementDialogBase { private _nameInput: azdata.InputBoxComponent; constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) { diff --git a/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts b/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts index ed0188c207..be9a324c8b 100644 --- a/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts @@ -10,8 +10,9 @@ import { AlterDatabaseRoleDocUrl, CreateDatabaseRoleDocUrl } from '../constants' import { FindObjectDialog } from './findObjectDialog'; import { DefaultMaxTableRowCount } from '../../ui/dialogBase'; import { PrincipalDialogBase } from './principalDialogBase'; +import { DatabaseRoleInfo, DatabaseRoleViewInfo } from '../interfaces'; -export class DatabaseRoleDialog extends PrincipalDialogBase { +export class DatabaseRoleDialog extends PrincipalDialogBase { // Sections private generalSection: azdata.GroupContainer; private ownedSchemasSection: azdata.GroupContainer; diff --git a/extensions/mssql/src/objectManagement/ui/loginDialog.ts b/extensions/mssql/src/objectManagement/ui/loginDialog.ts index c8a5277684..f19b215e76 100644 --- a/extensions/mssql/src/objectManagement/ui/loginDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/loginDialog.ts @@ -5,15 +5,16 @@ import * as azdata from 'azdata'; import * as vscode from 'vscode'; import { ObjectManagementDialogOptions } from './objectManagementDialogBase'; -import { IObjectManagementService, ObjectManagement } from 'mssql'; +import { IObjectManagementService } from 'mssql'; import * as objectManagementLoc from '../localizedConstants'; import * as uiLoc from '../../ui/localizedConstants'; import { AlterLoginDocUrl, CreateLoginDocUrl, PublicServerRoleName } from '../constants'; import { isValidSQLPassword } from '../utils'; import { DefaultMaxTableRowCount } from '../../ui/dialogBase'; import { PrincipalDialogBase } from './principalDialogBase'; +import { AuthenticationType, Login, LoginViewInfo } from '../interfaces'; -export class LoginDialog extends PrincipalDialogBase { +export class LoginDialog extends PrincipalDialogBase { private generalSection: azdata.GroupContainer; private sqlAuthSection: azdata.GroupContainer; private serverRoleSection: azdata.GroupContainer; @@ -46,7 +47,7 @@ export class LoginDialog extends PrincipalDialogBase { const errors = await super.validateInput(); - if (this.objectInfo.authenticationType === ObjectManagement.AuthenticationType.Sql) { + if (this.objectInfo.authenticationType === AuthenticationType.Sql) { if (!this.objectInfo.password && !(this.viewInfo.supportAdvancedPasswordOptions && !this.objectInfo.enforcePasswordPolicy)) { errors.push(objectManagementLoc.PasswordCannotBeEmptyError); } diff --git a/extensions/mssql/src/objectManagement/ui/principalDialogBase.ts b/extensions/mssql/src/objectManagement/ui/principalDialogBase.ts index b70204eda0..1010e95a74 100644 --- a/extensions/mssql/src/objectManagement/ui/principalDialogBase.ts +++ b/extensions/mssql/src/objectManagement/ui/principalDialogBase.ts @@ -12,6 +12,7 @@ import { FindObjectDialog, FindObjectDialogResult } from './findObjectDialog'; import { deepClone } from '../../util/objects'; import { DefaultTableWidth, getTableHeight } from '../../ui/dialogBase'; import { ObjectSelectionMethod, ObjectSelectionMethodDialog } from './objectSelectionMethodDialog'; +import { DatabaseLevelPrincipalViewInfo, SecurablePermissionItem, SecurablePermissions, SecurityPrincipalObject, SecurityPrincipalViewInfo } from '../interfaces'; const GrantColumnIndex = 2; const WithGrantColumnIndex = 3; @@ -25,14 +26,14 @@ export interface PrincipalDialogOptions extends ObjectManagementDialogOptions { /** * Base class for security principal dialogs such as user, role, etc. */ -export abstract class PrincipalDialogBase> extends ObjectManagementDialogBase { +export abstract class PrincipalDialogBase> extends ObjectManagementDialogBase { protected securableTable: azdata.TableComponent; protected permissionTable: azdata.TableComponent; protected effectivePermissionTable: azdata.TableComponent; protected securableSection: azdata.GroupContainer; protected explicitPermissionTableLabel: azdata.TextComponent; protected effectivePermissionTableLabel: azdata.TextComponent; - private securablePermissions: mssql.ObjectManagement.SecurablePermissions[] = []; + private securablePermissions: SecurablePermissions[] = []; constructor(objectManagementService: mssql.IObjectManagementService, private readonly dialogOptions: PrincipalDialogOptions) { super(objectManagementService, dialogOptions); @@ -82,7 +83,7 @@ export abstract class PrincipalDialogBase { const permissionName = this.permissionTable.data[arg.row][0]; const securable = this.securablePermissions[this.securableTable.selectedRows[0]]; - let permission: mssql.ObjectManagement.SecurablePermissionItem = securable.permissions.find(securablePermission => securablePermission.permission === permissionName); + let permission: SecurablePermissionItem = securable.permissions.find(securablePermission => securablePermission.permission === permissionName); if (!permission) { permission = { permission: permissionName, @@ -126,7 +127,7 @@ export abstract class PrincipalDialogBase>this.viewInfo).schemas, + schemas: (>this.viewInfo).schemas, }); await methodDialog.open(); const methodResult = await methodDialog.waitForClose(); diff --git a/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts b/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts index e0fce7b7df..f811e53771 100644 --- a/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts @@ -9,8 +9,9 @@ import * as localizedConstants from '../localizedConstants'; import { AlterServerRoleDocUrl, CreateServerRoleDocUrl } from '../constants'; import { FindObjectDialog } from './findObjectDialog'; import { PrincipalDialogBase } from './principalDialogBase'; +import { ServerRoleInfo, ServerRoleViewInfo } from '../interfaces'; -export class ServerRoleDialog extends PrincipalDialogBase { +export class ServerRoleDialog extends PrincipalDialogBase { // Sections private generalSection: azdata.GroupContainer; private membershipSection: azdata.GroupContainer; diff --git a/extensions/mssql/src/objectManagement/ui/userDialog.ts b/extensions/mssql/src/objectManagement/ui/userDialog.ts index 33105d2221..053bb0a710 100644 --- a/extensions/mssql/src/objectManagement/ui/userDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/userDialog.ts @@ -4,14 +4,15 @@ *--------------------------------------------------------------------------------------------*/ import * as azdata from 'azdata'; import { ObjectManagementDialogOptions } from './objectManagementDialogBase'; -import { IObjectManagementService, ObjectManagement } from 'mssql'; +import { IObjectManagementService } from 'mssql'; import * as localizedConstants from '../localizedConstants'; import { AlterUserDocUrl, CreateUserDocUrl } from '../constants'; import { isValidSQLPassword } from '../utils'; import { DefaultMaxTableRowCount } from '../../ui/dialogBase'; import { PrincipalDialogBase } from './principalDialogBase'; +import { User, UserType, UserViewInfo } from '../interfaces'; -export class UserDialog extends PrincipalDialogBase { +export class UserDialog extends PrincipalDialogBase { private generalSection: azdata.GroupContainer; private ownedSchemaSection: azdata.GroupContainer; private membershipSection: azdata.GroupContainer; @@ -45,7 +46,7 @@ export class UserDialog extends PrincipalDialogBase { const errors = await super.validateInput(); - if (this.objectInfo.type === ObjectManagement.UserType.SqlAuthentication) { + if (this.objectInfo.type === UserType.SqlAuthentication) { if (!this.objectInfo.password) { errors.push(localizedConstants.PasswordCannotBeEmptyError); } @@ -56,7 +57,7 @@ export class UserDialog extends PrincipalDialogBase