Skip to content
Merged
Show file tree
Hide file tree
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
Apr 28, 2023
861ee6f
feat!: separate bindings and allow for custom bindings. (#107)
VisualBean May 3, 2023
222ad97
chore: add readme.md to bindings pack
VisualBean May 3, 2023
44354de
feat: WIP bring in line with new bindings wf
May 4, 2023
d856ccc
feat: WIP fix file overwrite
May 4, 2023
1fac669
feat: WIP further attempts at serde
May 4, 2023
0edd5c9
feat: WIP fix typo
May 4, 2023
e7bc0df
feat: WIP more node work
May 4, 2023
980bf81
feat: WIP switch to display enum
May 5, 2023
8221472
feat: WIP fixed lists
May 5, 2023
ab5550f
feat: WIP fix write issues
May 5, 2023
286e64d
feat: WIP remove commented function
May 5, 2023
b8aceea
feat: WIP Complete SNS body
May 5, 2023
d0f0ceb
feat: WIP finish SNS channel binding
May 5, 2023
41ea55d
feat: WIP Add basic SNS operation serialization
May 10, 2023
11755d5
refactor: binding improvement
VisualBean May 11, 2023
9c0f0c6
Merge branch 'main' into feat-add-sns-aws-bindings
May 11, 2023
33769c3
feat: WIP Add sns op fix fields
May 11, 2023
6a9266f
feat: WIP Add correct required properties
May 11, 2023
6bcf4e2
feat: WIP remove constants
May 11, 2023
b4d3a56
feat: WIP move to block scoped namespaces
May 11, 2023
0e1a445
ci: pull_request_target
VisualBean May 12, 2023
2690f4c
ci: add build and test run for forks (#110)
VisualBean May 12, 2023
a7c3305
Merge branch 'main' into feat-add-sns-aws-bindings
VisualBean May 12, 2023
b244161
ci: delete new workflow
VisualBean May 12, 2023
7f10a91
Merge branch 'main' into feat-add-sns-aws-bindings
VisualBean May 12, 2023
eedb2fa
fix: update AsyncApiTextReader class name (#109)
gokerakc May 12, 2023
e948e3d
Merge branch 'main' into feat-add-sns-aws-bindings
dpwdec May 12, 2023
21caee9
feat: fix identifier fixed fields bug
May 15, 2023
e120788
feat: correct type property to be required
May 16, 2023
783a1d2
feat: rename ordering to match spec
May 16, 2023
e01e26c
chore: add bindings to labeler
VisualBean May 18, 2023
30b87fb
test: add 'any' example
VisualBean May 18, 2023
7a28082
Merge remote-tracking branch 'origin/main' into main
VisualBean May 18, 2023
a09cdac
Merge branch 'main' into feat-add-sns-aws-bindings
dpwdec May 18, 2023
2277518
feat: add any filter policy handling
May 18, 2023
ce6d084
feat: correct policy effect casing
May 19, 2023
55f22bd
feat: use write any
May 19, 2023
b589e4f
feat!: separate bindings and allow for custom bindings. (#107)
VisualBean May 3, 2023
d242484
ci: force pre-releases
VisualBean Jun 5, 2023
2e4bf25
chore: update readme with pre-release shields
VisualBean Jun 5, 2023
79f11a8
sync changes
Jun 8, 2023
b4f8cb1
feat: sync with main
Jun 9, 2023
2c934e7
feat: update nested extensible objects and tests
Jun 9, 2023
4a2386a
Merge branch 'main' of github.com:dpwdec/AsyncAPI.NET into main
Jun 9, 2023
ea82b09
Merge branch 'main' into feat-add-sns-aws-bindings
VisualBean Jun 9, 2023
bbf391d
feat: merge main
Jun 9, 2023
6c4b0da
feat: integrate StringOrStringList to SNS
Jun 9, 2023
cd94f2c
feat: reformat files
Jun 9, 2023
8a7befe
feat: integrate remote changes
Jun 9, 2023
8f08e2b
feat: update consumer description wording
Jun 12, 2023
57e16d9
Merge branch 'main' into feat-add-sns-aws-bindings
dpwdec Jun 12, 2023
da4e8d6
feat: match wording to spec
Jun 12, 2023
c17f85b
Merge remote-tracking branch 'origin/feat-add-sns-aws-bindings' into …
Jun 12, 2023
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
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;
}
}
}
3 changes: 3 additions & 0 deletions src/LEGO.AsyncAPI/Models/AsyncApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,8 @@ public static class AsyncApiConstants
public const string MaxMessageBytes = "max.message.bytes";
public const string TopicConfiguration = "topicConfiguration";
public const string GeoReplication = "geo-replication";
public const string Policy = "policy";
Comment thread
VisualBean marked this conversation as resolved.
Outdated
public const string Statements = "statements";
public const string Principal = "principal";
}
}
3 changes: 3 additions & 0 deletions src/LEGO.AsyncAPI/Models/Bindings/BindingType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ public enum BindingType

[Display("pulsar")]
Pulsar,

[Display("sns")]
Sns,
}
}
20 changes: 20 additions & 0 deletions src/LEGO.AsyncAPI/Models/Bindings/Sns/OrderingConfiguration.cs
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
}
27 changes: 27 additions & 0 deletions src/LEGO.AsyncAPI/Models/Bindings/Sns/Policy.cs
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 src/LEGO.AsyncAPI/Models/Bindings/Sns/SnsChannelBinding.cs
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);

}
}
48 changes: 48 additions & 0 deletions src/LEGO.AsyncAPI/Models/Bindings/Sns/Statement.cs
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; }
}
Comment thread
dpwdec marked this conversation as resolved.
Outdated
2 changes: 2 additions & 0 deletions src/LEGO.AsyncAPI/Writers/AsyncApiWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public static void WriteRequiredCollection<T>(
{
writer.WriteCollectionInternal(name, elements, action);
}

// public static void WriteOptionalObjectCollection<T>(this )
Comment thread
VisualBean marked this conversation as resolved.
Outdated

/// <summary>
/// Write the optional AsyncApi element map (string to string mapping).
Expand Down
57 changes: 57 additions & 0 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs
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);
Comment thread
dpwdec marked this conversation as resolved.

}
}
}