Skip to content

Commit

Permalink
Merge branch 'master' into snyk-fix-e8ec6ee4440f91a33b2e906a85efb7c3
Browse files Browse the repository at this point in the history
  • Loading branch information
bkapustik committed May 30, 2024
2 parents 72b1502 + 785ec8f commit c17e1bb
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"azuresigntool": {
"version": "4.0.1",
"commands": [
"azuresigntool"
]
}
}
}
32 changes: 25 additions & 7 deletions build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ parameters:
- name: AgentPoolName
displayName: Agent pool name
type: string
default: Default
default: ADO Windows Server 2022

- name: AgentName
displayName: Agent name - single char for any
type: string
default: ' '

resources:
repositories:
- repository: self
type: git

containers:
- container: Windows
image: base/mcr-dotnet-sdk-6.0-servercore-ltsc2022:release
endpoint: xperienceagentshub.azurecr.io

stages:
- stage: Build
jobs:
Expand All @@ -25,12 +35,13 @@ stages:
${{ if ne(length(parameters.AgentName), 1) }}:
demands:
- Agent.Name -equals ${{ parameters.AgentName }}
container: Windows

workspace:
clean: resources

variables:
- group: 14.0 Authenticode signature parameters
- group: Code Sign KV Auth

- name: Configuration
value: Release
Expand All @@ -39,11 +50,13 @@ stages:
value: 5.0.x

steps:
- task: UseDotNet@2
displayName: Select dotnet version
- task: DotNetCoreCLI@2
displayName: Restore dotnet tools
inputs:
packageType: sdk
version: ${{ variables.DotNetSdkVersion }}
command: custom
custom: tool
arguments: restore
workingDirectory: $(System.DefaultWorkingDirectory)

- task: DotNetCoreCLI@2
displayName: Restore dependencies
Expand All @@ -67,7 +80,7 @@ stages:
<AssemblyToSign Include="`$(RazorViewsTargetPath)" Condition="Exists('`$(RazorViewsTargetPath)')" />
</ItemGroup>
<SignFile CertificateThumbprint="`$(AuthenticodeCertificateThumbprint)" TimestampUrl="http://time.certum.pl" SigningTarget="%(AssemblyToSign.Identity)" />
<Exec Command="dotnet AzureSignTool sign --azure-key-vault-url $(AuthenticodeKeyVaultUrl) --azure-key-vault-tenant-id $(AuthenticodeTenantId) --azure-key-vault-client-id $(AuthenticodeClientId) --azure-key-vault-client-secret $(AuthenticodeClientSecret) --azure-key-vault-certificate $(AuthenticodeCertificateName) --timestamp-rfc3161 http://timestamp.digicert.com --skip-signed %(AssemblyToSign.Identity)" />
</Target>
</Project>
"@
Expand All @@ -81,6 +94,10 @@ stages:
command: build
projects: '**/*.csproj'
arguments: --no-restore --configuration ${{ variables.Configuration }}
env:
AuthenticodeClientSecret: $(AuthenticodeClientSecret)
# Roll-forward behavior set for AzureSignTool dotnet tool (see .config\dotnet-tools.json) which requires .Net 6.0 runtime
DOTNET_ROLL_FORWARD: Major

- task: DotNetCoreCLI@2
displayName: Test
Expand Down Expand Up @@ -119,6 +136,7 @@ stages:
${{ if ne(length(parameters.AgentName), 1) }}:
demands:
- Agent.Name -equals ${{ parameters.AgentName }}
container: Windows

workspace:
clean: resources
Expand Down
23 changes: 20 additions & 3 deletions src/AlgoliaSearchModule.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Configuration;

using System.Linq;
using Algolia.Search.Clients;

using CMS.Base;
using CMS.Core;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.Helpers;

using Kentico.Xperience.Algolia.Extensions;
using Kentico.Xperience.Algolia.Services;

Expand Down Expand Up @@ -59,7 +58,7 @@ protected override void OnInit()
conversionService = Service.Resolve<IConversionService>();

