-
Notifications
You must be signed in to change notification settings - Fork 18
feat(bindings): add SNS AWS bindings #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
578e237
feat: WIP Add sns channel bindings
861ee6f
feat!: separate bindings and allow for custom bindings. (#107)
VisualBean 222ad97
chore: add readme.md to bindings pack
VisualBean 44354de
feat: WIP bring in line with new bindings wf
d856ccc
feat: WIP fix file overwrite
1fac669
feat: WIP further attempts at serde
0edd5c9
feat: WIP fix typo
e7bc0df
feat: WIP more node work
980bf81
feat: WIP switch to display enum
8221472
feat: WIP fixed lists
ab5550f
feat: WIP fix write issues
286e64d
feat: WIP remove commented function
b8aceea
feat: WIP Complete SNS body
d0f0ceb
feat: WIP finish SNS channel binding
41ea55d
feat: WIP Add basic SNS operation serialization
11755d5
refactor: binding improvement
VisualBean 9c0f0c6
Merge branch 'main' into feat-add-sns-aws-bindings
33769c3
feat: WIP Add sns op fix fields
6a9266f
feat: WIP Add correct required properties
6bcf4e2
feat: WIP remove constants
b4d3a56
feat: WIP move to block scoped namespaces
0e1a445
ci: pull_request_target
VisualBean 2690f4c
ci: add build and test run for forks (#110)
VisualBean a7c3305
Merge branch 'main' into feat-add-sns-aws-bindings
VisualBean b244161
ci: delete new workflow
VisualBean 7f10a91
Merge branch 'main' into feat-add-sns-aws-bindings
VisualBean eedb2fa
fix: update AsyncApiTextReader class name (#109)
gokerakc e948e3d
Merge branch 'main' into feat-add-sns-aws-bindings
dpwdec 21caee9
feat: fix identifier fixed fields bug
e120788
feat: correct type property to be required
783a1d2
feat: rename ordering to match spec
e01e26c
chore: add bindings to labeler
VisualBean 30b87fb
test: add 'any' example
VisualBean 7a28082
Merge remote-tracking branch 'origin/main' into main
VisualBean a09cdac
Merge branch 'main' into feat-add-sns-aws-bindings
dpwdec 2277518
feat: add any filter policy handling
ce6d084
feat: correct policy effect casing
55f22bd
feat: use write any
b589e4f
feat!: separate bindings and allow for custom bindings. (#107)
VisualBean d242484
ci: force pre-releases
VisualBean 2e4bf25
chore: update readme with pre-release shields
VisualBean 79f11a8
sync changes
b4f8cb1
feat: sync with main
2c934e7
feat: update nested extensible objects and tests
4a2386a
Merge branch 'main' of github.com:dpwdec/AsyncAPI.NET into main
ea82b09
Merge branch 'main' into feat-add-sns-aws-bindings
VisualBean bbf391d
feat: merge main
6c4b0da
feat: integrate StringOrStringList to SNS
cd94f2c
feat: reformat files
8a7befe
feat: integrate remote changes
8f08e2b
feat: update consumer description wording
57e16d9
Merge branch 'main' into feat-add-sns-aws-bindings
dpwdec da4e8d6
feat: match wording to spec
c17f85b
Merge remote-tracking branch 'origin/feat-add-sns-aws-bindings' into …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/LEGO.AsyncAPI.Readers/Bindings/AsyncApiSnsBindingsDeserializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| namespace LEGO.AsyncAPI.Readers | ||
| { | ||
|
|
||
| using LEGO.AsyncAPI.Models.Bindings.Sns; | ||
| using LEGO.AsyncAPI.Readers.ParseNodes; | ||
|
|
||
| internal static partial class AsyncApiV2Deserializer | ||
| { | ||
| private static FixedFieldMap<SnsChannelBinding> snsChannelBindingFixedFields = new() | ||
| { | ||
| { "name", (a, n) => { a.Name = n.GetScalarValue(); } }, | ||
| { "policy", (a, n) => { a.Policy = LoadPolicy(n); } }, | ||
| }; | ||
|
|
||
| private static FixedFieldMap<Policy> policyFixedFields = new() | ||
| { | ||
| { "statements", (a, n) => { a.Statements = n.CreateSimpleList(s => LoadStatement(s)); } }, | ||
| }; | ||
|
|
||
| private static FixedFieldMap<Statement> statementFixedFields = new() | ||
| { | ||
| { "principal", (a, n) => { a.Principal = n.GetScalarValue(); } }, | ||
| }; | ||
|
|
||
| private static Policy LoadPolicy(ParseNode node) | ||
| { | ||
| var mapNode = node.CheckMapNode("policy"); | ||
| var policy = new Policy(); | ||
| ParseMap(mapNode, policy, policyFixedFields, null); | ||
| return policy; | ||
| } | ||
|
|
||
| private static Statement LoadStatement(ParseNode node) | ||
| { | ||
| var mapNode = node.CheckMapNode("statement"); | ||
| var statement = new Statement(); | ||
| ParseMap(mapNode, statement, statementFixedFields, null); | ||
| return statement; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,5 +17,8 @@ public enum BindingType | |
|
|
||
| [Display("pulsar")] | ||
| Pulsar, | ||
|
|
||
| [Display("sns")] | ||
| Sns, | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/LEGO.AsyncAPI/Models/Bindings/Sns/OrderingConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace LEGO.AsyncAPI.Models.Bindings.Sns; | ||
|
|
||
| public class OrderingConfiguration | ||
| { | ||
| /// <summary> | ||
| /// What type of SNS Topic is this? | ||
| /// </summary> | ||
| public Ordering Type { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// True to turn on de-duplication of messages for a channel. | ||
| /// </summary> | ||
| public bool ContentBasedDeduplication { get; set; } | ||
| } | ||
|
|
||
| public enum Ordering | ||
| { | ||
| Standard, | ||
| Fifo | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using System; | ||
| using LEGO.AsyncAPI.Models.Interfaces; | ||
| using LEGO.AsyncAPI.Writers; | ||
|
|
||
| namespace LEGO.AsyncAPI.Models.Bindings.Sns; | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| public class Policy : IAsyncApiElement | ||
| { | ||
| /// <summary> | ||
| /// An array of statement objects, each of which controls a permission for this topic. | ||
| /// </summary> | ||
| public List<Statement> Statements { get; set; } | ||
|
|
||
| public void Serialize(IAsyncApiWriter writer) | ||
| { | ||
| if (writer is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(writer)); | ||
| } | ||
|
|
||
| writer.WriteStartObject(); | ||
| writer.WriteOptionalCollection(AsyncApiConstants.Statements, this.Statements, (w, t) => t.Serialize(w)); | ||
| writer.WriteEndObject(); | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
src/LEGO.AsyncAPI/Models/Bindings/Sns/SnsChannelBinding.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using LEGO.AsyncAPI.Writers; | ||
|
|
||
| namespace LEGO.AsyncAPI.Models.Bindings.Sns; | ||
|
|
||
| using LEGO.AsyncAPI.Models.Interfaces; | ||
|
|
||
| /// <summary> | ||
| /// Binding class for SNS channel settings. | ||
| /// </summary> | ||
| public class SnsChannelBinding : IChannelBinding | ||
| { | ||
| /// <summary> | ||
| /// The name of the topic. Can be different from the channel name to allow flexibility around AWS resource naming limitations. | ||
| /// </summary> | ||
| public string Name { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// By default, we assume an unordered SNS topic. This field allows configuration of a FIFO SNS Topic. | ||
| /// </summary> | ||
| public OrderingConfiguration Ordering { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The security policy for the SNS Topic. | ||
| /// </summary> | ||
| public Policy Policy { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Key-value pairs that represent AWS tags on the topic. | ||
| /// </summary> | ||
| public Dictionary<string, string> Tags { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The version of this binding. | ||
| /// </summary> | ||
| public string BindingVersion { get; set; } | ||
|
|
||
| public BindingType Type => BindingType.Sns; | ||
|
|
||
| public bool UnresolvedReference { get; set; } | ||
|
|
||
| public AsyncApiReference Reference { get; set; } | ||
|
|
||
| public IDictionary<string, IAsyncApiExtension> Extensions { get; set; } = new Dictionary<string, IAsyncApiExtension>(); | ||
|
|
||
| public void SerializeV2WithoutReference(IAsyncApiWriter writer) | ||
| { | ||
| if (writer is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(writer)); | ||
| } | ||
|
|
||
| writer.WriteStartObject(); | ||
| writer.WriteOptionalProperty(AsyncApiConstants.Name, this.Name); | ||
| writer.WriteOptionalObject(AsyncApiConstants.Policy, this.Policy, (w, t) => t.Serialize(w)); | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| public void SerializeV2(IAsyncApiWriter writer) | ||
| { | ||
| if (writer is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(writer)); | ||
| } | ||
|
|
||
| if (this.Reference != null && !writer.GetSettings().ShouldInlineReference(this.Reference)) | ||
| { | ||
| this.Reference.SerializeV2(writer); | ||
| return; | ||
| } | ||
|
|
||
| this.SerializeV2WithoutReference(writer); | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using LEGO.AsyncAPI.Models.Interfaces; | ||
| using LEGO.AsyncAPI.Writers; | ||
|
|
||
| namespace LEGO.AsyncAPI.Models.Bindings.Sns; | ||
|
|
||
| public class Statement : IAsyncApiElement | ||
| { | ||
| public Effect Effect { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The AWS account or resource ARN that this statement applies to. | ||
| /// </summary> | ||
| // public StringOrStringList Principal { get; set; } | ||
| public string Principal { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The SNS permission being allowed or denied e.g. sns:Publish | ||
| /// </summary> | ||
| // public StringOrStringList Action { get; set; } | ||
|
|
||
| public void Serialize(IAsyncApiWriter writer) | ||
| { | ||
| if (writer is null) | ||
| { | ||
| throw new ArgumentNullException(nameof(writer)); | ||
| } | ||
|
|
||
| writer.WriteStartObject(); | ||
| // writer.WriteOptionalObject(AsyncApiConstants.Principal, this.Principal, (w, t) => t.Serialize(w)); | ||
| writer.WriteOptionalProperty(AsyncApiConstants.Principal, this.Principal); | ||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
|
|
||
| public enum Effect | ||
| { | ||
| Allow, | ||
| Deny | ||
| } | ||
|
|
||
| public class StringOrStringList : IAsyncApiElement | ||
| { | ||
| public string StringValue { get; set; } | ||
|
|
||
| public List<string> StringList { get; set; } | ||
| } | ||
|
dpwdec marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System; | ||
|
|
||
| namespace LEGO.AsyncAPI.Tests.Bindings.Sns | ||
| { | ||
| using NUnit.Framework; | ||
| using System.Collections.Generic; | ||
| using FluentAssertions; | ||
| using LEGO.AsyncAPI.Models; | ||
| using LEGO.AsyncAPI.Models.Bindings.Sns; | ||
| using LEGO.AsyncAPI.Readers; | ||
|
|
||
| internal class SnsBindings_Should | ||
| { | ||
| [Test] | ||
| public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes() | ||
| { | ||
| // Arrange | ||
| var expected = | ||
| @"bindings: | ||
| sns: | ||
| name: myTopic | ||
| policy: | ||
| statements: | ||
| - principal: hello"; | ||
|
|
||
| var channel = new AsyncApiChannel(); | ||
| channel.Bindings.Add(new SnsChannelBinding() | ||
| { | ||
| Name = "myTopic", | ||
| Policy = new Policy() | ||
| { | ||
| Statements = new List<Statement>() | ||
| { | ||
| new Statement() | ||
| { | ||
| Principal = "hello", | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Act | ||
| var actual = channel.SerializeAsYaml(AsyncApiVersion.AsyncApi2_0); | ||
|
|
||
| // Assert | ||
| actual = actual.MakeLineBreaksEnvironmentNeutral(); | ||
| expected = expected.MakeLineBreaksEnvironmentNeutral(); | ||
|
|
||
| var binding = new AsyncApiStringReader().ReadFragment<AsyncApiChannel>(actual, AsyncApiVersion.AsyncApi2_0, out _); | ||
|
|
||
| // Assert | ||
| Assert.AreEqual(actual, expected); | ||
| binding.Should().BeEquivalentTo(channel); | ||
|
dpwdec marked this conversation as resolved.
|
||
|
|
||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.