resolve conflicts

This commit is contained in:
Erik Pique 2019-02-06 10:35:02 +01:00
commit ce2724af69
41 changed files with 567 additions and 286 deletions

View File

@ -0,0 +1,9 @@
.dockerignore
.env
.git
.gitignore
.vs
.vscode
*/bin
*/obj
**/.toolstarget

View File

@ -6,6 +6,8 @@
<ServerGarbageCollection>True</ServerGarbageCollection> <ServerGarbageCollection>True</ServerGarbageCollection>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier> <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<TargetLatestRuntimePatch>False</TargetLatestRuntimePatch> <TargetLatestRuntimePatch>False</TargetLatestRuntimePatch>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>860c6d00-8a17-45b6-be76-28c2395d468e</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -16,6 +18,7 @@
<PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.3.617" /> <PackageReference Include="Microsoft.ServiceFabric.AspNetCore.Kestrel" Version="3.3.617" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "marketing.api", "Host": "marketingapi.eshoponservicefabric",
"Port": 80 "Port": 5110
} }
], ],
"UpstreamPathTemplate": "/api/{version}/m/{everything}", "UpstreamPathTemplate": "/api/{version}/m/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "locations.api", "Host": "locationsapi.eshoponservicefabric",
"Port": 80 "Port": 5109
} }
], ],
"UpstreamPathTemplate": "/api/{version}/l/{everything}", "UpstreamPathTemplate": "/api/{version}/l/{everything}",

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/api/{version}/c/{everything}", "UpstreamPathTemplate": "/api/{version}/c/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/api/{version}/b/{everything}", "UpstreamPathTemplate": "/api/{version}/b/{everything}",
@ -33,8 +33,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/api/{version}/o/{everything}", "UpstreamPathTemplate": "/api/{version}/o/{everything}",
@ -49,8 +49,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "mobileshoppingagg", "Host": "mobileshoppingagg.eshoponservicefabric",
"Port": 80 "Port": 5120
} }
], ],
"UpstreamPathTemplate": "/{everything}", "UpstreamPathTemplate": "/{everything}",
@ -65,8 +65,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/orders-api/{everything}", "UpstreamPathTemplate": "/orders-api/{everything}",
@ -77,8 +77,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/basket-api/{everything}", "UpstreamPathTemplate": "/basket-api/{everything}",
@ -89,8 +89,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/catalog-api/{everything}", "UpstreamPathTemplate": "/catalog-api/{everything}",
@ -101,8 +101,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "payment.api", "Host": "paymentapi.eshoponservicefabric",
"Port": 80 "Port": 5108
} }
], ],
"UpstreamPathTemplate": "/payment-api/{everything}", "UpstreamPathTemplate": "/payment-api/{everything}",

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "marketing.api", "Host": "marketingapi.eshoponservicefabric",
"Port": 80 "Port": 5110
} }
], ],
"UpstreamPathTemplate": "/api/{version}/m/{everything}", "UpstreamPathTemplate": "/api/{version}/m/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "locations.api", "Host": "locationsapi.eshoponservicefabric",
"Port": 80 "Port": 5109
} }
], ],
"UpstreamPathTemplate": "/api/{version}/l/{everything}", "UpstreamPathTemplate": "/api/{version}/l/{everything}",

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/api/{version}/c/{everything}", "UpstreamPathTemplate": "/api/{version}/c/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/api/{version}/b/{everything}", "UpstreamPathTemplate": "/api/{version}/b/{everything}",
@ -33,8 +33,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/api/{version}/o/{everything}", "UpstreamPathTemplate": "/api/{version}/o/{everything}",
@ -49,8 +49,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "webshoppingagg", "Host": "webshoppingagg.eshoponservicefabric",
"Port": 80 "Port": 5121
} }
], ],
"UpstreamPathTemplate": "/{everything}", "UpstreamPathTemplate": "/{everything}",
@ -65,8 +65,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/orders-api/{everything}", "UpstreamPathTemplate": "/orders-api/{everything}",
@ -77,7 +77,7 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.signalrhub", "Host": "ordering.signalrhub.eshoponservicefabric",
"Port": 80 "Port": 80
} }
], ],
@ -89,8 +89,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/basket-api/{everything}", "UpstreamPathTemplate": "/basket-api/{everything}",
@ -101,8 +101,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/catalog-api/{everything}", "UpstreamPathTemplate": "/catalog-api/{everything}",
@ -113,8 +113,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "payment.api", "Host": "paymentapi.eshoponservicefabric",
"Port": 80 "Port": 5108
} }
], ],
"UpstreamPathTemplate": "/payment-api/{everything}", "UpstreamPathTemplate": "/payment-api/{everything}",

