-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide capability to push events to Azure Event Grid via API (#29)
- Provide capability to push events to Azure Event Grid via API - Provide unit tests - Provide integration tests - Validation for configuration Relates to #24 and running integration tests in CI will be done via #28 . This PR depends on arcus-azure/arcus.eventgrid#65 as it's now using the preview package on MyGet and should be the official one instead.
- Loading branch information
1 parent
bb5af0b
commit f1c19a0
Showing
27 changed files
with
879 additions
and
24 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
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,16 @@ | ||
namespace Arcus.EventGrid.Proxy.Api | ||
{ | ||
public class Headers | ||
{ | ||
public class Response | ||
{ | ||
public class Events | ||
{ | ||
public const string Id = "X-Event-Id"; | ||
public const string Subject = "X-Event-Subject"; | ||
public const string Timestamp = "X-Event-Timestamp"; | ||
public const string DataVersion = "X-Event-Data-Version"; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
45 changes: 45 additions & 0 deletions
45
src/Arcus.EventGrid.Proxy.Api/Validation/RuntimeValidator.cs
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,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Arcus.EventGrid.Proxy.Api.Validation.Steps; | ||
using Arcus.EventGrid.Proxy.Api.Validation.Steps.Interfaces; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Arcus.EventGrid.Proxy.Api.Validation | ||
{ | ||
public class RuntimeValidator | ||
{ | ||
public static List<ValidationResult> Run(IConfiguration configuration) | ||
{ | ||
var validationSteps = new List<IValidationStep> | ||
{ | ||
new EventGridAuthKeyValidationStep(configuration), | ||
new EventGridTopicEndpointValidationStep(configuration) | ||
}; | ||
|
||
Console.WriteLine("Starting validation of runtime configuration..."); | ||
List<ValidationResult> validationOutcomes = new List<ValidationResult>(); | ||
foreach (var validationStep in validationSteps) | ||
{ | ||
var validationOutcome = validationStep.Execute(); | ||
validationOutcomes.Add(validationOutcome); | ||
} | ||
|
||
validationOutcomes.ForEach(LogValidationResults); | ||
Console.WriteLine("Validation of runtime configuration completed."); | ||
|
||
return validationOutcomes; | ||
} | ||
|
||
private static void LogValidationResults(ValidationResult validationResult) | ||
{ | ||
var validationOutcomeMessage = validationResult.Successful ? "successful" : "failed"; | ||
var validationInfoMessage = $"Validation step '{validationResult.StepName}' {validationOutcomeMessage}."; | ||
if (validationResult.Successful == false) | ||
{ | ||
validationInfoMessage += $" Error: {validationResult.ErrorMessage}"; | ||
} | ||
|
||
Console.WriteLine(validationInfoMessage); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Arcus.EventGrid.Proxy.Api/Validation/Steps/EventGridAuthKeyValidationStep.cs
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,28 @@ | ||
using Arcus.EventGrid.Proxy.Api.Validation.Steps.Interfaces; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Arcus.EventGrid.Proxy.Api.Validation.Steps | ||
{ | ||
public class EventGridAuthKeyValidationStep : IValidationStep | ||
{ | ||
private readonly IConfiguration _configuration; | ||
public string StepName { get; } = "Event Grid Authentication Key"; | ||
|
||
public EventGridAuthKeyValidationStep(IConfiguration configuration) | ||
{ | ||
_configuration = configuration; | ||
} | ||
|
||
public ValidationResult Execute() | ||
{ | ||
var authKey = _configuration[EnvironmentVariables.Runtime.EventGrid.AuthKey]; | ||
|
||
if (string.IsNullOrWhiteSpace(authKey)) | ||
{ | ||
return ValidationResult.Failure(StepName, "No authentication key was specified"); | ||
} | ||
|
||
return ValidationResult.Success(StepName); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Arcus.EventGrid.Proxy.Api/Validation/Steps/EventGridTopicEndpointValidationStep.cs
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,39 @@ | ||
using System; | ||
using Arcus.EventGrid.Proxy.Api.Validation.Steps.Interfaces; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Arcus.EventGrid.Proxy.Api.Validation.Steps | ||
{ | ||
public class EventGridTopicEndpointValidationStep : IValidationStep | ||
{ | ||
private readonly IConfiguration _configuration; | ||
|
||
public EventGridTopicEndpointValidationStep(IConfiguration configuration) | ||
{ | ||
_configuration = configuration; | ||
} | ||
|
||
public string StepName { get; } = "Event Grid Topic Endpoint"; | ||
|
||
public ValidationResult Execute() | ||
{ | ||
var rawTopicEndpoint = _configuration[EnvironmentVariables.Runtime.EventGrid.TopicEndpoint]; | ||
|
||
if (string.IsNullOrWhiteSpace(rawTopicEndpoint)) | ||
{ | ||
return ValidationResult.Failure(StepName, "No topic endpoint was specified"); | ||
} | ||
|
||
try | ||
{ | ||
var uri = new Uri(rawTopicEndpoint); | ||
|
||
return ValidationResult.Success(StepName); | ||
} | ||
catch | ||
{ | ||
return ValidationResult.Failure(StepName, "No valid topic endpoint was specified"); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Arcus.EventGrid.Proxy.Api/Validation/Steps/Interfaces/IValidationStep.cs
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,15 @@ | ||
namespace Arcus.EventGrid.Proxy.Api.Validation.Steps.Interfaces | ||
{ | ||
public interface IValidationStep | ||
{ | ||
/// <summary> | ||
/// Name of the validation step | ||
/// </summary> | ||
string StepName { get; } | ||
|
||
/// <summary> | ||
/// Executes the validation step | ||
/// </summary> | ||
ValidationResult Execute(); | ||
} | ||
} |
Oops, something went wrong.