Skip to content

Commit

Permalink
Merge branch 'main' into hwoodiwiss-native-aot
Browse files Browse the repository at this point in the history
  • Loading branch information
hwoodiwiss committed Feb 20, 2024
2 parents 68d150e + 54551ab commit 067b3a9
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Review dependencies
uses: actions/dependency-review-action@80f10bf419f34980065523f5efca7ebed17576aa # v4.1.0
uses: actions/dependency-review-action@be8bc500ee15e96754d2a6f2d34be14e945a46f3 # v4.1.2
with:
allow-licenses: 'Apache-2.0,BSD-2-Clause,BSD-3-Clause,MIT'
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<IsShipping>true</IsShipping>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions
static Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions.AddJustSayingWithAwsConfig(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration, System.Action<JustSaying.MessagingBusBuilder, System.IServiceProvider> builderConfig) -> void
static Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions.AddJustSayingWithAwsConfig(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.Configuration.IConfiguration configuration, System.Action<JustSaying.MessagingBusBuilder> builderConfig) -> void
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RootNamespace>StructureMap</RootNamespace>
<!-- StructureMap is not strong-named, so this assembly also cannot be -->
<SignAssembly>false</SignAssembly>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\JustSaying\JustSaying.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
static StructureMap.ConfigurationExpressionExtensions.AddJustSaying(this StructureMap.ConfigurationExpression registry) -> void
static StructureMap.ConfigurationExpressionExtensions.AddJustSaying(this StructureMap.ConfigurationExpression registry, string region) -> void
static StructureMap.ConfigurationExpressionExtensions.AddJustSaying(this StructureMap.ConfigurationExpression registry, System.Action<JustSaying.MessagingBusBuilder, StructureMap.IContext> configure) -> void
static StructureMap.ConfigurationExpressionExtensions.AddJustSaying(this StructureMap.ConfigurationExpression registry, System.Action<JustSaying.MessagingBusBuilder> configure) -> void
static StructureMap.RegistryExtensions.AddJustSayingHandler<TMessage, THandler>(this StructureMap.Registry registry) -> void
StructureMap.ConfigurationExpressionExtensions
StructureMap.RegistryExtensions
4 changes: 4 additions & 0 deletions src/JustSaying/AwsTools/MessageHandling/PublishException.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace JustSaying.AwsTools.MessageHandling;

#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class PublishException : Exception
{
public PublishException() : base("Failed to publish message")
Expand Down
74 changes: 38 additions & 36 deletions src/JustSaying/AwsTools/MessageHandling/SnsPolicyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,44 @@ internal static string BuildPolicyJson(SnsPolicyDetails policyDetails)
throw new ArgumentException("Must be a valid ARN.", nameof(policyDetails));
}
var accountId = arn.AccountId;
return $@"{{
""Version"" : ""2012-10-17"",
""Statement"" : [
{{
""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"",
""Effect"" : ""Allow"",
""Principal"" : {{
""AWS"" : ""*""
}},
""Action"" : [
""sns:GetTopicAttributes"",
""sns:SetTopicAttributes"",
""sns:AddPermission"",
""sns:RemovePermission"",
""sns:DeleteTopic"",
""sns:Subscribe"",
""sns:Publish""
],
""Resource"" : ""{policyDetails.SourceArn}"",
""Condition"" : {{
""StringEquals"" : {{
""AWS:SourceOwner"" : ""{accountId}""
}}
}}
}},
{{
""Sid"" : ""{Guid.NewGuid().ToString().Replace("-", "")}"",
""Effect"" : ""Allow"",
""Principal"" : {{
""AWS"" : {SerializeAccountIds(policyDetails.AccountIds)}
}},
""Action"" : ""sns:Subscribe"",
""Resource"" : ""{policyDetails.SourceArn}""
}}
]
}}";
return $$"""
{
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "{{Guid.NewGuid().ToString().Replace("-", "")}}",
"Effect" : "Allow",
"Principal" : {
"AWS" : "*"
},
"Action" : [
"sns:GetTopicAttributes",
"sns:SetTopicAttributes",
"sns:AddPermission",
"sns:RemovePermission",
"sns:DeleteTopic",
"sns:Subscribe",
"sns:Publish"
],
"Resource" : "{{policyDetails.SourceArn}}",
"Condition" : {
"StringEquals" : {
"AWS:SourceOwner" : "{{accountId}}"
}
}
},
{
"Sid" : "{{Guid.NewGuid().ToString().Replace("-", "")}}",
"Effect" : "Allow",
"Principal" : {
"AWS" : {{SerializeAccountIds(policyDetails.AccountIds)}}
},
"Action" : "sns:Subscribe",
"Resource" : "{{policyDetails.SourceArn}}"
}
]
}
""";
}

