Skip to content

Commit

Permalink
simplify principal input
Browse files Browse the repository at this point in the history
  • Loading branch information
adam.gloyne committed Aug 14, 2024
1 parent 0e00170 commit cdf9f8b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
17 changes: 11 additions & 6 deletions src/LEGO.AsyncAPI.Bindings/Sns/Principal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ namespace LEGO.AsyncAPI.Bindings.Sns;

public class Principal : IAsyncApiElement
{
public Principal(IPrincipalValue value)
public Principal(KeyValuePair<string, StringOrStringList> 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)
{
Expand All @@ -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:
{
Expand All @@ -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<string, StringOrStringList>(
var principalValue = new KeyValuePair<string, StringOrStringList>(
propertyNode.Name,
StringOrStringList.Parse(propertyNode.Value)));
StringOrStringList.Parse(propertyNode.Value));

return new Principal(principalValue);
}
Expand Down
17 changes: 11 additions & 6 deletions src/LEGO.AsyncAPI.Bindings/Sqs/Principal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ namespace LEGO.AsyncAPI.Bindings.Sqs;

public class Principal : IAsyncApiElement
{
public Principal(IPrincipalValue value)
public Principal(KeyValuePair<string, StringOrStringList> 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)
{
Expand All @@ -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:
{
Expand All @@ -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<string, StringOrStringList>(
var principalValue = new KeyValuePair<string, StringOrStringList>(
propertyNode.Name,
StringOrStringList.Parse(propertyNode.Value)));
StringOrStringList.Parse(propertyNode.Value));

return new Principal(principalValue);
}
Expand Down
6 changes: 3 additions & 3 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sns/SnsBindings_Should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()
{
"sns:Publish",
Expand All @@ -105,9 +105,9 @@ public void SnsChannelBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Allow,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny(new List<string>
{ "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<string, object>()
{
Expand Down
24 changes: 12 additions & 12 deletions test/LEGO.AsyncAPI.Tests/Bindings/Sqs/SqsBindings_should.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Deny,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann"))))),
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann")))),
Action = new StringOrStringList(new AsyncApiAny(new List<string>
{
"sqs:SendMessage",
Expand Down Expand Up @@ -166,9 +166,9 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Allow,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny(new List<string>
{ "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<string, object>()
{
Expand Down Expand Up @@ -223,8 +223,8 @@ public void SqsChannelBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Allow,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
"Service", new StringOrStringList(new AsyncApiAny("s3.amazonaws.com"))))),
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"Service", new StringOrStringList(new AsyncApiAny("s3.amazonaws.com")))),
Action = new StringOrStringList(new AsyncApiAny(new List<string>
{
"sqs:*",
Expand Down Expand Up @@ -377,8 +377,8 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Deny,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann"))))),
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann")))),
Action = new StringOrStringList(new AsyncApiAny(new List<string>()
{
"sqs:SendMessage",
Expand All @@ -398,9 +398,9 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Allow,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny(new List<string>
{ "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")),
},
},
Expand Down Expand Up @@ -446,8 +446,8 @@ public void SqsOperationBinding_WithFilledObject_SerializesAndDeserializes()
new Statement()
{
Effect = Effect.Allow,
Principal = new Principal(new PrincipalObject(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann"))))),
Principal = new Principal(new KeyValuePair<string, StringOrStringList>(
"AWS", new StringOrStringList(new AsyncApiAny("arn:aws:iam::123456789012:user/alex.wichmann")))),
Action = new StringOrStringList(new AsyncApiAny(new List<string>
{
"sqs:*",
Expand Down

0 comments on commit cdf9f8b

Please sign in to comment.