add orchestrators
This commit is contained in:
		
							parent
							
								
									4362eb0dce
								
							
						
					
					
						commit
						68f6c4988a
					
				
							
								
								
									
										8
									
								
								src/ApiGateways/ApiGw-Base/Enums/OrchestratorType.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/ApiGateways/ApiGw-Base/Enums/OrchestratorType.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
namespace OcelotApiGw.Enums
 | 
			
		||||
{
 | 
			
		||||
    public enum OrchestratorType
 | 
			
		||||
    {
 | 
			
		||||
        K8S,
 | 
			
		||||
        SF
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using OcelotApiGw.Enums;
 | 
			
		||||
 | 
			
		||||
namespace OcelotApiGw.Orchestrators
 | 
			
		||||
{
 | 
			
		||||
    public interface IOrchestratorStrategy
 | 
			
		||||
    {
 | 
			
		||||
        OrchestratorType OrchestratorType { get; }
 | 
			
		||||
 | 
			
		||||
        IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								src/ApiGateways/ApiGw-Base/Orchestrators/Kubernetes.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/ApiGateways/ApiGw-Base/Orchestrators/Kubernetes.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using OcelotApiGw.Enums;
 | 
			
		||||
using System.IO;
 | 
			
		||||
 | 
			
		||||
namespace OcelotApiGw.Orchestrators
 | 
			
		||||
{
 | 
			
		||||
    public class Kubernetes : IOrchestratorStrategy
 | 
			
		||||
    {
 | 
			
		||||
        public OrchestratorType OrchestratorType => OrchestratorType.K8S;
 | 
			
		||||
 | 
			
		||||
        public IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder)
 | 
			
		||||
        {
 | 
			
		||||
            builder.AddJsonFile(Path.Combine("configuration", "configuration.json"));
 | 
			
		||||
 | 
			
		||||
            return builder;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								src/ApiGateways/ApiGw-Base/Orchestrators/ServiceFabric.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/ApiGateways/ApiGw-Base/Orchestrators/ServiceFabric.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using OcelotApiGw.Enums;
 | 
			
		||||
using OcelotApiGw.Services;
 | 
			
		||||
 | 
			
		||||
namespace OcelotApiGw.Orchestrators
 | 
			
		||||
{
 | 
			
		||||
    public class ServiceFabric : IOrchestratorStrategy
 | 
			
		||||
    {
 | 
			
		||||
        private readonly ISettingService _settingService;
 | 
			
		||||
 | 
			
		||||
        public ServiceFabric(ISettingService settingService)
 | 
			
		||||
        {
 | 
			
		||||
            _settingService = settingService;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public OrchestratorType OrchestratorType => OrchestratorType.SF;
 | 
			
		||||
 | 
			
		||||
        public IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder)
 | 
			
		||||
        {
 | 
			
		||||
            var config = _settingService.GetConfiguration();
 | 
			
		||||
 | 
			
		||||
            return builder;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,13 +1,5 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore;
 | 
			
		||||
using Microsoft.AspNetCore;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
 | 
			
		||||
namespace OcelotApiGw
 | 
			
		||||
{
 | 
			
		||||
@ -18,14 +10,9 @@ namespace OcelotApiGw
 | 
			
		||||
            BuildWebHost(args).Run();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static IWebHost BuildWebHost(string[] args)
 | 
			
		||||
        {
 | 
			
		||||
            IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);
 | 
			
		||||
            builder.ConfigureServices(s => s.AddSingleton(builder))
 | 
			
		||||
                .ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json")))
 | 
			
		||||
                .UseStartup<Startup>();
 | 
			
		||||
            IWebHost host = builder.Build();
 | 
			
		||||
            return host;
 | 
			
		||||
        }
 | 
			
		||||
        public static IWebHost BuildWebHost(string[] args) =>
 | 
			
		||||
            WebHost.CreateDefaultBuilder(args)
 | 
			
		||||
                .UseStartup<Startup>()
 | 
			
		||||
                .Build();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								src/ApiGateways/ApiGw-Base/Services/ISettingService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/ApiGateways/ApiGw-Base/Services/ISettingService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace OcelotApiGw.Services
 | 
			
		||||
{
 | 
			
		||||
    public interface ISettingService
 | 
			
		||||
    {
 | 
			
		||||
        string GetConfiguration();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								src/ApiGateways/ApiGw-Base/Services/SettingService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/ApiGateways/ApiGw-Base/Services/SettingService.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace OcelotApiGw.Services
 | 
			
		||||
{
 | 
			
		||||
    public class SettingService : ISettingService
 | 
			
		||||
    {
 | 
			
		||||
        private readonly HttpClient _httpClient;
 | 
			
		||||
        private readonly IConfiguration _configuration;
 | 
			
		||||
 | 
			
		||||
        public SettingService(HttpClient httpClient, IConfiguration configuration)
 | 
			
		||||
        {
 | 
			
		||||
            _httpClient = httpClient;
 | 
			
		||||
            _configuration = configuration;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string GetConfiguration()
 | 
			
		||||
        {
 | 
			
		||||
            var strings = new List<string>();
 | 
			
		||||
 | 
			
		||||
            var tasks = new Func<Task>[]
 | 
			
		||||
            {
 | 
			
		||||
               async () => {
 | 
			
		||||
                   var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("MobilMarketing"));
 | 
			
		||||
                   strings.Add(res);
 | 
			
		||||
               },
 | 
			
		||||
               async () => {
 | 
			
		||||
                   var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("MobilShopping"));
 | 
			
		||||
                   strings.Add(res);
 | 
			
		||||
               },
 | 
			
		||||
               async () => {
 | 
			
		||||
                   var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("WebMarketing"));
 | 
			
		||||
                   strings.Add(res);
 | 
			
		||||
               },
 | 
			
		||||
               async () => {
 | 
			
		||||
                   var res = await _httpClient.GetStringAsync(_configuration.GetValue<string>("WebShopping"));
 | 
			
		||||
                   strings.Add(res);
 | 
			
		||||
               }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            Task.WaitAll(tasks.Select(task => task()).ToArray());
 | 
			
		||||
 | 
			
		||||
            return string.Concat(strings);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -5,66 +5,68 @@ using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using Ocelot.DependencyInjection;
 | 
			
		||||
using Ocelot.Middleware;
 | 
			
		||||
using OcelotApiGw.Enums;
 | 
			
		||||
using OcelotApiGw.Orchestrators;
 | 
			
		||||
using OcelotApiGw.Services;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
 | 
			
		||||
namespace OcelotApiGw
 | 
			
		||||
{
 | 
			
		||||
    public class Startup
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        private readonly IConfiguration _cfg;
 | 
			
		||||
        private readonly IConfiguration _configuration;
 | 
			
		||||
 | 
			
		||||
        public Startup(IConfiguration configuration)
 | 
			
		||||
        {
 | 
			
		||||
            _cfg = configuration;
 | 
			
		||||
            _configuration = configuration;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void ConfigureServices(IServiceCollection services)
 | 
			
		||||
        {
 | 
			
		||||
            var identityUrl = _cfg.GetValue<string>("IdentityUrl");
 | 
			
		||||
            var identityUrl = _configuration.GetValue<string>("IdentityUrl");
 | 
			
		||||
            var authenticationProviderKey = "IdentityApiKey";
 | 
			
		||||
 | 
			
		||||
            services.AddCors(options =>
 | 
			
		||||
            {
 | 
			
		||||
                options.AddPolicy("CorsPolicy",
 | 
			
		||||
                    builder => builder.AllowAnyOrigin()
 | 
			
		||||
                    .AllowAnyMethod()
 | 
			
		||||
                    .AllowAnyHeader()
 | 
			
		||||
                    .AllowCredentials());
 | 
			
		||||
                options.AddPolicy("CorsPolicy", builder =>
 | 
			
		||||
                    builder.AllowAnyOrigin()
 | 
			
		||||
                        .AllowAnyMethod()
 | 
			
		||||
                        .AllowAnyHeader()
 | 
			
		||||
                        .AllowCredentials());
 | 
			
		||||
            })
 | 
			
		||||
            .AddTransient<IOrchestratorStrategy, Kubernetes>()
 | 
			
		||||
            .AddTransient<IOrchestratorStrategy, ServiceFabric>()
 | 
			
		||||
            .AddAuthentication()
 | 
			
		||||
            .AddJwtBearer(authenticationProviderKey, options =>
 | 
			
		||||
            {
 | 
			
		||||
                options.Authority = identityUrl;
 | 
			
		||||
                options.RequireHttpsMetadata = false;
 | 
			
		||||
                options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
 | 
			
		||||
                {
 | 
			
		||||
                    ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "mobileshoppingagg", "webshoppingagg" }
 | 
			
		||||
                };
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            services.AddAuthentication()
 | 
			
		||||
                .AddJwtBearer(authenticationProviderKey, x =>
 | 
			
		||||
                {
 | 
			
		||||
                    x.Authority = identityUrl;
 | 
			
		||||
                    x.RequireHttpsMetadata = false;
 | 
			
		||||
                    x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
 | 
			
		||||
                    {
 | 
			
		||||
                        ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "mobileshoppingagg", "webshoppingagg" }
 | 
			
		||||
                    };
 | 
			
		||||
                    x.Events = new Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerEvents()
 | 
			
		||||
                    {
 | 
			
		||||
                        OnAuthenticationFailed = async ctx =>
 | 
			
		||||
                        {
 | 
			
		||||
                            int i = 0;
 | 
			
		||||
                        },
 | 
			
		||||
                        OnTokenValidated = async ctx =>
 | 
			
		||||
                        {
 | 
			
		||||
                            int i = 0;
 | 
			
		||||
                        },
 | 
			
		||||
            services.AddHttpClient<ISettingService, SettingService>();
 | 
			
		||||
 | 
			
		||||
                        OnMessageReceived = async ctx =>
 | 
			
		||||
                        {
 | 
			
		||||
                            int i = 0;
 | 
			
		||||
                        }
 | 
			
		||||
                    };
 | 
			
		||||
                });
 | 
			
		||||
            var orchestratorType = _configuration.GetValue<OrchestratorType>("OrchestratorType");
 | 
			
		||||
 | 
			
		||||
            services.AddOcelot(_cfg);
 | 
			
		||||
            var config = new ConfigurationBuilder()
 | 
			
		||||
                .AddConfiguration(_configuration);
 | 
			
		||||
 | 
			
		||||
            var cfg = services.BuildServiceProvider()
 | 
			
		||||
                .GetServices<IOrchestratorStrategy>()
 | 
			
		||||
                .Single(strategy => strategy.OrchestratorType == orchestratorType)
 | 
			
		||||
                .ConfigureOrchestrator(config)
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
            services.AddOcelot(cfg);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
 | 
			
		||||
        {
 | 
			
		||||
            var pathBase = _cfg["PATH_BASE"];
 | 
			
		||||
            var pathBase = _configuration.GetValue<string>("PATH_BASE");
 | 
			
		||||
 | 
			
		||||
            if (!string.IsNullOrEmpty(pathBase))
 | 
			
		||||
            {
 | 
			
		||||
                app.UsePathBase(pathBase);
 | 
			
		||||
@ -75,11 +77,11 @@ namespace OcelotApiGw
 | 
			
		||||
                app.UseDeveloperExceptionPage();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            loggerFactory.AddConsole(_cfg.GetSection("Logging"));
 | 
			
		||||
            loggerFactory.AddConsole(_configuration.GetSection("Logging"));
 | 
			
		||||
 | 
			
		||||
            app.UseCors("CorsPolicy");
 | 
			
		||||
 | 
			
		||||
            app.UseOcelot().Wait();
 | 
			
		||||
            app.UseCors("CorsPolicy")
 | 
			
		||||
                .UseOcelot()
 | 
			
		||||
                .Wait();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										30
									
								
								src/Web/WebMVC/wwwroot/js/site.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										30
									
								
								src/Web/WebMVC/wwwroot/js/site.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user