73 changed files with 1894 additions and 173 deletions
@ -0,0 +1,3 @@ |
|||
{ |
|||
"CurrentProjectSetting": null |
|||
} |
|||
Binary file not shown.
@ -0,0 +1,26 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Localization" Version="2.9.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Remove="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\en.json" /> |
|||
<None Remove="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\zh-Hans.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\en.json" /> |
|||
<EmbeddedResource Include="LINGYUN\ApiGateWay\Admin\Localization\DomainShared\zh-Hans.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Folder Include="LINGYUN\ApiGateWay\Admin\Routes\" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,32 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Localization; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Localization.ExceptionHandling; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
[DependsOn(typeof(AbpLocalizationModule))] |
|||
public class ApiGateWayAdminDomainSharedModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpVirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<ApiGateWayAdminDomainSharedModule>(); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Add<ApiGateWayAdminResource>("zh-Hans") |
|||
.AddVirtualJson("/LINGYUN/ApiGateWay/Admin/Localization/Resources"); |
|||
}); |
|||
|
|||
Configure<AbpExceptionLocalizationOptions>(options => |
|||
{ |
|||
options.MapCodeNamespace("ApiGateWayAdmin", typeof(ApiGateWayAdminResource)); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
public class HostAndPortConsts |
|||
{ |
|||
// 计算机名最大长度
|
|||
public const int MaxHostLength = 255; |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public class HttpDelegatingHandlerConsts |
|||
{ |
|||
public const int MaxNameLength = 256; |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Localization |
|||
{ |
|||
[LocalizationResourceName("ApiGatewayAdmin")] |
|||
public class ApiGateWayAdminResource |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,5 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
public class RouteGroupAppKey |
|||
{ |
|||
public string AppId { get; } |
|||
public string AppName { get; } |
|||
public RouteGroupAppKey(string appId, string appName) |
|||
{ |
|||
AppId = appId; |
|||
AppName = appName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Caching" Version="2.9.0" /> |
|||
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="2.9.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\LINGYUN.ApiGateWay.Admin.Domain.Shared\LINGYUN.ApiGateWay.Admin.Domain.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.Domain; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
[DependsOn( |
|||
typeof(ApiGateWayAdminDomainSharedModule), |
|||
typeof(AbpDddDomainModule))] |
|||
public class ApiGateWayAdminDomainModule : AbpModule |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Globals |
|||
{ |
|||
public class Global : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
public class HostAndPort : Entity<Guid> |
|||
{ |
|||
public virtual string Host { get; protected set; } |
|||
public virtual int? Port { get; protected set; } |
|||
protected HostAndPort() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public HostAndPort(Guid id, [NotNull] string host, int? port = null) |
|||
{ |
|||
Id = id; |
|||
BindHost(host, port); |
|||
} |
|||
|
|||
public void BindHost([NotNull] string host, int? port = null) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(host, nameof(host), HostAndPortConsts.MaxHostLength); |
|||
Host = host; |
|||
Port = port; |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Host.IsNullOrWhiteSpace()) |
|||
{ |
|||
if (Port.HasValue) |
|||
{ |
|||
return Host.GetHashCode() & Port.Value; |
|||
} |
|||
return Host.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Host.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is HostAndPort hostAndPort) |
|||
{ |
|||
if (Port.HasValue) |
|||
{ |
|||
return hostAndPort.Host.Equals(Host) && |
|||
Port.Equals(hostAndPort.Port); |
|||
} |
|||
return hostAndPort.Host.Equals(Host); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public class DownstreamHttpMethod : HttpMethod |
|||
{ |
|||
public DownstreamHttpMethod(Guid id, string method) |
|||
: base(id, method) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public class HttpDelegatingHandler : Entity<Guid> |
|||
{ |
|||
public virtual string Name { get; protected set; } |
|||
protected HttpDelegatingHandler() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public HttpDelegatingHandler(Guid id, [NotNull] string name) |
|||
{ |
|||
Id = id; |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name), HttpDelegatingHandlerConsts.MaxNameLength); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Name.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Name.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Name.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is HttpDelegatingHandler handler) |
|||
{ |
|||
return Name.Equals(handler.Name, StringComparison.CurrentCultureIgnoreCase); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public class HttpHandler : Entity<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// 每台服务器最大连接数
|
|||
/// </summary>
|
|||
public virtual int? MaxConnectionsPerServer { get; protected set; } |
|||
/// <summary>
|
|||
/// 允许自动重定向
|
|||
/// </summary>
|
|||
public virtual bool AllowAutoRedirect { get; set; } |
|||
/// <summary>
|
|||
/// 使用Cookie容器
|
|||
/// </summary>
|
|||
public virtual bool UseCookieContainer { get; set; } |
|||
/// <summary>
|
|||
/// 启用跟踪
|
|||
/// </summary>
|
|||
public virtual bool UseTracing { get; set; } |
|||
/// <summary>
|
|||
/// 启用代理
|
|||
/// </summary>
|
|||
public virtual bool UseProxy { get; set; } |
|||
protected HttpHandler() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public HttpHandler(Guid id) |
|||
{ |
|||
Id = id; |
|||
} |
|||
|
|||
public void ChangeMaxConnection(int? maxConnection = 1000) |
|||
{ |
|||
MaxConnectionsPerServer = maxConnection; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public abstract class HttpHeader : Entity<Guid> |
|||
{ |
|||
public virtual string Key { get; protected set; } |
|||
public virtual string Value { get; protected set; } |
|||
|
|||
protected HttpHeader() |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected HttpHeader(Guid id, [NotNull] string key, [NotNull] string value) |
|||
{ |
|||
Id = id; |
|||
Key = Check.NotNullOrWhiteSpace(key, nameof(key)); |
|||
Value = Check.NotNullOrWhiteSpace(value, nameof(value)); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Key.IsNullOrWhiteSpace() && |
|||
!Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Key.GetHashCode() & Value.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Key.IsNullOrWhiteSpace() || |
|||
Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is HttpHeader httpHeader) |
|||
{ |
|||
return httpHeader.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase) && |
|||
httpHeader.Value.Equals(Value, StringComparison.CurrentCultureIgnoreCase); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public abstract class HttpMethod : Entity<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// Http调用方法
|
|||
/// </summary>
|
|||
public virtual string Method { get; protected set; } |
|||
protected HttpMethod() |
|||
{ |
|||
|
|||
} |
|||
protected HttpMethod(Guid id, string method) |
|||
{ |
|||
Id = id; |
|||
Method = method; |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Method.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Method.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Method.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is HttpMethod httpMethod) |
|||
{ |
|||
return httpMethod.Method.Equals(Method); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public class HttpQuery : Entity<Guid> |
|||
{ |
|||
public virtual string Key { get; protected set; } |
|||
public virtual string Value { get; protected set; } |
|||
|
|||
protected HttpQuery() |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected HttpQuery(Guid id, [NotNull] string key, [NotNull] string value) |
|||
{ |
|||
Id = id; |
|||
Key = Check.NotNullOrWhiteSpace(key, nameof(key)); |
|||
Value = Check.NotNullOrWhiteSpace(value, nameof(value)); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Key.IsNullOrWhiteSpace() && |
|||
!Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Key.GetHashCode() & Value.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Key.IsNullOrWhiteSpace() || |
|||
Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is HttpQuery httpQuery) |
|||
{ |
|||
return Key.Equals(httpQuery.Key, StringComparison.CurrentCultureIgnoreCase) && |
|||
Value.Equals(httpQuery.Value, StringComparison.CurrentCultureIgnoreCase); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Http |
|||
{ |
|||
public class UpstreamHttpMethod : HttpMethod |
|||
{ |
|||
public UpstreamHttpMethod(Guid id, string method) |
|||
: base(id, method) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
public class LoadBalancer : Entity<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// 负载均衡类型
|
|||
/// </summary>
|
|||
public virtual string Type { get; private set; } |
|||
/// <summary>
|
|||
/// 用于Cookie会话密钥
|
|||
/// </summary>
|
|||
public virtual string Key { get; private set; } |
|||
/// <summary>
|
|||
/// 会话阻断时间
|
|||
/// </summary>
|
|||
public virtual int? Expiry { get; private set; } |
|||
protected LoadBalancer() |
|||
{ |
|||
|
|||
} |
|||
public LoadBalancer(Guid id, string type, string key, int? expiry = null) |
|||
{ |
|||
Id = id; |
|||
ApplyPolicy(type, key, expiry); |
|||
} |
|||
|
|||
public void ApplyPolicy(string type, string key, int? expiry = null) |
|||
{ |
|||
Type = type; |
|||
Key = key; |
|||
Expiry = expiry; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
public class QoS : Entity<Guid> |
|||
{ |
|||
public virtual int? ExceptionsAllowedBeforeBreaking { get; private set; } |
|||
|
|||
public virtual int? DurationOfBreak { get; private set; } |
|||
|
|||
public virtual int? TimeoutValue { get; private set; } |
|||
|
|||
protected QoS() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public QoS(Guid id, int? exceptionsAllowdBeforeBreaking = null, int? durationOfBreak = null, int? timeOut = null) |
|||
{ |
|||
Id = id; |
|||
ApplyPolicy(exceptionsAllowdBeforeBreaking, durationOfBreak, timeOut); |
|||
} |
|||
|
|||
public void ApplyPolicy(int? exceptionsAllowdBeforeBreaking = null, int? durationOfBreak = null, int? timeOut = null) |
|||
{ |
|||
ExceptionsAllowedBeforeBreaking = exceptionsAllowdBeforeBreaking; |
|||
DurationOfBreak = durationOfBreak; |
|||
TimeoutValue = timeOut; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Security; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin |
|||
{ |
|||
public class RateLimitRule : Entity<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// 客户端白名单列表,多个以分号分隔
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteClientWhite> ClientWhiteList { get; private set; } |
|||
/// <summary>
|
|||
/// 是否启用流量现值
|
|||
/// </summary>
|
|||
public virtual bool EnableRateLimiting { get; private set; } |
|||
/// <summary>
|
|||
/// 限速时段
|
|||
/// </summary>
|
|||
public virtual string Period { get; private set; } |
|||
/// <summary>
|
|||
/// 速率极限周期
|
|||
/// </summary>
|
|||
public virtual double? PeriodTimespan { get; private set; } |
|||
/// <summary>
|
|||
/// 客户端在定义的时间内可以发出的最大请求数
|
|||
/// </summary>
|
|||
public virtual long? Limit { get; private set; } |
|||
|
|||
protected RateLimitRule() |
|||
{ |
|||
ClientWhiteList = new List<RouteClientWhite>(); |
|||
} |
|||
|
|||
public RateLimitRule(Guid id, string period = "", double? periodTimespan = null, |
|||
long? limit = null, bool enabled = true) |
|||
{ |
|||
Id = id; |
|||
ChangeRateLimitState(enabled); |
|||
ApplyPolicy(period, periodTimespan, limit); |
|||
} |
|||
|
|||
public void ChangeRateLimitState(bool enabled = true) |
|||
{ |
|||
EnableRateLimiting = enabled; |
|||
} |
|||
|
|||
public void ApplyPolicy(string period = "", double? periodTimespan = null, |
|||
long? limit = null) |
|||
{ |
|||
Period = period; |
|||
PeriodTimespan = periodTimespan; |
|||
Limit = limit; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,348 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Security; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.Linq; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
using Volo.Abp.Guids; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class Route : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// 应用标识
|
|||
/// </summary>
|
|||
public virtual string AppId { get; protected set; } |
|||
/// <summary>
|
|||
/// 路由名称
|
|||
/// </summary>
|
|||
public virtual string Name { get; protected set; } |
|||
/// <summary>
|
|||
/// 请求标识
|
|||
/// </summary>
|
|||
public virtual string RequestIdKey { get; set; } |
|||
/// <summary>
|
|||
/// 是否区分大小写
|
|||
/// </summary>
|
|||
public virtual bool RouteIsCaseSensitive { get; set; } |
|||
/// <summary>
|
|||
/// 服务名称
|
|||
/// </summary>
|
|||
public virtual string ServiceName { get; protected set; } |
|||
/// <summary>
|
|||
/// 服务命名空间
|
|||
/// </summary>
|
|||
public virtual string ServiceNamespace { get; protected set; } |
|||
/// <summary>
|
|||
/// 下游协议
|
|||
/// </summary>
|
|||
public virtual string DownstreamScheme { get; set; } |
|||
/// <summary>
|
|||
/// 下游路由路径
|
|||
/// </summary>
|
|||
public virtual string DownstreamPathTemplate { get; protected set; } |
|||
/// <summary>
|
|||
/// 上游路由路径
|
|||
/// </summary>
|
|||
public virtual string UpstreamPathTemplate { get; protected set; } |
|||
/// <summary>
|
|||
/// 变更下游路径
|
|||
/// </summary>
|
|||
public virtual string ChangeDownstreamPathTemplate { get; protected set; } |
|||
/// <summary>
|
|||
/// 上游主机
|
|||
/// </summary>
|
|||
public virtual string UpstreamHost { get; set; } |
|||
/// <summary>
|
|||
/// 聚合标识
|
|||
/// </summary>
|
|||
public virtual string Key { get; set; } |
|||
/// <summary>
|
|||
/// 优先级
|
|||
/// </summary>
|
|||
public virtual int? Priority { get; set; } |
|||
/// <summary>
|
|||
/// 超时时间
|
|||
/// </summary>
|
|||
public virtual int? Timeout { get; set; } |
|||
/// <summary>
|
|||
/// 忽略SSL警告
|
|||
/// </summary>
|
|||
public virtual bool DangerousAcceptAnyServerCertificateValidator { get; set; } |
|||
/// <summary>
|
|||
/// 下游版本号
|
|||
/// </summary>
|
|||
public virtual string DownstreamHttpVersion { get; set; } |
|||
/// <summary>
|
|||
/// 下游Http方法列表
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteUpstreamHttpMethod> UpstreamHttpMethods { get; protected set; } |
|||
/// <summary>
|
|||
/// 上游Http方法列表
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteDownstreamHttpMethod> DownstreamHttpMethods { get; protected set; } |
|||
/// <summary>
|
|||
/// 添加请求头参数
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteAddRequestHttpHeader> AddHeadersToRequest { get; protected set; } |
|||
/// <summary>
|
|||
/// 下游请求头转换
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteUpstreamTransformHttpHeader> UpstreamHeaderTransform { get; protected set; } |
|||
/// <summary>
|
|||
/// 上游请求头转换
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteDownstreamTransformHttpHeader> DownstreamHeaderTransform { get; protected set; } |
|||
/// <summary>
|
|||
/// 请求声明转换
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteAddToRequestClaim> AddClaimsToRequest { get; protected set; } |
|||
/// <summary>
|
|||
/// 请求必须的声明
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteRequirementClaim> RouteClaimsRequirement { get; protected set; } |
|||
/// <summary>
|
|||
/// 用户声明到请求头转换
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteAddToRequestHttpQuery> AddQueriesToRequest { get; protected set; } |
|||
/// <summary>
|
|||
/// 下游主机列表
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteDownstreamHostAndPort> DownstreamHostAndPorts { get; protected set; } |
|||
/// <summary>
|
|||
/// 授权处理器列表
|
|||
/// </summary>
|
|||
public virtual ICollection<RouteHttpDelegatingHandler> DelegatingHandlers { get; protected set; } |
|||
/// <summary>
|
|||
/// Http选项
|
|||
/// </summary>
|
|||
public virtual RouteHttpHandler HttpHandler { get; protected set; } |
|||
/// <summary>
|
|||
/// 授权
|
|||
/// </summary>
|
|||
public virtual RouteAuthentication Authentication { get; protected set; } |
|||
/// <summary>
|
|||
/// 速率限制
|
|||
/// </summary>
|
|||
public virtual RouteRateLimitRule RouteRateLimitRule { get; protected set; } |
|||
/// <summary>
|
|||
/// 负债均衡
|
|||
/// </summary>
|
|||
public virtual RouteLoadBalancer LoadBalancer { get; protected set; } |
|||
/// <summary>
|
|||
/// 服务质量
|
|||
/// </summary>
|
|||
public virtual RouteQos QoS { get; protected set; } |
|||
/// <summary>
|
|||
/// 文件缓存
|
|||
/// </summary>
|
|||
public virtual RouteCache Cache { get; protected set; } |
|||
/// <summary>
|
|||
/// 安全策略
|
|||
/// </summary>
|
|||
public virtual RouteSecurity Security { get; protected set; } |
|||
|
|||
protected Route() |
|||
{ |
|||
UpstreamHttpMethods = new Collection<RouteUpstreamHttpMethod>(); |
|||
DownstreamHttpMethods = new Collection<RouteDownstreamHttpMethod>(); |
|||
AddHeadersToRequest = new Collection<RouteAddRequestHttpHeader>(); |
|||
UpstreamHeaderTransform = new Collection<RouteUpstreamTransformHttpHeader>(); |
|||
DownstreamHeaderTransform = new Collection<RouteDownstreamTransformHttpHeader>(); |
|||
AddClaimsToRequest = new Collection<RouteAddToRequestClaim>(); |
|||
RouteClaimsRequirement = new Collection<RouteRequirementClaim>(); |
|||
AddQueriesToRequest = new Collection<RouteAddToRequestHttpQuery>(); |
|||
DownstreamHostAndPorts = new Collection<RouteDownstreamHostAndPort>(); |
|||
DelegatingHandlers = new Collection<RouteHttpDelegatingHandler>(); |
|||
} |
|||
|
|||
public void AddDownstreamHttpMethod(IGuidGenerator generator, string method) |
|||
{ |
|||
DownstreamHttpMethods.AddIfNotContains(new RouteDownstreamHttpMethod(Id, generator.Create(), method)); ; |
|||
} |
|||
|
|||
public void RemoveDownstreamHttpMethod(string method) |
|||
{ |
|||
DownstreamHttpMethods.RemoveAll(x => x.Method.Equals(method, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllDownstreamHttpMethod() |
|||
{ |
|||
DownstreamHttpMethods.Clear(); |
|||
} |
|||
|
|||
public void AddUpstreamHttpMethod(IGuidGenerator generator, string method) |
|||
{ |
|||
UpstreamHttpMethods.AddIfNotContains(new RouteUpstreamHttpMethod(Id, generator.Create(), method)); |
|||
} |
|||
|
|||
public void RemoveUpstreamHttpMethod(string method) |
|||
{ |
|||
UpstreamHttpMethods.RemoveAll(x => x.Method.Equals(method, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllUpstreamHttpMethod() |
|||
{ |
|||
UpstreamHttpMethods.Clear(); |
|||
} |
|||
|
|||
public void AddRequestHeader(IGuidGenerator generator, string key, string value) |
|||
{ |
|||
AddHeadersToRequest.AddIfNotContains(new RouteAddRequestHttpHeader(Id, generator.Create(), key, value)); |
|||
} |
|||
|
|||
public void RemoveRequestHeader(string key, string value) |
|||
{ |
|||
AddHeadersToRequest.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllRequestHeader() |
|||
{ |
|||
AddHeadersToRequest.Clear(); |
|||
} |
|||
|
|||
public void AddUpstreamHeaderTransform(IGuidGenerator generator, string key, string value) |
|||
{ |
|||
UpstreamHeaderTransform.AddIfNotContains(new RouteUpstreamTransformHttpHeader(Id, generator.Create(), key, value)); |
|||
} |
|||
|
|||
public void RemoveUpstreamHeaderTransform(string key, string value) |
|||
{ |
|||
UpstreamHeaderTransform.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllUpstreamHeaderTransform() |
|||
{ |
|||
UpstreamHeaderTransform.Clear(); |
|||
} |
|||
|
|||
public void AddDownstreamHeaderTransform(IGuidGenerator generator, string key, string value) |
|||
{ |
|||
DownstreamHeaderTransform.AddIfNotContains(new RouteDownstreamTransformHttpHeader(Id, generator.Create(), key, value)); |
|||
} |
|||
|
|||
public void RemoveDownstreamHeaderTransform(string key, string value) |
|||
{ |
|||
DownstreamHeaderTransform.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllDownstreamHeaderTransform() |
|||
{ |
|||
DownstreamHeaderTransform.Clear(); |
|||
} |
|||
|
|||
public void AddRequestClaim(IGuidGenerator generator, string key, string value) |
|||
{ |
|||
AddClaimsToRequest.AddIfNotContains(new RouteAddToRequestClaim(Id, generator.Create(), key, value)); |
|||
} |
|||
|
|||
public void RemoveRequestClaim(string key, string value) |
|||
{ |
|||
AddClaimsToRequest.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllRequestClaim() |
|||
{ |
|||
AddClaimsToRequest.Clear(); |
|||
} |
|||
|
|||
public void AddRequirementClaim(IGuidGenerator generator, string key, string value) |
|||
{ |
|||
RouteClaimsRequirement.AddIfNotContains(new RouteRequirementClaim(Id, generator.Create(), key, value)); |
|||
} |
|||
|
|||
public void RemoveRequirementClaim(string key, string value) |
|||
{ |
|||
RouteClaimsRequirement.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllRequirementClaim() |
|||
{ |
|||
RouteClaimsRequirement.Clear(); |
|||
} |
|||
|
|||
public void AddRequestQuery(IGuidGenerator generator, string key, string value) |
|||
{ |
|||
AddQueriesToRequest.AddIfNotContains(new RouteAddToRequestHttpQuery(Id, generator.Create(), key, value)); |
|||
} |
|||
|
|||
public void RemoveRequestQuery(string key, string value) |
|||
{ |
|||
AddQueriesToRequest.RemoveAll(x => x.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Value.Equals(value, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllRequestQuery() |
|||
{ |
|||
AddQueriesToRequest.Clear(); |
|||
} |
|||
|
|||
public void AddDownstreamHost(IGuidGenerator generator, string host, int? port) |
|||
{ |
|||
DownstreamHostAndPorts.AddIfNotContains(new RouteDownstreamHostAndPort(Id, generator.Create(), host, port)); |
|||
} |
|||
|
|||
public void RemoveDownstreamHost(string host, int? port) |
|||
{ |
|||
DownstreamHostAndPorts.RemoveAll(x => x.Host.Equals(host, StringComparison.CurrentCultureIgnoreCase) |
|||
&& x.Port.Equals(port)); |
|||
} |
|||
|
|||
public void RemoveAllDownstreamHost() |
|||
{ |
|||
DownstreamHostAndPorts.Clear(); |
|||
} |
|||
|
|||
public void AddDelegatingHandler(IGuidGenerator generator, string name) |
|||
{ |
|||
DelegatingHandlers.AddIfNotContains(new RouteHttpDelegatingHandler(Id, generator.Create(), name)); |
|||
} |
|||
|
|||
public void RemoveDelegatingHandler(string name) |
|||
{ |
|||
DelegatingHandlers.RemoveAll(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllDelegatingHandler() |
|||
{ |
|||
DelegatingHandlers.Clear(); |
|||
} |
|||
|
|||
public void BindService(string serviceName, string @namespace) |
|||
{ |
|||
ServiceName = serviceName; |
|||
ServiceNamespace = @namespace; |
|||
} |
|||
|
|||
public void UseHttpHandler(IGuidGenerator generator, bool autoRedirect = false, bool useCookie = false, |
|||
bool useTracking = false, bool useProxy = false, int? maxConnection = 1000) |
|||
{ |
|||
if (HttpHandler == null) |
|||
{ |
|||
HttpHandler = new RouteHttpHandler(generator.Create(), Id); |
|||
} |
|||
HttpHandler.UseProxy = useProxy; |
|||
HttpHandler.UseTracing = useTracking; |
|||
HttpHandler.UseCookieContainer = useCookie; |
|||
HttpHandler.AllowAutoRedirect = autoRedirect; |
|||
HttpHandler.ChangeMaxConnection(maxConnection); |
|||
} |
|||
|
|||
public void UseAuthentication(IGuidGenerator generator, string provider, IEnumerable<string> allowScope) |
|||
{ |
|||
if (Authentication == null) |
|||
{ |
|||
Authentication = new RouteAuthentication(generator.Create(), Id, provider); |
|||
} |
|||
Authentication.AddScopes(allowScope); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteAddRequestHttpHeader : HttpHeader |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteAddRequestHttpHeader() |
|||
{ |
|||
|
|||
} |
|||
public RouteAddRequestHttpHeader(Guid routeId, Guid httpHeaderId, string key, string value) |
|||
: base(httpHeaderId, key, value) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Security; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteAddToRequestClaim : Claim |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteAddToRequestClaim() |
|||
{ |
|||
|
|||
} |
|||
public RouteAddToRequestClaim(Guid routeId, Guid claimId, string key, string value) |
|||
: base(claimId, key, value) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteAddToRequestHttpQuery : HttpQuery |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteAddToRequestHttpQuery() |
|||
{ |
|||
|
|||
} |
|||
public RouteAddToRequestHttpQuery(Guid routeId, Guid httpQueryId, string key, string value) |
|||
: base(httpQueryId, key, value) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteAllowedScope : Entity<int> |
|||
{ |
|||
public virtual string Scope { get; protected set; } |
|||
public virtual Guid AuthenticationId { get; protected set; } |
|||
public virtual RouteAuthentication Authentication { get; protected set; } |
|||
protected RouteAllowedScope() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public RouteAllowedScope(Guid authenticationId, string scope) |
|||
{ |
|||
AuthenticationId = authenticationId; |
|||
Scope = scope; |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Scope.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Scope.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Scope.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is RouteAllowedScope allowedScope) |
|||
{ |
|||
return allowedScope.Scope.Equals(Scope); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteAuthentication : Entity<Guid> |
|||
{ |
|||
public virtual string AuthenticationProviderKey { get; private set; } |
|||
public virtual ICollection<RouteAllowedScope> AllowedScopes { get; set; } |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteAuthentication() |
|||
{ |
|||
AllowedScopes = new List<RouteAllowedScope>(); |
|||
} |
|||
|
|||
public RouteAuthentication(Guid id, Guid routeId, string providerKey) |
|||
{ |
|||
Id = id; |
|||
RouteId = routeId; |
|||
ChangeProvider(providerKey); |
|||
} |
|||
|
|||
public void ChangeProvider(string providerKey) |
|||
{ |
|||
AuthenticationProviderKey = providerKey; |
|||
} |
|||
|
|||
public void AddScope(string scope) |
|||
{ |
|||
AllowedScopes.AddIfNotContains(new RouteAllowedScope(Id, scope)); |
|||
} |
|||
|
|||
public void AddScopes(IEnumerable<string> scope) |
|||
{ |
|||
foreach(var scop in scope) |
|||
{ |
|||
AddScope(scop); |
|||
} |
|||
} |
|||
|
|||
public void RemoveScope(string scope) |
|||
{ |
|||
AllowedScopes.RemoveAll(x => x.Scope.Equals(scope, StringComparison.CurrentCultureIgnoreCase)); |
|||
} |
|||
|
|||
public void RemoveAllScope() |
|||
{ |
|||
AllowedScopes.Clear(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteCache : Entity<int> |
|||
{ |
|||
public virtual int? TtlSeconds { get; private set; } |
|||
public virtual string Region { get; private set; } |
|||
public virtual Guid RouteId { get; private set; } |
|||
public virtual Route Route { get; private set; } |
|||
protected RouteCache() |
|||
{ |
|||
} |
|||
public RouteCache(Guid routeId, string region = "", int? ttlSeconds = null) |
|||
{ |
|||
RouteId = routeId; |
|||
Region = region; |
|||
TtlSeconds = ttlSeconds; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteDownstreamHostAndPort : HostAndPort |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteDownstreamHostAndPort() |
|||
{ |
|||
|
|||
} |
|||
public RouteDownstreamHostAndPort(Guid routeId, Guid hostId, string key, int? port) |
|||
: base(hostId, key, port) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteDownstreamHttpMethod : HttpMethod |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteDownstreamHttpMethod() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public RouteDownstreamHttpMethod(Guid routeId, Guid httpMethodId, string method) |
|||
: base(httpMethodId, method) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteDownstreamTransformHttpHeader : HttpHeader |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteDownstreamTransformHttpHeader() |
|||
{ |
|||
|
|||
} |
|||
public RouteDownstreamTransformHttpHeader(Guid routeId, Guid httpHeaderId, string key, string value) |
|||
: base(httpHeaderId, key, value) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using JetBrains.Annotations; |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteHttpDelegatingHandler : HttpDelegatingHandler |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteHttpDelegatingHandler() |
|||
{ |
|||
|
|||
} |
|||
public RouteHttpDelegatingHandler(Guid routeId, Guid httpHandlerId, [NotNull] string name) |
|||
: base(httpHandlerId, name) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteHttpHandler : HttpHandler |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteHttpHandler() |
|||
{ |
|||
|
|||
} |
|||
public RouteHttpHandler(Guid id, Guid routeId) |
|||
{ |
|||
Id = id; |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteHttpMethod |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteLoadBalancer : Entity<int> |
|||
{ |
|||
public virtual Guid LoadBalancerId { get; private set; } |
|||
public virtual LoadBalancer LoadBalancer { get; private set; } |
|||
public virtual Guid RouteId { get; private set; } |
|||
public virtual Route Route { get; private set; } |
|||
protected RouteLoadBalancer() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public RouteLoadBalancer(Guid routeId, Guid loadBalancerId) |
|||
{ |
|||
RouteId = routeId; |
|||
LoadBalancerId = loadBalancerId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteQos : Entity<int> |
|||
{ |
|||
public virtual Guid QoSId { get; protected set; } |
|||
public virtual QoS QoS { get; protected set; } |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteQos() |
|||
{ |
|||
|
|||
} |
|||
public RouteQos(Guid routeId, Guid qosId) |
|||
{ |
|||
RouteId = routeId; |
|||
QoSId = qosId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteRateLimitRule : Entity<int> |
|||
{ |
|||
public virtual Guid RateLimitRuleId { get; protected set; } |
|||
public virtual RateLimitRule RateLimitRule { get; protected set; } |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteRateLimitRule() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public RouteRateLimitRule(Guid routeId, Guid rateLimitRuleId) |
|||
{ |
|||
RouteId = routeId; |
|||
RateLimitRuleId = rateLimitRuleId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Security; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteRequirementClaim : Claim |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteRequirementClaim() |
|||
{ |
|||
|
|||
} |
|||
public RouteRequirementClaim(Guid routeId, Guid claimId, string key, string value) |
|||
: base(claimId, key, value) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteUpstreamHttpMethod : HttpMethod |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteUpstreamHttpMethod() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public RouteUpstreamHttpMethod(Guid routeId, Guid httpMethodId, string method) |
|||
: base(httpMethodId, method) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Http; |
|||
using System; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Routes |
|||
{ |
|||
public class RouteUpstreamTransformHttpHeader : HttpHeader |
|||
{ |
|||
public virtual Guid RouteId { get; protected set; } |
|||
public virtual Route Route { get; protected set; } |
|||
protected RouteUpstreamTransformHttpHeader() |
|||
{ |
|||
|
|||
} |
|||
public RouteUpstreamTransformHttpHeader(Guid routeId, Guid httpHeaderId, string key, string value) |
|||
: base(httpHeaderId, key, value) |
|||
{ |
|||
RouteId = routeId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Security |
|||
{ |
|||
public class Claim : Entity<Guid> |
|||
{ |
|||
public virtual string Key { get; protected set; } |
|||
public virtual string Value { get; protected set; } |
|||
protected Claim() |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected Claim(Guid id, [NotNull] string key, [NotNull] string value) |
|||
{ |
|||
Id = id; |
|||
Key = Check.NotNullOrWhiteSpace(key, nameof(key)); |
|||
Value = Check.NotNullOrWhiteSpace(value, nameof(value)); |
|||
} |
|||
|
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Key.IsNullOrWhiteSpace() && |
|||
!Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Key.GetHashCode() & Value.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Key.IsNullOrWhiteSpace() || |
|||
Value.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is Claim claim) |
|||
{ |
|||
return claim.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase) && |
|||
claim.Value.Equals(Value, StringComparison.CurrentCultureIgnoreCase); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Security |
|||
{ |
|||
public class RouteClientWhite : Entity<int> |
|||
{ |
|||
public virtual string ClientId { get; private set; } |
|||
public virtual Guid RateLimitRuleId { get; private set; } |
|||
public virtual RateLimitRule RateLimitRule { get; private set; } |
|||
public override int GetHashCode() |
|||
{ |
|||
if (!ClientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
return ClientId.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
ClientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is RouteClientWhite clientWhite) |
|||
{ |
|||
return clientWhite.ClientId.Equals(ClientId); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Security |
|||
{ |
|||
public class RouteIPBlock : Entity<int> |
|||
{ |
|||
public virtual string Address { get; private set; } |
|||
public virtual Guid SecurityId { get; private set; } |
|||
public virtual RouteSecurity Security { get; private set; } |
|||
protected RouteIPBlock() { } |
|||
public RouteIPBlock(Guid securityId, string address) |
|||
{ |
|||
SecurityId = securityId; |
|||
Address = address; |
|||
} |
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Address.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Address.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if (obj == null || |
|||
Address.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is RouteIPBlock iPBlock) |
|||
{ |
|||
return iPBlock.Address.Equals(Address); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Security |
|||
{ |
|||
public class RouteIPWhite : Entity<int> |
|||
{ |
|||
public virtual string Address { get; private set; } |
|||
public virtual Guid SecurityId { get; private set; } |
|||
public virtual RouteSecurity Security { get; private set; } |
|||
|
|||
protected RouteIPWhite() { } |
|||
public RouteIPWhite(Guid securityId, string address) |
|||
{ |
|||
SecurityId = securityId; |
|||
Address = address; |
|||
} |
|||
public override int GetHashCode() |
|||
{ |
|||
if (!Address.IsNullOrWhiteSpace()) |
|||
{ |
|||
return Address.GetHashCode(); |
|||
} |
|||
return base.GetHashCode(); |
|||
} |
|||
|
|||
public override bool Equals(object obj) |
|||
{ |
|||
if(obj == null || |
|||
Address.IsNullOrWhiteSpace()) |
|||
{ |
|||
return false; |
|||
} |
|||
if (obj is RouteIPWhite iPWhite) |
|||
{ |
|||
return iPWhite.Address.Equals(Address); |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
using LINGYUN.ApiGateWay.Admin.Routes; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace LINGYUN.ApiGateWay.Admin.Security |
|||
{ |
|||
public class RouteSecurity : Entity<Guid> |
|||
{ |
|||
public virtual ICollection<RouteIPWhite> IPAllowedList { get; private set; } |
|||
public virtual ICollection<RouteIPBlock> IPBlockedList { get; private set; } |
|||
public virtual Guid RouteId { get; private set; } |
|||
public virtual Route Route { get; private set; } |
|||
protected RouteSecurity() |
|||
{ |
|||
IPAllowedList = new List<RouteIPWhite>(); |
|||
IPBlockedList = new List<RouteIPBlock>(); |
|||
} |
|||
|
|||
public RouteSecurity(Guid id, Guid routeId) : this() |
|||
{ |
|||
Id = id; |
|||
RouteId = routeId; |
|||
} |
|||
|
|||
public void AddIpWhite(string address) |
|||
{ |
|||
IPAllowedList.AddIfNotContains(new RouteIPWhite(Id, address)); |
|||
} |
|||
|
|||
public void RemoveIpWhite(string address) |
|||
{ |
|||
IPAllowedList.RemoveAll(ip => ip.Address.Equals(address)); |
|||
} |
|||
|
|||
public void RemoveAllIpWhite() |
|||
{ |
|||
IPAllowedList.Clear(); |
|||
} |
|||
|
|||
public void AddIpBlock(string address) |
|||
{ |
|||
IPBlockedList.AddIfNotContains(new RouteIPBlock(Id, address)); |
|||
} |
|||
|
|||
public void RemoveIpBlock(string address) |
|||
{ |
|||
IPBlockedList.RemoveAll(ip => ip.Address.Equals(address)); |
|||
} |
|||
|
|||
public void RemoveAllIpBlock() |
|||
{ |
|||
IPBlockedList.Clear(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.PermissionManagement |
|||
{ |
|||
// fix: https://github.com/abpframework/abp/issues/6022
|
|||
// TODO: 在4.0正式版中已修复此问题,升级后需要移除
|
|||
[Dependency(ReplaceServices = true)] |
|||
[ExposeServices(typeof(ClientPermissionValueProvider))] |
|||
public class FixClientPermissionValueProvider : ClientPermissionValueProvider |
|||
{ |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
public FixClientPermissionValueProvider( |
|||
IPermissionStore permissionStore, |
|||
ICurrentTenant currentTenant) : base(permissionStore) |
|||
{ |
|||
CurrentTenant = currentTenant; |
|||
} |
|||
|
|||
public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context) |
|||
{ |
|||
using (CurrentTenant.Change(null)) |
|||
{ |
|||
return await base.CheckAsync(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using System.Linq; |
|||
using Volo.Abp.AspNetCore.MultiTenancy; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.BackendAdmin.MultiTenancy |
|||
{ |
|||
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase |
|||
{ |
|||
public override string Name => "Authorization"; |
|||
|
|||
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
|||
{ |
|||
if (httpContext.User?.Identity == null) |
|||
{ |
|||
return null; |
|||
} |
|||
if (!httpContext.User.Identity.IsAuthenticated) |
|||
{ |
|||
return null; |
|||
} |
|||
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey; |
|||
|
|||
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId)); |
|||
|
|||
if (tenantClaim == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return tenantClaim.Value; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.BackendAdmin.Tests |
|||
{ |
|||
public class ProxyConnectTestMiddleware |
|||
{ |
|||
private readonly RequestDelegate _next; |
|||
public ProxyConnectTestMiddleware(RequestDelegate next) |
|||
{ |
|||
_next = next; |
|||
} |
|||
|
|||
public async Task Invoke(HttpContext context) |
|||
{ |
|||
if (context.Request.Path.StartsWithSegments("/api/connect")) |
|||
{ |
|||
var contentBuilder = new StringBuilder(); |
|||
|
|||
contentBuilder.AppendLine("Connection:"); |
|||
contentBuilder.AppendLine($"Id: {context.Connection.Id}"); |
|||
contentBuilder.AppendLine($"LocalIpAddress: {context.Connection.LocalIpAddress}:{context.Connection.LocalPort}"); |
|||
contentBuilder.AppendLine($"RemoteIpAddress: {context.Connection.RemoteIpAddress}:{context.Connection.RemotePort}"); |
|||
contentBuilder.AppendLine(); |
|||
contentBuilder.AppendLine("Headers:"); |
|||
contentBuilder.Append(context.Request.Headers.Select(h => $"Key:{h.Key}, Value:{h.Value}").JoinAsString(Environment.NewLine)); |
|||
contentBuilder.AppendLine(); |
|||
contentBuilder.AppendLine(); |
|||
contentBuilder.AppendLine("Host:"); |
|||
contentBuilder.AppendLine(context.Request.Host.ToUriComponent()); |
|||
contentBuilder.AppendLine(); |
|||
contentBuilder.AppendLine("Scheme:"); |
|||
contentBuilder.AppendLine(context.Request.Scheme); |
|||
await context.Response.WriteAsync(contentBuilder.ToString()); |
|||
return; |
|||
} |
|||
await _next(context); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using LINGYUN.Abp.BackendAdmin.Tests; |
|||
|
|||
namespace Microsoft.AspNetCore.Builder |
|||
{ |
|||
public static class ProxyConnectTestMiddlewareExtensions |
|||
{ |
|||
public static IApplicationBuilder UseProxyConnectTest(this IApplicationBuilder app) |
|||
{ |
|||
return app.UseMiddleware<ProxyConnectTestMiddleware>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using System.Linq; |
|||
using Volo.Abp.AspNetCore.MultiTenancy; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.IdentityServer4 |
|||
{ |
|||
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase |
|||
{ |
|||
public override string Name => "Authorization"; |
|||
|
|||
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
|||
{ |
|||
if (httpContext.User?.Identity == null) |
|||
{ |
|||
return null; |
|||
} |
|||
if (!httpContext.User.Identity.IsAuthenticated) |
|||
{ |
|||
return null; |
|||
} |
|||
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey; |
|||
|
|||
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId)); |
|||
|
|||
if (tenantClaim == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return tenantClaim.Value; |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using System.Linq; |
|||
using Volo.Abp.AspNetCore.MultiTenancy; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.MultiTenancy |
|||
{ |
|||
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase |
|||
{ |
|||
public override string Name => "Authorization"; |
|||
|
|||
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
|||
{ |
|||
if (httpContext.User?.Identity == null) |
|||
{ |
|||
return null; |
|||
} |
|||
if (!httpContext.User.Identity.IsAuthenticated) |
|||
{ |
|||
return null; |
|||
} |
|||
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey; |
|||
|
|||
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId)); |
|||
|
|||
if (tenantClaim == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return tenantClaim.Value; |
|||
} |
|||
} |
|||
} |
|||
@ -1,35 +0,0 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using System.Linq; |
|||
using Volo.Abp.AspNetCore.MultiTenancy; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Platform.MultiTenancy |
|||
{ |
|||
public class AuthorizationTenantResolveContributor : HttpTenantResolveContributorBase |
|||
{ |
|||
public override string Name => "Authorization"; |
|||
|
|||
protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) |
|||
{ |
|||
if (httpContext.User?.Identity == null) |
|||
{ |
|||
return null; |
|||
} |
|||
if (!httpContext.User.Identity.IsAuthenticated) |
|||
{ |
|||
return null; |
|||
} |
|||
var tenantIdKey = context.GetAbpAspNetCoreMultiTenancyOptions().TenantKey; |
|||
|
|||
var tenantClaim = httpContext.User.Claims.FirstOrDefault(x => x.Type.Equals(AbpClaimTypes.TenantId)); |
|||
|
|||
if (tenantClaim == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return tenantClaim.Value; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue