mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Fix application names to respect connection's appname property (#2034)
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
|||||||
public const string ContentLengthFormatString = "Content-Length: {0}\r\n\r\n";
|
public const string ContentLengthFormatString = "Content-Length: {0}\r\n\r\n";
|
||||||
public static readonly JsonSerializerSettings JsonSerializerSettings;
|
public static readonly JsonSerializerSettings JsonSerializerSettings;
|
||||||
|
|
||||||
|
public static readonly string DefaultApplicationName = "azdata";
|
||||||
public static readonly string SqlLoginAuthenticationType = "SqlLogin";
|
public static readonly string SqlLoginAuthenticationType = "SqlLogin";
|
||||||
|
|
||||||
static Constants()
|
static Constants()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ using Microsoft.SqlTools.Authentication.Sql;
|
|||||||
using Microsoft.SqlTools.Authentication;
|
using Microsoft.SqlTools.Authentication;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.SqlTools.Hosting.Utility;
|
using Microsoft.SqlTools.Hosting.Utility;
|
||||||
|
using Constants = Microsoft.SqlTools.Hosting.Protocol.Constants;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||||
{
|
{
|
||||||
@@ -470,19 +471,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetApplicationNameWithFeature(string applicationName, string featureName)
|
internal static string GetApplicationNameWithFeature(string applicationName, string featureName)
|
||||||
{
|
{
|
||||||
string appNameWithFeature = applicationName;
|
string appNameWithFeature = applicationName;
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(applicationName) && !string.IsNullOrWhiteSpace(featureName))
|
if (!string.IsNullOrWhiteSpace(applicationName) && !string.IsNullOrWhiteSpace(featureName) && !applicationName.EndsWith(featureName))
|
||||||
{
|
{
|
||||||
int index = applicationName.IndexOf('-');
|
int azdataStartIndex = applicationName.IndexOf(Constants.DefaultApplicationName);
|
||||||
string appName = applicationName;
|
string originalAppName = azdataStartIndex != -1
|
||||||
if (index > 0)
|
? applicationName.Substring(0, azdataStartIndex + Constants.DefaultApplicationName.Length)
|
||||||
{
|
: applicationName; // Reset to default if azdata not found.
|
||||||
appName = applicationName.Substring(0, index);
|
appNameWithFeature = $"{originalAppName}-{featureName}";
|
||||||
}
|
|
||||||
appNameWithFeature = $"{appName}-{featureName}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return appNameWithFeature;
|
return appNameWithFeature;
|
||||||
@@ -1162,7 +1161,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cachePath = Path.Combine(applicationPath, applicationName, AzureTokenFolder);
|
var cachePath = Path.Combine(applicationPath, applicationName, AzureTokenFolder);
|
||||||
return new Authenticator(new (ApplicationClientId, applicationName, cachePath, MsalCacheName), () => this.encryptionKeys);
|
return new Authenticator(new(ApplicationClientId, applicationName, cachePath, MsalCacheName), () => this.encryptionKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task HandleEncryptionKeysNotificationEvent(EncryptionKeysChangeParams @params, EventContext context)
|
private Task HandleEncryptionKeysNotificationEvent(EncryptionKeysChangeParams @params, EventContext context)
|
||||||
@@ -1377,7 +1376,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
break;
|
break;
|
||||||
case SqlLogin:
|
case SqlLogin:
|
||||||
connectionBuilder.UserID = connectionDetails.UserName;
|
connectionBuilder.UserID = connectionDetails.UserName;
|
||||||
connectionBuilder.Password = string.IsNullOrEmpty(connectionDetails.Password)
|
connectionBuilder.Password = string.IsNullOrEmpty(connectionDetails.Password)
|
||||||
? string.Empty // Support empty password for accounts without password
|
? string.Empty // Support empty password for accounts without password
|
||||||
: connectionDetails.Password;
|
: connectionDetails.Password;
|
||||||
connectionBuilder.Authentication = SqlAuthenticationMethod.SqlPassword;
|
connectionBuilder.Authentication = SqlAuthenticationMethod.SqlPassword;
|
||||||
@@ -1596,9 +1595,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
ConnectionInfo info;
|
ConnectionInfo info;
|
||||||
SqlConnectionStringBuilder connStringBuilder;
|
SqlConnectionStringBuilder connStringBuilder;
|
||||||
// set connection string using connection uri if connection details are undefined
|
// set connection string using connection uri if connection details are undefined
|
||||||
if (connStringParams.ConnectionDetails == null)
|
if (connStringParams.ConnectionDetails == null && TryFindConnection(connStringParams.OwnerUri, out info))
|
||||||
{
|
{
|
||||||
TryFindConnection(connStringParams.OwnerUri, out info);
|
|
||||||
connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
||||||
}
|
}
|
||||||
// set connection string using connection details
|
// set connection string using connection details
|
||||||
@@ -1611,9 +1609,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||||
}
|
}
|
||||||
// default connection string application name to always be included unless set to false
|
// default connection string application name to always be included unless set to false
|
||||||
if (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true)
|
if (connStringBuilder.ApplicationName == null && (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true))
|
||||||
{
|
{
|
||||||
connStringBuilder.ApplicationName = "sqlops-connection-string";
|
connStringBuilder.ApplicationName = Constants.DefaultApplicationName;
|
||||||
}
|
}
|
||||||
connectionString = connStringBuilder.ConnectionString;
|
connectionString = connStringBuilder.ConnectionString;
|
||||||
|
|
||||||
|
|||||||
@@ -399,7 +399,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
{
|
{
|
||||||
var builder = ConnectionService.CreateConnectionStringBuilder(session.ConnectionInfo.ConnectionDetails);
|
var builder = ConnectionService.CreateConnectionStringBuilder(session.ConnectionInfo.ConnectionDetails);
|
||||||
builder.InitialCatalog = node.NodeValue;
|
builder.InitialCatalog = node.NodeValue;
|
||||||
builder.ApplicationName = TableDesignerService.TableDesignerApplicationName;
|
builder.ApplicationName = ConnectionService.GetApplicationNameWithFeature(builder.ApplicationName, TableDesignerService.TableDesignerApplicationNameSuffix);
|
||||||
// Set Access Token only when authentication mode is not specified.
|
// Set Access Token only when authentication mode is not specified.
|
||||||
var azureToken = builder.Authentication == SqlAuthenticationMethod.NotSpecified
|
var azureToken = builder.Authentication == SqlAuthenticationMethod.NotSpecified
|
||||||
? session.ConnectionInfo.ConnectionDetails.AzureAccountToken : null;
|
? session.ConnectionInfo.ConnectionDetails.AzureAccountToken : null;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ObjectManagementService
|
public class ObjectManagementService
|
||||||
{
|
{
|
||||||
public const string ApplicationName = "azdata-object-management";
|
public const string ApplicationName = "object-management";
|
||||||
private static Lazy<ObjectManagementService> objectManagementServiceInstance = new Lazy<ObjectManagementService>(() => new ObjectManagementService());
|
private static Lazy<ObjectManagementService> objectManagementServiceInstance = new Lazy<ObjectManagementService>(() => new ObjectManagementService());
|
||||||
public static ObjectManagementService Instance => objectManagementServiceInstance.Value;
|
public static ObjectManagementService Instance => objectManagementServiceInstance.Value;
|
||||||
public static ConnectionService connectionService;
|
public static ConnectionService connectionService;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
|
|||||||
using Dac = Microsoft.Data.Tools.Sql.DesignServices.TableDesigner;
|
using Dac = Microsoft.Data.Tools.Sql.DesignServices.TableDesigner;
|
||||||
using STSHost = Microsoft.SqlTools.ServiceLayer.Hosting.ServiceHost;
|
using STSHost = Microsoft.SqlTools.ServiceLayer.Hosting.ServiceHost;
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||||
{
|
{
|
||||||
@@ -25,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class TableDesignerService : IDisposable
|
public sealed class TableDesignerService : IDisposable
|
||||||
{
|
{
|
||||||
public const string TableDesignerApplicationName = "azdata-table-designer";
|
public const string TableDesignerApplicationNameSuffix = "TableDesigner";
|
||||||
|
|
||||||
private Dictionary<string, Dac.TableDesigner> idTableMap = new Dictionary<string, Dac.TableDesigner>();
|
private Dictionary<string, Dac.TableDesigner> idTableMap = new Dictionary<string, Dac.TableDesigner>();
|
||||||
private bool disposed = false;
|
private bool disposed = false;
|
||||||
@@ -1798,7 +1799,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
|||||||
{
|
{
|
||||||
var connectionStringBuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
var connectionStringBuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
||||||
connectionStringBuilder.InitialCatalog = tableInfo.Database;
|
connectionStringBuilder.InitialCatalog = tableInfo.Database;
|
||||||
connectionStringBuilder.ApplicationName = TableDesignerService.TableDesignerApplicationName;
|
connectionStringBuilder.ApplicationName = ConnectionService.GetApplicationNameWithFeature(connectionStringBuilder.ApplicationName, TableDesignerService.TableDesignerApplicationNameSuffix);
|
||||||
var connectionString = connectionStringBuilder.ToString();
|
var connectionString = connectionStringBuilder.ToString();
|
||||||
|
|
||||||
// Set Access Token only when authentication mode is not specified.
|
// Set Access Token only when authentication mode is not specified.
|
||||||
|
|||||||
Reference in New Issue
Block a user