View File

@ -11,20 +11,20 @@ namespace ApiGw_Base.Controllers
public class ConfigurationController : ControllerBase public class ConfigurationController : ControllerBase
{ {
[HttpGet("mobile/marketing")] [HttpGet("mobile/marketing")]
public IActionResult MobileMarketing() => ReadConfigurationFile(ConfigurationType.Mobile, ConfigurationBffType.Marketing); public IActionResult MobileMarketing() => ReadConfigurationFile(Channel.Mobile, ChannelType.Marketing);
[HttpGet("mobile/shopping")] [HttpGet("mobile/shopping")]
public IActionResult MobileShopping() => ReadConfigurationFile(ConfigurationType.Mobile, ConfigurationBffType.Shopping); public IActionResult MobileShopping() => ReadConfigurationFile(Channel.Mobile, ChannelType.Shopping);
[HttpGet("web/marketing")] [HttpGet("web/marketing")]
public IActionResult WebMarketing() => ReadConfigurationFile(ConfigurationType.Web, ConfigurationBffType.Marketing); public IActionResult WebMarketing() => ReadConfigurationFile(Channel.Web, ChannelType.Marketing);
[HttpGet("web/shopping")] [HttpGet("web/shopping")]
public IActionResult WebShopping() => ReadConfigurationFile(ConfigurationType.Web, ConfigurationBffType.Shopping); public IActionResult WebShopping() => ReadConfigurationFile(Channel.Web, ChannelType.Shopping);
private IActionResult ReadConfigurationFile(ConfigurationType configurationType, ConfigurationBffType configurationBffType) private IActionResult ReadConfigurationFile(Channel channel, ChannelType channelType)
{ {
var path = $"{AppDomain.CurrentDomain.BaseDirectory}/Configurations/configuration.{configurationType}.Bff.{configurationBffType}.json"; var path = $"{AppDomain.CurrentDomain.BaseDirectory}/Configurations/configuration.{channel}.Bff.{channelType}.json";
using (var streamReader = new StreamReader(path, Encoding.UTF8)) using (var streamReader = new StreamReader(path, Encoding.UTF8))
{ {
@ -32,7 +32,7 @@ namespace ApiGw_Base.Controllers
if (string.IsNullOrWhiteSpace(jsonString)) if (string.IsNullOrWhiteSpace(jsonString))
{ {
return BadRequest($"Configuration file 'configuration.{configurationType}.Bff.{configurationBffType}.json' not found"); return BadRequest($"Configuration file 'configuration.{channel}.Bff.{channelType}.json' not found");
} }
return Ok(jsonString); return Ok(jsonString);

View File

@ -1,6 +1,6 @@
namespace ApiGw_Base.Enums namespace ApiGw_Base.Enums
{ {
public enum ConfigurationType public enum Channel
{ {
Web, Web,
Mobile Mobile

View File

@ -1,6 +1,6 @@
namespace ApiGw_Base.Enums namespace ApiGw_Base.Enums
{ {
public enum ConfigurationBffType public enum ChannelType
{ {
Marketing, Marketing,
Shopping Shopping

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric"> <Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<!-- Add your custom configuration sections and parameters here --> <!-- Add your custom configuration sections and parameters here -->
<!-- <!--<Section Name="ServiceFabricSettings">
<Section Name="MyConfigSection"> <Parameter Name="UrlMobilMarketing" Value="configuration/mobile/marketing" />
<Parameter Name="MyParameter" Value="Value1" /> <Parameter Name="UrlMobilShopping" Value="/configuration/mobile/shopping" />
</Section> <Parameter Name="UrlWebMarketing" Value="/configuration/web/marketing" />
--> <Parameter Name="UrlWebShopping" Value="/configuration/web/shopping" />
</Section>-->
</Settings> </Settings>

View File

@ -17,9 +17,18 @@
<Program>ApiGw_Base.exe</Program> <Program>ApiGw_Base.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder> <WorkingFolder>CodePackage</WorkingFolder>
</ExeHost> </ExeHost>
<!--<ContainerHost>
<ImageName>eshop/sf.linux.settings.api:#{tag}#</ImageName>
</ContainerHost>-->
</EntryPoint> </EntryPoint>
<EnvironmentVariables> <EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/> <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="Development"/>
<EnvironmentVariable Name="ASPNETCORE_URLS" Value="http://0.0.0.0:80"/>
<EnvironmentVariable Name="UrlMobilMarketing" Value="http://apigw_base.eshoponservicefabricapigwtype/configuration/mobile/marketing" />
<EnvironmentVariable Name="UrlMobilShopping" Value="http://apigw_base.eshoponservicefabricapigwtype/configuration/mobile/shopping" />
<EnvironmentVariable Name="UrlWebMarketing" Value="http://apigw_base.eshoponservicefabricapigwtype/configuration/web/marketing" />
<EnvironmentVariable Name="UrlWebShopping" Value="http://apigw_base.eshoponservicefabricapigwtype/configuration/web/shopping" />
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables> </EnvironmentVariables>
</CodePackage> </CodePackage>
@ -32,6 +41,7 @@
<!-- This endpoint is used by the communication listener to obtain the port on which to <!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. --> replicas of different partitions that are placed in your code. -->
<!--<Endpoint UriScheme="http" Name="sf.linux.settings.api.endpoint" Port="8912" />-->
<Endpoint Protocol="https" Name="ServiceEndpoint" Type="Input" Port="8912" /> <Endpoint Protocol="https" Name="ServiceEndpoint" Type="Input" Port="8912" />
</Endpoints> </Endpoints>
</Resources> </Resources>

View File

@ -1,5 +1,4 @@
{ {
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
@ -8,6 +7,7 @@
"sslPort": 44363 "sslPort": 44363
} }
}, },
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": { "profiles": {
"IIS Express": { "IIS Express": {
"commandName": "IISExpress", "commandName": "IISExpress",
@ -21,10 +21,15 @@
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "api/values", "launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} },
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values"
} }
} }
} }

View File

@ -13,6 +13,11 @@
<EnvironmentOverrides CodePackageRef="code"> <EnvironmentOverrides CodePackageRef="code">
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[ApiGw_Base_ASPNETCORE_ENVIRONMENT]" /> <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[ApiGw_Base_ASPNETCORE_ENVIRONMENT]" />
</EnvironmentOverrides> </EnvironmentOverrides>
<!--<Policies>
<ContainerHostPolicies CodePackageRef="Code">
<PortBinding ContainerPort="80" EndpointRef="sf.linux.settings.api.endpoint" />
</ContainerHostPolicies>
</Policies>-->
</ServiceManifestImport> </ServiceManifestImport>
<DefaultServices> <DefaultServices>
<!-- The section below creates instances of service types, when an instance of this <!-- The section below creates instances of service types, when an instance of this
@ -20,7 +25,7 @@
ServiceFabric PowerShell module. ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. --> The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="ApiGw_Base" ServicePackageActivationMode="ExclusiveProcess"> <Service Name="ApiGw_Base" ServiceDnsName="apigw_base.eshoponservicefabricapigwtype" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="ApiGw_BaseType" InstanceCount="[ApiGw_Base_InstanceCount]"> <StatelessService ServiceTypeName="ApiGw_BaseType" InstanceCount="[ApiGw_Base_InstanceCount]">
<SingletonPartition /> <SingletonPartition />
</StatelessService> </StatelessService>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<!-- Add your custom configuration sections and parameters here -->
<!--
<Section Name="MyConfigSection">
<Parameter Name="MyParameter" Value="Value1" />
</Section>
-->
</Settings>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="OrderingSignalrhubPkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<!-- This is the name of your ServiceType.
The UseImplicitHost attribute indicates this is a guest service. -->
<StatelessServiceType ServiceTypeName="OrderingSignalrhubType" UseImplicitHost="true" />
</ServiceTypes>
<!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<!-- Follow this link for more information about deploying Windows containers to Service Fabric: https://aka.ms/sfguestcontainers -->
<ContainerHost>
<ImageName>eshop/ordering.signalrhub:#{tag}#</ImageName>
</ContainerHost>
</EntryPoint>
<!-- Pass environment variables to your container: -->
<!--
<EnvironmentVariables>
<EnvironmentVariable Name="VariableName" Value="VariableValue"/>
</EnvironmentVariables>
-->
</CodePackage>
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
independently-updateable and versioned set of custom configuration settings for your service. -->
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Name="OrderingSignalrhubTypeEndpoint" Port="5112" />
</Endpoints>
</Resources>
</ServiceManifest>

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "marketing.api", "Host": "marketingapi.eshoponservicefabric",
"Port": 80 "Port": 5110
} }
], ],
"UpstreamPathTemplate": "/api/{version}/m/{everything}", "UpstreamPathTemplate": "/api/{version}/m/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "locations.api", "Host": "locationsapi.eshoponservicefabric",
"Port": 80 "Port": 5109
} }
], ],
"UpstreamPathTemplate": "/api/{version}/l/{everything}", "UpstreamPathTemplate": "/api/{version}/l/{everything}",

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/api/{version}/c/{everything}", "UpstreamPathTemplate": "/api/{version}/c/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/api/{version}/b/{everything}", "UpstreamPathTemplate": "/api/{version}/b/{everything}",
@ -33,8 +33,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/api/{version}/o/{everything}", "UpstreamPathTemplate": "/api/{version}/o/{everything}",
@ -49,8 +49,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "mobileshoppingagg", "Host": "mobileshoppingagg.eshoponservicefabric",
"Port": 80 "Port": 5120
} }
], ],
"UpstreamPathTemplate": "/{everything}", "UpstreamPathTemplate": "/{everything}",
@ -65,8 +65,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/orders-api/{everything}", "UpstreamPathTemplate": "/orders-api/{everything}",
@ -77,8 +77,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/basket-api/{everything}", "UpstreamPathTemplate": "/basket-api/{everything}",
@ -89,8 +89,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/catalog-api/{everything}", "UpstreamPathTemplate": "/catalog-api/{everything}",
@ -101,8 +101,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "payment.api", "Host": "paymentapi.eshoponservicefabric",
"Port": 80 "Port": 5108
} }
], ],
"UpstreamPathTemplate": "/payment-api/{everything}", "UpstreamPathTemplate": "/payment-api/{everything}",

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "marketing.api", "Host": "marketingapi.eshoponservicefabric",
"Port": 80 "Port": 5110
} }
], ],
"UpstreamPathTemplate": "/api/{version}/m/{everything}", "UpstreamPathTemplate": "/api/{version}/m/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "locations.api", "Host": "locationsapi.eshoponservicefabric",
"Port": 80 "Port": 5109
} }
], ],
"UpstreamPathTemplate": "/api/{version}/l/{everything}", "UpstreamPathTemplate": "/api/{version}/l/{everything}",

