mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Modify Get Connection String Request to use connection details (#1394)
* connection string accepts connectionInfo * get connection string from disconnected scenarios
This commit is contained in:
@@ -532,7 +532,11 @@ Get a connection string for the provided connection.
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string OwnerUri { get; set; }
|
public string OwnerUri { get; set; }
|
||||||
|
|
||||||
|
/// Connection info of the connection
|
||||||
|
/// </summary>
|
||||||
|
public ConnectionDetails ConnectionDetails { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
||||||
/// Indicates whether the password should be return in the connection string. Default is false.
|
/// Indicates whether the password should be return in the connection string. Default is false.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IncludePassword { get; set; }
|
public bool IncludePassword { get; set; }
|
||||||
|
|||||||
@@ -1317,12 +1317,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
{
|
{
|
||||||
string connectionString = string.Empty;
|
string connectionString = string.Empty;
|
||||||
ConnectionInfo info;
|
ConnectionInfo info;
|
||||||
if (TryFindConnection(connStringParams.OwnerUri, out info))
|
SqlConnectionStringBuilder connStringBuilder;
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SqlConnectionStringBuilder connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
// set connection string using connection uri if connection details are undefined
|
||||||
|
if (connStringParams.ConnectionDetails == null)
|
||||||
|
{
|
||||||
|
TryFindConnection(connStringParams.OwnerUri, out info);
|
||||||
|
connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
||||||
|
}
|
||||||
|
// set connection string using connection details
|
||||||
|
else
|
||||||
|
{
|
||||||
|
connStringBuilder = CreateConnectionStringBuilder(connStringParams.ConnectionDetails as ConnectionDetails);
|
||||||
|
}
|
||||||
if (!connStringParams.IncludePassword)
|
if (!connStringParams.IncludePassword)
|
||||||
{
|
{
|
||||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||||
@@ -1338,7 +1346,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
{
|
{
|
||||||
await requestContext.SendError(e.ToString());
|
await requestContext.SendError(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await requestContext.SendResult(connectionString);
|
await requestContext.SendResult(connectionString);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string OwnerUri { get; set; }
|
public string OwnerUri { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connection information of the connection
|
||||||
|
/// </summary>
|
||||||
|
public ConnectionDetails ConnectionDetails { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether the password should be return in the connection string
|
/// Indicates whether the password should be return in the connection string
|
||||||
/// default is set to false
|
/// default is set to false
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
var requestParams = new GetConnectionStringParams()
|
var requestParams = new GetConnectionStringParams()
|
||||||
{
|
{
|
||||||
OwnerUri = result.ConnectionInfo.OwnerUri,
|
OwnerUri = result.ConnectionInfo.OwnerUri,
|
||||||
|
ConnectionDetails = null,
|
||||||
IncludePassword = false,
|
IncludePassword = false,
|
||||||
IncludeApplicationName = true
|
IncludeApplicationName = true
|
||||||
};
|
};
|
||||||
@@ -159,6 +160,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
var requestParams = new GetConnectionStringParams()
|
var requestParams = new GetConnectionStringParams()
|
||||||
{
|
{
|
||||||
OwnerUri = result.ConnectionInfo.OwnerUri,
|
OwnerUri = result.ConnectionInfo.OwnerUri,
|
||||||
|
ConnectionDetails = null,
|
||||||
IncludePassword = false,
|
IncludePassword = false,
|
||||||
IncludeApplicationName = false
|
IncludeApplicationName = false
|
||||||
};
|
};
|
||||||
@@ -166,5 +168,32 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Connection
|
|||||||
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
|
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
|
||||||
requestContext.VerifyAll();
|
requestContext.VerifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test HandleGetConnectionStringRequest
|
||||||
|
/// Using connection details to build connection string
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public async Task GetCurrentConnectionStringTestwithConnectionDetails()
|
||||||
|
{
|
||||||
|
// If we make a connection to a live database
|
||||||
|
ConnectionService service = ConnectionService.Instance;
|
||||||
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
||||||
|
var resultConnectionDetails = result.ConnectionInfo.ConnectionDetails;
|
||||||
|
var requestContext = new Mock<SqlTools.Hosting.Protocol.RequestContext<string>>();
|
||||||
|
|
||||||
|
requestContext.Setup(x => x.SendResult(It.Is<string>((connectionString) => connectionString.Contains(resultConnectionDetails.ToString()))))
|
||||||
|
.Returns(Task.FromResult(new object()));
|
||||||
|
var requestParams = new GetConnectionStringParams()
|
||||||
|
{
|
||||||
|
OwnerUri = null,
|
||||||
|
ConnectionDetails = {ServerName = "testServer", DatabaseName = "testDatabase", UserName = "sa", Password = "password", ApplicationName = "TestApp"},
|
||||||
|
IncludePassword = true,
|
||||||
|
IncludeApplicationName = true
|
||||||
|
};
|
||||||
|
|
||||||
|
await service.HandleGetConnectionStringRequest(requestParams, requestContext.Object);
|
||||||
|
requestContext.VerifyAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user