From cdf9f8b798574283d130171ff543c8562a9de9db Mon Sep 17 00:00:00 2001 From: "adam.gloyne" Date: Wed, 14 Aug 2024 16:59:29 +0100 Subject: [PATCH] simplify principal input --- src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs | 17 ++++++++----- src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs | 17 ++++++++----- .../Bindings/Sns/SnsBindings_Should.cs | 6 ++--- .../Bindings/Sqs/SqsBindings_should.cs | 24 +++++++++---------- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs b/src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs index 6d9ffa4a..40acd9c0 100644 --- a/src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs +++ b/src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs @@ -12,12 +12,17 @@ namespace LEGO.AsyncAPI.Bindings.Sns; public class Principal : IAsyncApiElement { - public Principal(IPrincipalValue value) + public Principal(KeyValuePair value) { - this.Value = value; + this.Value = new PrincipalObject(value); } - public IPrincipalValue Value { get; set; } + public Principal() + { + this.Value = new PrincipalStar(); + } + + public IPrincipalValue Value { get; private set; } public static Principal Parse(ParseNode node) { @@ -31,7 +36,7 @@ public static Principal Parse(ParseNode node) $"Principal value without a property name can only be a string value of '*'."); } - return new Principal(new PrincipalStar()); + return new Principal(); case MapNode mapNode: { @@ -42,9 +47,9 @@ public static Principal Parse(ParseNode node) $"Node should contain a valid AWS principal property name."); } - IPrincipalValue principalValue = new PrincipalObject(new KeyValuePair( + var principalValue = new KeyValuePair( propertyNode.Name, - StringOrStringList.Parse(propertyNode.Value))); + StringOrStringList.Parse(propertyNode.Value)); return new Principal(principalValue); } diff --git a/src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs b/src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs index bf4948a2..acffe8d3 100644 --- a/src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs +++ b/src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs @@ -12,12 +12,17 @@ namespace LEGO.AsyncAPI.Bindings.Sqs; public class Principal : IAsyncApiElement { - public Principal(IPrincipalValue value) + public Principal(KeyValuePair value) { - this.Value = value; + this.Value = new PrincipalObject(value); } - public IPrincipalValue Value { get; set; } + public Principal() + { + this.Value = new PrincipalStar(); + } + + public IPrincipalValue Value { get; private set; } public static Principal Parse(ParseNode node) { @@ -31,7 +36,7 @@ public static Principal Parse(ParseNode node) $"Principal value without a property name can only be a string value of '*'."); } - return new Principal(new PrincipalStar()); + return new Principal(); case MapNode mapNode: { @@ -42,9 +47,9 @@ public static Principal Parse(ParseNode node) $"Node should contain a valid AWS principal property name."); } - IPrincipalValue principalValue = new PrincipalObject(new KeyValuePair( + var principalValue = new KeyValuePair( propertyNode.Name, - StringOrStringList.Parse(propertyNode.Value))); + StringOrStringList.Parse(propertyNode.Value)); return new Principal(principalValue); } diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs index 56d3bcfc..f3deb55c 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs @@ -86,7 +86,7 @@ public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Deny, - Principal = new Principal(new PrincipalStar()), + Principal = new Principal(), Action = new StringOrStringList(new AsyncApiAny(new List() { "sns:Publish", @@ -105,9 +105,9 @@ public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Allow, - Principal = new Principal(new PrincipalObject(new KeyValuePair( + Principal = new Principal(new KeyValuePair( "AWS", new StringOrStringList(new AsyncApiAny(new List - { "arn:aws:iam::123456789012:user/alex.wichmann", "arn:aws:iam::123456789012:user/dec.kolakowski" }))))), + { "arn:aws:iam::123456789012:user/alex.wichmann", "arn:aws:iam::123456789012:user/dec.kolakowski" })))), Action = new StringOrStringList(new AsyncApiAny("sns:Create")), Condition = new AsyncApiAny(new Dictionary() { diff --git a/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs b/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs index dd3b8a26..65978a80 100644 --- a/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs +++ b/test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs @@ -136,8 +136,8 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Deny, - Principal = new Principal(new PrincipalObject(new KeyValuePair( - "AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann"))))), + Principal = new Principal(new KeyValuePair( + "AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann")))), Action = new StringOrStringList(new AsyncApiAny(new List { "sqs:SendMessage", @@ -166,9 +166,9 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Allow, - Principal = new Principal(new PrincipalObject(new KeyValuePair( + Principal = new Principal(new KeyValuePair( "AWS", new StringOrStringList(new AsyncApiAny(new List - { "arn:aws:iam::123456789012:user/alex.wichmann", "arn:aws:iam::123456789012:user/dec.kolakowski" }))))), + { "arn:aws:iam::123456789012:user/alex.wichmann", "arn:aws:iam::123456789012:user/dec.kolakowski" })))), Action = new StringOrStringList(new AsyncApiAny("sqs:CreateQueue")), Condition = new AsyncApiAny(new Dictionary() { @@ -223,8 +223,8 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Allow, - Principal = new Principal(new PrincipalObject(new KeyValuePair( - "Service", new StringOrStringList(new AsyncApiAny("s3.amazonaws.com"))))), + Principal = new Principal(new KeyValuePair( + "Service", new StringOrStringList(new AsyncApiAny("s3.amazonaws.com")))), Action = new StringOrStringList(new AsyncApiAny(new List { "sqs:*", @@ -377,8 +377,8 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Deny, - Principal = new Principal(new PrincipalObject(new KeyValuePair( - "AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann"))))), + Principal = new Principal(new KeyValuePair( + "AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann")))), Action = new StringOrStringList(new AsyncApiAny(new List() { "sqs:SendMessage", @@ -398,9 +398,9 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Allow, - Principal = new Principal(new PrincipalObject(new KeyValuePair( + Principal = new Principal(new KeyValuePair( "AWS", new StringOrStringList(new AsyncApiAny(new List - { "arn:aws:iam::123456789012:user/alex.wichmann", "arn:aws:iam::123456789012:user/dec.kolakowski" }))))), + { "arn:aws:iam::123456789012:user/alex.wichmann", "arn:aws:iam::123456789012:user/dec.kolakowski" })))), Action = new StringOrStringList(new AsyncApiAny("sqs:CreateQueue")), }, }, @@ -446,8 +446,8 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes() new Statement() { Effect = Effect.Allow, - Principal = new Principal(new PrincipalObject(new KeyValuePair( - "AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann"))))), + Principal = new Principal(new KeyValuePair( + "AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann")))), Action = new StringOrStringList(new AsyncApiAny(new List { "sqs:*",