-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@inherits BlazorApp.Pages.Common.PageBase | ||
@if (_diagramDef is { Length: > 0 }) | ||
{ | ||
<MermaidDiagram Definition=@_diagramDef></MermaidDiagram> | ||
} |
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,109 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using BlazorApp.Pages.Common; | ||
using Entity.Crd.Gateway; | ||
using Mapster; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace BlazorApp.Pages.Gateway; | ||
|
||
public partial class RulesDetailView : PageBase | ||
{ | ||
[Parameter] public IList<HTTPRouteRule> Rules { get; set; } | ||
|
||
string _diagramDef = ""; | ||
|
||
// const string template = @" | ||
// flowchart LR | ||
// A[HTTPRouteRule] | ||
// A-- text -->B | ||
// A-- text -->C | ||
// "; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
if (Rules is { Count: > 0 }) | ||
{ | ||
_diagramDef = "flowchart LR"; | ||
|
||
|
||
foreach (var rule in Rules) | ||
{ | ||
if (rule.Matches is { Count: > 0 }) | ||
{ | ||
foreach (var match in rule.Matches) | ||
{ | ||
_diagramDef += $"\r\n Gateway --> {match.Path?.Value ?? ""}\r\n"; | ||
|
||
var matchValue = match.Path?.Value ?? ""; | ||
|
||
if (match.Headers is { Count: > 0 }) | ||
{ | ||
foreach (var header in match.Headers) | ||
{ | ||
var backends = rule.BackendRefs?.Adapt<IList<BackendRefWithWeight>>(); | ||
if (backends is { Count: > 0 }) | ||
{ | ||
foreach (var backend in backends) | ||
{ | ||
_diagramDef += | ||
$"\r\n {matchValue} -- {header.Name}={header.Value} --> {backend.Name}:{backend.Port}\r\n"; | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
var backends = rule.BackendRefs?.Adapt<IList<BackendRefWithWeight>>(); | ||
if (backends is { Count: > 0 }) | ||
{ | ||
foreach (var backend in backends) | ||
{ | ||
_diagramDef += | ||
$"\r\n {matchValue} -- {backend.Weight} --> {backend.Name}:{backend.Port}\r\n"; | ||
} | ||
} | ||
} | ||
|
||
|
||
if (rule.Filters is { Count: > 0 }) | ||
{ | ||
var mirrorList = rule.Filters.Where(x => x.Type == HTTPRouteFilterType.RequestMirror) | ||
.ToList(); | ||
foreach (var item in mirrorList) | ||
{ | ||
var backend = item.RequestMirror?.BackendRef; | ||
if (backend is not null) | ||
{ | ||
_diagramDef += | ||
$"\r\n {matchValue} -- Mirror --> {backend.Name}:{backend.Port}\r\n"; | ||
} | ||
} | ||
|
||
var redirectList = rule.Filters.Where(x => x.Type == HTTPRouteFilterType.RequestRedirect) | ||
.ToList(); | ||
foreach (var item in redirectList) | ||
{ | ||
var backend = item.RequestRedirect; | ||
if (backend?.Hostname != null || backend?.Scheme != null) | ||
{ | ||
_diagramDef += | ||
$"\r\n {matchValue} -- Redirect --> {backend.Scheme}://{backend.Hostname}\r\n"; | ||
} | ||
|
||
if (backend?.Path != null) | ||
{ | ||
_diagramDef += | ||
$"\r\n {matchValue} -- Redirect --> {backend.Path.ReplaceFullPath}\r\n"; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
await base.OnInitializedAsync(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,9 +6,8 @@ | |
|
||
const string def1 = @" | ||
flowchart LR | ||
A --> B | ||
B --> C | ||
C --> A | ||
A-- text -->B | ||
A-- text -->C | ||
"; | ||
|
||
} | ||
} |
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