mirror of https://github.com/Squidex/squidex.git
30 changed files with 402 additions and 186 deletions
@ -1,26 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.Configuration; |
|||
|
|||
namespace Squidex |
|||
{ |
|||
public static class AppConfiguration |
|||
{ |
|||
public static void AddAppConfiguration(this IConfigurationBuilder builder, string environmentName, string[] args) |
|||
{ |
|||
builder.Sources.Clear(); |
|||
|
|||
builder.AddJsonFile("appsettings.json", true, true); |
|||
builder.AddJsonFile($"appsettings.{environmentName}.json", true); |
|||
|
|||
builder.AddEnvironmentVariables(); |
|||
|
|||
builder.AddCommandLine(args); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Authentication.Cookies; |
|||
using Microsoft.AspNetCore.Authentication.OpenIdConnect; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Squidex.Shared.Identity; |
|||
|
|||
namespace Squidex.Areas.OrleansDashboard.Middlewares |
|||
{ |
|||
public sealed class OrleansDashboardAuthenticationMiddleware |
|||
{ |
|||
private readonly RequestDelegate next; |
|||
|
|||
public OrleansDashboardAuthenticationMiddleware(RequestDelegate next) |
|||
{ |
|||
this.next = next; |
|||
} |
|||
|
|||
public async Task Invoke(HttpContext context) |
|||
{ |
|||
var authentication = await context.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); |
|||
|
|||
if (!authentication.Succeeded || !authentication.Principal.IsInRole(SquidexRoles.Administrator)) |
|||
{ |
|||
await context.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties |
|||
{ |
|||
RedirectUri = context.Request.PathBase + context.Request.Path |
|||
}); |
|||
} |
|||
else |
|||
{ |
|||
await next(context); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.AspNetCore.Builder; |
|||
using Orleans; |
|||
using Squidex.Areas.OrleansDashboard.Middlewares; |
|||
using Squidex.Config; |
|||
|
|||
namespace Squidex.Areas.OrleansDashboard |
|||
{ |
|||
public static class Startup |
|||
{ |
|||
public static void ConfigureOrleansDashboard(this IApplicationBuilder app) |
|||
{ |
|||
app.Map(Constants.OrleansPrefix, orleansApp => |
|||
{ |
|||
orleansApp.UseAuthentication(); |
|||
orleansApp.UseMiddleware<OrleansDashboardAuthenticationMiddleware>(); |
|||
orleansApp.UseOrleansDashboard(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Orleans; |
|||
using Squidex.Infrastructure.EventSourcing.Grains; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public static class ClientServices |
|||
{ |
|||
public static void AddAppClient(this IServiceCollection services) |
|||
{ |
|||
services.AddSingletonAs(c => c.GetRequiredService<IClusterClient>()) |
|||
.As<IGrainFactory>(); |
|||
|
|||
services.AddSingletonAs(c => |
|||
{ |
|||
var client = new ClientBuilder() |
|||
.ConfigureApplicationParts(builder => |
|||
{ |
|||
builder.AddApplicationPart(typeof(EventConsumerGrain).Assembly); |
|||
}) |
|||
.UseStaticGatewayListProvider(options => |
|||
{ |
|||
options.Gateways.Add(new Uri("gwy.tcp://127.0.0.1:40000/0")); |
|||
}) |
|||
.Build(); |
|||
|
|||
client.Connect().Wait(); |
|||
|
|||
return client; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Orleans; |
|||
using Orleans.Runtime.Configuration; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public sealed class ClientWrapper : IInitializable, IDisposable |
|||
{ |
|||
private readonly IClusterClient client; |
|||
|
|||
public IClusterClient Client |
|||
{ |
|||
get { return client; } |
|||
} |
|||
|
|||
public ClientWrapper() |
|||
{ |
|||
client = new ClientBuilder() |
|||
.UseConfiguration(ClientConfiguration.LocalhostSilo()) |
|||
.UseDashboard() |
|||
.ConfigureApplicationParts(builder => |
|||
{ |
|||
builder.AddApplicationPart(SquidexInfrastructure.Assembly); |
|||
}) |
|||
.UseStaticGatewayListProvider(options => |
|||
{ |
|||
options.Gateways.Add(new Uri("gwy.tcp://127.0.0.1:40000/0")); |
|||
}) |
|||
.Build(); |
|||
} |
|||
|
|||
public void Initialize() |
|||
{ |
|||
client.Connect().Wait(); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
client.Close().Wait(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Orleans; |
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public static class OrleansServices |
|||
{ |
|||
public static void AddOrleansSilo(this IServiceCollection services) |
|||
{ |
|||
services.AddSingletonAs<SiloWrapper>() |
|||
.As<IInitializable>(); |
|||
} |
|||
|
|||
public static void AddOrleansClient(this IServiceCollection services) |
|||
{ |
|||
services.AddServicesForSelfHostedDashboard(null, options => |
|||
{ |
|||
options.HideTrace = true; |
|||
}); |
|||
|
|||
services.AddSingletonAs<ClientWrapper>() |
|||
.As<IInitializable>() |
|||
.AsSelf(); |
|||
|
|||
services.AddSingletonAs(c => c.GetRequiredService<ClientWrapper>().Client) |
|||
.As<IClusterClient>(); |
|||
|
|||
services.AddSingletonAs(c => c.GetRequiredService<ClientWrapper>().Client) |
|||
.As<IGrainFactory>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,90 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Orleans; |
|||
using Orleans.Hosting; |
|||
using Orleans.Runtime.Configuration; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Log.Adapter; |
|||
|
|||
namespace Squidex.Config.Orleans |
|||
{ |
|||
public class SiloWrapper : IInitializable, IDisposable |
|||
{ |
|||
private readonly ISiloHost silo; |
|||
|
|||
internal sealed class Source : IConfigurationSource |
|||
{ |
|||
private readonly IConfigurationProvider configurationProvider; |
|||
|
|||
public Source(IConfigurationProvider configurationProvider) |
|||
{ |
|||
this.configurationProvider = configurationProvider; |
|||
} |
|||
|
|||
public IConfigurationProvider Build(IConfigurationBuilder builder) |
|||
{ |
|||
return configurationProvider; |
|||
} |
|||
} |
|||
|
|||
public SiloWrapper(IConfiguration configuration) |
|||
{ |
|||
silo = SiloHostBuilder.CreateDefault() |
|||
.UseConfiguration(ClusterConfiguration.LocalhostPrimarySilo(33333)) |
|||
.UseContentRoot(Directory.GetCurrentDirectory()) |
|||
.UseDashboard(options => |
|||
{ |
|||
options.HostSelf = false; |
|||
}) |
|||
.ConfigureApplicationParts(builder => |
|||
{ |
|||
builder.AddApplicationPart(SquidexInfrastructure.Assembly); |
|||
}) |
|||
.ConfigureLogging(builder => |
|||
{ |
|||
builder.AddSemanticLog(); |
|||
}) |
|||
.ConfigureServices((context, services) => |
|||
{ |
|||
services.AddAppSiloServices(context.Configuration); |
|||
services.AddAppServices(context.Configuration); |
|||
}) |
|||
.ConfigureAppConfiguration((hostContext, builder) => |
|||
{ |
|||
if (configuration is IConfigurationRoot root) |
|||
{ |
|||
foreach (var provider in root.Providers) |
|||
{ |
|||
builder.Add(new Source(provider)); |
|||
} |
|||
} |
|||
}) |
|||
.Build(); |
|||
} |
|||
|
|||
public void Initialize() |
|||
{ |
|||
silo.StartAsync().Wait(); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
silo.StopAsync().Wait(); |
|||
} |
|||
|
|||
private static string GetEnvironment() |
|||
{ |
|||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); |
|||
|
|||
return environment ?? "Development"; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue