mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Get Application Path from command options (#1916)
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.SqlTools.Authentication.Utility;
|
using Microsoft.SqlTools.Authentication.Utility;
|
||||||
|
using Microsoft.SqlTools.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.Authentication.Sql
|
namespace Microsoft.SqlTools.Authentication.Sql
|
||||||
{
|
{
|
||||||
@@ -27,13 +28,23 @@ namespace Microsoft.SqlTools.Authentication.Sql
|
|||||||
/// Instantiates AuthenticationProvider to be used for AAD authentication with MSAL.NET and MSAL.js co-ordinated.
|
/// Instantiates AuthenticationProvider to be used for AAD authentication with MSAL.NET and MSAL.js co-ordinated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="applicationName">Application Name that identifies user folder path location for reading/writing to shared cache.</param>
|
/// <param name="applicationName">Application Name that identifies user folder path location for reading/writing to shared cache.</param>
|
||||||
|
/// <param name="applicationPath">Application Path directory where application cache folder is present.</param>
|
||||||
/// <param name="authCallback">Callback that handles AAD authentication when user interaction is needed.</param>
|
/// <param name="authCallback">Callback that handles AAD authentication when user interaction is needed.</param>
|
||||||
public AuthenticationProvider(string applicationName)
|
public AuthenticationProvider(string applicationName, string applicationPath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(applicationName))
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(applicationName)) {
|
|
||||||
applicationName = nameof(SqlTools);
|
applicationName = nameof(SqlTools);
|
||||||
|
Logger.Warning($"Application Name not received with command options, using default application name as: {applicationName}");
|
||||||
}
|
}
|
||||||
var cachePath = Path.Combine(Utils.BuildAppDirectoryPath(), applicationName, AzureTokenFolder);
|
|
||||||
|
if (string.IsNullOrEmpty(applicationPath))
|
||||||
|
{
|
||||||
|
applicationPath = Utils.BuildAppDirectoryPath();
|
||||||
|
Logger.Warning($"Application Path not received with command options, using default application path as: {applicationPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var cachePath = Path.Combine(applicationPath, applicationName, AzureTokenFolder);
|
||||||
this.authenticator = new Authenticator(ApplicationClientId, applicationName, cachePath, MsalCacheName);
|
this.authenticator = new Authenticator(ApplicationClientId, applicationName, cachePath, MsalCacheName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Microsoft.SqlTools.Authentication.Utility
|
|||||||
/// <exception cref="Exception">When called on unsupported platform.</exception>
|
/// <exception cref="Exception">When called on unsupported platform.</exception>
|
||||||
public static string BuildAppDirectoryPath()
|
public static string BuildAppDirectoryPath()
|
||||||
{
|
{
|
||||||
var homedir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var homedir = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||||
|
|
||||||
// Windows
|
// Windows
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ namespace Microsoft.SqlTools.Utility
|
|||||||
case "-application-name":
|
case "-application-name":
|
||||||
ApplicationName = args[++i];
|
ApplicationName = args[++i];
|
||||||
break;
|
break;
|
||||||
|
case "-data-path":
|
||||||
|
ApplicationPath = args[++i];
|
||||||
|
break;
|
||||||
case "-autoflush-log":
|
case "-autoflush-log":
|
||||||
AutoFlushLog = true;
|
AutoFlushLog = true;
|
||||||
break;
|
break;
|
||||||
@@ -110,6 +113,11 @@ namespace Microsoft.SqlTools.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ApplicationName { get; private set; }
|
public string ApplicationName { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Path of application home directory
|
||||||
|
/// </summary>
|
||||||
|
public string ApplicationPath { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains any error messages during execution
|
/// Contains any error messages during execution
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1076,7 +1076,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
|||||||
if (commandOptions != null && commandOptions.EnableSqlAuthenticationProvider)
|
if (commandOptions != null && commandOptions.EnableSqlAuthenticationProvider)
|
||||||
{
|
{
|
||||||
// Register SqlAuthenticationProvider with SqlConnection for AAD Interactive (MFA) authentication.
|
// Register SqlAuthenticationProvider with SqlConnection for AAD Interactive (MFA) authentication.
|
||||||
var provider = new AuthenticationProvider(commandOptions.ApplicationName);
|
var provider = new AuthenticationProvider(commandOptions.ApplicationName, commandOptions.ApplicationPath);
|
||||||
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, provider);
|
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive, provider);
|
||||||
|
|
||||||
this.EnableSqlAuthenticationProvider = true;
|
this.EnableSqlAuthenticationProvider = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user