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 static readonly JsonSerializerSettings JsonSerializerSettings;
|
||||
|
||||
public static readonly string DefaultApplicationName = "azdata";
|
||||
public static readonly string SqlLoginAuthenticationType = "SqlLogin";
|
||||
|
||||
static Constants()
|
||||
|
||||
@@ -29,6 +29,7 @@ using Microsoft.SqlTools.Authentication.Sql;
|
||||
using Microsoft.SqlTools.Authentication;
|
||||
using System.IO;
|
||||
using Microsoft.SqlTools.Hosting.Utility;
|
||||
using Constants = Microsoft.SqlTools.Hosting.Protocol.Constants;
|
||||
|
||||
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;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(applicationName) && !string.IsNullOrWhiteSpace(featureName))
|
||||
if (!string.IsNullOrWhiteSpace(applicationName) && !string.IsNullOrWhiteSpace(featureName) && !applicationName.EndsWith(featureName))
|
||||
{
|
||||
int index = applicationName.IndexOf('-');
|
||||
string appName = applicationName;
|
||||
if (index > 0)
|
||||
{
|
||||
appName = applicationName.Substring(0, index);
|
||||
}
|
||||
appNameWithFeature = $"{appName}-{featureName}";
|
||||
int azdataStartIndex = applicationName.IndexOf(Constants.DefaultApplicationName);
|
||||
string originalAppName = azdataStartIndex != -1
|
||||
? applicationName.Substring(0, azdataStartIndex + Constants.DefaultApplicationName.Length)
|
||||
: applicationName; // Reset to default if azdata not found.
|
||||
appNameWithFeature = $"{originalAppName}-{featureName}";
|
||||
}
|
||||
|
||||
return appNameWithFeature;
|
||||
@@ -1162,7 +1161,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -1596,9 +1595,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
ConnectionInfo info;
|
||||
SqlConnectionStringBuilder connStringBuilder;
|
||||
// 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);
|
||||
}
|
||||
// set connection string using connection details
|
||||
@@ -1611,9 +1609,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||
}
|
||||
// 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;
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
{
|
||||
var builder = ConnectionService.CreateConnectionStringBuilder(session.ConnectionInfo.ConnectionDetails);
|
||||
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.
|
||||
var azureToken = builder.Authentication == SqlAuthenticationMethod.NotSpecified
|
||||
? session.ConnectionInfo.ConnectionDetails.AzureAccountToken : null;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectManagement
|
||||
/// </summary>
|
||||
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());
|
||||
public static ObjectManagementService Instance => objectManagementServiceInstance.Value;
|
||||
public static ConnectionService connectionService;
|
||||
|
||||
@@ -17,6 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
|
||||
using Dac = Microsoft.Data.Tools.Sql.DesignServices.TableDesigner;
|
||||
using STSHost = Microsoft.SqlTools.ServiceLayer.Hosting.ServiceHost;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
{
|
||||
@@ -25,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
/// </summary>
|
||||
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 bool disposed = false;
|
||||
@@ -1798,7 +1799,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
|
||||
{
|
||||
var connectionStringBuilder = new SqlConnectionStringBuilder(tableInfo.ConnectionString);
|
||||
connectionStringBuilder.InitialCatalog = tableInfo.Database;
|
||||
connectionStringBuilder.ApplicationName = TableDesignerService.TableDesignerApplicationName;
|
||||
connectionStringBuilder.ApplicationName = ConnectionService.GetApplicationNameWithFeature(connectionStringBuilder.ApplicationName, TableDesignerService.TableDesignerApplicationNameSuffix);
|
||||
var connectionString = connectionStringBuilder.ToString();
|
||||
|
||||
// Set Access Token only when authentication mode is not specified.
|
||||
|
||||
Reference in New Issue
Block a user