Skip to content
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
5 changes: 5 additions & 0 deletions source/Calamari.Contracts/ArgoCD/FileHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public record FileHash(string FilePath, string Hash);
5 changes: 5 additions & 0 deletions source/Calamari.Contracts/ArgoCD/FileJsonPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public record FileJsonPatch(string FilePath, string JsonPatch);
18 changes: 18 additions & 0 deletions source/Calamari.Contracts/ArgoCD/ServiceMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public static class ServiceMessages
{
public static class ArgoCDFilesUpdated
{
public const string Name = "argocd-files-updated";

public static class Attributes
{
public const string GatewayId = "gatewayId";
public const string ApplicationName = "applicationName";
public const string Sources = "sources";
}
}
}
10 changes: 10 additions & 0 deletions source/Calamari.Contracts/ArgoCD/SourceFileChanges.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Octopus.Calamari.Contracts.ArgoCD;

public record SourceFileChanges(
string? CommitSha,
DateTimeOffset? CommitTimestamp,
int SourceIndex,
List<FileHash> ReplacedFiles,
List<FileJsonPatch> PatchedFiles);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Calamari.Testing.Helpers;
using FluentAssertions;
using NUnit.Framework;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.Tests.ArgoCD
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void AnonymousCloneWhenNoCredentialsMatch()
public class SshUrlTests : AuthenticatingRepositoryFactoryTestBase
{
[Test]
// SSH not currently functional on Windows
[Category(TestCategory.CompatibleOS.OnlyNixOrMac)]
public void SshCredentialBranch_IsSelectedAndDispatchesSshKeyGitConnection()
{
// Use an ssh:// URL so the new strict validation allows it, and mock the factory
Expand Down Expand Up @@ -108,6 +110,8 @@ public void HttpsCredentialTakesPriorityOverSshWhenBothMatchAnSshUrl()
}

[Test]
// SSH not currently functional on Windows
[Category(TestCategory.CompatibleOS.OnlyNixOrMac)]
public void KnownHostsFromDtoAreCarriedOntoSshKeyGitConnection()
{
const string sshUrl = "ssh://git@github.com/org/repo.git";
Expand Down
2 changes: 2 additions & 0 deletions source/Calamari.Tests/ArgoCD/Git/RepositoryFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public void CanCloneAnExistingRepositoryAtHEADAndAssociatedFiles()
}

[Test]
// SSH not currently functional on Windows
[Category(TestCategory.CompatibleOS.OnlyNixOrMac)]
public void CloningSshKeyGitConnectionDoesNotResolveAPullRequestClientAndLogsVerboseMessage()
{
var filename = "sshTest.txt";
Expand Down
36 changes: 18 additions & 18 deletions source/Calamari/ArgoCD/ArgoCDFilesUpdatedReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.ServiceMessages;
using Calamari.Kubernetes;
using ArgoCDFilesUpdatedAttributes = Calamari.Kubernetes.SpecialVariables.ServiceMessages.ArgoCDFilesUpdated.Attributes;
using Octopus.Calamari.Contracts.ArgoCD;
using ArgoCDFilesUpdatedAttributes = Octopus.Calamari.Contracts.ArgoCD.ServiceMessages.ArgoCDFilesUpdated.Attributes;

namespace Calamari.ArgoCD
{
Expand All @@ -34,33 +35,32 @@ public void ReportFilesUpdated(GitCommitParameters gitCommitParameters, IReadOnl
{
{ ArgoCDFilesUpdatedAttributes.GatewayId, appResult.GatewayId },
{ ArgoCDFilesUpdatedAttributes.ApplicationName, appResult.ApplicationName.Value },
{ ArgoCDFilesUpdatedAttributes.Sources, JsonSerializer.Serialize(ConvertPathsToPosix(appResult.TrackedSourceDetails)) }
{ ArgoCDFilesUpdatedAttributes.Sources, JsonSerializer.Serialize(appResult.TrackedSourceDetails.Select(MapSource).ToList()) }
};

var message = new ServiceMessage(
SpecialVariables.ServiceMessages.ArgoCDFilesUpdated.Name,
ServiceMessages.ArgoCDFilesUpdated.Name,
parameters);

log.WriteServiceMessage(message);
}
}

List<TrackedSourceDetail> ConvertPathsToPosix(List<TrackedSourceDetail> inputs)
static SourceFileChanges MapSource(TrackedSourceDetail trackedSourceDetail)
{
return inputs.Select(usd => usd with
{
ReplacedFiles = usd.ReplacedFiles.Select(rf => rf with
{
FilePath = rf.FilePath.EnsurePosixDirectorySeparator()
})
.ToList(),
PatchedFiles = usd.PatchedFiles.Select(pf => pf with
{
FilePath = pf.FilePath.EnsurePosixDirectorySeparator()
})
.ToList()
})
.ToList();
return new SourceFileChanges(
trackedSourceDetail.CommitSha,
trackedSourceDetail.CommitTimestamp,
trackedSourceDetail.SourceIndex,
trackedSourceDetail.ReplacedFiles.Select(f => f with
{
FilePath = f.FilePath.EnsurePosixDirectorySeparator()
}).ToList(),
trackedSourceDetail.PatchedFiles.Select(f => f with
{
FilePath = f.FilePath.EnsurePosixDirectorySeparator()
}).ToList()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Calamari.Common.Plumbing.Extensions;
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Octopus.Calamari.Contracts.ArgoCD;
using Octopus.CoreUtilities.Extensions;

namespace Calamari.ArgoCD.Conventions.ManifestTemplating;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions.ManifestTemplating;

Expand Down
1 change: 1 addition & 0 deletions source/Calamari/ArgoCD/Conventions/SourceUpdateResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using Calamari.ArgoCD.Git;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Calamari.Kubernetes.Patching.JsonPatch;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Calamari.Common.Plumbing.Logging;
using Calamari.Kubernetes.Patching;
using Calamari.Kubernetes.Patching.JsonPatch;
using Octopus.Calamari.Contracts.ArgoCD;
using YamlDotNet.RepresentationModel;

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

Expand Down
4 changes: 3 additions & 1 deletion source/Calamari/ArgoCD/Git/RepositoryFactory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Calamari.ArgoCD.Git.PullRequests;
using Calamari.Common.Commands;
using Calamari.Common.Plumbing;
using Calamari.Common.Plumbing.Extensions;
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
Expand Down Expand Up @@ -48,6 +48,8 @@ public RepositoryFactory(ILog log, ICalamariFileSystem fileSystem, string reposi

public RepositoryWrapper CloneRepository(string repositoryName, IGitConnection gitConnection)
{
WindowsSshKeys.AssertSupported(gitConnection);

var repositoryPath = Path.Combine(repositoryParentDirectory, repositoryName);
fileSystem.CreateDirectory(repositoryPath);

Expand Down
20 changes: 20 additions & 0 deletions source/Calamari/ArgoCD/Git/WindowsSshKeys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using Calamari.Common.Plumbing;
using NuGet.Commands;

namespace Calamari.ArgoCD.Git;

// Our fork LibGit2Sharp uses WinCNG for it's SSH support, and WinCNG does not support some keys.
// This first implementation blocks on all as we want to get the feature out for Linux first and
// we'll come back to attempt to handle it more gracefully at a later date.
public class WindowsSshKeys
{
public static void AssertSupported(IGitConnection? connection)
{
if (!CalamariEnvironment.IsRunningOnWindows) return;
if (connection is not SshKeyGitConnection) return;

throw new CommandException(
"SSH credentials are not currently supported for Git operations running on Windows. Use HTTPS credentials (username + password or PAT) instead or run the deployment on a Linux worker.");
}
}
5 changes: 1 addition & 4 deletions source/Calamari/ArgoCD/ProcessApplicationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
using System.Collections.Generic;
using System.Linq;
using Calamari.ArgoCD.Models;
using Octopus.Calamari.Contracts.ArgoCD;

namespace Calamari.ArgoCD
{
public record FileHash(string FilePath, string Hash);

public record FileJsonPatch(string FilePath, string JsonPatch);

public record TrackedSourceDetail(
string? CommitSha,
DateTimeOffset? CommitTimestamp,
Expand Down
12 changes: 0 additions & 12 deletions source/Calamari/Kubernetes/SpecialVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ public static class ManifestApplied
public const string ManifestAttribute = "manifest";
public const string NamespaceAttribute = "ns";
}

public static class ArgoCDFilesUpdated
{
public const string Name = "argocd-files-updated";

public static class Attributes
{
public const string GatewayId = "gatewayId";
public const string ApplicationName = "applicationName";
public const string Sources = "sources";
}
}
}
}
}