diff --git a/scripts/templates/Modules/aks.bicep b/scripts/templates/Modules/aks.bicep index 8744662e..5e8d32c3 100644 --- a/scripts/templates/Modules/aks.bicep +++ b/scripts/templates/Modules/aks.bicep @@ -35,11 +35,11 @@ resource aksAcrPull 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' } } -resource aks 'Microsoft.ContainerService/managedClusters@2022-05-02-preview' = { +resource aks 'Microsoft.ContainerService/managedClusters@2023-05-01' = { name: aksClusterName location: location sku:{ - name: 'Basic' + name: 'Base' tier: 'Free' } identity: { diff --git a/src/SqlBuildManager.Console/Batch/BatchManager.cs b/src/SqlBuildManager.Console/Batch/BatchManager.cs index e25fa98f..05051e88 100644 --- a/src/SqlBuildManager.Console/Batch/BatchManager.cs +++ b/src/SqlBuildManager.Console/Batch/BatchManager.cs @@ -99,7 +99,7 @@ public BatchManager(CommandLineArgs cmdLine, string queryFile, string outputFile log.LogInformation($"Extracting Platinum Dacpac from {cmdLine.DacPacArgs.PlatinumServerSource} : {cmdLine.DacPacArgs.PlatinumDbSource}"); string dacpacName = Path.Combine(cmdLine.RootLoggingPath, cmdLine.DacPacArgs.PlatinumDbSource + ".dacpac"); - if (!DacPacHelper.ExtractDacPac(cmdLine.DacPacArgs.PlatinumDbSource, cmdLine.DacPacArgs.PlatinumServerSource, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, dacpacName, cmdLine.TimeoutRetryCount)) + if (!DacPacHelper.ExtractDacPac(cmdLine.DacPacArgs.PlatinumDbSource, cmdLine.DacPacArgs.PlatinumServerSource, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, dacpacName, cmdLine.TimeoutRetryCount, cmdLine.IdentityArgs.ClientId)) { log.LogError($"Error creating the Platinum dacpac from {cmdLine.DacPacArgs.PlatinumServerSource} : {cmdLine.DacPacArgs.PlatinumDbSource}"); } diff --git a/src/SqlBuildManager.Console/CommandLine/CommandLineBuilder.Utility.cs b/src/SqlBuildManager.Console/CommandLine/CommandLineBuilder.Utility.cs index 9d6c1c01..9edf86f2 100644 --- a/src/SqlBuildManager.Console/CommandLine/CommandLineBuilder.Utility.cs +++ b/src/SqlBuildManager.Console/CommandLine/CommandLineBuilder.Utility.cs @@ -243,6 +243,22 @@ private static Command OverrideFromSqlUtilityCommand } } + private static Command DecryptSettingsFile + { + get + { + var cmd = new Command("decrypt", "Decrypt a settings file") + { + settingsfileExistingRequiredOption, + settingsfileKeyRequiredOption + }; + cmd.Handler = CommandHandler.Create(Worker.DecryptSettingsFile); + cmd.IsHidden = true; + return cmd; + + } + } + /// /// Utility commands for generating override file from SQL statement and interrogating Service Bus and EventHubs /// @@ -254,8 +270,9 @@ private static Command UtilityCommand { OverrideFromSqlUtilityCommand, QueueUtilityCommand, - EventHubUtilityCommand - }; + EventHubUtilityCommand, + DecryptSettingsFile + }; return cmd; } } diff --git a/src/SqlBuildManager.Console/Threaded/ThreadedManager.cs b/src/SqlBuildManager.Console/Threaded/ThreadedManager.cs index 9050739e..4550cc21 100644 --- a/src/SqlBuildManager.Console/Threaded/ThreadedManager.cs +++ b/src/SqlBuildManager.Console/Threaded/ThreadedManager.cs @@ -369,7 +369,7 @@ private async Task ExecuteFromQueue(CommandLineArgs cmdLine, string buildRe log.LogInformation($"Extracting Platinum Dacpac from {cmdLine.DacPacArgs.PlatinumServerSource} : {cmdLine.DacPacArgs.PlatinumDbSource}"); string dacpacName = Path.Combine(ThreadedManager.rootLoggingPath, cmdLine.DacPacArgs.PlatinumDbSource + ".dacpac"); - if (!DacPacHelper.ExtractDacPac(cmdLine.DacPacArgs.PlatinumDbSource, cmdLine.DacPacArgs.PlatinumServerSource, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, dacpacName, cmdLine.DefaultScriptTimeout)) + if (!DacPacHelper.ExtractDacPac(cmdLine.DacPacArgs.PlatinumDbSource, cmdLine.DacPacArgs.PlatinumServerSource, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, dacpacName, cmdLine.DefaultScriptTimeout, cmdLine.IdentityArgs.ClientId)) { var m = new LogMsg() { diff --git a/src/SqlBuildManager.Console/Threaded/ThreadedRunner.cs b/src/SqlBuildManager.Console/Threaded/ThreadedRunner.cs index 550412cb..66404111 100644 --- a/src/SqlBuildManager.Console/Threaded/ThreadedRunner.cs +++ b/src/SqlBuildManager.Console/Threaded/ThreadedRunner.cs @@ -191,7 +191,7 @@ internal async Task RunDatabaseBuild(ThreadedLogging threadedLog) { runData.ForceCustomDacpac = true; //This will set the BuildData and BuildFileName and ProjectFileName properties on runData - var status = DacPacHelper.UpdateBuildRunDataForDacPacSync(ref runData, server, targetDatabase, authType, username, password, loggingDirectory, cmdArgs.BuildRevision, cmdArgs.DefaultScriptTimeout, cmdArgs.AllowObjectDelete); + var status = DacPacHelper.UpdateBuildRunDataForDacPacSync(ref runData, server, targetDatabase, authType, username, password, loggingDirectory, cmdArgs.BuildRevision, cmdArgs.DefaultScriptTimeout, cmdArgs.AllowObjectDelete, cmdArgs.IdentityArgs.ClientId); switch (status) { case DacpacDeltasStatus.Success: diff --git a/src/SqlBuildManager.Console/Worker/Worker.Utility.cs b/src/SqlBuildManager.Console/Worker/Worker.Utility.cs index 20de7662..090a4bdc 100644 --- a/src/SqlBuildManager.Console/Worker/Worker.Utility.cs +++ b/src/SqlBuildManager.Console/Worker/Worker.Utility.cs @@ -1,9 +1,6 @@ using Microsoft.Extensions.Logging; using Spectre.Console; using SqlBuildManager.Console.CommandLine; -using SqlBuildManager.Console.KeyVault; -using SqlBuildManager.Console.Kubernetes; -using SqlBuildManager.Console.Queue; using SqlBuildManager.Enterprise.Policy; using SqlBuildManager.Interfaces.Console; using SqlSync.SqlBuild.MultiDb; @@ -11,10 +8,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.Intrinsics.X86; using System.Text; using System.Text.Json; -using System.Threading.Tasks; using sb = SqlSync.SqlBuild; namespace SqlBuildManager.Console @@ -41,7 +36,7 @@ internal static int CreateDacpac(CommandLineArgs cmdLine) Directory.CreateDirectory(path); } - if (!sb.DacPacHelper.ExtractDacPac(cmdLine.Database, cmdLine.Server, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, fullName, cmdLine.DefaultScriptTimeout)) + if (!sb.DacPacHelper.ExtractDacPac(cmdLine.Database, cmdLine.Server, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, fullName, cmdLine.DefaultScriptTimeout, cmdLine.IdentityArgs.ClientId)) { log.LogError($"Error creating the dacpac from {cmdLine.Server} : {cmdLine.Database}"); return (int)ExecutionReturn.BuildFileExtractionError; @@ -270,7 +265,7 @@ internal static int CreatePackageFromDiff(CommandLineArgs cmdLine) string id = Guid.NewGuid().ToString(); string goldTmp = Path.Combine(path, $"gold-{id}.dacpac"); string targetTmp = Path.Combine(path, $"target-{id}.dacpac"); - if (!sb.DacPacHelper.ExtractDacPac(cmdLine.SynchronizeArgs.GoldDatabase, cmdLine.SynchronizeArgs.GoldServer, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, goldTmp, cmdLine.DefaultScriptTimeout)) + if (!sb.DacPacHelper.ExtractDacPac(cmdLine.SynchronizeArgs.GoldDatabase, cmdLine.SynchronizeArgs.GoldServer, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, goldTmp, cmdLine.DefaultScriptTimeout, cmdLine.IdentityArgs.ClientId)) { log.LogError($"Error creating the tempprary dacpac from {cmdLine.SynchronizeArgs.GoldServer} : {cmdLine.SynchronizeArgs.GoldDatabase}"); return (int)ExecutionReturn.BuildFileExtractionError; @@ -280,7 +275,7 @@ internal static int CreatePackageFromDiff(CommandLineArgs cmdLine) log.LogInformation($"Temporary DACPAC created from {cmdLine.SynchronizeArgs.GoldServer} : {cmdLine.SynchronizeArgs.GoldDatabase} saved to -- {goldTmp}"); } - if (!sb.DacPacHelper.ExtractDacPac(cmdLine.Database, cmdLine.Server, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, targetTmp, cmdLine.DefaultScriptTimeout)) + if (!sb.DacPacHelper.ExtractDacPac(cmdLine.Database, cmdLine.Server, cmdLine.AuthenticationArgs.AuthenticationType, cmdLine.AuthenticationArgs.UserName, cmdLine.AuthenticationArgs.Password, targetTmp, cmdLine.DefaultScriptTimeout, cmdLine.IdentityArgs.ClientId)) { log.LogError($"Error creating the tempprary dacpac from {cmdLine.Server} : {cmdLine.Database}"); return (int)ExecutionReturn.BuildFileExtractionError; @@ -575,7 +570,7 @@ internal static sb.DacpacDeltasStatus GetSbmFromDacPac(CommandLineArgs cmd, Mult cmd.AuthenticationArgs.Password, cmd.BuildRevision, cmd.DefaultScriptTimeout, - multiDb, out sbmName, batchScripts, cmd.AllowObjectDelete); + multiDb, out sbmName, batchScripts, cmd.AllowObjectDelete, cmd.IdentityArgs.ClientId); } else { @@ -589,7 +584,7 @@ internal static sb.DacpacDeltasStatus GetSbmFromDacPac(CommandLineArgs cmd, Mult cmd.AuthenticationArgs.Password, cmd.BuildRevision, cmd.DefaultScriptTimeout, - multiDb, out sbmName, batchScripts, cmd.AllowObjectDelete); + multiDb, out sbmName, batchScripts, cmd.AllowObjectDelete, cmd.IdentityArgs.ClientId); } } @@ -750,6 +745,16 @@ internal static string ConsoleTableBuilder(List splits, List sect return sb.ToString().Trim(); } + internal static void DecryptSettingsFile(CommandLineArgs cmdLine, string settingsfilekey) + { + (var success, cmdLine) = Init(cmdLine); + var serialized = JsonSerializer.Serialize(cmdLine, new JsonSerializerOptions() { WriteIndented = true }); + System.Console.WriteLine(); + System.Console.WriteLine(serialized); + System.Console.WriteLine(); + + } + internal static int ShowCommands(bool markdown) { var filledCmdDocs = CommandLineBuilder.ListCommands_ForDocs(); diff --git a/src/SqlBuildManager.Console/sbm.csproj b/src/SqlBuildManager.Console/sbm.csproj index 20f4acfa..20bc1fff 100644 --- a/src/SqlBuildManager.Console/sbm.csproj +++ b/src/SqlBuildManager.Console/sbm.csproj @@ -22,16 +22,16 @@ - - - + + + - + @@ -61,7 +61,7 @@ - + diff --git a/src/SqlBuildManager.Logging/SqlBuildManager.Logging.csproj b/src/SqlBuildManager.Logging/SqlBuildManager.Logging.csproj index 9bdb04f8..2414d70d 100644 --- a/src/SqlBuildManager.Logging/SqlBuildManager.Logging.csproj +++ b/src/SqlBuildManager.Logging/SqlBuildManager.Logging.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/src/SqlSync.Connection/ConnectionHelper.cs b/src/SqlSync.Connection/ConnectionHelper.cs index 65edde80..8129cd76 100644 --- a/src/SqlSync.Connection/ConnectionHelper.cs +++ b/src/SqlSync.Connection/ConnectionHelper.cs @@ -159,6 +159,7 @@ public static bool TestDatabaseConnection(ConnectionData connData) DbConnection conn = null; try { + connData.ScriptTimeout = 60; conn = GetConnection(connData); conn.Open(); conn.Close(); diff --git a/src/SqlSync.SqlBuild/DacPacHelper.cs b/src/SqlSync.SqlBuild/DacPacHelper.cs index 150abfff..c304f9a8 100644 --- a/src/SqlSync.SqlBuild/DacPacHelper.cs +++ b/src/SqlSync.SqlBuild/DacPacHelper.cs @@ -15,7 +15,7 @@ public class DacPacHelper { private static ILogger log = SqlBuildManager.Logging.ApplicationLogging.CreateLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public static bool ExtractDacPac(string sourceDatabase, string sourceServer, AuthenticationType authType, string userName, string password, string dacPacFileName, int timeouts) + public static bool ExtractDacPac(string sourceDatabase, string sourceServer, AuthenticationType authType, string userName, string password, string dacPacFileName, int timeouts, string managedIdentityClientId) { try @@ -35,7 +35,7 @@ public static bool ExtractDacPac(string sourceDatabase, string sourceServer, Aut if (!string.IsNullOrWhiteSpace(password)) connData.Password = password; //Pre-test the connection. the DacServices can hang for a long time if the connection is bad - if (!ConnectionHelper.TestDatabaseConnection(connData)) + if (!ConnectionHelper.TestDatabaseConnection(sourceDatabase, sourceServer, userName, password,authType, timeouts, managedIdentityClientId)) { log.LogError($"Unable to create Dacpac for {sourceServer}.{sourceDatabase}. Database connection test failed."); return false; @@ -279,10 +279,10 @@ internal static DacpacDeltasStatus CleanDacPacScript(string dacPacGeneratedScrip } - public static DacpacDeltasStatus UpdateBuildRunDataForDacPacSync(ref SqlBuildRunData runData, string targetServerName, string targetDatabase, AuthenticationType authType, string userName, string password, string workingDirectory, string buildRevision, int defaultScriptTimeout, bool allowObjectDelete) + public static DacpacDeltasStatus UpdateBuildRunDataForDacPacSync(ref SqlBuildRunData runData, string targetServerName, string targetDatabase, AuthenticationType authType, string userName, string password, string workingDirectory, string buildRevision, int defaultScriptTimeout, bool allowObjectDelete, string managedIdentityClientId) { string tmpDacPacName = Path.Combine(workingDirectory, targetDatabase + ".dacpac"); - if (!ExtractDacPac(targetDatabase, targetServerName, authType, userName, password, tmpDacPacName, runData.DefaultScriptTimeout)) + if (!ExtractDacPac(targetDatabase, targetServerName, authType, userName, password, tmpDacPacName, runData.DefaultScriptTimeout, managedIdentityClientId)) { return DacpacDeltasStatus.ExtractionFailure; } @@ -320,7 +320,7 @@ public static DacpacDeltasStatus UpdateBuildRunDataForDacPacSync(ref SqlBuildRun return DacpacDeltasStatus.Success; } - public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string platinumDacPac, string targetDacpac, string database, string server, AuthenticationType authType, string username, string password, string buildRevision, int defaultScriptTimeout, MultiDbData multiDb, out string sbmName, bool batchScripts, bool allowObjectDelete) + public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string platinumDacPac, string targetDacpac, string database, string server, AuthenticationType authType, string username, string password, string buildRevision, int defaultScriptTimeout, MultiDbData multiDb, out string sbmName, bool batchScripts, bool allowObjectDelete, string managedIdentityClientId) { string workingFolder = (!string.IsNullOrEmpty(rootLoggingPath) ? rootLoggingPath : Path.GetTempPath()); @@ -341,7 +341,7 @@ public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string else if (!string.IsNullOrEmpty(database) && !string.IsNullOrEmpty(server)) { string targetDacPac = Path.Combine(workingFolder, database + ".dacpac"); - if (!DacPacHelper.ExtractDacPac(database, server, authType, username, password, targetDacPac, defaultScriptTimeout)) + if (!DacPacHelper.ExtractDacPac(database, server, authType, username, password, targetDacPac, defaultScriptTimeout, managedIdentityClientId)) { log.LogError($"Error extracting dacpac from {database} : {server}"); return DacpacDeltasStatus.ExtractionFailure; @@ -359,7 +359,7 @@ public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string database = serv.Overrides.ElementAt(i).OverrideDbTarget; string targetDacPac = Path.Combine(workingFolder, database + ".dacpac"); - if (!DacPacHelper.ExtractDacPac(database, server, authType, username, password, targetDacPac, defaultScriptTimeout)) + if (!DacPacHelper.ExtractDacPac(database, server, authType, username, password, targetDacPac, defaultScriptTimeout, managedIdentityClientId)) { log.LogError($"Error extracting dacpac from {server} : {database}"); return DacpacDeltasStatus.ExtractionFailure; @@ -407,9 +407,9 @@ public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string } return stat; } - public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string platinumDacPac, string database, AuthenticationType authType, string server, string username, string password, string buildRevision, int defaultScriptTimeout, MultiDbData multiDb, out string sbmName, bool batchScripts, bool allowObjectDelete) + public static DacpacDeltasStatus GetSbmFromDacPac(string rootLoggingPath, string platinumDacPac, string database, AuthenticationType authType, string server, string username, string password, string buildRevision, int defaultScriptTimeout, MultiDbData multiDb, out string sbmName, bool batchScripts, bool allowObjectDelete, string managedIdentityClientId) { - return GetSbmFromDacPac(rootLoggingPath, platinumDacPac, string.Empty, database, server, authType, username, password, buildRevision, defaultScriptTimeout, multiDb, out sbmName, batchScripts, allowObjectDelete); + return GetSbmFromDacPac(rootLoggingPath, platinumDacPac, string.Empty, database, server, authType, username, password, buildRevision, defaultScriptTimeout, multiDb, out sbmName, batchScripts, allowObjectDelete, managedIdentityClientId); } diff --git a/src/SqlSync.SqlBuild/SqlBuildHelper.cs b/src/SqlSync.SqlBuild/SqlBuildHelper.cs index 863dbd14..c78913f0 100644 --- a/src/SqlSync.SqlBuild/SqlBuildHelper.cs +++ b/src/SqlSync.SqlBuild/SqlBuildHelper.cs @@ -307,7 +307,7 @@ internal SqlSyncBuildData.BuildRow ProcessBuild(SqlBuildRunData runData, Backgro var database = ((SqlSyncBuildData.ScriptRow)filteredScripts[0].Row).Database; string targetDatabase = GetTargetDatabase(database); log.LogWarning($"Custom dacpac required for {serverName} : {targetDatabase}. Generating file."); - var stat = DacPacHelper.UpdateBuildRunDataForDacPacSync(ref runData, serverName, targetDatabase, connData.AuthenticationType, connData.UserId, connData.Password, projectFilePath, runData.BuildRevision, runData.DefaultScriptTimeout, runData.AllowObjectDelete); + var stat = DacPacHelper.UpdateBuildRunDataForDacPacSync(ref runData, serverName, targetDatabase, connData.AuthenticationType, connData.UserId, connData.Password, projectFilePath, runData.BuildRevision, runData.DefaultScriptTimeout, runData.AllowObjectDelete, connData.ManagedIdentityClientId); if (stat == DacpacDeltasStatus.Success) {