Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade #153

Merged
merged 14 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.Net.Http.Headers;

namespace EmailSender.WebApi.Configuration;
namespace EmailSender.Backend.Configuration;

[ExcludeFromCodeCoverage]
public static class CorsPolicy
Expand All @@ -20,7 +21,7 @@
{
builder.UseCors(policyBuilder =>
{
policyBuilder

Check warning on line 24 in EmailSender.Backend/EmailSender.Backend.Configuration/CorsPolicy.cs

View workflow job for this annotation

GitHub Actions / dev-branch-check

Make sure this permissive CORS policy is safe here. (https://rules.sonarsource.com/csharp/RSPEC-5122)
.AllowAnyOrigin()
.WithHeaders(
HeaderNames.Accept,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Net;
using System.Net.Sockets;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.DependencyInjection;

namespace EmailSender.WebApi.Configuration;
namespace EmailSender.Backend.Configuration;

[ExcludeFromCodeCoverage]
public static class DockerSupport
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.26" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.26" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.26" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.26">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.26" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.35.0" />
<PackageReference Include="Polly" Version="8.2.1" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.Sinks.AzureBlobStorage" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.35.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EmailSender.Backend.Core\EmailSender.Backend.Core.csproj" />
<ProjectReference Include="..\EmailSender.Backend.Shared\EmailSender.Backend.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Newtonsoft.Json;

namespace EmailSender.Backend.Configuration;

public static class HealthCheckSupport
{
public static HealthCheckOptions WriteResponse()
{
return new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
{
var result = new
{
status = report.Status.ToString(),
errors = report.Entries.Select(pair
=> new
{
key = pair.Key,
value = Enum.GetName(typeof(HealthStatus), pair.Value.Status)
})
};
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(JsonConvert.SerializeObject(result));
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Configuration;
using Serilog;
using Serilog.Events;
using ILogger = Serilog.ILogger;

namespace EmailSender.WebApi.Configuration.Logger;
namespace EmailSender.Backend.Configuration.Logger;

public static class Configuration
{
Expand All @@ -14,7 +15,7 @@
var connectionString = configuration.GetValue<string>("AZ_Storage_ConnectionString");
var containerName = configuration.GetValue<string>("AZ_Storage_ContainerName");

return new LoggerConfiguration()

Check warning on line 18 in EmailSender.Backend/EmailSender.Backend.Configuration/Logger/Configuration.cs

View workflow job for this annotation

GitHub Actions / dev-branch-check

Make sure that this logger's configuration is safe. (https://rules.sonarsource.com/csharp/RSPEC-4792)
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Console()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Polly.Extensions.Http;
using Polly;

namespace EmailSender.WebApi.Configuration;
namespace EmailSender.Backend.Configuration;

[ExcludeFromCodeCoverage]
public static class PollyPolicyHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;

namespace EmailSender.Backend.Configuration;

[ExcludeFromCodeCoverage]
public static class PollySupport
{
public static void SetupRetryPolicyWithPolly(IServiceCollection services)
{
services.AddHttpClient("RetryHttpClient", options =>
{
options.DefaultRequestHeaders.Add("Accept", "application/json");
options.Timeout = TimeSpan.FromMinutes(5);
options.DefaultRequestHeaders.ConnectionClose = true;
}).AddPolicyHandler(PollyPolicyHandler.SetupRetry());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;

namespace EmailSender.WebApi.Configuration;
namespace EmailSender.Backend.Configuration;

[ExcludeFromCodeCoverage]
public static class SwaggerSupport
Expand Down
2 changes: 1 addition & 1 deletion EmailSender.ClientApp/clientapp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WORKDIR /usr/share/nginx/html

RUN rm -rf ./*
RUN apt-get update
RUN apt-get upgrade
RUN apt-get -y upgrade
RUN apt-get -y install bash
RUN apt-get -y install nginx
RUN apt-get -y install nginx-full
Expand Down
1 change: 0 additions & 1 deletion EmailSender.ClientApp/nginx/nginx-http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ http {
}

location /api {
include /etc/nginx/nginx-proxy.conf;
proxy_pass http://backend;
}

Expand Down
1 change: 0 additions & 1 deletion EmailSender.ClientApp/nginx/nginx-https.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ http {
}

location /api {
include /etc/nginx/nginx-proxy.conf;
proxy_pass http://backend;
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private async Task<ServerData> GetServerData(string address, CancellationToken c
Server = email.ServerName,
Key = email.ServerKey,
Port = email.ServerPort,
IsSSL = email.ServerSsl
IsSsl = email.ServerSsl
};
}

Expand All @@ -140,7 +140,7 @@ private async Task<ServerData> GetServerData(Guid addressId, CancellationToken c
Server = email.ServerName,
Key = email.ServerKey,
Port = email.ServerPort,
IsSSL = email.ServerSsl
IsSsl = email.ServerSsl
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public class ServerData

public int Port { get; set; }

public bool IsSSL { get; set; }
public bool IsSsl { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public ServerData ServerData { get; set; } = new();

public SecureSocketOptions SslOnConnect => ServerData.IsSSL
public SecureSocketOptions SslOnConnect => ServerData.IsSsl
? SecureSocketOptions.SslOnConnect
: SecureSocketOptions.None;

Expand Down Expand Up @@ -123,7 +123,7 @@
try
{
// ReSharper disable once UnusedVariable
var address = new MailAddress(emailAddress);

Check warning on line 126 in EmailSender.Services/EmailSender.Services.SmtpService/SmtpClientService.cs

View workflow job for this annotation

GitHub Actions / dev-branch-check

Remove the unused local variable 'address'. (https://rules.sonarsource.com/csharp/RSPEC-1481)
return true;
}
catch (FormatException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public string GetPrivateKeyFromHeader(string headerName = "X-Private-Key")
{
return _httpContextAccessor.HttpContext is null
? string.Empty
: _httpContextAccessor.HttpContext.Request.Headers[headerName].ToString();
: _httpContextAccessor.HttpContext.Request.Headers[headerName].ToString()
?? string.Empty;
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions EmailSender.WebApi.Dto/AddUserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

namespace EmailSender.WebApi.Dto;

/// <summary>
/// Use it when you want to register new user.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddUserDto
{
/// <summary>
/// Name.
/// </summary>
public string FirstName { get; set; } = "";

/// <summary>
/// Surname.
/// </summary>
public string LastName { get; set; } = "";

/// <summary>
/// Email address.
/// </summary>
public string EmailAddress { get; set; } = "";
}
9 changes: 9 additions & 0 deletions EmailSender.WebApi.Dto/AddUserEmailDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

namespace EmailSender.WebApi.Dto;

/// <summary>
/// Use it when you want to add new user email address.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddUserEmailDto
{
/// <summary>
/// User ID.
/// </summary>
public Guid? UserId { get; set; }

/// <summary>
/// Email ID.
/// </summary>
public Guid EmailId { get; set; }
}
9 changes: 9 additions & 0 deletions EmailSender.WebApi.Dto/AlterUserStatusDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@

namespace EmailSender.WebApi.Dto;

/// <summary>
/// Use it when you want to change use status.
/// </summary>
[ExcludeFromCodeCoverage]
public class AlterUserStatusDto
{
/// <summary>
/// User ID.
/// </summary>
public Guid? UserId { get; set; }

/// <summary>
/// Desired user status.
/// </summary>
public UserStatus Status { get; set; }
}
2 changes: 2 additions & 0 deletions EmailSender.WebApi.Dto/EmailSender.WebApi.Dto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions EmailSender.WebApi.Dto/GeneratePrivateKeyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace EmailSender.WebApi.Dto;

/// <summary>
/// Use it when you want to generate new PK.
/// </summary>
[ExcludeFromCodeCoverage]
public class GeneratePrivateKeyDto
{
/// <summary>
/// User ID.
/// </summary>
public Guid? UserId { get; set; }
}
9 changes: 9 additions & 0 deletions EmailSender.WebApi.Dto/RemoveUserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

namespace EmailSender.WebApi.Dto;

/// <summary>
/// Use it when you want to remove user.
/// </summary>
[ExcludeFromCodeCoverage]
public class RemoveUserDto
{
/// <summary>
/// User ID.
/// </summary>
public Guid? UserId { get; set; }

/// <summary>
/// Enable/Disable soft delete.
/// </summary>
public bool SoftDelete { get; set; }
}
9 changes: 9 additions & 0 deletions EmailSender.WebApi.Dto/RemoveUserEmailDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

namespace EmailSender.WebApi.Dto;

/// <summary>
/// Use it when you want to remove user email.
/// </summary>
[ExcludeFromCodeCoverage]
public class RemoveUserEmailDto
{
/// <summary>
/// User ID.
/// </summary>
public Guid? UserId { get; set; }

/// <summary>
/// Email ID.
/// </summary>
public Guid EmailId { get; set; }
}
Loading
Loading