private void GivenTheFollowingConfig(IOcelotConfiguration config) { _config = config; _provider .Setup(x => x.Get()) .ReturnsAsync(new OkResponse <IOcelotConfiguration>(_config)); }
private void GivenTheConfigurationIs(IOcelotConfiguration config) { var response = new Ocelot.Responses.OkResponse <IOcelotConfiguration>(config); _provider .Setup(x => x.Get()).ReturnsAsync(response); }
public async Task <Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration) { lock (LockObject) { _ocelotConfiguration = ocelotConfiguration; } return(new OkResponse()); }
public Task <Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration) { lock (LockObject) { _ocelotConfiguration = ocelotConfiguration; } return(Task.FromResult <Response>(new OkResponse())); }
private void GivenThereIsAFakeConsulServiceDiscoveryProvider(string url) { _fakeConsulBuilder = new WebHostBuilder() .UseUrls(url) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseUrls(url) .Configure(app => { app.Run(async context => { if (context.Request.Method.ToLower() == "get" && context.Request.Path.Value == "/v1/kv/OcelotConfiguration") { var json = JsonConvert.SerializeObject(_config); var bytes = Encoding.UTF8.GetBytes(json); var base64 = Convert.ToBase64String(bytes); var kvp = new FakeConsulGetResponse(base64); await context.Response.WriteJsonAsync(new FakeConsulGetResponse[] { kvp }); } else if (context.Request.Method.ToLower() == "put" && context.Request.Path.Value == "/v1/kv/OcelotConfiguration") { try { var reader = new StreamReader(context.Request.Body); var json = reader.ReadToEnd(); var settings = new JsonSerializerSettings(); settings.Converters.Add(new AuthenticationConfigConverter()); _config = JsonConvert.DeserializeObject <OcelotConfiguration>(json, settings); var response = JsonConvert.SerializeObject(true); await context.Response.WriteAsync(response); } catch (Exception e) { Console.WriteLine(e); throw; } } }); }) .Build(); _fakeConsulBuilder.Start(); }
public HttpPeer(string hostAndPort, HttpClient httpClient, IBaseUrlFinder finder, IOcelotConfiguration config, IIdentityServerConfiguration identityServerConfiguration) { _identityServerConfiguration = identityServerConfiguration; _config = config; Id = hostAndPort; _hostAndPort = hostAndPort; _httpClient = httpClient; _jsonSerializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }; _baseSchemeUrlAndPort = finder.Find(); }
public HttpPeer(string hostAndPort, HttpClient httpClient, IWebHostBuilder builder, IOcelotConfiguration config, IIdentityServerConfiguration identityServerConfiguration) { _identityServerConfiguration = identityServerConfiguration; _config = config; Id = hostAndPort; _hostAndPort = hostAndPort; _httpClient = httpClient; _jsonSerializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }; _baseSchemeUrlAndPort = builder.GetSetting(WebHostDefaults.ServerUrlsKey); }
private static void CreateAdministrationArea(IApplicationBuilder builder, IOcelotConfiguration configuration) { if (!string.IsNullOrEmpty(configuration.AdministrationPath)) { builder.Map(configuration.AdministrationPath, app => { //todo - hack so we know that we are using internal identity server var identityServerConfiguration = (IIdentityServerConfiguration)builder.ApplicationServices.GetService(typeof(IIdentityServerConfiguration)); if (identityServerConfiguration != null) { app.UseIdentityServer(); } app.UseAuthentication(); app.UseMvc(); }); } }
public async Task <Response> AddOrReplace(IOcelotConfiguration ocelotConfiguration) { var json = JsonConvert.SerializeObject(ocelotConfiguration); var bytes = Encoding.UTF8.GetBytes(json); var kvPair = new KVPair(_ocelotConfiguration) { Value = bytes }; var result = await _consul.KV.Put(kvPair); if (result.Response) { _cache.AddAndDelete(_ocelotConfiguration, ocelotConfiguration, TimeSpan.FromSeconds(3)); return(new OkResponse()); } return(new ErrorResponse(new UnableToSetConfigInConsulError("Unable to set config in consul"))); }
public Response <DownstreamRoute> FindDownstreamRoute(string upstreamUrlPath, string upstreamHttpMethod, IOcelotConfiguration configuration) { upstreamUrlPath = upstreamUrlPath.SetLastCharacterAs('/'); var applicableReRoutes = configuration.ReRoutes.Where(r => r.UpstreamHttpMethod.Count == 0 || r.UpstreamHttpMethod.Select(x => x.Method.ToLower()).Contains(upstreamHttpMethod.ToLower())); foreach (var reRoute in applicableReRoutes) { if (upstreamUrlPath == reRoute.UpstreamTemplatePattern) { var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return(new OkResponse <DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute))); } var urlMatch = _urlMatcher.Match(upstreamUrlPath, reRoute.UpstreamTemplatePattern); if (urlMatch.Data.Match) { var templateVariableNameAndValues = _urlPathPlaceholderNameAndValueFinder.Find(upstreamUrlPath, reRoute.UpstreamPathTemplate.Value); return(new OkResponse <DownstreamRoute>(new DownstreamRoute(templateVariableNameAndValues.Data, reRoute))); } } return(new ErrorResponse <DownstreamRoute>(new List <Error> { new UnableToFindDownstreamRouteError() })); }
public Response <DownstreamRoute> FindDownstreamRoute(string path, string httpMethod, IOcelotConfiguration configuration, string upstreamHost) { var downstreamRoutes = new List <DownstreamRoute>(); var applicableReRoutes = configuration.ReRoutes .Where(r => RouteIsApplicableToThisRequest(r, httpMethod, upstreamHost)) .OrderByDescending(x => x.UpstreamTemplatePattern.Priority); foreach (var reRoute in applicableReRoutes) { var urlMatch = _urlMatcher.Match(path, reRoute.UpstreamTemplatePattern.Template); if (urlMatch.Data.Match) { downstreamRoutes.Add(GetPlaceholderNamesAndValues(path, reRoute)); } } if (downstreamRoutes.Any()) { var notNullOption = downstreamRoutes.FirstOrDefault(x => !string.IsNullOrEmpty(x.ReRoute.UpstreamHost)); var nullOption = downstreamRoutes.FirstOrDefault(x => string.IsNullOrEmpty(x.ReRoute.UpstreamHost)); return(notNullOption != null ? new OkResponse <DownstreamRoute>(notNullOption) : new OkResponse <DownstreamRoute>(nullOption)); } return(new ErrorResponse <DownstreamRoute>(new List <Error> { new UnableToFindDownstreamRouteError() })); }
private void GivenTheConfigurationIs(IOcelotConfiguration config) { _config = config; }
private static async Task CreateAdministrationArea(IApplicationBuilder builder, IOcelotConfiguration configuration) { var identityServerConfiguration = (IIdentityServerConfiguration)builder.ApplicationServices.GetService(typeof(IIdentityServerConfiguration)); if (!string.IsNullOrEmpty(configuration.AdministrationPath) && identityServerConfiguration != null) { builder.Map(configuration.AdministrationPath, app => { app.UseIdentityServer(); app.UseAuthentication(); app.UseMvc(); }); } }
public Response <DownstreamRoute> FindDownstreamRoute(string path, string httpMethod, IOcelotConfiguration configuration) { var applicableReRoutes = configuration.ReRoutes.Where(r => r.UpstreamHttpMethod.Count == 0 || r.UpstreamHttpMethod.Select(x => x.Method.ToLower()).Contains(httpMethod.ToLower())).OrderByDescending(x => x.UpstreamTemplatePattern.Priority); foreach (var reRoute in applicableReRoutes) { if (path == reRoute.UpstreamTemplatePattern.Template) { return(GetPlaceholderNamesAndValues(path, reRoute)); } var urlMatch = _urlMatcher.Match(path, reRoute.UpstreamTemplatePattern.Template); if (urlMatch.Data.Match) { return(GetPlaceholderNamesAndValues(path, reRoute)); } } return(new ErrorResponse <DownstreamRoute>(new List <Error> { new UnableToFindDownstreamRouteError() })); }
// Inject Service Discovery Client into app private static void UserSteeltoeServiceDiscovery(IApplicationBuilder builder, IOcelotConfiguration configuration) { if (configuration != null && configuration.ServiceProviderConfiguration != null && configuration.ServiceProviderConfiguration.Type == "Steeltoe") { builder.UseDiscoveryClient(); } }