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
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # 5.0.0
with:
dotnet-version: |
6.0.x
8.0.x

- name: Install dependencies
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # 5.0.0
with:
dotnet-version: |
6.0.x
8.0.x

- name: Install dependencies
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/publish-artifacts-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # 5.0.0
with:
dotnet-version: |
6.0.x
8.0.x

- name: Build libraries
Expand Down Expand Up @@ -64,7 +63,6 @@ jobs:
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # 5.0.0
with:
dotnet-version: |
6.0.x
8.0.x

- name: Download packages
Expand Down Expand Up @@ -124,7 +122,6 @@ jobs:
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # 5.0.0
with:
dotnet-version: |
6.0.x
8.0.x

- name: Setup GitHub Packages source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ public IdempotencyBuilder WithOptions(IdempotencyOptions options)
return this;
}

#if NET8_0_OR_GREATER
/// <summary>
/// Set Customer JsonSerializerContext to append to IdempotencySerializationContext
/// Set Customer JsonSerializerContext to append to IdempotencySerializationContext
/// </summary>
/// <param name="context"></param>
/// <returns>IdempotencyBuilder</returns>
Expand All @@ -177,6 +176,5 @@ public IdempotencyBuilder WithJsonSerializationContext(JsonSerializerContext con
IdempotencySerializer.AddTypeInfoResolver(context);
return this;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class IdempotencyOptionsBuilder
/// <summary>
/// Default Hash function
/// </summary>
private string _hashFunction = "MD5";
private readonly string _hashFunction = "MD5";

/// <summary>
/// Response hook function
Expand Down Expand Up @@ -160,15 +160,9 @@ public IdempotencyOptionsBuilder WithExpiration(TimeSpan duration)
/// </summary>
/// <param name="hashFunction">Can be any algorithm supported by HashAlgorithm.Create</param>
/// <returns>the instance of the builder (to chain operations)</returns>
#if NET8_0_OR_GREATER
[Obsolete("Idempotency uses MD5 and does not support other hash algorithms.")]
#endif
public IdempotencyOptionsBuilder WithHashFunction(string hashFunction)
{
#if NET6_0
// for backward compability keep this code in .net 6
_hashFunction = hashFunction;
#endif
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@

namespace AWS.Lambda.Powertools.Idempotency.Internal.Serializers;

#if NET8_0_OR_GREATER


/// <summary>
/// The source generated JsonSerializerContext to be used to Serialize Idempotency types
/// The source generated JsonSerializerContext to be used to Serialize Idempotency types
/// </summary>
[JsonSerializable(typeof(string))]
[JsonSerializable(typeof(object))]
public partial class IdempotencySerializationContext : JsonSerializerContext
{

}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ private static void BuildDefaultOptions()
{
PropertyNameCaseInsensitive = true
};
#if NET8_0_OR_GREATER
if (!RuntimeFeatureWrapper.IsDynamicCodeSupported)
{
_jsonOptions.TypeInfoResolverChain.Add(IdempotencySerializationContext.Default);
}
#endif
}

#if NET8_0_OR_GREATER

/// <summary>
/// Adds a JsonTypeInfoResolver to the JsonSerializerOptions.
/// </summary>
Expand Down Expand Up @@ -73,7 +69,6 @@ internal static void SetJsonOptions(JsonSerializerOptions options)
{
_jsonOptions = options;
}
#endif

/// <summary>
/// Serializes the specified object to a JSON string.
Expand All @@ -83,9 +78,6 @@ internal static void SetJsonOptions(JsonSerializerOptions options)
/// <returns>A JSON string representation of the object.</returns>
internal static string Serialize(object value, Type inputType)
{
#if NET6_0
return JsonSerializer.Serialize(value, _jsonOptions);
#else
if (RuntimeFeatureWrapper.IsDynamicCodeSupported)
{
#pragma warning disable
Expand All @@ -100,7 +92,6 @@ internal static string Serialize(object value, Type inputType)
}

return JsonSerializer.Serialize(value, typeInfo);
#endif
}

/// <summary>
Expand All @@ -113,15 +104,11 @@ internal static string Serialize(object value, Type inputType)
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "False positive")]
internal static T Deserialize<T>(string value)
{
#if NET6_0
return JsonSerializer.Deserialize<T>(value,_jsonOptions);
#else
if (RuntimeFeatureWrapper.IsDynamicCodeSupported)
{
return JsonSerializer.Deserialize<T>(value, _jsonOptions);
}

return (T)JsonSerializer.Deserialize(value, GetTypeInfo(typeof(T)));
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,8 @@ private static bool IsMissingIdempotencyKey(JsonElement data)
/// <exception cref="ArgumentException"></exception>
internal string GenerateHash(JsonElement data)
{
#if NET8_0_OR_GREATER
// starting .NET 8 no option to change hash algorithm
using var hashAlgorithm = MD5.Create();
#else
using var hashAlgorithm = HashAlgorithm.Create(_idempotencyOptions.HashFunction);
#endif
if (hashAlgorithm == null)
{
throw new ArgumentException("Invalid HashAlgorithm");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace AWS.Lambda.Powertools.JMESPath.Serializers;

#if NET8_0_OR_GREATER

/// <summary>
/// The source generated JsonSerializerContext to be used to Serialize JMESPath types
/// </summary>
Expand All @@ -16,6 +14,4 @@ namespace AWS.Lambda.Powertools.JMESPath.Serializers;
[JsonSerializable(typeof(JsonElement))]
public partial class JmesPathSerializationContext : JsonSerializerContext
{
}

#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ internal static class JmesPathSerializer
/// <returns>System.String.</returns>
internal static string Serialize(object value, Type inputType)
{
#if NET6_0
return JsonSerializer.Serialize(value);
#else

return JsonSerializer.Serialize(value, inputType, JmesPathSerializationContext.Default);
#endif
}

/// <summary>
Expand All @@ -32,11 +27,6 @@ internal static string Serialize(object value, Type inputType)
/// <returns>T.</returns>
internal static T Deserialize<T>(string value)
{
#if NET6_0
return JsonSerializer.Deserialize<T>(value);
#else

return (T)JsonSerializer.Deserialize(value, typeof(T), JmesPathSerializationContext.Default);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,7 @@ private object GetFormattedLogEntry(LogLevel logLevel, DateTime timestamp, objec
if (logObject is null)
throw new LogFormatException($"{logFormatter.GetType().FullName} returned Null value.");

#if NET8_0_OR_GREATER
return PowertoolsLoggerHelpers.ObjectToDictionary(logObject);
#else
return logObject;
#endif
}
catch (Exception e)
{
Expand All @@ -425,7 +421,6 @@ private static bool CustomFormatter<TState>(TState state, Exception exception, o
if (exception is not null)
return false;

#if NET8_0_OR_GREATER
var stateKeys = new Dictionary<string, object>();
if (state is IEnumerable<KeyValuePair<string, object>> keyValuePairs)
{
Expand All @@ -434,16 +429,6 @@ private static bool CustomFormatter<TState>(TState state, Exception exception, o
stateKeys[kvp.Key] = PowertoolsLoggerHelpers.ObjectToDictionary(kvp.Value);
}
}
#else
var stateKeys = new Dictionary<string, object>();
if (state is IEnumerable<KeyValuePair<string, object>> keyValuePairs)
{
foreach (var kvp in keyValuePairs)
{
stateKeys[kvp.Key] = kvp.Value;
}
}
#endif

if (stateKeys.Count != 2)
return false;
Expand Down
4 changes: 0 additions & 4 deletions libraries/src/AWS.Lambda.Powertools.Logging/Logger.Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ public static void AppendKey(string key, object value)
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentNullException(nameof(key));

#if NET8_0_OR_GREATER
Scope[key] = PowertoolsLoggerHelpers.ObjectToDictionary(value) ??
throw new ArgumentNullException(nameof(value));
#else
Scope[key] = value ?? throw new ArgumentNullException(nameof(value));
#endif
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if NET8_0_OR_GREATER

using System;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
Expand Down Expand Up @@ -40,5 +38,4 @@ public JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
return null;
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

namespace AWS.Lambda.Powertools.Logging.Serializers;

#if NET8_0_OR_GREATER

/// <summary>
/// Custom JSON serializer context for AWS.Lambda.Powertools.Logging
/// </summary>
Expand All @@ -27,7 +25,4 @@ namespace AWS.Lambda.Powertools.Logging.Serializers;
[JsonSerializable(typeof(LogEntry))]
public partial class PowertoolsLoggingSerializationContext : JsonSerializerContext
{
}


#endif
}
Loading
Loading