From 1823c832a6230f81ad75e0cf828dc6e769d8a3ab Mon Sep 17 00:00:00 2001 From: Tom Pallister Date: Fri, 11 May 2018 07:59:03 +0100 Subject: [PATCH] +semver: major merged netstandard2.0 upgrade and updated all packages. Also had to change identity server test due to scope deduping and put a few awaits in. --- docs/introduction/gettingstarted.rst | 4 +- src/Ocelot/Ocelot.csproj | 26 +++++------ src/Ocelot/Raft/HttpPeer.cs | 44 ++++++++----------- src/Ocelot/Raft/RaftController.cs | 14 +++--- src/Ocelot/Raft/SqlLiteLog.cs | 3 +- .../AuthenticationTests.cs | 2 - .../Ocelot.AcceptanceTests.csproj | 20 ++++----- test/Ocelot.AcceptanceTests/Steps.cs | 3 +- .../Ocelot.Benchmarks.csproj | 2 +- .../Ocelot.IntegrationTests.csproj | 18 ++++---- test/Ocelot.IntegrationTests/RaftTests.cs | 2 +- .../Ocelot.ManualTest.csproj | 18 ++++---- test/Ocelot.UnitTests/Ocelot.UnitTests.csproj | 18 ++++---- 13 files changed, 84 insertions(+), 90 deletions(-) diff --git a/docs/introduction/gettingstarted.rst b/docs/introduction/gettingstarted.rst index 089acc4f..f523ea1b 100644 --- a/docs/introduction/gettingstarted.rst +++ b/docs/introduction/gettingstarted.rst @@ -2,14 +2,14 @@ Getting Started =============== Ocelot is designed to work with .NET Core only and is currently -built to netcoreapp2.0 `this `_ documentation may prove helpful when working out if Ocelot would be suitable for you. +built to netstandard2.0 `this `_ documentation may prove helpful when working out if Ocelot would be suitable for you. .NET Core 2.0 ^^^^^^^^^^^^^ **Install NuGet package** -Install Ocelot and it's dependencies using nuget. You will need to create a netcoreapp2.0 project and bring the package into it. Then follow the Startup below and :doc:`../features/configuration` sections +Install Ocelot and it's dependencies using nuget. You will need to create a netstandard2.0 project and bring the package into it. Then follow the Startup below and :doc:`../features/configuration` sections to get up and running. ``Install-Package Ocelot`` diff --git a/src/Ocelot/Ocelot.csproj b/src/Ocelot/Ocelot.csproj index c7dfcfda..5bd94b0c 100644 --- a/src/Ocelot/Ocelot.csproj +++ b/src/Ocelot/Ocelot.csproj @@ -30,21 +30,21 @@ NU1701 - - - - + + + + - - - + + + NU1701 - - - - + + + + all @@ -53,9 +53,9 @@ - + - + diff --git a/src/Ocelot/Raft/HttpPeer.cs b/src/Ocelot/Raft/HttpPeer.cs index 135e1d02..93d81cd4 100644 --- a/src/Ocelot/Raft/HttpPeer.cs +++ b/src/Ocelot/Raft/HttpPeer.cs @@ -34,27 +34,25 @@ namespace Ocelot.Raft _baseSchemeUrlAndPort = finder.Find(); } - public string Id {get; private set;} + public string Id { get; } public async Task Request(RequestVote requestVote) { if(_token == null) { - SetToken(); + await SetToken(); } var json = JsonConvert.SerializeObject(requestVote, _jsonSerializerSettings); var content = new StringContent(json); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); - var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/requestvote", content).GetAwaiter().GetResult(); + var response = await _httpClient.PostAsync($"{_hostAndPort}/administration/raft/requestvote", content); if(response.IsSuccessStatusCode) { return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings); } - else - { - return new RequestVoteResponse(false, requestVote.Term); - } + + return new RequestVoteResponse(false, requestVote.Term); } public async Task Request(AppendEntries appendEntries) @@ -63,21 +61,19 @@ namespace Ocelot.Raft { if(_token == null) { - SetToken(); - } + await SetToken(); + } var json = JsonConvert.SerializeObject(appendEntries, _jsonSerializerSettings); var content = new StringContent(json); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); - var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/appendEntries", content).GetAwaiter().GetResult(); + var response = await _httpClient.PostAsync($"{_hostAndPort}/administration/raft/appendEntries", content); if(response.IsSuccessStatusCode) { return JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings); } - else - { - return new AppendEntriesResponse(appendEntries.Term, false); - } + + return new AppendEntriesResponse(appendEntries.Term, false); } catch(Exception ex) { @@ -92,27 +88,25 @@ namespace Ocelot.Raft Console.WriteLine("SENDING REQUEST...."); if(_token == null) { - SetToken(); + await SetToken(); } var json = JsonConvert.SerializeObject(command, _jsonSerializerSettings); var content = new StringContent(json); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); - var response = _httpClient.PostAsync($"{_hostAndPort}/administration/raft/command", content).GetAwaiter().GetResult(); + var response = await _httpClient.PostAsync($"{_hostAndPort}/administration/raft/command", content); if(response.IsSuccessStatusCode) { Console.WriteLine("REQUEST OK...."); - var okResponse = JsonConvert.DeserializeObject>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult(), _jsonSerializerSettings); + var okResponse = JsonConvert.DeserializeObject>(await response.Content.ReadAsStringAsync(), _jsonSerializerSettings); return new OkResponse((T)okResponse.Command); } - else - { - Console.WriteLine("REQUEST NOT OK...."); - return new ErrorResponse(await response.Content.ReadAsStringAsync(), command); - } + + Console.WriteLine("REQUEST NOT OK...."); + return new ErrorResponse(await response.Content.ReadAsStringAsync(), command); } - private void SetToken() + private async Task SetToken() { var tokenUrl = $"{_baseSchemeUrlAndPort}{_config.AdministrationPath}/connect/token"; var formData = new List> @@ -123,8 +117,8 @@ namespace Ocelot.Raft new KeyValuePair("grant_type", "client_credentials") }; var content = new FormUrlEncodedContent(formData); - var response = _httpClient.PostAsync(tokenUrl, content).GetAwaiter().GetResult(); - var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + var response = await _httpClient.PostAsync(tokenUrl, content); + var responseContent = await response.Content.ReadAsStringAsync(); response.EnsureSuccessStatusCode(); _token = JsonConvert.DeserializeObject(responseContent); _httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(_token.TokenType, _token.AccessToken); diff --git a/src/Ocelot/Raft/RaftController.cs b/src/Ocelot/Raft/RaftController.cs index c1222e4d..0b8d4989 100644 --- a/src/Ocelot/Raft/RaftController.cs +++ b/src/Ocelot/Raft/RaftController.cs @@ -20,9 +20,9 @@ namespace Ocelot.Raft public class RaftController : Controller { private readonly INode _node; - private IOcelotLogger _logger; - private string _baseSchemeUrlAndPort; - private JsonSerializerSettings _jsonSerialiserSettings; + private readonly IOcelotLogger _logger; + private readonly string _baseSchemeUrlAndPort; + private readonly JsonSerializerSettings _jsonSerialiserSettings; public RaftController(INode node, IOcelotLoggerFactory loggerFactory, IBaseUrlFinder finder) { @@ -45,7 +45,7 @@ namespace Ocelot.Raft _logger.LogDebug($"{_baseSchemeUrlAndPort}/appendentries called, my state is {_node.State.GetType().FullName}"); - var appendEntriesResponse = _node.Handle(appendEntries); + var appendEntriesResponse = await _node.Handle(appendEntries); return new OkObjectResult(appendEntriesResponse); } @@ -62,7 +62,7 @@ namespace Ocelot.Raft _logger.LogDebug($"{_baseSchemeUrlAndPort}/requestvote called, my state is {_node.State.GetType().FullName}"); - var requestVoteResponse = _node.Handle(requestVote); + var requestVoteResponse = await _node.Handle(requestVote); return new OkObjectResult(requestVoteResponse); } @@ -81,7 +81,7 @@ namespace Ocelot.Raft _logger.LogDebug($"{_baseSchemeUrlAndPort}/command called, my state is {_node.State.GetType().FullName}"); - var commandResponse = _node.Accept(command); + var commandResponse = await _node.Accept(command); json = JsonConvert.SerializeObject(commandResponse, _jsonSerialiserSettings); @@ -91,7 +91,7 @@ namespace Ocelot.Raft catch(Exception e) { _logger.LogError($"THERE WAS A PROBLEM ON NODE {_node.State.CurrentState.Id}", e); - throw e; + throw; } } } diff --git a/src/Ocelot/Raft/SqlLiteLog.cs b/src/Ocelot/Raft/SqlLiteLog.cs index 4e74e97a..f0db2047 100644 --- a/src/Ocelot/Raft/SqlLiteLog.cs +++ b/src/Ocelot/Raft/SqlLiteLog.cs @@ -8,7 +8,8 @@ using System.Collections.Generic; using System.Threading.Tasks; namespace Ocelot.Raft -{ +{ + //todo - use async await [ExcludeFromCoverage] public class SqlLiteLog : ILog { diff --git a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs index bc76ccff..770deaa1 100644 --- a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs @@ -316,8 +316,6 @@ namespace Ocelot.AcceptanceTests { new Scope("api2"), new Scope("api2.readOnly"), - new Scope("openid"), - new Scope("offline_access") }, ApiSecrets = new List() { diff --git a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj index b8ec7eb6..fe4877ec 100644 --- a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj +++ b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj @@ -34,21 +34,21 @@ - - + + all - - - - - - - - + + + + + + + + diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index 72fad48b..5041088e 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -664,7 +664,8 @@ namespace Ocelot.AcceptanceTests { using (var httpClient = new HttpClient()) { - var response = httpClient.GetAsync($"{url}/.well-known/openid-configuration").Result; + var response = httpClient.GetAsync($"{url}/.well-known/openid-configuration").GetAwaiter().GetResult(); + var content = response.Content.ReadAsStringAsync().GetAwaiter(); response.EnsureSuccessStatusCode(); } } diff --git a/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj b/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj index 7761dab1..e97450d3 100644 --- a/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj +++ b/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj @@ -19,7 +19,7 @@ - + all diff --git a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj index 32cf393a..5ec67320 100644 --- a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj +++ b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj @@ -25,22 +25,22 @@ - + all - - - - - - - + + + + + + + - + diff --git a/test/Ocelot.IntegrationTests/RaftTests.cs b/test/Ocelot.IntegrationTests/RaftTests.cs index a7a173e0..96cd6687 100644 --- a/test/Ocelot.IntegrationTests/RaftTests.cs +++ b/test/Ocelot.IntegrationTests/RaftTests.cs @@ -263,7 +263,7 @@ namespace Ocelot.IntegrationTests catch(Exception e) { //_output.WriteLine($"{e.Message}, {e.StackTrace}"); - //Console.WriteLine(e); + Console.WriteLine(e); return false; } } diff --git a/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj b/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj index a43e6b23..b7c3ac18 100644 --- a/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj +++ b/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj @@ -24,16 +24,16 @@ - - - - - - - - + + + + + + + + - + all diff --git a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj index 6f219ad3..9aa7db12 100644 --- a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj +++ b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj @@ -29,21 +29,21 @@ - - + + all - - - - - - - + + + + + + +