View File

@ -5,8 +5,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/api/{version}/c/{everything}", "UpstreamPathTemplate": "/api/{version}/c/{everything}",
@ -17,8 +17,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/api/{version}/b/{everything}", "UpstreamPathTemplate": "/api/{version}/b/{everything}",
@ -33,8 +33,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/api/{version}/o/{everything}", "UpstreamPathTemplate": "/api/{version}/o/{everything}",
@ -49,8 +49,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "webshoppingagg", "Host": "webshoppingagg.eshoponservicefabric",
"Port": 80 "Port": 5121
} }
], ],
"UpstreamPathTemplate": "/{everything}", "UpstreamPathTemplate": "/{everything}",
@ -65,8 +65,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.api", "Host": "orderingapi.eshoponservicefabric",
"Port": 80 "Port": 5102
} }
], ],
"UpstreamPathTemplate": "/orders-api/{everything}", "UpstreamPathTemplate": "/orders-api/{everything}",
@ -77,7 +77,7 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "ordering.signalrhub", "Host": "ordering.signalrhub.eshoponservicefabric",
"Port": 80 "Port": 80
} }
], ],
@ -89,8 +89,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "basket.api", "Host": "basketapi.eshoponservicefabric",
"Port": 80 "Port": 5103
} }
], ],
"UpstreamPathTemplate": "/basket-api/{everything}", "UpstreamPathTemplate": "/basket-api/{everything}",
@ -101,8 +101,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "catalog.api", "Host": "catalogapi.eshoponservicefabric",
"Port": 80 "Port": 5101
} }
], ],
"UpstreamPathTemplate": "/catalog-api/{everything}", "UpstreamPathTemplate": "/catalog-api/{everything}",
@ -113,8 +113,8 @@
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHostAndPorts": [ "DownstreamHostAndPorts": [
{ {
"Host": "payment.api", "Host": "paymentapi.eshoponservicefabric",
"Port": 80 "Port": 5108
} }
], ],
"UpstreamPathTemplate": "/payment-api/{everything}", "UpstreamPathTemplate": "/payment-api/{everything}",

