Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature toggle to disable FSharp script execution #1411

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion source/Calamari.Common/FeatureToggles/FeatureToggle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum FeatureToggle {
PreventHelmV2DeploymentsFeatureToggle,
KubernetesLiveObjectStatusFeatureToggle,
KubernetesAuthAwsCliWithExecFeatureToggle,
ForceUtf8ZipFileDecodingFeatureToggle
ForceUtf8ZipFileDecodingFeatureToggle,
DisableFSharpScriptExecutionFeatureToggle
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Calamari.Common.Commands;
using Calamari.Common.Features.Processes;
using Calamari.Common.FeatureToggles;
using Calamari.Common.Plumbing.Logging;
Expand All @@ -22,6 +23,12 @@ protected override IEnumerable<ScriptExecution> PrepareExecution(Script script,
IVariables variables,
Dictionary<string, string>? environmentVars = null)
{
//if the feature toggle to disable FSharp scripts is enabled, just blow up
if (FeatureToggle.DisableFSharpScriptExecutionFeatureToggle.IsEnabled(variables))
{
throw new CommandException($"FSharp scripts are no longer supported. Please read our deprecation {log.FormatLink("https://oc.to/fsharp-deprecation", "blog post")} for more details.");
}

LogFSharpDeprecationWarning(variables);

var workingDirectory = Path.GetDirectoryName(script.File);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@
<hash>\Microsoft.WindowsAzure.Packaging.dll
<hash>\Microsoft.WindowsAzure.ServiceModel.Common.dll
<hash>\Microsoft.WindowsAzure.Storage.dll
<hash>\mscordaccore.dll
<hash>\mscordaccore.dll
<hash>\mscordaccore_amd64_amd64_<version>.dll
<hash>\mscordaccore_amd64_amd64_<version>.dll
<hash>\mscordaccore.dll
<hash>\mscordaccore.dll
<hash>\mscordbi.dll
<hash>\mscordbi.dll
<hash>\mscorlib.dll
Expand Down Expand Up @@ -415,13 +415,13 @@
<hash>\SharpCompress.dll
<hash>\SharpCompress.dll
<hash>\SharpCompress.dll
<hash>\sos_amd64_amd64_<version>.dll
<hash>\SOS_README.md
<hash>\SOS_README.md
<hash>\sos.dll
<hash>\SOS.NETCore.dll
<hash>\SOS.NETCore.dll
<hash>\SOS.NETCore.dll
<hash>\sos_amd64_amd64_<version>.dll
<hash>\SOS_README.md
<hash>\SOS_README.md
<hash>\sosdocsunix.txt
<hash>\Sprache.dll
<hash>\Sprache.dll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
using Calamari.Common.Commands;
using Calamari.Common.Features.Processes;
using Calamari.Common.Features.Scripting;
using Calamari.Common.Features.Scripting.FSharp;
using Calamari.Common.FeatureToggles;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;
using FluentAssertions;
using NSubstitute;
using NUnit.Framework;

Expand Down Expand Up @@ -54,5 +56,29 @@ public void LogsFSharpDeprecationWarningWhenToggledOn(KeyValuePair<string, strin
log.DidNotReceive().Warn(Arg.Any<string>());
}
}

[Test]
public void WhenDisableFSharpScriptExecutionFeatureToggleIsEnabled_ScriptExecutionThrowsAnException()
{
// Arrange
var log = Substitute.For<ILog>();
var script = new Script("fakeScript.fsx");
var variables = new CalamariVariables
{
[KnownVariables.EnabledFeatureToggles] = FeatureToggle.DisableFSharpScriptExecutionFeatureToggle.ToString()
};

var commandResult = new CommandResult("fakeCommand", 0);
var commandLineRunner = Substitute.For<ICommandLineRunner>();
commandLineRunner.Execute(Arg.Any<CommandLineInvocation>()).Returns(commandResult);

var executor = new FSharpExecutor(log);

// Act
Action act = () => executor.Execute(script, variables, commandLineRunner);

// Assert
act.Should().Throw<CommandException>();
}
}
}