Browse Source

Merge 723bd1209f into 42abcad37e

pull/1756/merge
Veysel MUTLU 3 years ago
committed by GitHub
parent
commit
4e095f83ac
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 163 additions and 141 deletions
  1. +1
    -4
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  2. +11
    -33
      src/Services/Catalog/Catalog.API/Controllers/PicController.cs
  3. +6
    -3
      src/Services/Catalog/Catalog.API/Extensions/CatalogItemExtensions.cs
  4. +1
    -4
      src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs
  5. +85
    -0
      src/Services/Identity/Identity.API/Extensions/StartupConfigurationExtensions.cs
  6. +0
    -4
      src/Services/Identity/Identity.API/Identity.API.csproj
  7. +2
    -0
      src/Services/Identity/Identity.API/Services/ProfileService.cs
  8. +6
    -66
      src/Services/Identity/Identity.API/Startup.cs
  9. +19
    -0
      src/Services/Ordering/Ordering.API/Startup.cs
  10. +15
    -0
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BaseConfiguration.cs
  11. +4
    -7
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTypeConfiguration.cs
  12. +5
    -6
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs
  13. +4
    -7
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs
  14. +4
    -7
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs

+ 1
- 4
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -304,10 +304,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
var baseUri = _settings.PicBaseUrl;
var azureStorageEnabled = _settings.AzureStorageEnabled;
foreach (var item in items)
{
item.FillProductUrl(baseUri, azureStorageEnabled: azureStorageEnabled);
}
items.ForEach(item => { item.FillProductUrl(baseUri, azureStorageEnabled: azureStorageEnabled); });
return items;
}


+ 11
- 33
src/Services/Catalog/Catalog.API/Controllers/PicController.cs View File

@ -56,40 +56,18 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
private string GetImageMimeTypeFromImageFileExtension(string extension)
{
string mimetype;
switch (extension)
string mimetype = extension switch
{
case ".png":
mimetype = "image/png";
break;
case ".gif":
mimetype = "image/gif";
break;
case ".jpg":
case ".jpeg":
mimetype = "image/jpeg";
break;
case ".bmp":
mimetype = "image/bmp";
break;
case ".tiff":
mimetype = "image/tiff";
break;
case ".wmf":
mimetype = "image/wmf";
break;
case ".jp2":
mimetype = "image/jp2";
break;
case ".svg":
mimetype = "image/svg+xml";
break;
default:
mimetype = "application/octet-stream";
break;
}
".png" => "image/png",
".gif" => "image/gif",
".jpg" or ".jpeg" => "image/jpeg",
".bmp" => "image/bmp",
".tiff" => "image/tiff",
".wmf" => "image/wmf",
".jp2" => "image/jp2",
".svg" => "image/svg+xml",
_ => "application/octet-stream",
};
return mimetype;
}
}


+ 6
- 3
src/Services/Catalog/Catalog.API/Extensions/CatalogItemExtensions.cs View File

@ -6,9 +6,12 @@
{
if (item != null)
{
item.PictureUri = azureStorageEnabled
? picBaseUrl + item.PictureFileName
: picBaseUrl.Replace("[0]", item.Id.ToString());
// https://www.linkedin.com/feed/update/urn:li:activity:6841055191211491328/
item.PictureUri = azureStorageEnabled switch
{
true => picBaseUrl + item.PictureFileName,
_ => picBaseUrl.Replace("[0]", item.Id.ToString())
};
}
}
}


+ 1
- 4
src/Services/Identity/Identity.API/Devspaces/DevspacesRedirectUriValidator.cs View File

