Revert "Feat: Reforma de unificación de bases de datos."
This reverts commit 32cf2ba74a.
# Conflicts:
# Backend/MotoresArgentinosV2.API/Program.cs
This commit is contained in:
@@ -39,8 +39,6 @@ builder.Services.AddCors(options =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
// FORWARDED HEADERS (CRÍTICO PARA DOCKER/NGINX)
|
// FORWARDED HEADERS (CRÍTICO PARA DOCKER/NGINX)
|
||||||
// Por defecto, .NET solo confía en localhost. En Docker, Nginx tiene otra IP.
|
|
||||||
// Debemos limpiar las redes conocidas para que confíe en el proxy interno de Docker.
|
|
||||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
{
|
{
|
||||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||||
@@ -55,18 +53,15 @@ builder.Services.AddRateLimiter(options =>
|
|||||||
|
|
||||||
options.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(context =>
|
options.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(context =>
|
||||||
{
|
{
|
||||||
// En producción detrás de Nginx, RemoteIpAddress será la IP real del usuario.
|
|
||||||
// Si por alguna razón falla (ej: conexión directa local), usamos "unknown".
|
|
||||||
var remoteIp = context.Connection.RemoteIpAddress?.ToString() ?? "unknown";
|
var remoteIp = context.Connection.RemoteIpAddress?.ToString() ?? "unknown";
|
||||||
|
|
||||||
// Si es Loopback (localhost), sin límites (útil para dev)
|
|
||||||
if (System.Net.IPAddress.IsLoopback(context.Connection.RemoteIpAddress!))
|
if (System.Net.IPAddress.IsLoopback(context.Connection.RemoteIpAddress!))
|
||||||
{
|
{
|
||||||
return RateLimitPartition.GetNoLimiter("loopback");
|
return RateLimitPartition.GetNoLimiter("loopback");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RateLimitPartition.GetFixedWindowLimiter(
|
return RateLimitPartition.GetFixedWindowLimiter(
|
||||||
partitionKey: remoteIp, // Clave correcta: IP del usuario
|
partitionKey: remoteIp,
|
||||||
factory: _ => new FixedWindowRateLimiterOptions
|
factory: _ => new FixedWindowRateLimiterOptions
|
||||||
{
|
{
|
||||||
AutoReplenishment = true,
|
AutoReplenishment = true,
|
||||||
@@ -78,7 +73,6 @@ builder.Services.AddRateLimiter(options =>
|
|||||||
|
|
||||||
options.AddPolicy("AuthPolicy", context =>
|
options.AddPolicy("AuthPolicy", context =>
|
||||||
{
|
{
|
||||||
// Si es localhost, SIN LÍMITES (Evita auto-bloqueo en desarrollo)
|
|
||||||
var remoteIp = context.Connection.RemoteIpAddress;
|
var remoteIp = context.Connection.RemoteIpAddress;
|
||||||
if (remoteIp != null && System.Net.IPAddress.IsLoopback(remoteIp))
|
if (remoteIp != null && System.Net.IPAddress.IsLoopback(remoteIp))
|
||||||
{
|
{
|
||||||
@@ -100,9 +94,13 @@ builder.Services.Configure<HostOptions>(options =>
|
|||||||
options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
|
options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
|
||||||
});
|
});
|
||||||
|
|
||||||
// DB CONTEXTS (Legacy unificado en eldia)
|
// DB CONTEXTS
|
||||||
|
builder.Services.AddDbContext<InternetDbContext>(options =>
|
||||||
|
options.UseSqlServer(builder.Configuration.GetConnectionString("Internet")));
|
||||||
|
|
||||||
builder.Services.AddDbContext<EldiaDbContext>(options =>
|
builder.Services.AddDbContext<EldiaDbContext>(options =>
|
||||||
options.UseSqlServer(builder.Configuration.GetConnectionString("eldia")));
|
options.UseSqlServer(builder.Configuration.GetConnectionString("eldia")));
|
||||||
|
|
||||||
builder.Services.AddDbContext<MotoresV2DbContext>(options =>
|
builder.Services.AddDbContext<MotoresV2DbContext>(options =>
|
||||||
options.UseSqlServer(builder.Configuration.GetConnectionString("MotoresV2"),
|
options.UseSqlServer(builder.Configuration.GetConnectionString("MotoresV2"),
|
||||||
sqlOptions => sqlOptions.EnableRetryOnFailure()));
|
sqlOptions => sqlOptions.EnableRetryOnFailure()));
|
||||||
@@ -144,7 +142,6 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||||||
{
|
{
|
||||||
OnMessageReceived = context =>
|
OnMessageReceived = context =>
|
||||||
{
|
{
|
||||||
// Buscar el token en la cookie llamada "accessToken"
|
|
||||||
var accessToken = context.Request.Cookies["accessToken"];
|
var accessToken = context.Request.Cookies["accessToken"];
|
||||||
if (!string.IsNullOrEmpty(accessToken))
|
if (!string.IsNullOrEmpty(accessToken))
|
||||||
{
|
{
|
||||||
@@ -175,11 +172,7 @@ app.Use(async (context, next) =>
|
|||||||
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
|
context.Response.Headers.Append("X-Content-Type-Options", "nosniff");
|
||||||
context.Response.Headers.Append("Referrer-Policy", "strict-origin-when-cross-origin");
|
context.Response.Headers.Append("Referrer-Policy", "strict-origin-when-cross-origin");
|
||||||
context.Response.Headers.Append("X-XSS-Protection", "1; mode=block");
|
context.Response.Headers.Append("X-XSS-Protection", "1; mode=block");
|
||||||
|
|
||||||
// Permissions-Policy: Bloquear funcionalidades sensibles del navegador no usadas
|
|
||||||
context.Response.Headers.Append("Permissions-Policy", "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()");
|
context.Response.Headers.Append("Permissions-Policy", "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()");
|
||||||
|
|
||||||
// CSP adaptada para permitir pagos en Payway y WebSockets de Vite
|
|
||||||
string csp = "default-src 'self'; " +
|
string csp = "default-src 'self'; " +
|
||||||
"img-src 'self' data: https: blob:; " +
|
"img-src 'self' data: https: blob:; " +
|
||||||
"script-src 'self' 'unsafe-inline'; " +
|
"script-src 'self' 'unsafe-inline'; " +
|
||||||
@@ -190,7 +183,6 @@ app.Use(async (context, next) =>
|
|||||||
"form-action 'self' https://developers-ventasonline.payway.com.ar; " +
|
"form-action 'self' https://developers-ventasonline.payway.com.ar; " +
|
||||||
"frame-ancestors 'none';";
|
"frame-ancestors 'none';";
|
||||||
context.Response.Headers.Append("Content-Security-Policy", csp);
|
context.Response.Headers.Append("Content-Security-Policy", csp);
|
||||||
|
|
||||||
context.Response.Headers.Remove("Server");
|
context.Response.Headers.Remove("Server");
|
||||||
context.Response.Headers.Remove("X-Powered-By");
|
context.Response.Headers.Remove("X-Powered-By");
|
||||||
await next();
|
await next();
|
||||||
@@ -204,7 +196,6 @@ if (app.Environment.IsDevelopment())
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 🔒 HSTS en Producción
|
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Backend/MotoresArgentinosV2.Infrastructure/Data/InternetDbContext.cs
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using MotoresArgentinosV2.Core.DTOs;
|
||||||
|
|
||||||
|
namespace MotoresArgentinosV2.Infrastructure.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contexto de Entity Framework para la base de datos Internet (legacy)
|
||||||
|
/// Servidor: ...
|
||||||
|
/// Base de Datos: internet
|
||||||
|
/// Propósito: Acceso a datos de avisos web
|
||||||
|
/// </summary>
|
||||||
|
public class InternetDbContext : DbContext
|
||||||
|
{
|
||||||
|
public InternetDbContext(DbContextOptions<InternetDbContext> options) : base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
|
// Registrar el DTO como entidad sin llave (Keyless) para que SqlQueryRaw funcione bien
|
||||||
|
modelBuilder.Entity<DatosAvisoDto>(e =>
|
||||||
|
{
|
||||||
|
e.HasNoKey();
|
||||||
|
e.ToView(null); // No mapea a tabla
|
||||||
|
|
||||||
|
// Configurar precisión de decimales para silenciar warnings
|
||||||
|
e.Property(p => p.ImporteSiniva).HasColumnType("decimal(18,2)");
|
||||||
|
e.Property(p => p.ImporteTotsiniva).HasColumnType("decimal(18,2)");
|
||||||
|
e.Property(p => p.PorcentajeCombinado).HasColumnType("decimal(18,2)");
|
||||||
|
e.Property(p => p.Centimetros).HasColumnType("decimal(18,2)");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,10 @@ namespace MotoresArgentinosV2.Infrastructure.Services;
|
|||||||
|
|
||||||
public class AvisosLegacyService : IAvisosLegacyService
|
public class AvisosLegacyService : IAvisosLegacyService
|
||||||
{
|
{
|
||||||
private readonly EldiaDbContext _context;
|
private readonly InternetDbContext _context;
|
||||||
private readonly ILogger<AvisosLegacyService> _logger;
|
private readonly ILogger<AvisosLegacyService> _logger;
|
||||||
|
|
||||||
public AvisosLegacyService(EldiaDbContext context, ILogger<AvisosLegacyService> logger)
|
public AvisosLegacyService(InternetDbContext context, ILogger<AvisosLegacyService> logger)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class LegacyPaymentService : ILegacyPaymentService
|
|||||||
|
|
||||||
public LegacyPaymentService(IConfiguration config, MotoresV2DbContext v2Context, ILogger<LegacyPaymentService> logger)
|
public LegacyPaymentService(IConfiguration config, MotoresV2DbContext v2Context, ILogger<LegacyPaymentService> logger)
|
||||||
{
|
{
|
||||||
_internetConn = config.GetConnectionString("eldia") ?? "";
|
_internetConn = config.GetConnectionString("Internet") ?? "";
|
||||||
_v2Context = v2Context;
|
_v2Context = v2Context;
|
||||||
_config = config;
|
_config = config;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ namespace MotoresArgentinosV2.Infrastructure.Services;
|
|||||||
|
|
||||||
public class UsuariosLegacyService : IUsuariosLegacyService
|
public class UsuariosLegacyService : IUsuariosLegacyService
|
||||||
{
|
{
|
||||||
private readonly EldiaDbContext _context;
|
private readonly InternetDbContext _context;
|
||||||
private readonly ILogger<UsuariosLegacyService> _logger;
|
private readonly ILogger<UsuariosLegacyService> _logger;
|
||||||
|
|
||||||
public UsuariosLegacyService(EldiaDbContext context, ILogger<UsuariosLegacyService> logger)
|
public UsuariosLegacyService(InternetDbContext context, ILogger<UsuariosLegacyService> logger)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|||||||
Reference in New Issue
Block a user