From ffda1ec5e27f3761c23f4739dd1f162364f73321 Mon Sep 17 00:00:00 2001
From: Henrique <999396+hjgraca@users.noreply.github.com>
Date: Wed, 5 Feb 2025 18:40:35 +0000
Subject: [PATCH] feat(idempotency): add support for custom key prefixes in
IdempotencyHandler and related tests
---
.../IdempotentAttribute.cs | 9 +-
.../Internal/IdempotencyAspectHandler.cs | 4 +-
.../Persistence/BasePersistenceStore.cs | 93 +++++++++++--------
...IdempotencyAttributeWithCustomKeyPrefix.cs | 21 +++++
.../IdempotencyFunctionMethodDecorated.cs | 5 -
.../IdempotencyHandlerWithCustomKeyPrefix.cs | 16 ++++
.../Internal/IdempotentAspectTests.cs | 43 ++++++++-
.../Persistence/BasePersistenceStoreTests.cs | 59 ++++++++----
.../DynamoDBPersistenceStoreTests.cs | 6 +-
.../Function/src/Function/Function.cs | 18 ++++
.../test/Function.Tests/FunctionTests.cs | 18 +++-
11 files changed, 219 insertions(+), 73 deletions(-)
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/Handlers/IdempotencyAttributeWithCustomKeyPrefix.cs
create mode 100644 libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/Handlers/IdempotencyHandlerWithCustomKeyPrefix.cs
diff --git a/libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotentAttribute.cs b/libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotentAttribute.cs
index 0204ee1af..fcd19f989 100644
--- a/libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotentAttribute.cs
+++ b/libraries/src/AWS.Lambda.Powertools.Idempotency/IdempotentAttribute.cs
@@ -63,6 +63,11 @@ namespace AWS.Lambda.Powertools.Idempotency;
[Injection(typeof(UniversalWrapperAspect), Inherited = true)]
public class IdempotentAttribute : UniversalWrapperAttribute
{
+ ///
+ /// Custom prefix for idempotency key: key_prefix#hash
+ ///
+ public string KeyPrefix { get; set; }
+
///
/// Wraps as a synchronous operation, simply throws IdempotencyConfigurationException
///
@@ -90,7 +95,7 @@ protected internal sealed override T WrapSync(Func