@ -9,10 +9,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Devspaces
public class DevspacesRedirectUriValidator : IRedirectUriValidator
{
private readonly ILogger _logger;
public DevspacesRedirectUriValidator(ILogger<DevspacesRedirectUriValidator> logger)
{
_logger = logger;
}
public DevspacesRedirectUriValidator(ILogger<DevspacesRedirectUriValidator> logger) => (_logger) = (logger);
public Task<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client)
{


+ 85
- 0
src/Services/Identity/Identity.API/Extensions/StartupConfigurationExtensions.cs View File

@ -0,0 +1,85 @@
using IdentityServer4.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Identity.API;
using Microsoft.eShopOnContainers.Services.Identity.API.Certificates;
using Microsoft.eShopOnContainers.Services.Identity.API.Data;
using Microsoft.eShopOnContainers.Services.Identity.API.Devspaces;
using Microsoft.eShopOnContainers.Services.Identity.API.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Reflection;
using Microsoft.eShopOnContainers.Services.Identity.API.Services;
namespace Identity.API.Extensions
{
public static class StartupConfigurationExtensions
{
public static void RegisterAppInsights(this IServiceCollection services, IConfiguration configuration)
{
services.AddApplicationInsightsTelemetry(configuration);
services.AddApplicationInsightsKubernetesEnricher();
}
// Add framework services.
public static void ConfigureDatabase(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(configuration["ConnectionString"],
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
}));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
}
// Adds IdentityServer
public static void ConfigureIdentityServer(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration["ConnectionString"];
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer(x =>
{
x.IssuerUri = "null";
x.Authentication.CookieLifetime = TimeSpan.FromHours(2);
})
.AddDevspacesIfNeeded(configuration.GetValue("EnableDevspaces", false))
.AddSigningCredential(Certificate.Get())
.AddAspNetIdentity<ApplicationUser>()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(migrationsAssembly);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(migrationsAssembly);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
})
.Services.AddTransient<IProfileService, ProfileService>();
}
public static void ConfigureDependecyInjections(this IServiceCollection services)
{
services.AddTransient<ILoginService<ApplicationUser>, EFLoginService>();
services.AddTransient<IRedirectService, RedirectService>();
}
}
}

+ 0
- 4
src/Services/Identity/Identity.API/Identity.API.csproj View File

@ -63,8 +63,4 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Extensions\" />
</ItemGroup>
</Project>

+ 2
- 0
src/Services/Identity/Identity.API/Services/ProfileService.cs View File

@ -21,6 +21,8 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Services
_userManager = userManager;
}
//New Method ArgumentNullException.ThrowIfNull (obj) Added to .NET 6
//https://davidshergilashvili.space/2021/09/08/new-method-argumentnullexception-throwifnull-obj-added-to-net-6/
async public Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var subject = context.Subject ?? throw new ArgumentNullException(nameof(context.Subject));


+ 6
- 66
src/Services/Identity/Identity.API/Startup.cs View File

@ -1,18 +1,11 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using HealthChecks.UI.Client;
using IdentityServer4.Services;
using Identity.API.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Identity.API.Certificates;
using Microsoft.eShopOnContainers.Services.Identity.API.Data;
using Microsoft.eShopOnContainers.Services.Identity.API.Devspaces;
using Microsoft.eShopOnContainers.Services.Identity.API.Models;
using Microsoft.eShopOnContainers.Services.Identity.API.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
@ -20,37 +13,22 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using System;
using System.Reflection;
namespace Microsoft.eShopOnContainers.Services.Identity.API
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public Startup(IConfiguration configuration) => (Configuration) = (configuration);
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
RegisterAppInsights(services);
services.RegisterAppInsights(Configuration);
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["ConnectionString"],
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
}));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.ConfigureDatabase(Configuration);
services.Configure<AppSettings>(Configuration);
@ -69,42 +47,10 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
name: "IdentityDB-check",
tags: new string[] { "IdentityDB" });
services.AddTransient<ILoginService<ApplicationUser>, EFLoginService>();
services.AddTransient<IRedirectService, RedirectService>();
var connectionString = Configuration["ConnectionString"];
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.ConfigureDependecyInjections();
// Adds IdentityServer
services.AddIdentityServer(x =>
{
x.IssuerUri = "null";
x.Authentication.CookieLifetime = TimeSpan.FromHours(2);
})
.AddDevspacesIfNeeded(Configuration.GetValue("EnableDevspaces", false))
.AddSigningCredential(Certificate.Get())
.AddAspNetIdentity<ApplicationUser>()
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(migrationsAssembly);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder => builder.UseSqlServer(connectionString,
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(migrationsAssembly);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
})
.Services.AddTransient<IProfileService, ProfileService>();
services.ConfigureIdentityServer(Configuration);
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
services.AddControllers();
@ -174,11 +120,5 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API
});
});
}
private void RegisterAppInsights(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry(Configuration);
services.AddApplicationInsightsKubernetesEnricher();
}
}
}

+ 19
- 0
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -278,6 +278,25 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
}
});
/*
* resource: https://twitter.com/CoderBora/status/1436392448356495362
* Swagger => Authorization: Bearer {token} : DO YOU WANT TO WRITE "Bearer" to the Value each time?
AddSecurityDefinition=>{ in Swagger
Type = SecuritySchemeType Choose "Http" instead of "ApiKey". Avoid typing "Bearer" instead of token
*
*/
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = @"JWT Authorization header using the Bearer scheme. Example: \'Authorization: Bearer {token}\'",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Scheme = "Bearer"
});
options.OperationFilter<AuthorizeCheckOperationFilter>();
});