DocumentEvents.Delete.Before += HandleDocumentEvent;
DocumentEvents.Update.Before += HandleDocumentEvent;
DocumentEvents.Update.Before += HandleDocumentUpdate;
DocumentEvents.Insert.After += HandleDocumentEvent;
WorkflowEvents.Publish.After += HandleWorkflowEvent;
WorkflowEvents.Archive.After += HandleWorkflowEvent;
Expand Down Expand Up @@ -104,5 +103,23 @@ private void HandleDocumentEvent(object sender, DocumentEventArgs e)

algoliaTaskLogger.HandleEvent(e.Node, e.CurrentHandler.Name);
}

private void HandleDocumentUpdate(object sender, DocumentEventArgs e)
{
if (!EventShouldContinue(e.Node))
{
return;
}

algoliaTaskLogger.HandleEvent(e.Node, e.CurrentHandler.Name);

var columns = e.Node.ChangedColumns();
if (columns.Any(x => x.Equals(nameof(TreeNode.NodeParentID), System.StringComparison.OrdinalIgnoreCase)))
{
var treeProvider = new TreeProvider();
var node = treeProvider.SelectSingleDocument(e.Node.DocumentID, coupledData: true);
algoliaTaskLogger.ForceHandleEvent(node, e.CurrentHandler.Name);
}
}
}
}
1 change: 1 addition & 0 deletions src/Services/IAlgoliaTaskLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface IAlgoliaTaskLogger
/// <param name="node">The <see cref="TreeNode"/> that triggered the event.</param>
/// <param name="eventName">The name of the Xperience event that was triggered.</param>
void HandleEvent(TreeNode node, string eventName);
void ForceHandleEvent(TreeNode node, string eventName);
}
}
22 changes: 18 additions & 4 deletions src/Services/Implementations/DefaultAlgoliaTaskLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal class DefaultAlgoliaTaskLogger : IAlgoliaTaskLogger
{
private readonly IEventLogService eventLogService;


public DefaultAlgoliaTaskLogger(IEventLogService eventLogService) {
this.eventLogService = eventLogService;
}
Expand All @@ -32,6 +31,22 @@ public void HandleEvent(TreeNode node, string eventName)
return;
}

LogAlgoliaTask(node, eventName, nameof(HandleEvent));
}

/// <summary>
/// Loops through all registered Algolia indexes and logs a task if the passed
/// <paramref name="node"/> is indexed. Does not check for worklfow of the node and indexes the node even if under a workflow.
/// </summary>
/// <param name="node">The <see cref="TreeNode"/> that triggered the event.</param>
/// <param name="eventName">The name of the Xperience event that was triggered.</param>
public void ForceHandleEvent(TreeNode node, string eventName)
{
LogAlgoliaTask(node, eventName, nameof(ForceHandleEvent));
}

private void LogAlgoliaTask(TreeNode node, string eventName, string exceptionLogEventCode)
{
foreach (var indexName in IndexStore.Instance.GetAll().Select(index => index.IndexName))
{
if (!node.IsIndexedByIndex(indexName))
Expand All @@ -46,16 +61,15 @@ public void HandleEvent(TreeNode node, string eventName)
}
catch (InvalidOperationException ex)
{
eventLogService.LogException(nameof(DefaultAlgoliaTaskLogger), nameof(HandleEvent), ex);
eventLogService.LogException(nameof(DefaultAlgoliaTaskLogger), exceptionLogEventCode, ex);
}
}
}


private AlgoliaTaskType GetTaskType(TreeNode node, string eventName)
{
if (eventName.Equals(DocumentEvents.Insert.Name, StringComparison.OrdinalIgnoreCase) ||
(eventName.Equals(WorkflowEvents.Publish.Name, StringComparison.OrdinalIgnoreCase) && node.WorkflowHistory.Count == 0))
(eventName.Equals(WorkflowEvents.Publish.Name, StringComparison.OrdinalIgnoreCase) && (node.WorkflowHistory == null || node.WorkflowHistory.Count == 0)))
{
return AlgoliaTaskType.CREATE;
}
Expand Down

0 comments on commit c17e1bb

Please sign in to comment.