private static string SerializeAccountIds(IReadOnlyCollection<string> accountIds)
Expand Down
40 changes: 21 additions & 19 deletions src/JustSaying/AwsTools/MessageHandling/SqsPolicyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ public static string BuildPolicyJson(SqsPolicyDetails policyDetails)
? "*"
: CreateTopicArnWildcard(policyDetails.SourceArn);

var policyJson = $@"{{
""Version"" : ""2012-10-17"",
""Statement"" : [
{{
""Sid"" : ""{sid}"",
""Effect"" : ""Allow"",
""Principal"" : {{
""AWS"" : ""*""
}},
""Action"" : ""sqs:SendMessage"",
""Resource"" : ""{resource}"",
""Condition"" : {{
""ArnLike"" : {{
""aws:SourceArn"" : ""{topicArnWildcard}""
}}
}}
}}
]
}}";
var policyJson = $$"""
{
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "{{sid}}",
"Effect" : "Allow",
"Principal" : {
"AWS" : "*"
},
"Action" : "sqs:SendMessage",
"Resource" : "{{resource}}",
"Condition" : {
"ArnLike" : {
"aws:SourceArn" : "{{topicArnWildcard}}"
}
}
}
]
}
""";
return policyJson;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace JustSaying.AwsTools.QueueCreation;

#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class ConfigurationErrorsException : Exception
{
public ConfigurationErrorsException() : base("Invalid configuration")
Expand Down
4 changes: 4 additions & 0 deletions src/JustSaying/HandlerNotRegisteredWithContainerException.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace JustSaying;

#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class HandlerNotRegisteredWithContainerException : Exception
{
public HandlerNotRegisteredWithContainerException() : base("Handler not registered with container")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#if !NET8_0_OR_GREATER
using System.Runtime.Serialization;
#endif

namespace JustSaying.Messaging.MessageSerialization;

#if !NET8_0_OR_GREATER
[Serializable]
#endif
public class MessageFormatNotSupportedException : Exception
{
public MessageFormatNotSupportedException() : base("Message format not supported")
Expand All @@ -18,6 +22,7 @@ public MessageFormatNotSupportedException(string message, Exception innerExcepti
}

Check failure on line 22 in src/JustSaying/Messaging/MessageSerialization/MessageFormatNotSupportedException.cs

View workflow job for this annotation

GitHub Actions / code-ql (csharp)

} expected

Check failure on line 22 in src/JustSaying/Messaging/MessageSerialization/MessageFormatNotSupportedException.cs

View workflow job for this annotation

GitHub Actions / code-ql (csharp)

} expected

Check failure on line 22 in src/JustSaying/Messaging/MessageSerialization/MessageFormatNotSupportedException.cs

View workflow job for this annotation

GitHub Actions / windows-latest

} expected
#if !NET8_0_OR_GREATER

#if !NET8_0_OR_GREATER
protected MessageFormatNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ namespace JustSaying.Messaging.MessageSerialization;
#endif
public partial class SystemTextJsonSerializer : IMessageSerializer
{
private static readonly JsonSerializerOptions DefaultJsonSerializerOptions = new()
{
#if NET8_0_OR_GREATER
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
#else
IgnoreNullValues = true,
#endif
Converters =
{
new JsonStringEnumConverter(),
},
};

private readonly JsonSerializerOptions _options;

/// <summary>
Expand All @@ -30,21 +43,7 @@ public SystemTextJsonSerializer()
/// <param name="options">The optional <see cref="JsonSerializerOptions"/> to use.</param>
public SystemTextJsonSerializer(JsonSerializerOptions options)
{
if (options == null)
{
options = new JsonSerializerOptions
{
#if NET8_0_OR_GREATER
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
#else
IgnoreNullValues = true,
#endif
};

options.Converters.Add(new JsonStringEnumConverter());
}

_options = options;
_options = options ?? DefaultJsonSerializerOptions;
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task Messages_Are_Throttled_But_Still_Delivered(int throttleMessage
{
var batchEntry = new SendMessageBatchRequestEntry
{
MessageBody = $"{{\"Subject\":\"SimpleMessage\", \"Message\": {{ \"Content\": \"{entriesAdded}\"}}}}",
MessageBody = $$"""{"Subject":"SimpleMessage", "Message": { "Content": "{{entriesAdded}}"} }""",
Id = Guid.NewGuid().ToString()
};

Expand Down

0 comments on commit 067b3a9

Please sign in to comment.