mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Provide connection options to host process (#267)
* Stage changes to other machine * Add connection options in init message * Fix option type
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.Hosting.Contracts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines a message that is sent from the client to request
|
||||||
|
/// the version of the server.
|
||||||
|
/// </summary>
|
||||||
|
public class CapabilitiesRequest
|
||||||
|
{
|
||||||
|
public static readonly
|
||||||
|
RequestType<CapabilitiesRequest, CapabilitiesResult> Type =
|
||||||
|
RequestType<CapabilitiesRequest, CapabilitiesResult>.Create("capabilities/list");
|
||||||
|
|
||||||
|
public string HostName { get; set; }
|
||||||
|
|
||||||
|
public string HostVersion { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CapabilitiesResult
|
||||||
|
{
|
||||||
|
public DmpServerCapabilities Capabilities { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.Hosting.Contracts
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the connection provider options that the DMP server
|
||||||
|
/// implements. This includes metadata regarding supported connection
|
||||||
|
/// properties.
|
||||||
|
/// </summary>
|
||||||
|
public class ConnectionProviderOptions
|
||||||
|
{
|
||||||
|
public ConnectionOption[] Options { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ConnectionOption
|
||||||
|
{
|
||||||
|
public static readonly string ValueTypeString = "string";
|
||||||
|
public static readonly string ValueTypeMultiString = "multistring";
|
||||||
|
public static readonly string ValueTypePassword = "password";
|
||||||
|
public static readonly string ValueTypeNumber = "number";
|
||||||
|
public static readonly string ValueTypeCategory = "category";
|
||||||
|
public static readonly string ValueTypeBoolean = "boolean";
|
||||||
|
|
||||||
|
public static readonly string SpecialValueServerName = "serverName";
|
||||||
|
public static readonly string SpecialValueDatabaseName = "databaseName";
|
||||||
|
public static readonly string SpecialValueAuthType = "authType";
|
||||||
|
public static readonly string SpecialValueUserName = "userName";
|
||||||
|
public static readonly string SpecialValuePasswordName = "password";
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Type of the parameter. Can be either string, number, or category.
|
||||||
|
/// </summary>
|
||||||
|
public string ValueType { get; set; }
|
||||||
|
|
||||||
|
public string DefaultValue { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set of permitted values if ValueType is category.
|
||||||
|
/// </summary>
|
||||||
|
public string[] CategoryValues { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the parameter is one of the 'specical' known values.
|
||||||
|
/// Can be either Server Name, Database Name, Authentication Type,
|
||||||
|
/// User Name, or Password
|
||||||
|
/// </summary>
|
||||||
|
public string SpecialValueType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flag to indicate that this option is part of the connection identity
|
||||||
|
/// </summary>
|
||||||
|
public bool IsIdentity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Flag to indicate that this option is required
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRequired { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,11 +5,17 @@
|
|||||||
|
|
||||||
namespace Microsoft.SqlTools.Hosting.Contracts
|
namespace Microsoft.SqlTools.Hosting.Contracts
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the DMP server capabilities
|
||||||
|
/// </summary>
|
||||||
public class DmpServerCapabilities
|
public class DmpServerCapabilities
|
||||||
{
|
{
|
||||||
public string ProviderName { get; set;
|
public string ProtocolVersion { get; set; }
|
||||||
}
|
|
||||||
public bool? HoverProvider { get; set; }
|
public string ProviderName { get; set; }
|
||||||
|
|
||||||
|
public string ProviderDisplayName { get; set; }
|
||||||
|
|
||||||
|
public ConnectionProviderOptions ConnectionProvider { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
public void InitializeRequestHandlers()
|
public void InitializeRequestHandlers()
|
||||||
{
|
{
|
||||||
// Register the requests that this service host will handle
|
// Register the requests that this service host will handle
|
||||||
this.SetRequestHandler(InitializeRequest.Type, this.HandleInitializeRequest);
|
this.SetRequestHandler(InitializeRequest.Type, HandleInitializeRequest);
|
||||||
this.SetRequestHandler(ShutdownRequest.Type, this.HandleShutdownRequest);
|
this.SetRequestHandler(CapabilitiesRequest.Type, HandleCapabilitiesRequest);
|
||||||
|
this.SetRequestHandler(ShutdownRequest.Type, HandleShutdownRequest);
|
||||||
this.SetRequestHandler(VersionRequest.Type, HandleVersionRequest);
|
this.SetRequestHandler(VersionRequest.Type, HandleVersionRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +172,140 @@ namespace Microsoft.SqlTools.ServiceLayer.Hosting
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal async Task HandleCapabilitiesRequest(
|
||||||
|
CapabilitiesRequest initializeParams,
|
||||||
|
RequestContext<CapabilitiesResult> requestContext)
|
||||||
|
{
|
||||||
|
await requestContext.SendResult(
|
||||||
|
new CapabilitiesResult
|
||||||
|
{
|
||||||
|
Capabilities = new DmpServerCapabilities
|
||||||
|
{
|
||||||
|
ProtocolVersion = "1.0",
|
||||||
|
ProviderName = "MSSQL",
|
||||||
|
ProviderDisplayName = "Microsoft SQL Server",
|
||||||
|
ConnectionProvider = ServiceHost.BuildConnectionProviderOptions()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ConnectionProviderOptions BuildConnectionProviderOptions()
|
||||||
|
{
|
||||||
|
return new ConnectionProviderOptions
|
||||||
|
{
|
||||||
|
Options = new ConnectionOption[]
|
||||||
|
{
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Server Name",
|
||||||
|
ValueType = ConnectionOption.ValueTypeString,
|
||||||
|
SpecialValueType = ConnectionOption.SpecialValueServerName,
|
||||||
|
IsIdentity = true,
|
||||||
|
IsRequired = true
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Initial Catalog",
|
||||||
|
DisplayName = "Database Name",
|
||||||
|
ValueType = ConnectionOption.ValueTypeString,
|
||||||
|
SpecialValueType = ConnectionOption.SpecialValueDatabaseName,
|
||||||
|
IsIdentity = true,
|
||||||
|
IsRequired = true
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Auth Type",
|
||||||
|
ValueType = ConnectionOption.ValueTypeCategory,
|
||||||
|
SpecialValueType = ConnectionOption.SpecialValueAuthType,
|
||||||
|
CategoryValues = new string[] { "SQL Login", "Integrated Auth" },
|
||||||
|
IsIdentity = true,
|
||||||
|
IsRequired = true
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Username",
|
||||||
|
ValueType = ConnectionOption.ValueTypeString,
|
||||||
|
SpecialValueType = ConnectionOption.SpecialValueUserName,
|
||||||
|
IsIdentity = true,
|
||||||
|
IsRequired = true
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Password",
|
||||||
|
DisplayName = "Database Name",
|
||||||
|
ValueType = ConnectionOption.ValueTypePassword,
|
||||||
|
SpecialValueType = ConnectionOption.SpecialValuePasswordName,
|
||||||
|
IsIdentity = true,
|
||||||
|
IsRequired = true
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Application Intent",
|
||||||
|
ValueType = ConnectionOption.ValueTypeCategory,
|
||||||
|
CategoryValues = new string[] { "ReadWrite", "ReadOnly" }
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Asynchronous Processing",
|
||||||
|
ValueType = ConnectionOption.ValueTypeBoolean
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Connect Timeout",
|
||||||
|
ValueType = ConnectionOption.ValueTypeNumber,
|
||||||
|
DefaultValue = "15"
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Current Language",
|
||||||
|
ValueType = ConnectionOption.ValueTypeString
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Column Encrytion Setting",
|
||||||
|
ValueType = ConnectionOption.ValueTypeCategory,
|
||||||
|
CategoryValues = new string[] { "Disabled", "Enabled" }
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Encrypt",
|
||||||
|
ValueType = ConnectionOption.ValueTypeBoolean
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Persist Security Info",
|
||||||
|
ValueType = ConnectionOption.ValueTypeBoolean
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Trust Server Certificate",
|
||||||
|
ValueType = ConnectionOption.ValueTypeBoolean
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Persist Security Info",
|
||||||
|
ValueType = ConnectionOption.ValueTypeBoolean
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Trust Server Certificate",
|
||||||
|
ValueType = ConnectionOption.ValueTypeBoolean
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Attached DB File Name",
|
||||||
|
ValueType = ConnectionOption.ValueTypeString
|
||||||
|
},
|
||||||
|
new ConnectionOption
|
||||||
|
{
|
||||||
|
Name = "Context Connection",
|
||||||
|
ValueType = ConnectionOption.ValueTypeString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the version request. Sends back the server version as result.
|
/// Handles the version request. Sends back the server version as result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.SqlTools.Hosting.Contracts;
|
||||||
|
using Microsoft.SqlTools.Hosting.Protocol;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Capabilities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Test cases for the capabilities discovery messages
|
||||||
|
/// </summary>
|
||||||
|
public class Capabilities
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task TestCapabilities()
|
||||||
|
{
|
||||||
|
Hosting.ServiceHost host = Hosting.ServiceHost.Instance;
|
||||||
|
var requestContext = new Mock<RequestContext<CapabilitiesResult>>();
|
||||||
|
requestContext.Setup(x => x.SendResult(It.IsAny<CapabilitiesResult>())).Returns(Task.FromResult(new object()));
|
||||||
|
|
||||||
|
await host.HandleCapabilitiesRequest(new CapabilitiesRequest
|
||||||
|
{
|
||||||
|
HostName = "Test Host", HostVersion = "1.0"
|
||||||
|
}, requestContext.Object);
|
||||||
|
|
||||||
|
requestContext.Verify(x => x.SendResult(It.Is<CapabilitiesResult>(
|
||||||
|
i => i.Capabilities.ConnectionProvider.Options != null)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user