Add SSRPHandler and update SqlConnector

This commit is contained in:
samsharma2700 2024-07-22 16:22:22 -07:00
Родитель d9ba4ecc86
Коммит db26a24488
5 изменённых файлов: 74 добавлений и 13 удалений

Просмотреть файл

@ -931,6 +931,7 @@
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginSubHandlers\Tds8TlsHandler.cs" />
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginSubHandlers\Tds74TlsHandler.cs" />
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\PreloginSubHandlers\TlsAuthenticator.cs" />
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\SSRPHandler.cs" />
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\TransportCreationHandler.cs" />
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\TransportCreation\IpAddressVersionComparer.cs" />
<Compile Include="Microsoft\Data\SqlClientX\Handlers\Connection\TransportCreation\NamedPipeTransportCreationHandler.cs" />
@ -997,6 +998,9 @@
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="$(MicrosoftIdentityModelProtocolsOpenIdConnectVersion)" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="$(MicrosoftIdentityModelJsonWebTokensVersion)" />
</ItemGroup>
<ItemGroup>
<Folder Include="microsoft.data.sqlclient\netcore\src\microsoft\data\sqlclientx\handlers\connection\" />
</ItemGroup>
<Import Project="$(ToolsDir)targets\GenerateThisAssemblyCs.targets" />
<Import Project="$(ToolsDir)targets\ResolveContract.targets" Condition="'$(OSGroup)' == 'AnyOS'" />
<Import Project="$(ToolsDir)targets\NotSupported.targets" Condition="'$(OSGroup)' == 'AnyOS'" />

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.Data.SqlClient.SNI
/// <summary>
/// Finds instance port number for given instance name.
/// </summary>
/// <param name="browserHostName">SQL Sever Browser hostname</param>
/// <param name="browserHostName">SQL Server Browser hostname</param>
/// <param name="instanceName">instance name to find port number</param>
/// <param name="timeout">Connection timer expiration</param>
/// <param name="allIPsInParallel">query all resolved IP addresses in parallel</param>

Просмотреть файл

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient.SNI;
namespace Microsoft.Data.SqlClientX.Handlers.Connection
{
/// <summary>
/// Handler to resolve SSRP related ports,instance name etc.
/// </summary>
internal class SSRPHandler : ContextHandler<ConnectionHandlerContext>
{
private const int DefaultPort = 1434;
public override async ValueTask Handle(ConnectionHandlerContext request, bool isAsync, CancellationToken ct)
{
bool isAdmin = request.DataSource.ResolvedProtocol == DataSource.Protocol.Admin;
bool instanceNameProvided = !string.IsNullOrWhiteSpace(request.DataSource.InstanceName);
bool isPortProvided = request.DataSource.Port == -1;
if (isAdmin)
{
if (instanceNameProvided)
{
//TODO: resolve DAC port via SSRP
throw new NotImplementedException();
}
else if (isPortProvided)
{
request.DataSource.ResolvedPort = request.DataSource.Port;
}
else
{
request.DataSource.ResolvedPort = DefaultPort;
}
}
if (NextHandler is not null)
{
await NextHandler.Handle(request, isAsync, ct).ConfigureAwait(false);
}
}
}
}

Просмотреть файл

@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.SqlClientX.Handlers.Connection;
@ -12,29 +13,31 @@ namespace Microsoft.Data.SqlClientX.Handlers
/// <summary>
/// Class responsible for creation of chain of handlers and initiate the chain
/// </summary>
private ConnectionHandlerContext _initialConnectionHandlerContext;
public HandlerOrchestrator(ConnectionHandlerContext initialConnectionHandlerContext)
private static readonly Lazy<HandlerOrchestrator> lazyInstance = new Lazy<HandlerOrchestrator>(() => new HandlerOrchestrator());
private HandlerOrchestrator()
{
_initialConnectionHandlerContext = initialConnectionHandlerContext;
}
public static HandlerOrchestrator Instance => lazyInstance.Value;
/// <summary>
/// Intiates the pre-defined chain of handlers
/// </summary>
/// <param name="handlerContext"></param>
/// <param name="isAsync"></param>
/// <param name="ct"></param>
/// <returns></returns>
public async ValueTask ProcessRequestAsync(bool isAsync, CancellationToken ct)
public async ValueTask ProcessRequestAsync(ConnectionHandlerContext handlerContext, bool isAsync, CancellationToken ct)
{
//TODO: replace with a static line of creating the chain
DataSourceParsingHandler dataSourceParsingHandler = new DataSourceParsingHandler();
TransportCreationHandler transportCreationHandler = new TransportCreationHandler();
SSRPHandler ssrpHandler = new SSRPHandler();
PreloginHandler preloginHandler = new PreloginHandler();
dataSourceParsingHandler.NextHandler = transportCreationHandler;
dataSourceParsingHandler.NextHandler = ssrpHandler;
ssrpHandler.NextHandler = transportCreationHandler;
transportCreationHandler.NextHandler = preloginHandler;
await dataSourceParsingHandler.Handle(_initialConnectionHandlerContext, isAsync, ct).ConfigureAwait(false);
await dataSourceParsingHandler.Handle(handlerContext, isAsync, ct).ConfigureAwait(false);
}
}
}

Просмотреть файл

@ -6,9 +6,11 @@
using System;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClientX.Handlers;
using Microsoft.Data.SqlClientX.Handlers.Connection;
#nullable enable
@ -61,9 +63,15 @@ namespace Microsoft.Data.SqlClientX
/// <param name = "cancellationToken">The token used to cancel an ongoing asynchronous call.</param>
/// <returns>A Task indicating the result of the operation.</returns>
/// <exception cref="NotImplementedException"></exception>
internal ValueTask Open(TimeSpan timeout, bool async, CancellationToken cancellationToken)
internal async ValueTask Open(TimeSpan timeout, bool async, CancellationToken cancellationToken)
{
throw new NotImplementedException();
HandlerOrchestrator orchestrator = HandlerOrchestrator.Instance;
ConnectionHandlerContext context = new ConnectionHandlerContext
{
ConnectionString = new SqlConnectionString(DataSource.ConnectionString)
};
//TODO: a call to SqlCommandX once you reach end of chain.
await orchestrator.ProcessRequestAsync(context, async, cancellationToken).ConfigureAwait(false);
}
/// <summary>