Skip to content

Commit

Permalink
More Legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
zentron committed Sep 7, 2024
1 parent 0dd875c commit 63dbb2e
Show file tree
Hide file tree
Showing 26 changed files with 427 additions and 240 deletions.
51 changes: 44 additions & 7 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public Build()
Lazy<string> NugetVersion { get; }

Target CheckForbiddenWords =>
_ => _.Executes(() =>
_ => _
.OnlyWhenStatic(() => !IsLocalBuild)
.Executes(() =>
{
Log.Information("Checking codebase for forbidden words");

Expand Down Expand Up @@ -169,6 +171,18 @@ public Build()
{
Log.Information("Compiling Calamari v{CalamariVersion}", NugetVersion.Value);

DotNetBuild(_ => _.SetProjectFile(SourceDirectory / "Calamari.FullFrameworkTools"/ "Calamari.FullFrameworkTools.csproj")
.SetConfiguration(Configuration)
.DisableNoRestore()
.SetVersion(NugetVersion.Value)
.SetInformationalVersion(GitVersionInfo?.InformationalVersion));

DotNetBuild(_ => _.SetProjectFile(SourceDirectory / "Calamari.FullFrameworkTools.Tests"/ "Calamari.FullFrameworkTools.Tests.csproj")
.SetConfiguration(Configuration)
.DisableNoRestore()
.SetVersion(NugetVersion.Value)
.SetInformationalVersion(GitVersionInfo?.InformationalVersion));

DotNetBuild(_ => _.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetNoRestore(true)
Expand Down Expand Up @@ -219,11 +233,32 @@ public Build()
nugetVersion,
FixedRuntimes.Cloud);

// Create the self-contained Calamari packages for each runtime ID defined in Calamari.csproj
foreach (var rid in GetRuntimeIdentifiers(Solution.GetProject(RootProjectName)!)!)
DoPublish(RootProjectName, Frameworks.Net60, nugetVersion, rid);
});
if (OperatingSystem.IsWindows())
{
var path = SourceDirectory / "Calamari.FullFrameworkTools" / "bin" / Configuration / Frameworks.Net462 ;
CopyDirectoryRecursively(path, (PublishDirectory / "Calamari" / Frameworks.Net462 / "Calamari.FullFrameworkTools"), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
CopyDirectoryRecursively(path, (PublishDirectory / "Calamari" / Frameworks.Net60 / "Calamari.FullFrameworkTools"), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
}

// Create the self-contained Calamari packages for each runtime ID defined in Calamari.csproj
foreach (var rid in GetRuntimeIdentifiers(Solution.GetProject(RootProjectName)!)!)
{
var publishPath = DoPublish(RootProjectName, Frameworks.Net60, nugetVersion, rid);

if (rid == FixedRuntimes.Windows && OperatingSystem.IsWindows())
{
CopyFullFrameworkFiles(publishPath);
}
}
});


void CopyFullFrameworkFiles(AbsolutePath targetPath)
{
var path = SourceDirectory / "Calamari.FullFrameworkTools" / "bin" / Configuration / Frameworks.Net462;
CopyDirectoryRecursively(path, (targetPath / "Calamari.FullFrameworkTools"), DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
}

Target PublishCalamariFlavourProjects =>
_ => _
.DependsOn(Compile)
Expand Down Expand Up @@ -329,7 +364,7 @@ void PublishPackage(CalamariPackageMetadata calamariPackageMetadata)
File.Copy(RootDirectory / "global.json", outputDirectory / "global.json");

}

static void StageLegacyCalamariAssemblies(CalamariPackageMetadata[] packagesToPublish) {

if (!OperatingSystem.IsWindows())
Expand All @@ -340,7 +375,7 @@ static void StageLegacyCalamariAssemblies(CalamariPackageMetadata[] packagesToPu
}

packagesToPublish
//We only need to bundle executable (not tests or libraries) full framework projects
//We only need to bundle executable (not tests or libraries) full framework projects
.Where(d => d.Framework == Frameworks.Net462 && d.Project.GetOutputType() == "Exe")
.ForEach(calamariPackageMetadata =>
{
Expand Down Expand Up @@ -434,6 +469,8 @@ void CompressCalamariProject(Project project)
var defaultTarget = OperatingSystem.IsWindows() ? Frameworks.Net462 : Frameworks.Net60;
AbsolutePath binFolder = SourceDirectory / "Calamari.Tests" / "bin" / Configuration / defaultTarget;
Directory.Exists(binFolder);

CopyFullFrameworkFiles(binFolder);
var actions = new List<Action>
{
() =>
Expand Down
10 changes: 5 additions & 5 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@

<ItemGroup>
<PackageReference Include="NuGet.CommandLine" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nuke.Common" Version="7.0.6" />
</ItemGroup>

<ItemGroup>
<PackageDownload Include="AzureSignTool" Version="[3.0.0]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.12.0]" />
<PackageDownload Include="AzureSignTool" Version="[3.0.0]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.12.0]" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\source\Calamari.ConsolidateCalamariPackages\Calamari.ConsolidateCalamariPackages.csproj" />
<ProjectReference Include="..\source\Calamari.ConsolidateCalamariPackages\Calamari.ConsolidateCalamariPackages.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions source/Calamari.FullFrameworkTools.Tests/IisCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void GivenOneParameter_ThenException()
var iisServer = Substitute.For<IInternetInformationServer>();
var cmd = new IisCommand(iisServer);

Assert.Throws<InvalidOperationException>(() => cmd.Execute(new string[] { Guid.NewGuid().ToString()}));
Assert.Throws<CommandException>(() => cmd.Execute(new string[] { Guid.NewGuid().ToString()}));
}

[Test]
Expand All @@ -35,7 +35,7 @@ public void GivenNoParameter_ThenException()
var iisServer = Substitute.For<IInternetInformationServer>();
var cmd = new IisCommand(iisServer);

Assert.Throws<InvalidOperationException>(() => cmd.Execute(Array.Empty<string>()));
Assert.Throws<CommandException>(() => cmd.Execute(Array.Empty<string>()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net462" Version="1.0.2" />
<PackageReference Include="Microsoft.Web.Administration" Version="7.0.0.0" />
Expand Down
20 changes: 15 additions & 5 deletions source/Calamari.FullFrameworkTools/Command/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
using System;
using Calamari.FullFrameworkTools.Iis;
using Calamari.FullFrameworkTools.WindowsCertStore;
using Calamari.FullFrameworkTools.WindowsCertStore.Contracts;

namespace Calamari.FullFrameworkTools.Command;

public interface ICommandHandler
{
object Handle(IRequest obj);
}
public class CommandHandler: ICommandHandler

public class CommandHandler : ICommandHandler
{
readonly IWindowsX509CertificateStore certificateStore;
readonly IInternetInformationServer internetInformationServer;
Expand All @@ -25,17 +27,25 @@ public object Handle(IRequest obj)
return obj switch
{
null => throw new NotImplementedException(),

//IIS Comments
OverwriteHomeDirectoryRequest req => req.DoIt(internetInformationServer),

// Windows Cert Commands
FindCertificateStoreRequest req => req.DoIt(certificateStore),
ImportCertificateToStoreByUserRequest req => req.DoIt(certificateStore),
ImportCertificateToStoreByLocationRequest req => req.DoIt(certificateStore),
AddPrivateKeyAccessRulesRequest req => req.DoIt(certificateStore),

_ => throw new ArgumentOutOfRangeException($"Unknown Request {obj.GetType().Name}"),
};
}
}
}

public interface IFullFrameworkToolResponse
{
}

public class StringResponse : IFullFrameworkToolResponse { public string? Value { get; set; } }
public class VoidResponse : IFullFrameworkToolResponse { }
public class BoolResponse : IFullFrameworkToolResponse { public bool Value { get; set; } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Calamari.FullFrameworkTools.Command;

namespace Calamari.FullFrameworkTools.WindowsCertStore.Contracts;

public class AddPrivateKeyAccessRulesRequest : IRequest
{
public AddPrivateKeyAccessRulesRequest(string thumbprint, StoreLocation storeLocation, string storeName, List<PrivateKeyAccessRule> privateKeyAccessRules)
{
this.Thumbprint = thumbprint;
StoreName = storeName;
PrivateKeyAccessRules = privateKeyAccessRules;
StoreLocation = storeLocation;
}

public string Thumbprint { get; set; }
public StoreLocation StoreLocation { get; set; }
public string StoreName { get; set; }
public List<PrivateKeyAccessRule> PrivateKeyAccessRules { get; set; }


public VoidResponse DoIt(IWindowsX509CertificateStore certificateStore)
{
if (string.IsNullOrEmpty(StoreName))
{
certificateStore.AddPrivateKeyAccessRules(Thumbprint, StoreLocation, PrivateKeyAccessRules);
}
else
{
certificateStore.AddPrivateKeyAccessRules(Thumbprint, StoreLocation, StoreName, PrivateKeyAccessRules);
}

return new VoidResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#nullable enable
using System;
using System.Security.Cryptography.X509Certificates;
using Calamari.FullFrameworkTools.Command;

namespace Calamari.FullFrameworkTools.WindowsCertStore.Contracts;

public class FindCertificateStoreRequest : IRequest
{
public FindCertificateStoreRequest(string thumbprint, StoreLocation storeLocation)
{
Thumbprint = thumbprint;
StoreLocation = storeLocation;
}

public string Thumbprint { get; }
public StoreLocation StoreLocation { get; }

public VoidResponse DoIt(IWindowsX509CertificateStore certificateStore)
{
certificateStore.FindCertificateStore(Thumbprint, StoreLocation);
return new VoidResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#nullable enable
using System;
using System.Security.Cryptography.X509Certificates;
using Calamari.FullFrameworkTools.Command;

namespace Calamari.FullFrameworkTools.WindowsCertStore.Contracts;

public class ImportCertificateToStoreByLocationRequest : IRequest
{
public ImportCertificateToStoreByLocationRequest(byte[] pfxBytes, string password, StoreLocation storeLocation,string storeName, bool privateKeyExportable)
{
PfxBytes = pfxBytes;
Password = password;
StoreLocation = storeLocation;
StoreName = storeName;
PrivateKeyExportable = privateKeyExportable;
}

public byte[] PfxBytes { get; set; }
public string Password { get; set; }
public StoreLocation StoreLocation { get; set; }
public string StoreName { get; set; }
public bool PrivateKeyExportable { get; set; }

public VoidResponse DoIt(IWindowsX509CertificateStore certificateStore)
{
certificateStore.ImportCertificateToStore(PfxBytes, Password, StoreLocation, StoreName, PrivateKeyExportable);
return new VoidResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#nullable enable
using System;
using Calamari.FullFrameworkTools.Command;

namespace Calamari.FullFrameworkTools.WindowsCertStore.Contracts;

public class ImportCertificateToStoreByUserRequest : IRequest
{
public ImportCertificateToStoreByUserRequest(byte[] pfxBytes, string password, string userName, string storeName, bool privateKeyExportable)
{
PfxBytes = pfxBytes;
Password = password;
UserName = userName;
StoreName = storeName;
PrivateKeyExportable = privateKeyExportable;
}

public byte[] PfxBytes { get; set; }
public string Password { get; set; }
public string UserName { get; set; }
public string StoreName { get; set; }
public bool PrivateKeyExportable { get; set; }

public VoidResponse DoIt(IWindowsX509CertificateStore certificateStore)
{
certificateStore.ImportCertificateToStore(PfxBytes, Password, UserName, StoreName, PrivateKeyExportable);
return new VoidResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#nullable enable
using System;
using Calamari.FullFrameworkTools.Command;
using Calamari.FullFrameworkTools.Iis;

namespace Calamari.FullFrameworkTools.WindowsCertStore.Contracts;

public class OverwriteHomeDirectoryRequest : IRequest
{
public OverwriteHomeDirectoryRequest(string iisWebSiteName, string path, bool legacySupport)
{
IisWebSiteName = iisWebSiteName;
Path = path;
LegacySupport = legacySupport;
}

public string IisWebSiteName { get; set; }
public string Path { get; set; }
public bool LegacySupport { get; set; }

public BoolResponse DoIt(IInternetInformationServer certificateStore)
{
certificateStore.OverwriteHomeDirectory(IisWebSiteName, Path, LegacySupport);
return new BoolResponse();
}
}
Loading

0 comments on commit 63dbb2e

Please sign in to comment.