/// <summary> /// 设置网关配置 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <BaseOutput> SetApiGatewayConfiguration(SetApiGatewayConfigurationInput input) { var configInfo = new ApiGatewayConfigurationInfo { GatewayId = input.GatewayId, BaseUrl = input.BaseUrl, DownstreamScheme = input.DownstreamScheme, GatewayKey = input.GatewayKey, HttpHandlerOptions = Json.ToJson(input.HttpHandlerOptions), LoadBalancerOptions = Json.ToJson(input.LoadBalancerOptions), QoSOptions = Json.ToJson(input.QoSOptions), RateLimitOptions = Json.ToJson(input.RateLimitOptions), RequestIdKey = input.RequestIdKey, ServiceDiscoveryProvider = Json.ToJson(input.ServiceDiscoveryProvider) }; if (configInfo.GatewayId > 0) { await _configDbRepository.UpdateAsync(configInfo); } else { await _configDbRepository.InsertAsync(configInfo); } return(new BaseOutput { }); }
/// <summary> /// 设置网关路由 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <BaseOutput> SetApiGatewayReRoute(SetApiGatewayReRouteInput input) { var rerouteInfo = new ApiGatewayReRouteInfo { AuthenticationOptions = Json.ToJson(input.AuthenticationOptions), CacheOptions = Json.ToJson(input.FileCacheOptions), DelegatingHandlers = Json.ToJson(input.DelegatingHandlers), DownstreamHostAndPorts = Json.ToJson(input.DownstreamHostAndPorts), DownstreamPathTemplate = input.DownstreamPathTemplate, Id = input.Id, Key = input.Key, Priority = input.Priority, SecurityOptions = Json.ToJson(input.SecurityOptions), ServiceName = input.ServiceName, State = input.State, Timeout = input.Timeout, UpstreamHost = input.UpstreamHost, UpstreamHttpMethod = Json.ToJson(input.UpstreamHttpMethod), UpstreamPathTemplate = input.UpstreamPathTemplate, GatewayId = input.GatewayId, DownstreamScheme = input.DownstreamScheme, HttpHandlerOptions = Json.ToJson(input.HttpHandlerOptions), LoadBalancerOptions = Json.ToJson(input.LoadBalancerOptions), QoSOptions = Json.ToJson(input.QoSOptions), RateLimitOptions = Json.ToJson(input.RateLimitOptions), RequestIdKey = input.RequestIdKey, }; if (rerouteInfo.Id > 0) { var route = _routeDbRepository.GetFirst(it => it.UpstreamPathTemplate == rerouteInfo.UpstreamPathTemplate && it.GatewayId == rerouteInfo.GatewayId); if (route != null && route.Id != rerouteInfo.Id) { throw new BucketException("ms_003", "上游路由规则已存在"); } await _routeDbRepository.UpdateAsync(rerouteInfo); } else { // 在网关内已存在 if (_routeDbRepository.IsAny(it => it.UpstreamPathTemplate == rerouteInfo.UpstreamPathTemplate && it.GatewayId == rerouteInfo.GatewayId)) { throw new BucketException("ms_003", "上游路由规则已存在"); } await _routeDbRepository.InsertAsync(rerouteInfo); } return(new BaseOutput { }); }