+ 15
- 0
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BaseConfiguration.cs View File

@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
namespace Ordering.Infrastructure.EntityConfigurations
{
public class BaseConfiguration<TEntity> : IEntityTypeConfiguration<TEntity> where TEntity : Entity
{
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
{
builder.Ignore(b => b.DomainEvents);
builder.HasKey(e => e.Id);
}
}
}

+ 4
- 7
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/BuyerEntityTypeConfiguration.cs View File

@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
namespace Ordering.Infrastructure.EntityConfigurations
{
class BuyerEntityTypeConfiguration
: IEntityTypeConfiguration<Buyer>
class BuyerEntityTypeConfiguration : BaseConfiguration<Buyer>
{
public void Configure(EntityTypeBuilder<Buyer> buyerConfiguration)
public override void Configure(EntityTypeBuilder<Buyer> buyerConfiguration)
{
buyerConfiguration.ToTable("buyers", OrderingContext.DEFAULT_SCHEMA);
buyerConfiguration.HasKey(b => b.Id);
buyerConfiguration.Ignore(b => b.DomainEvents);
buyerConfiguration.Property(b => b.Id)
.UseHiLo("buyerseq", OrderingContext.DEFAULT_SCHEMA);
@ -36,6 +31,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods));
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
base.Configure(buyerConfiguration);
}
}
}

+ 5
- 6
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs View File

@ -7,16 +7,12 @@ using System;
namespace Ordering.Infrastructure.EntityConfigurations
{
class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order>
class OrderEntityTypeConfiguration : BaseConfiguration<Order>
{
public void Configure(EntityTypeBuilder<Order> orderConfiguration)
public override void Configure(EntityTypeBuilder<Order> orderConfiguration)
{
orderConfiguration.ToTable("orders", OrderingContext.DEFAULT_SCHEMA);
orderConfiguration.HasKey(o => o.Id);
orderConfiguration.Ignore(b => b.DomainEvents);
orderConfiguration.Property(o => o.Id)
.UseHiLo("orderseq", OrderingContext.DEFAULT_SCHEMA);
@ -81,6 +77,9 @@ namespace Ordering.Infrastructure.EntityConfigurations
.WithMany()
// .HasForeignKey("OrderStatusId");
.HasForeignKey("_orderStatusId");
base.Configure(orderConfiguration);
}
}
}

+ 4
- 7
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderItemEntityTypeConfiguration.cs View File

@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
namespace Ordering.Infrastructure.EntityConfigurations
{
class OrderItemEntityTypeConfiguration
: IEntityTypeConfiguration<OrderItem>
class OrderItemEntityTypeConfiguration : BaseConfiguration<OrderItem>
{
public void Configure(EntityTypeBuilder<OrderItem> orderItemConfiguration)
public override void Configure(EntityTypeBuilder<OrderItem> orderItemConfiguration)
{
orderItemConfiguration.ToTable("orderItems", OrderingContext.DEFAULT_SCHEMA);
orderItemConfiguration.HasKey(o => o.Id);
orderItemConfiguration.Ignore(b => b.DomainEvents);
orderItemConfiguration.Property(o => o.Id)
.UseHiLo("orderitemseq");
@ -54,6 +49,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
.UsePropertyAccessMode(PropertyAccessMode.Field)
.HasColumnName("PictureUrl")
.IsRequired(false);
base.Configure(orderItemConfiguration);
}
}
}

+ 4
- 7
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/PaymentMethodEntityTypeConfiguration.cs View File

@ -6,17 +6,12 @@ using System;
namespace Ordering.Infrastructure.EntityConfigurations
{
class PaymentMethodEntityTypeConfiguration
: IEntityTypeConfiguration<PaymentMethod>
class PaymentMethodEntityTypeConfiguration : BaseConfiguration<PaymentMethod>
{
public void Configure(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
public override void Configure(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
{
paymentConfiguration.ToTable("paymentmethods", OrderingContext.DEFAULT_SCHEMA);
paymentConfiguration.HasKey(b => b.Id);
paymentConfiguration.Ignore(b => b.DomainEvents);
paymentConfiguration.Property(b => b.Id)
.UseHiLo("paymentseq", OrderingContext.DEFAULT_SCHEMA);
@ -60,6 +55,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
paymentConfiguration.HasOne(p => p.CardType)
.WithMany()
.HasForeignKey("_cardTypeId");
base.Configure(paymentConfiguration);
}
}
}

Loading…
Cancel
Save