mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
trying to get cluster working
This commit is contained in:
parent
bc7bfc8917
commit
2d94884c6f
@ -13,6 +13,8 @@ namespace Ocelot.Configuration.Creator
|
|||||||
var username = Environment.GetEnvironmentVariable("OCELOT_USERNAME");
|
var username = Environment.GetEnvironmentVariable("OCELOT_USERNAME");
|
||||||
var hash = Environment.GetEnvironmentVariable("OCELOT_HASH");
|
var hash = Environment.GetEnvironmentVariable("OCELOT_HASH");
|
||||||
var salt = Environment.GetEnvironmentVariable("OCELOT_SALT");
|
var salt = Environment.GetEnvironmentVariable("OCELOT_SALT");
|
||||||
|
var credentialsSigningCertificateLocation = Environment.GetEnvironmentVariable("OCELOT_CERTIFICATE");
|
||||||
|
var credentialsSigningCertificatePassword = Environment.GetEnvironmentVariable("OCELOT_CERTIFICATE_PASSWORD");
|
||||||
|
|
||||||
return new IdentityServerConfiguration(
|
return new IdentityServerConfiguration(
|
||||||
"admin",
|
"admin",
|
||||||
@ -28,7 +30,9 @@ namespace Ocelot.Configuration.Creator
|
|||||||
new List<User>
|
new List<User>
|
||||||
{
|
{
|
||||||
new User("admin", username, hash, salt)
|
new User("admin", username, hash, salt)
|
||||||
}
|
},
|
||||||
|
credentialsSigningCertificateLocation,
|
||||||
|
credentialsSigningCertificatePassword
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,5 +17,7 @@ namespace Ocelot.Configuration.Provider
|
|||||||
AccessTokenType AccessTokenType {get;}
|
AccessTokenType AccessTokenType {get;}
|
||||||
bool RequireClientSecret {get;}
|
bool RequireClientSecret {get;}
|
||||||
List<User> Users {get;}
|
List<User> Users {get;}
|
||||||
|
string CredentialsSigningCertificateLocation { get; }
|
||||||
|
string CredentialsSigningCertificatePassword { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ namespace Ocelot.Configuration.Provider
|
|||||||
IEnumerable<string> grantType,
|
IEnumerable<string> grantType,
|
||||||
AccessTokenType accessTokenType,
|
AccessTokenType accessTokenType,
|
||||||
bool requireClientSecret,
|
bool requireClientSecret,
|
||||||
List<User> users)
|
List<User> users, string credentialsSigningCertificateLocation, string credentialsSigningCertificatePassword)
|
||||||
{
|
{
|
||||||
ApiName = apiName;
|
ApiName = apiName;
|
||||||
RequireHttps = requireHttps;
|
RequireHttps = requireHttps;
|
||||||
@ -30,6 +30,8 @@ namespace Ocelot.Configuration.Provider
|
|||||||
AccessTokenType = accessTokenType;
|
AccessTokenType = accessTokenType;
|
||||||
RequireClientSecret = requireClientSecret;
|
RequireClientSecret = requireClientSecret;
|
||||||
Users = users;
|
Users = users;
|
||||||
|
CredentialsSigningCertificateLocation = credentialsSigningCertificateLocation;
|
||||||
|
CredentialsSigningCertificatePassword = credentialsSigningCertificatePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ApiName { get; private set; }
|
public string ApiName { get; private set; }
|
||||||
@ -43,5 +45,7 @@ namespace Ocelot.Configuration.Provider
|
|||||||
public AccessTokenType AccessTokenType {get;private set;}
|
public AccessTokenType AccessTokenType {get;private set;}
|
||||||
public bool RequireClientSecret {get;private set;}
|
public bool RequireClientSecret {get;private set;}
|
||||||
public List<User> Users {get;private set;}
|
public List<User> Users {get;private set;}
|
||||||
|
public string CredentialsSigningCertificateLocation { get; private set; }
|
||||||
|
public string CredentialsSigningCertificatePassword { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -41,6 +41,8 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Ocelot.Configuration;
|
using Ocelot.Configuration;
|
||||||
using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
|
using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
|
||||||
|
|
||||||
@ -87,8 +89,7 @@ namespace Ocelot.DependencyInjection
|
|||||||
{
|
{
|
||||||
services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
|
services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
|
||||||
services.TryAddSingleton<IHashMatcher, HashMatcher>();
|
services.TryAddSingleton<IHashMatcher, HashMatcher>();
|
||||||
services.AddIdentityServer()
|
var identityServerBuilder = services.AddIdentityServer()
|
||||||
.AddTemporarySigningCredential()
|
|
||||||
.AddInMemoryApiResources(new List<ApiResource>
|
.AddInMemoryApiResources(new List<ApiResource>
|
||||||
{
|
{
|
||||||
new ApiResource
|
new ApiResource
|
||||||
@ -120,6 +121,16 @@ namespace Ocelot.DependencyInjection
|
|||||||
RequireClientSecret = identityServerConfiguration.RequireClientSecret
|
RequireClientSecret = identityServerConfiguration.RequireClientSecret
|
||||||
}
|
}
|
||||||
}).AddResourceOwnerValidator<OcelotResourceOwnerPasswordValidator>();
|
}).AddResourceOwnerValidator<OcelotResourceOwnerPasswordValidator>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword))
|
||||||
|
{
|
||||||
|
identityServerBuilder.AddTemporarySigningCredential();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var cert = new X509Certificate2(identityServerConfiguration.CredentialsSigningCertificateLocation, identityServerConfiguration.CredentialsSigningCertificatePassword);
|
||||||
|
identityServerBuilder.AddSigningCredential(cert);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var assembly = typeof(FileConfigurationController).GetTypeInfo().Assembly;
|
var assembly = typeof(FileConfigurationController).GetTypeInfo().Assembly;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="configuration.json">
|
<None Update="configuration.json;idsrv3test.pfx">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -19,15 +19,19 @@ namespace Ocelot.IntegrationTests
|
|||||||
public class AdministrationTests : IDisposable
|
public class AdministrationTests : IDisposable
|
||||||
{
|
{
|
||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly HttpClient _httpClientTwo;
|
||||||
private HttpResponseMessage _response;
|
private HttpResponseMessage _response;
|
||||||
private IWebHost _builder;
|
private IWebHost _builder;
|
||||||
private IWebHostBuilder _webHostBuilder;
|
private IWebHostBuilder _webHostBuilder;
|
||||||
private readonly string _ocelotBaseUrl;
|
private readonly string _ocelotBaseUrl;
|
||||||
private BearerToken _token;
|
private BearerToken _token;
|
||||||
|
private IWebHostBuilder _webHostBuilderTwo;
|
||||||
|
private IWebHost _builderTwo;
|
||||||
|
|
||||||
public AdministrationTests()
|
public AdministrationTests()
|
||||||
{
|
{
|
||||||
_httpClient = new HttpClient();
|
_httpClient = new HttpClient();
|
||||||
|
_httpClientTwo = new HttpClient();
|
||||||
_ocelotBaseUrl = "http://localhost:5000";
|
_ocelotBaseUrl = "http://localhost:5000";
|
||||||
_httpClient.BaseAddress = new Uri(_ocelotBaseUrl);
|
_httpClient.BaseAddress = new Uri(_ocelotBaseUrl);
|
||||||
}
|
}
|
||||||
@ -70,6 +74,27 @@ namespace Ocelot.IntegrationTests
|
|||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_be_able_to_use_token_from_ocelot_a_on_ocelot_b()
|
||||||
|
{
|
||||||
|
var configuration = new FileConfiguration
|
||||||
|
{
|
||||||
|
GlobalConfiguration = new FileGlobalConfiguration
|
||||||
|
{
|
||||||
|
AdministrationPath = "/administration"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Given(x => GivenThereIsAConfiguration(configuration))
|
||||||
|
.And(x => GivenOcelotIsRunning())
|
||||||
|
.And(x => GivenIHaveAnOcelotToken("/administration"))
|
||||||
|
.And(x => GivenIHaveAddedATokenToMyRequest())
|
||||||
|
.And(x => GivenAnotherOcelotIsRunning("http://localhost:5007"))
|
||||||
|
.When(x => WhenIGetUrlOnTheSecondOcelot("/administration/configuration"))
|
||||||
|
.Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_file_configuration()
|
public void should_return_file_configuration()
|
||||||
{
|
{
|
||||||
@ -193,6 +218,29 @@ namespace Ocelot.IntegrationTests
|
|||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenAnotherOcelotIsRunning(string baseUrl)
|
||||||
|
{
|
||||||
|
_httpClientTwo.BaseAddress = new Uri(baseUrl);
|
||||||
|
|
||||||
|
_webHostBuilderTwo = new WebHostBuilder()
|
||||||
|
.UseUrls(baseUrl)
|
||||||
|
.UseKestrel()
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.ConfigureServices(x => {
|
||||||
|
x.AddSingleton(_webHostBuilder);
|
||||||
|
})
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
|
||||||
|
_builderTwo = _webHostBuilderTwo.Build();
|
||||||
|
|
||||||
|
_builderTwo.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WhenIGetUrlOnTheSecondOcelot(string url)
|
||||||
|
{
|
||||||
|
_response = _httpClientTwo.GetAsync(url).Result;
|
||||||
|
}
|
||||||
|
|
||||||
private void WhenIPostOnTheApiGateway(string url, FileConfiguration updatedConfiguration)
|
private void WhenIPostOnTheApiGateway(string url, FileConfiguration updatedConfiguration)
|
||||||
{
|
{
|
||||||
var json = JsonConvert.SerializeObject(updatedConfiguration);
|
var json = JsonConvert.SerializeObject(updatedConfiguration);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="configuration.json;appsettings.json">
|
<None Update="configuration.json;appsettings.json;idsrv3test.pfx">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user