-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into vnext
- Loading branch information
Showing
15 changed files
with
394 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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,63 @@ | ||
namespace LEGO.AsyncAPI.Bindings.Sns; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using LEGO.AsyncAPI.Models.Interfaces; | ||
using LEGO.AsyncAPI.Readers.ParseNodes; | ||
using LEGO.AsyncAPI.Writers; | ||
|
||
public abstract class Principal : IAsyncApiElement | ||
{ | ||
public abstract void Serialize(IAsyncApiWriter writer); | ||
|
||
public static Principal Parse(ParseNode node) | ||
{ | ||
switch (node) | ||
{ | ||
case ValueNode: | ||
var nodeValue = node.GetScalarValue(); | ||
if (!IsStarString(nodeValue)) | ||
{ | ||
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " + | ||
$"Principal value without a property name can only be a string value of '*'."); | ||
} | ||
|
||
return new PrincipalStar(); | ||
|
||
case MapNode mapNode: | ||
{ | ||
var propertyNode = mapNode.First(); | ||
if (!IsValidPrincipalProperty(propertyNode.Name)) | ||
{ | ||
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " + | ||
$"Node should contain a valid AWS principal property name."); | ||
} | ||
|
||
var principalValue = new KeyValuePair<string, StringOrStringList>( | ||
propertyNode.Name, | ||
StringOrStringList.Parse(propertyNode.Value)); | ||
|
||
return new PrincipalObject(principalValue); | ||
} | ||
|
||
default: | ||
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " + | ||
$"Node should contain a string value of '*' or a valid AWS principal property."); | ||
} | ||
} | ||
|
||
private static bool IsStarString(JsonNode value) | ||
{ | ||
var element = JsonDocument.Parse(value.ToJsonString()).RootElement; | ||
|
||
return element.ValueKind == JsonValueKind.String && element.ValueEquals("*"); | ||
} | ||
|
||
private static bool IsValidPrincipalProperty(string property) | ||
{ | ||
return new[] { "AWS", "Service" }.Contains(property); | ||
} | ||
} |
This file contains 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 @@ | ||
namespace LEGO.AsyncAPI.Bindings.Sns; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using LEGO.AsyncAPI.Writers; | ||
|
||
public class PrincipalObject : Principal | ||
{ | ||
private KeyValuePair<string, StringOrStringList> PrincipalValue; | ||
|
||
public PrincipalObject(KeyValuePair<string, StringOrStringList> principalValue) | ||
{ | ||
this.PrincipalValue = principalValue; | ||
} | ||
|
||
public override void Serialize(IAsyncApiWriter writer) | ||
{ | ||
if (writer is null) | ||
{ | ||
throw new ArgumentNullException(nameof(writer)); | ||
} | ||
|
||
writer.WriteStartObject(); | ||
writer.WriteRequiredObject(this.PrincipalValue.Key, this.PrincipalValue.Value, (w, t) => t.Value.Write(w)); | ||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains 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,24 @@ | ||
namespace LEGO.AsyncAPI.Bindings.Sns; | ||
|
||
using System; | ||
using LEGO.AsyncAPI.Writers; | ||
|
||
public class PrincipalStar : Principal | ||
{ | ||
private string PrincipalValue; | ||
|
||
public PrincipalStar() | ||
{ | ||
this.PrincipalValue = "*"; | ||
} | ||
|
||
public override void Serialize(IAsyncApiWriter writer) | ||
{ | ||
if (writer is null) | ||
{ | ||
throw new ArgumentNullException(nameof(writer)); | ||
} | ||
|
||
writer.WriteValue(this.PrincipalValue); | ||
} | ||
} |
This file contains 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 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 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,65 @@ | ||
// Copyright (c) The LEGO Group. All rights reserved. | ||
|
||
namespace LEGO.AsyncAPI.Bindings.Sqs; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using LEGO.AsyncAPI.Models.Interfaces; | ||
using LEGO.AsyncAPI.Readers.ParseNodes; | ||
using LEGO.AsyncAPI.Writers; | ||
|
||
public abstract class Principal : IAsyncApiElement | ||
{ | ||
public abstract void Serialize(IAsyncApiWriter writer); | ||
|
||
public static Principal Parse(ParseNode node) | ||
{ | ||
switch (node) | ||
{ | ||
case ValueNode: | ||
var nodeValue = node.GetScalarValue(); | ||
if (!IsStarString(nodeValue)) | ||
{ | ||
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " + | ||
$"Principal value without a property name can only be a string value of '*'."); | ||
} | ||
|
||
return new PrincipalStar(); | ||
|
||
case MapNode mapNode: | ||
{ | ||
var propertyNode = mapNode.First(); | ||
if (!IsValidPrincipalProperty(propertyNode.Name)) | ||
{ | ||
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " + | ||
$"Node should contain a valid AWS principal property name."); | ||
} | ||
|
||
var principalValue = new KeyValuePair<string, StringOrStringList>( | ||
propertyNode.Name, | ||
StringOrStringList.Parse(propertyNode.Value)); | ||
|
||
return new PrincipalObject(principalValue); | ||
} | ||
|
||
default: | ||
throw new ArgumentException($"An error occured while parsing a {nameof(Principal)} node. " + | ||
$"Node should contain a string value of '*' or a valid AWS principal property."); | ||
} | ||
} | ||
|
||
private static bool IsStarString(JsonNode value) | ||
{ | ||
var element = JsonDocument.Parse(value.ToJsonString()).RootElement; | ||
|
||
return element.ValueKind == JsonValueKind.String && element.ValueEquals("*"); | ||
} | ||
|
||
private static bool IsValidPrincipalProperty(string property) | ||
{ | ||
return new[] { "AWS", "Service" }.Contains(property); | ||
} | ||
} |
This file contains 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 @@ | ||
namespace LEGO.AsyncAPI.Bindings.Sqs; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using LEGO.AsyncAPI.Writers; | ||
|
||
public class PrincipalObject : Principal | ||
{ | ||
private KeyValuePair<string, StringOrStringList> PrincipalValue; | ||
|
||
public PrincipalObject(KeyValuePair<string, StringOrStringList> principalValue) | ||
{ | ||
this.PrincipalValue = principalValue; | ||
} | ||
|
||
public override void Serialize(IAsyncApiWriter writer) | ||
{ | ||
if (writer is null) | ||
{ | ||
throw new ArgumentNullException(nameof(writer)); | ||
} | ||
|
||
writer.WriteStartObject(); | ||
writer.WriteRequiredObject(this.PrincipalValue.Key, this.PrincipalValue.Value, (w, t) => t.Value.Write(w)); | ||
writer.WriteEndObject(); | ||
} | ||
} |
This file contains 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,24 @@ | ||
namespace LEGO.AsyncAPI.Bindings.Sqs; | ||
|
||
using System; | ||
using LEGO.AsyncAPI.Writers; | ||
|
||
public class PrincipalStar : Principal | ||
{ | ||
private string PrincipalValue; | ||
|
||
public PrincipalStar() | ||
{ | ||
this.PrincipalValue = "*"; | ||
} | ||
|
||
public override void Serialize(IAsyncApiWriter writer) | ||
{ | ||
if (writer is null) | ||
{ | ||
throw new ArgumentNullException(nameof(writer)); | ||
} | ||
|
||
writer.WriteValue(this.PrincipalValue); | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.