View File

@ -11,20 +11,20 @@ namespace ApiGw_Base.Controllers
public class ConfigurationController : ControllerBase public class ConfigurationController : ControllerBase
{ {
[HttpGet("mobile/marketing")] [HttpGet("mobile/marketing")]
public IActionResult MobileMarketing() => ReadConfigurationFile(ConfigurationType.Mobile, ConfigurationBffType.Marketing); public IActionResult MobileMarketing() => ReadConfigurationFile(Channel.Mobile, ChannelType.Marketing);
[HttpGet("mobile/shopping")] [HttpGet("mobile/shopping")]
public IActionResult MobileShopping() => ReadConfigurationFile(ConfigurationType.Mobile, ConfigurationBffType.Shopping); public IActionResult MobileShopping() => ReadConfigurationFile(Channel.Mobile, ChannelType.Shopping);
[HttpGet("web/marketing")] [HttpGet("web/marketing")]
public IActionResult WebMarketing() => ReadConfigurationFile(ConfigurationType.Web, ConfigurationBffType.Marketing); public IActionResult WebMarketing() => ReadConfigurationFile(Channel.Web, ChannelType.Marketing);
[HttpGet("web/shopping")] [HttpGet("web/shopping")]
public IActionResult WebShopping() => ReadConfigurationFile(ConfigurationType.Web, ConfigurationBffType.Shopping); public IActionResult WebShopping() => ReadConfigurationFile(Channel.Web, ChannelType.Shopping);
private IActionResult ReadConfigurationFile(ConfigurationType configurationType, ConfigurationBffType configurationBffType) private IActionResult ReadConfigurationFile(Channel channel, ChannelType channelType)
{ {
var path = $"{AppDomain.CurrentDomain.BaseDirectory}/Configurations/configuration.{configurationType}.Bff.{configurationBffType}.json"; var path = $"{AppDomain.CurrentDomain.BaseDirectory}/Configurations/configuration.{channel}.Bff.{channelType}.json";
using (var streamReader = new StreamReader(path, Encoding.UTF8)) using (var streamReader = new StreamReader(path, Encoding.UTF8))
{ {
@ -32,7 +32,7 @@ namespace ApiGw_Base.Controllers
if (string.IsNullOrWhiteSpace(jsonString)) if (string.IsNullOrWhiteSpace(jsonString))
{ {
return BadRequest($"Configuration file 'configuration.{configurationType}.Bff.{configurationBffType}.json' not found"); return BadRequest($"Configuration file 'configuration.{channel}.Bff.{channelType}.json' not found");
} }
return Ok(jsonString); return Ok(jsonString);

View File

@ -1,6 +1,6 @@
namespace ApiGw_Base.Enums namespace ApiGw_Base.Enums
{ {
public enum ConfigurationType public enum Channel
{ {
Web, Web,
Mobile Mobile

View File

@ -1,6 +1,6 @@
namespace ApiGw_Base.Enums namespace ApiGw_Base.Enums
{ {
public enum ConfigurationBffType public enum ChannelType
{ {
Marketing, Marketing,
Shopping Shopping

View File

@ -19,7 +19,13 @@
</ExeHost> </ExeHost>
</EntryPoint> </EntryPoint>
<EnvironmentVariables> <EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/> <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="Development"/>
<EnvironmentVariable Name="ASPNETCORE_URLS" Value="http://0.0.0.0:80"/>
<EnvironmentVariable Name="UrlMobilMarketing" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/mobile/marketing" />
<EnvironmentVariable Name="UrlMobilShopping" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/mobile/shopping" />
<EnvironmentVariable Name="UrlWebMarketing" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/web/marketing" />
<EnvironmentVariable Name="UrlWebShopping" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/web/shopping" />
<EnvironmentVariable Name="OrchestratorType" Value="SF"/>
</EnvironmentVariables> </EnvironmentVariables>
</CodePackage> </CodePackage>

View File

@ -12,6 +12,12 @@
<ConfigOverrides /> <ConfigOverrides />
<EnvironmentOverrides CodePackageRef="code"> <EnvironmentOverrides CodePackageRef="code">
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[ApiGw_Base_ASPNETCORE_ENVIRONMENT]" /> <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="[ApiGw_Base_ASPNETCORE_ENVIRONMENT]" />
<EnvironmentVariable Name="ASPNETCORE_URLS" Value="http://0.0.0.0:80" />
<EnvironmentVariable Name="UrlMobilMarketing" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/mobile/marketing" />
<EnvironmentVariable Name="UrlMobilShopping" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/mobile/shopping" />
<EnvironmentVariable Name="UrlWebMarketing" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/web/marketing" />
<EnvironmentVariable Name="UrlWebShopping" Value="http://apigw_base.eshoponservicefabricapigwtype:8949/configuration/web/shopping" />
<EnvironmentVariable Name="OrchestratorType" Value="SF" />
</EnvironmentOverrides> </EnvironmentOverrides>
</ServiceManifestImport> </ServiceManifestImport>
<DefaultServices> <DefaultServices>
@ -20,7 +26,7 @@
ServiceFabric PowerShell module. ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. --> The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="ApiGw_Base" ServicePackageActivationMode="ExclusiveProcess"> <Service Name="ApiGw_Base" ServiceDnsName="apigw_base.eshoponservicefabricapigwtype" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="ApiGw_BaseType" InstanceCount="[ApiGw_Base_InstanceCount]"> <StatelessService ServiceTypeName="ApiGw_BaseType" InstanceCount="[ApiGw_Base_InstanceCount]">
<SingletonPartition /> <SingletonPartition />
</StatelessService> </StatelessService>

View File

@ -8,4 +8,7 @@
--> -->
<ClusterConnectionParameters /> <ClusterConnectionParameters />
<ApplicationParameterFile Path="..\ApplicationParameters\Local.5Node.xml" /> <ApplicationParameterFile Path="..\ApplicationParameters\Local.5Node.xml" />
<UpgradeDeployment Mode="UnmonitoredAuto" Enabled="false">
<Parameters UpgradeReplicaSetCheckTimeoutSec="1" Force="True" />
</UpgradeDeployment>
</PublishProfile> </PublishProfile>

View File

@ -379,4 +379,3 @@ services:
- UseLoadTest=${USE_LOADTEST:-False} - UseLoadTest=${USE_LOADTEST:-False}
ports: ports:
- "5100:80" - "5100:80"

View File

@ -304,4 +304,3 @@ services:
ports: ports:
- "80" # Important: In a production environment your should remove the external port (5121) kept here for microservice debugging purposes. - "80" # Important: In a production environment your should remove the external port (5121) kept here for microservice debugging purposes.
# The API Gateway redirects and access through the internal port (80). # The API Gateway redirects and access through the internal port (80).

View File

@ -216,4 +216,3 @@ services:
- webshoppingagg - webshoppingagg
- webshoppingapigw - webshoppingapigw
- webmarketingapigw - webmarketingapigw

View File

@ -0,0 +1,8 @@
namespace OcelotApiGw.Enums
{
public enum OrchestratorType
{
K8S,
SF
}
}

View File

@ -0,0 +1,13 @@
namespace OcelotApiGw.Models
{
public class ServiceFabricSettings
{
public string UrlMobilMarketing { get; set; }
public string UrlMobilShopping { get; set; }
public string UrlWebMarketing { get; set; }
public string UrlWebShopping { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.Extensions.Configuration;
using OcelotApiGw.Enums;
namespace OcelotApiGw.Orchestrators
{
public interface IOrchestratorStrategy
{
OrchestratorType OrchestratorType { get; }
IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder);
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.Extensions.Configuration;
using OcelotApiGw.Enums;
namespace OcelotApiGw.Orchestrators
{
public class Kubernetes : IOrchestratorStrategy
{
public OrchestratorType OrchestratorType => OrchestratorType.K8S;
public IConfigurationBuilder ConfigureOrchestrator(IConfigurationBuilder builder) => builder;
}
}

View File

@ -0,0 +1,30 @@
using Microsoft.Extensions.Configuration;
using OcelotApiGw.Enums;
using OcelotApiGw.Providers;
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();
var memoryFileProvider = new InMemoryFileProvider(config);
builder.AddJsonFile(memoryFileProvider, string.Empty, false, false);
return builder;
}
}
}

View File

@ -1,11 +1,7 @@
using System; using Microsoft.AspNetCore;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using System.IO;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Serilog; using Serilog;
@ -16,24 +12,22 @@ namespace OcelotApiGw
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
BuildWebHost(args).Run(); WebHost.CreateDefaultBuilder(args)
} .ConfigureAppConfiguration((hostingContext, config) =>
public static IWebHost BuildWebHost(string[] args)
{ {
IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args); config.SetBasePath(Directory.GetCurrentDirectory());
builder.ConfigureServices(s => s.AddSingleton(builder)) config.AddJsonFile(Path.Combine("configuration", "configuration.json"));
.ConfigureAppConfiguration(ic => ic.AddJsonFile(Path.Combine("configuration", "configuration.json"))) config.AddCommandLine(args);
.UseStartup<Startup>() })
.UseSerilog((builderContext, config) => .UseSerilog((builderContext, config) =>
{ {
config config
.MinimumLevel.Information() .MinimumLevel.Information()
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.Console(); .WriteTo.Console();
}); })
IWebHost host = builder.Build(); .Build()
return host; .Run();
} }
} }
} }

View File

@ -0,0 +1,28 @@
using Microsoft.Extensions.FileProviders;
using System;
using System.IO;
using System.Text;
namespace OcelotApiGw.Providers
{
public class InMemoryFile : IFileInfo
{
private readonly byte[] _data;
public InMemoryFile(string data) => _data = Encoding.UTF8.GetBytes(data);
public Stream CreateReadStream() => new MemoryStream(_data);
public bool Exists { get; } = true;
public long Length => _data.Length;
public string PhysicalPath { get; } = string.Empty;
public string Name { get; } = string.Empty;
public DateTimeOffset LastModified { get; } = DateTimeOffset.UtcNow;
public bool IsDirectory { get; } = false;
}
}

View File

@ -0,0 +1,18 @@
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
namespace OcelotApiGw.Providers
{
public class InMemoryFileProvider : IFileProvider
{
private readonly IFileInfo _fileInfo;
public InMemoryFileProvider(string data) => _fileInfo = new InMemoryFile(data);
public IFileInfo GetFileInfo(string subpath) => _fileInfo;
public IDirectoryContents GetDirectoryContents(string subpath) => null;
public IChangeToken Watch(string filter) => NullChangeToken.Singleton;
}
}

View File

@ -0,0 +1,7 @@
namespace OcelotApiGw.Services
{
public interface ISettingService
{
string GetConfiguration();
}
}

View File

@ -0,0 +1,51 @@
using Microsoft.Extensions.Options;
using OcelotApiGw.Models;
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 ServiceFabricSettings _serviceFabricSettings;
public SettingService(HttpClient httpClient, IOptions<ServiceFabricSettings> serviceFabricSettings)
{
_httpClient = httpClient;
_serviceFabricSettings = serviceFabricSettings.Value;
}
public string GetConfiguration()
{
var strings = new List<string>();
var tasks = new Func<Task>[]
{
async () => {
var configuration = await _httpClient.GetStringAsync(_serviceFabricSettings.UrlMobilMarketing);
strings.Add(configuration);
},
async () => {
var configuration = await _httpClient.GetStringAsync(_serviceFabricSettings.UrlMobilShopping);
strings.Add(configuration);
},
async () => {
var configuration = await _httpClient.GetStringAsync(_serviceFabricSettings.UrlWebMarketing);
strings.Add(configuration);
},
async () => {
var configuration = await _httpClient.GetStringAsync(_serviceFabricSettings.UrlWebShopping);
strings.Add(configuration);
}
};
Task.WaitAll(tasks.Select(task => task()).ToArray());
return string.Join(',', strings);
}
}
}

View File

@ -1,84 +1,90 @@
using Microsoft.AspNetCore.Builder; using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection; using Ocelot.DependencyInjection;
using Ocelot.Middleware; using Ocelot.Middleware;
using OcelotApiGw.Enums;
using OcelotApiGw.Models;
using OcelotApiGw.Orchestrators;
using OcelotApiGw.Providers;
using OcelotApiGw.Services;
using System; using System;
using HealthChecks.UI.Client; using System.Linq;
using Microsoft.Extensions.Diagnostics.HealthChecks;
namespace OcelotApiGw namespace OcelotApiGw
{ {
public class Startup public class Startup
{ {
private readonly IConfiguration _cfg; private IConfiguration _configuration;
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
_cfg = configuration; _configuration = configuration;
} }
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
var identityUrl = _cfg.GetValue<string>("IdentityUrl"); var identityUrl = _configuration.GetValue<string>("IdentityUrl");
var authenticationProviderKey = "IdentityApiKey"; var authenticationProviderKey = "IdentityApiKey";
services.AddHealthChecks() services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy()) .AddCheck("self", () => HealthCheckResult.Healthy())
.AddUrlGroup(new Uri(_cfg["CatalogUrlHC"]), name: "catalogapi-check", tags: new string[] { "catalogapi" }) .AddUrlGroup(new Uri(_configuration["CatalogUrlHC"]), name: "catalogapi-check", tags: new string[] { "catalogapi" })
.AddUrlGroup(new Uri(_cfg["OrderingUrlHC"]), name: "orderingapi-check", tags: new string[] { "orderingapi" }) .AddUrlGroup(new Uri(_configuration["OrderingUrlHC"]), name: "orderingapi-check", tags: new string[] { "orderingapi" })
.AddUrlGroup(new Uri(_cfg["BasketUrlHC"]), name: "basketapi-check", tags: new string[] { "basketapi" }) .AddUrlGroup(new Uri(_configuration["BasketUrlHC"]), name: "basketapi-check", tags: new string[] { "basketapi" })
.AddUrlGroup(new Uri(_cfg["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" }) .AddUrlGroup(new Uri(_configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" })
.AddUrlGroup(new Uri(_cfg["MarketingUrlHC"]), name: "marketingapi-check", tags: new string[] { "marketingapi" }) .AddUrlGroup(new Uri(_configuration["MarketingUrlHC"]), name: "marketingapi-check", tags: new string[] { "marketingapi" })
.AddUrlGroup(new Uri(_cfg["PaymentUrlHC"]), name: "paymentapi-check", tags: new string[] { "paymentapi" }) .AddUrlGroup(new Uri(_configuration["PaymentUrlHC"]), name: "paymentapi-check", tags: new string[] { "paymentapi" })
.AddUrlGroup(new Uri(_cfg["LocationUrlHC"]), name: "locationapi-check", tags: new string[] { "locationapi" }); .AddUrlGroup(new Uri(_configuration["LocationUrlHC"]), name: "locationapi-check", tags: new string[] { "locationapi" });
services.AddCors(options => services.AddCors(options =>
{ {
options.AddPolicy("CorsPolicy", options.AddPolicy("CorsPolicy", builder =>
builder => builder builder.AllowAnyOrigin()
.AllowAnyMethod() .AllowAnyMethod()
.AllowAnyHeader() .AllowAnyHeader()
.SetIsOriginAllowed((host) => true)
.AllowCredentials()); .AllowCredentials());
}); })
.AddTransient<IOrchestratorStrategy, Kubernetes>()
services.AddAuthentication() .AddTransient<IOrchestratorStrategy, ServiceFabric>()
.AddJwtBearer(authenticationProviderKey, x => .AddTransient<IFileProvider, InMemoryFileProvider>()
.AddAuthentication()
.AddJwtBearer(authenticationProviderKey, options =>
{ {
x.Authority = identityUrl; options.Authority = identityUrl;
x.RequireHttpsMetadata = false; options.RequireHttpsMetadata = false;
x.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters() options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{ {
ValidAudiences = new[] { "orders", "basket", "locations", "marketing", "mobileshoppingagg", "webshoppingagg" } 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;
},
OnMessageReceived = async ctx =>
{
int i = 0;
}
};
}); });
services.AddOcelot(_cfg); services.Configure<ServiceFabricSettings>(_configuration);
services.AddHttpClient<ISettingService, SettingService>();
var orchestratorType = _configuration.GetValue<OrchestratorType>("OrchestratorType");
var config = new ConfigurationBuilder()
.AddConfiguration(_configuration);
_configuration = services.BuildServiceProvider()
.GetServices<IOrchestratorStrategy>()
.Single(strategy => strategy.OrchestratorType == orchestratorType)
.ConfigureOrchestrator(config)
.Build();
services.AddOcelot(_configuration);
} }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 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)) if (!string.IsNullOrEmpty(pathBase))
{ {
@ -101,11 +107,13 @@ namespace OcelotApiGw
Predicate = r => r.Name.Contains("self") Predicate = r => r.Name.Contains("self")
}); });
loggerFactory.AddConsole(_cfg.GetSection("Logging")); #pragma warning disable CS0618 // Type or member is obsolete
loggerFactory.AddConsole(_configuration.GetSection("Logging"));
#pragma warning restore CS0618 // Type or member is obsolete
app.UseCors("CorsPolicy"); app.UseCors("CorsPolicy")
.UseOcelot()
app.UseOcelot().Wait(); .Wait();
} }
} }
} }

View File

@ -27,9 +27,9 @@
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.1.0" /> <PackageReference Include="IdentityServer4.AspNetIdentity" Version="2.1.0" />
<PackageReference Include="IdentityServer4.EntityFramework" Version="2.1.1" /> <PackageReference Include="IdentityServer4.EntityFramework" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Redis" Version="0.3.3" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> <PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Redis" Version="2.2.0-preview2-35157" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.163" /> <PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="1.0.163" />
</ItemGroup> </ItemGroup>

View File

@ -27,4 +27,9 @@
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\BuildingBlocks\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />
<ProjectReference Include="..\..\BuildingBlocks\HealthChecks\src\Microsoft.Extensions.HealthChecks\Microsoft.Extensions.HealthChecks.csproj" />
</ItemGroup>
</Project> </Project>