Compare commits
	
		
			15 Commits
		
	
	
		
			feature/us
			...
			82166f5042
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 82166f5042 | ||
|   | a14cec8fb1 | ||
| 5922a53b93 | |||
| 13774093b4 | |||
| 7cd08411b9 | |||
| 1d52ee424d | |||
| 4a26ecc83a | |||
| c85897fd1a | |||
| 3511043209 | |||
|   | 99964d14b8 | ||
| 1ae0b600ae | |||
|   | 6cb0aea1a0 | ||
|   | 8207048c25 | ||
|   | f5b5f7d0f0 | ||
| ffc1afa8c9 | 
| @@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application" | |||||||
| EndProject | EndProject | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" | ||||||
| EndProject | EndProject | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Infrastructure", "Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}" |  | ||||||
| EndProject |  | ||||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" | ||||||
| EndProject | EndProject | ||||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | ||||||
| @@ -29,10 +27,6 @@ Global | |||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Debug|Any CPU.Build.0 = Debug|Any CPU | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.ActiveCfg = Release|Any CPU | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.Build.0 = Release|Any CPU | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |  | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Debug|Any CPU.Build.0 = Debug|Any CPU |  | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Release|Any CPU.ActiveCfg = Release|Any CPU |  | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Release|Any CPU.Build.0 = Release|Any CPU |  | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.Build.0 = Debug|Any CPU | 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Release|Any CPU.ActiveCfg = Release|Any CPU | 		{8CAE8380-475F-46B8-AF90-C495AAC58606}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
| @@ -44,7 +38,6 @@ Global | |||||||
| 	GlobalSection(NestedProjects) = preSolution | 	GlobalSection(NestedProjects) = preSolution | ||||||
| 		{F00B4683-03B3-487A-9608-4B30675AA278} = {36839283-6407-476A-BB33-F0EE90383E2B} | 		{F00B4683-03B3-487A-9608-4B30675AA278} = {36839283-6407-476A-BB33-F0EE90383E2B} | ||||||
| 		{BE8E05D6-05B2-4317-B619-21853B7D21DB} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | 		{BE8E05D6-05B2-4317-B619-21853B7D21DB} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | ||||||
| 		{43BD5F47-132F-4E78-83F1-A1FEED01A502} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} |  | ||||||
| 		{8CAE8380-475F-46B8-AF90-C495AAC58606} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | 		{8CAE8380-475F-46B8-AF90-C495AAC58606} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E} | ||||||
| 	EndGlobalSection | 	EndGlobalSection | ||||||
| 	GlobalSection(ExtensibilityGlobals) = postSolution | 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Mvc; | |||||||
| using Microsoft.Graph; | using Microsoft.Graph; | ||||||
| using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for module authentication. |     /// Handles all requests for module authentication. | ||||||
| @@ -25,6 +25,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|     public class ModuleController(IModuleProvider service) : ControllerBase |     public class ModuleController(IModuleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -38,7 +39,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] |         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -59,7 +59,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("ModuleManagement.Read")] |         [Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -86,11 +85,10 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("ModuleManagement.Read")] |         [Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetModuleById(_id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetModuleById(id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |             { | ||||||
| @@ -110,7 +108,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal e|ror.</response> |         /// <response code="500">The service internal e|ror.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("ModuleManagement.Write")] |         [Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -133,11 +130,10 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("ModuleManagement.Write")] |         [Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string _id, ModuleAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (_id != entity._Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Module ID mismatch"); |                 return BadRequest("Module ID mismatch"); | ||||||
|             } |             } | ||||||
| @@ -162,7 +158,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("ModuleManagement.Write")] |         [Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Mvc; | |||||||
| using Microsoft.Graph; | using Microsoft.Graph; | ||||||
| using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for permission authentication. |     /// Handles all requests for permission authentication. | ||||||
| @@ -25,6 +25,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|     public class PermissionController(IPermissionProvider service) : ControllerBase |     public class PermissionController(IPermissionProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -38,7 +39,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] |         [Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -59,13 +59,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("PermissionManagement.Read")] |         [Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (permissions == null || !permissions.Any()) |             if (permissions == null || !permissions.Any()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Module identifiers are required."); |                 return BadRequest("Permissions identifiers are required."); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var result = await service.GetAllPermissionsByList(permissions, cancellationToken).ConfigureAwait(false); |             var result = await service.GetAllPermissionsByList(permissions, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -85,11 +84,10 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("PermissionManagement.Read")] |         [Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetPermissionById(_id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |             { | ||||||
| @@ -109,7 +107,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal e|ror.</response> |         /// <response code="500">The service internal e|ror.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("PermissionManagement.Write")] |         [Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) |         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -132,11 +129,10 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("PermissionManagement.Write")] |         [Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string _id, PermissionAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (_id != entity._Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Permission ID mismatch"); |                 return BadRequest("Permission ID mismatch"); | ||||||
|             } |             } | ||||||
| @@ -161,7 +157,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("PermissionManagement.Write")] |         [Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Authorization; | |||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
| using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for role authentication. |     /// Handles all requests for role authentication. | ||||||
| @@ -24,6 +24,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|  |     [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|     public class RoleController(IRoleProvider service) : ControllerBase |     public class RoleController(IRoleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -35,7 +36,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Read")] |         [Permission("RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) |         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -54,11 +54,10 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Read")] |         [Permission("RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetRoleById(_id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |             { | ||||||
| @@ -78,7 +77,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |         [Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) |         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -99,11 +97,10 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpPut] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |         [Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string _id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (_id != entity._Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Role ID mismatch"); |                 return BadRequest("Role ID mismatch"); | ||||||
|             } |             } | ||||||
| @@ -126,7 +123,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpPatch] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |         [Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) |         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -146,7 +142,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost(Routes.AddApplication)] |         [HttpPost(Routes.AddApplication)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |         [Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) |         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
| @@ -166,7 +161,6 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpDelete(Routes.RemoveApplication)] |         [HttpDelete(Routes.RemoveApplication)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("RoleManagement.Write")] |         [Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) |         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Mvc; | |||||||
| using Microsoft.Graph; | using Microsoft.Graph; | ||||||
| using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for user authentication. |     /// Handles all requests for user authentication. | ||||||
| @@ -56,9 +56,9 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Read")] |         [Permission("UserManagement.Read")] | ||||||
|         public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken) |         public async Task<IActionResult> GetUserById([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false); |             var result = await service.GetUserById(id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|             if (result == null) |             if (result == null) | ||||||
|             { |             { | ||||||
| @@ -79,7 +79,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Email)] |         [Route(Routes.Email)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); |             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -150,9 +150,9 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("UserManagement.Write")] |         [Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateUserAsync([FromRoute] string _id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) |         public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (_id != entity._Id?.ToString()) |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("User ID mismatch"); |                 return BadRequest("User ID mismatch"); | ||||||
|             } |             } | ||||||
| @@ -173,7 +173,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPatch(Routes.LogIn)] |         [HttpPatch(Routes.LogIn)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); |             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -194,7 +194,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPatch(Routes.LogOut)] |         [HttpPatch(Routes.LogOut)] | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); |             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); | ||||||
| @@ -300,7 +300,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Permission("UserManagement.Write")] |         [Permission("UserManagement.Write")] | ||||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) |         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var result = await service.RemoveCompanyFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); |             var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -315,7 +315,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route("{email}/GetTokenAdapter")] |         [Route("{email}/GetTokenAdapter")] | ||||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] |         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.GoogleScheme}")] | ||||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) |         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); |             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Blueprint.Logging" Version="0.0.1" /> |     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|   | |||||||
							
								
								
									
										104
									
								
								Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,104 @@ | |||||||
|  | using Asp.Versioning.ApiExplorer; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using Microsoft.Graph.ExternalConnectors; | ||||||
|  | using Microsoft.OpenApi.Any; | ||||||
|  | using Microsoft.OpenApi.Models; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerGen; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerUI; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.DAL.API.Extensions | ||||||
|  | { | ||||||
|  |     public static class SwaggerExtensions | ||||||
|  |     { | ||||||
|  |         public static void AddSwagger(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             services.AddEndpointsApiExplorer(); | ||||||
|  |             AddSwaggerGen(services, configuration); | ||||||
|  |             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public static void AddSwaggerGen(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             services.AddSwaggerGen(c => | ||||||
|  |             { | ||||||
|  |                 c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme | ||||||
|  |                 { | ||||||
|  |                     Description = "JWT Authorization header using the Bearer scheme", | ||||||
|  |                     Name = "Authorization", | ||||||
|  |                     In = ParameterLocation.Header, | ||||||
|  |                     Type = SecuritySchemeType.Http, | ||||||
|  |                     Scheme = "bearer", | ||||||
|  |                     BearerFormat = "JWT" | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |                 c.AddSecurityRequirement(new OpenApiSecurityRequirement | ||||||
|  |                 { | ||||||
|  |                     { | ||||||
|  |                         new OpenApiSecurityScheme | ||||||
|  |                         { | ||||||
|  |                             Reference = new OpenApiReference | ||||||
|  |                             { | ||||||
|  |                                 Type = ReferenceType.SecurityScheme, | ||||||
|  |                                 Id = "Bearer" | ||||||
|  |                             } | ||||||
|  |                         }, | ||||||
|  |                         Array.Empty<string>() | ||||||
|  |                     } | ||||||
|  |                 }); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public static void ConfigureSwagger(this WebApplication app) | ||||||
|  |         { | ||||||
|  |             app.UseSwagger(); | ||||||
|  |             app.UseSwaggerUI(options => | ||||||
|  |             { | ||||||
|  |                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||||
|  |                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||||
|  |  | ||||||
|  |                 options.DisplayRequestDuration(); | ||||||
|  |                 options.EnableTryItOutByDefault(); | ||||||
|  |                 options.DocExpansion(DocExpansion.None); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |         public static IServiceCollection AddVersioning(this IServiceCollection services) | ||||||
|  |         { | ||||||
|  |             services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||||
|  |                    .AddApiExplorer(options => | ||||||
|  |                    { | ||||||
|  |                        options.GroupNameFormat = "'v'VVV"; | ||||||
|  |                        options.SubstituteApiVersionInUrl = true; | ||||||
|  |                    }); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||||||
|  |     { | ||||||
|  |         private readonly IApiVersionDescriptionProvider _provider; | ||||||
|  |  | ||||||
|  |         public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) | ||||||
|  |         { | ||||||
|  |             _provider = provider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public void Configure(SwaggerGenOptions options) | ||||||
|  |         { | ||||||
|  |             foreach (var description in _provider.ApiVersionDescriptions) | ||||||
|  |                 options.SwaggerDoc(description.GroupName, new() | ||||||
|  |                 { | ||||||
|  |                     Title = AppDomain.CurrentDomain.FriendlyName, | ||||||
|  |                     Version = description.ApiVersion.ToString() | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             //Map ALL Values Format TODO | ||||||
|  |             options.MapType<DateOnly>(() => new() | ||||||
|  |             { | ||||||
|  |                 Format = "date", | ||||||
|  |                 Example = new OpenApiString(DateOnly.MinValue.ToString()) | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,90 +1,85 @@ | |||||||
|  | using Core.Blueprint.DAL.Mongo.Configuration; | ||||||
| using Core.Blueprint.Logging.Configuration; | using Core.Blueprint.Logging.Configuration; | ||||||
|  | using Core.Blueprint.Redis.Configuration; | ||||||
| using Core.Thalos.Adapters.Extensions; | using Core.Thalos.Adapters.Extensions; | ||||||
| using Core.Thalos.Adapters.Helpers; | using Core.Thalos.BuildingBlocks.Authentication.Extensions; | ||||||
|  | using Core.Thalos.DAL.API.Extensions; | ||||||
| using Core.Thalos.Provider; | using Core.Thalos.Provider; | ||||||
| using Microsoft.AspNetCore.RateLimiting; | using Microsoft.AspNetCore.HttpLogging; | ||||||
| using Microsoft.AspNetCore.ResponseCompression; |  | ||||||
| using System.IO.Compression; |  | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
| using System.Threading.RateLimiting; | using System.Text.Json.Serialization; | ||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "thalos_dal"); | builder.Services.ConfigureAuthentication(builder.Configuration); | ||||||
|  |  | ||||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); |  | ||||||
|  |  | ||||||
| builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly()).AddEnvironmentVariables(); |  | ||||||
|  |  | ||||||
| // Add services to the container. |  | ||||||
|  |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); | builder.Services.AddEndpointsApiExplorer(); | ||||||
|  | builder.Services.AddSwaggerGen(); | ||||||
|  | builder.Configuration | ||||||
|  |     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||||
|  |     .AddEnvironmentVariables(); | ||||||
|  |  | ||||||
| builder.Services.AddLogs(builder); | builder.Services.AddResponseCompression(); | ||||||
|  |  | ||||||
| builder.Services.AddCors(options => |  | ||||||
| { |  | ||||||
|     options.AddPolicy("AllowAll", policyBuilder => |  | ||||||
|         policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); |  | ||||||
| }); |  | ||||||
| builder.Services.AddMvc().AddJsonOptions(options => |  | ||||||
| { |  | ||||||
|     options.JsonSerializerOptions.WriteIndented = true; |  | ||||||
|     options.JsonSerializerOptions.MaxDepth = 20; |  | ||||||
|     options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; |  | ||||||
| }); |  | ||||||
| builder.Services.Configure<BrotliCompressionProviderOptions>(options => |  | ||||||
| { |  | ||||||
|     options.Level = CompressionLevel.Fastest; |  | ||||||
| }); |  | ||||||
| builder.Services.Configure<GzipCompressionProviderOptions>(options => |  | ||||||
| { |  | ||||||
|     options.Level = CompressionLevel.SmallestSize; |  | ||||||
| }); |  | ||||||
| builder.Services.AddResponseCompression(options => |  | ||||||
| { |  | ||||||
|     options.EnableForHttps = true; |  | ||||||
|     options.Providers.Add<BrotliCompressionProvider>(); |  | ||||||
|     options.Providers.Add<GzipCompressionProvider>(); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| builder.Services.AddRateLimiter(_ => _ |  | ||||||
|     .AddFixedWindowLimiter("fixed", options => |  | ||||||
|     { |  | ||||||
|         options.PermitLimit = 5; |  | ||||||
|         options.Window = TimeSpan.FromSeconds(10); |  | ||||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; |  | ||||||
|         options.QueueLimit = 2; |  | ||||||
|     }) |  | ||||||
|     .AddSlidingWindowLimiter("sliding", options => |  | ||||||
|     { |  | ||||||
|         options.PermitLimit = 5; |  | ||||||
|         options.Window = TimeSpan.FromSeconds(10); |  | ||||||
|         options.SegmentsPerWindow = 5; |  | ||||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; |  | ||||||
|         options.QueueLimit = 2; |  | ||||||
|     })); |  | ||||||
|  |  | ||||||
| builder.Services.AddResponseCaching(); |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
| builder.Services.AddSwagger(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings); |  | ||||||
| builder.Services.AddVersioning(builder.Configuration); |  | ||||||
| builder.Services.AddLogging(); |  | ||||||
| builder.Services.AddProblemDetails(); | builder.Services.AddProblemDetails(); | ||||||
|  | builder.Services.AddMemoryCache(); | ||||||
|  | builder.Services.AddLogs(builder); | ||||||
|  | builder.Services.AddRedis(builder.Configuration); | ||||||
|  | builder.Services.AddMongoLayer(builder.Configuration); | ||||||
|  | builder.Services.AddDALLayerServices(builder.Configuration); | ||||||
|  |  | ||||||
|  | builder.Host.ConfigureServices((context, services) => | ||||||
|  | { | ||||||
|  |  | ||||||
| builder.Services.AddDALLayer(builder.Configuration); |     services.AddLogging(); | ||||||
|  |     services.AddControllers(); | ||||||
|  |     services.AddProblemDetails(); | ||||||
|  |     services.AddCors(options | ||||||
|  |         => options.AddDefaultPolicy(policyBuilder | ||||||
|  |             => policyBuilder | ||||||
|  |                 .AllowAnyOrigin() | ||||||
|  |                 .AllowAnyHeader() | ||||||
|  |                 .AllowAnyMethod())); | ||||||
|  |  | ||||||
|  |     builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => | ||||||
|  |     { | ||||||
|  |         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     services | ||||||
|  |         .AddEndpointsApiExplorer() | ||||||
|  |         .AddVersioning() | ||||||
|  |         .AddSwagger(builder.Configuration); | ||||||
|  |  | ||||||
|  |     services.AddHealthChecks(); | ||||||
|  |     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||||
|  |  | ||||||
|  |     builder.Services.AddOutputCache(options => | ||||||
|  |     { | ||||||
|  |         options.AddBasePolicy(builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(10))); | ||||||
|  |         options.AddPolicy("Expire20", builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(20))); | ||||||
|  |         options.AddPolicy("Expire30", builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(30))); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  |  | ||||||
| var app = builder.Build(); | var app = builder.Build(); | ||||||
|  |  | ||||||
| app.UseSwaggerUI(builder.Configuration, authSettings); | app.UseSwagger(); | ||||||
| app.ConfigureSwagger(builder.Configuration); | app.UseSwaggerUI(); | ||||||
| app.UseLogging(builder.Configuration); |  | ||||||
| app.UseHttpsRedirection(); |  | ||||||
| app.UseAuthorization(); |  | ||||||
| app.MapControllers(); | app.MapControllers(); | ||||||
|  | app.UseCors(); | ||||||
|  | app.ConfigureSwagger(); | ||||||
|  | app.UseHttpsRedirection(); | ||||||
|  | app.UseStaticFiles(); | ||||||
|  | app.UseRouting(); | ||||||
|  | app.UseResponseCompression(); | ||||||
|  | app.UseOutputCache(); | ||||||
|  | app.UseResponseCaching(); | ||||||
|  | app.UseAuthentication(); | ||||||
|  | app.UseAuthorization(); | ||||||
|  | app.UseLogging(builder.Configuration); | ||||||
|  | app.MapHealthChecks("/health"); | ||||||
|  |  | ||||||
| app.Run(); | app.Run(); | ||||||
| @@ -5,4 +5,18 @@ | |||||||
|       "Microsoft.AspNetCore": "Warning" |       "Microsoft.AspNetCore": "Warning" | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://localhost:27017", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								Core.Thalos.DAL.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Core.Thalos.DAL.API/appsettings.Local.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|  |     "Redis": "100.123.31.103:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   }, | ||||||
|  |   "ServiceSettings": { | ||||||
|  |     "ApplicationName": "thalos", | ||||||
|  |     "LayerName": "dal" | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -6,7 +6,30 @@ | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   "AllowedHosts": "*", |   "AllowedHosts": "*", | ||||||
|   "Endpoints": { |   "ConnectionStrings": { | ||||||
|     "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" |     "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|   } |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   }, | ||||||
|  |   "Authentication": { | ||||||
|  |     "Google": { | ||||||
|  |       "ClientId": "128345072002-mtfdgpcur44o9tbd7q6e0bb9qnp2crfp.apps.googleusercontent.com", | ||||||
|  |       "ClientSecret": "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", | ||||||
|  |       "ApplicationName": "Thalos", | ||||||
|  |       "RedirectUri": "https://localhost:7239/api/v1/Authentication/callback" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "JwtIssuerOptions": { | ||||||
|  |     "Audience": "https://localhost:7239/", | ||||||
|  |     "Issuer": "webApi" | ||||||
|  |   }, | ||||||
|  |   "SecretKey": "iNivDmHLpUA223sqsfhqGbMRdRj1PVkH1" | ||||||
| } | } | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ | |||||||
|     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) |     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) | ||||||
|     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) |     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) | ||||||
|     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) |     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) | ||||||
|     "ClientId": "" // Client ID for Kerberos application (STORED IN KEY VAULT) |     "ClientId": "" // Client ID for Thalos application (STORED IN KEY VAULT) | ||||||
|   }, |   }, | ||||||
|   "MicrosoftGraph": { |   "MicrosoftGraph": { | ||||||
|     "Scopes": "", // Scopes for Microsoft Graph API access |     "Scopes": "", // Scopes for Microsoft Graph API access | ||||||
|   | |||||||
| @@ -1,42 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="ModuleMapper.cs"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="ModuleRequest"/>, |  | ||||||
|     /// and <see cref="ModuleAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class ModuleMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the permissionRequest to ModuleAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newModule">The Module to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="ModuleAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static ModuleAdapter ToAdapter(this ModuleRequest newModule, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new ModuleAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Name = newModule.Name, |  | ||||||
|                 Description = newModule.Description, |  | ||||||
|                 Icon = newModule.Icon, |  | ||||||
|                 Route = newModule.Route, |  | ||||||
|                 Order = newModule.Order, |  | ||||||
|                 Application = newModule.Application, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty, |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,39 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="PermissionMapper.cs"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="PermissionRequest"/>, |  | ||||||
|     /// and <see cref="PermissionAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class PermissionMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the permissionRequest to PermissionAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newPermission">The Permission to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="PermissionAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static PermissionAdapter ToAdapter(this PermissionRequest newPermission, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new PermissionAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Name = newPermission.Name, |  | ||||||
|                 Description = newPermission.Description, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty, |  | ||||||
|                 AccessLevel = newPermission.AccessLevel |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,42 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="RoleMapper.cs"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
|  |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="RoleRequest"/>, |  | ||||||
|     /// and <see cref="RoleAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class RoleMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the RoleRequest to RoleAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newRole">The Role to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="RoleAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static RoleAdapter ToAdapter(this RoleRequest newRole, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new RoleAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Name = newRole.Name, |  | ||||||
|                 Description = newRole.Description, |  | ||||||
|                 Applications = newRole.Applications, |  | ||||||
|                 Modules = newRole.Modules, |  | ||||||
|                 Permissions = newRole.Permissions, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,46 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="UserMapper.cs"> |  | ||||||
| //    AgileWebs |  | ||||||
| // </copyright> |  | ||||||
| // *********************************************************************** |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.AspNetCore.Http; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Security.Claims; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles mappings between |  | ||||||
|     /// <see cref="UserRequest"/>, |  | ||||||
|     /// and <see cref="UserAdapter"/> |  | ||||||
|     /// </summary> |  | ||||||
|     public static class UserMapper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Maps the UserRequest to UserAdapter. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newUser">The User to be mapped.</param> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public static UserAdapter ToAdapter(this UserRequest newUser, IHttpContextAccessor httpContextAccessor) |  | ||||||
|         { |  | ||||||
|             return new UserAdapter |  | ||||||
|             { |  | ||||||
|                 Id = ObjectId.GenerateNewId().ToString(), |  | ||||||
|                 Guid = Guid.NewGuid().ToString(), |  | ||||||
|                 Email = newUser.Email, |  | ||||||
|                 Name = newUser.Name, |  | ||||||
|                 MiddleName = newUser.MiddleName, |  | ||||||
|                 LastName = newUser.LastName, |  | ||||||
|                 DisplayName = $"{newUser.Name} {newUser.MiddleName} {newUser.LastName}", |  | ||||||
|                 RoleId = newUser.RoleId, |  | ||||||
|                 Companies = newUser.Companies, |  | ||||||
|                 Projects = newUser.Projects, |  | ||||||
|                 CreatedAt = DateTime.UtcNow, |  | ||||||
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty |  | ||||||
|             }; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -7,7 +7,7 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Thalos.Building.Blocks" Version="0.0.2" /> |     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.5" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -1,30 +0,0 @@ | |||||||
| using Core.Thalos.Infraestructure.Caching.Configs; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Dapper.Service.Caching |  | ||||||
| { |  | ||||||
|     public static class CacheHelper |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Determines the cache duration based on specific duration, settings, or a default value. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="specificCacheDuration">Specific cache duration in minutes, if provided.</param> |  | ||||||
|         /// <param name="cacheSettings">General cache settings containing default duration values.</param> |  | ||||||
|         /// <returns>The cache duration as a TimeSpan.</returns> |  | ||||||
|         public static TimeSpan GetCacheDuration(CacheSettings cacheSettings, int? specificCacheDuration = 0) |  | ||||||
|         { |  | ||||||
|             var defaultCacheDuration = TimeSpan.FromMinutes(.5); |  | ||||||
|  |  | ||||||
|             if (specificCacheDuration.HasValue && specificCacheDuration.Value > 0) |  | ||||||
|             { |  | ||||||
|                 return TimeSpan.FromMinutes(specificCacheDuration.Value); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             if (cacheSettings.DefaultCacheDurationInMinutes > 0) |  | ||||||
|             { |  | ||||||
|                 return TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return defaultCacheDuration; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,47 +0,0 @@ | |||||||
| using System.Reflection; |  | ||||||
| using System.Text; |  | ||||||
| using System.Text.RegularExpressions; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Dapper.Service.Caching |  | ||||||
| { |  | ||||||
|     public static class CacheKeyHelper |  | ||||||
|     { |  | ||||||
|         public static string GenerateCacheKey(object instance, string methodName, params object[] parameters) |  | ||||||
|         { |  | ||||||
|             var className = instance.GetType().Name; |  | ||||||
|             var keyBuilder = new StringBuilder($"{className}.{methodName}"); |  | ||||||
|  |  | ||||||
|             foreach (var param in parameters) |  | ||||||
|             { |  | ||||||
|                 string normalizedParam = NormalizeParameter(param); |  | ||||||
|                 keyBuilder.Append($".{normalizedParam}"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return keyBuilder.ToString(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static string NormalizeParameter(object param) |  | ||||||
|         { |  | ||||||
|             if (param == null) |  | ||||||
|             { |  | ||||||
|                 return "null"; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             string paramString; |  | ||||||
|  |  | ||||||
|             if (param is DateTime dateTime) |  | ||||||
|             { |  | ||||||
|                 paramString = dateTime.ToString("yyyyMMdd"); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 paramString = param.ToString(); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             // Replace special characters with an underscore |  | ||||||
|             string normalizedParam = Regex.Replace(paramString, @"[^a-zA-Z0-9]", "_"); |  | ||||||
|  |  | ||||||
|             return normalizedParam; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,133 +0,0 @@ | |||||||
| using Azure.Identity; |  | ||||||
| using Core.Thalos.Infraestructure.Caching.Contracts; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using StackExchange.Redis; |  | ||||||
| using System.Text.Json; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Dapper.Service.Caching |  | ||||||
| { |  | ||||||
|     public class CacheService : ICacheService |  | ||||||
|     { |  | ||||||
|         private IDatabase _cacheDatabase = null!; |  | ||||||
|         private readonly ILogger<CacheService> _logger; |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         public CacheService(string connectionString, ILogger<CacheService> logger) |  | ||||||
|         { |  | ||||||
|             _logger = logger; |  | ||||||
|             Task.Run(async () => |  | ||||||
|             { |  | ||||||
|                 _cacheDatabase = await GetRedisDatabase(connectionString); |  | ||||||
|             }).Wait(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private async Task<IDatabase> GetRedisDatabase(string connectionString) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var configurationOptions = await ConfigurationOptions.Parse($"{connectionString}") |  | ||||||
|                     .ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()); |  | ||||||
|  |  | ||||||
|                 configurationOptions.AbortOnConnectFail = false; |  | ||||||
|                 var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions); |  | ||||||
|  |  | ||||||
|                 _logger.LogInformation("Successfully connected to Redis."); |  | ||||||
|  |  | ||||||
|                 return connectionMultiplexer.GetDatabase(); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, "Error establishing Redis connection."); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         public async Task<T> GetAsync<T>(string key) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var value = await _cacheDatabase.StringGetAsync(key); |  | ||||||
|                 if (value.IsNullOrEmpty) |  | ||||||
|                 { |  | ||||||
|                     _logger.LogInformation($"Cache miss for key: {key}"); |  | ||||||
|                     return default; |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 _logger.LogInformation($"Cache hit for key: {key}"); |  | ||||||
|                 return JsonSerializer.Deserialize<T>(value); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error getting cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task SetAsync<T>(string key, T value, TimeSpan? expiry = null) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var json = JsonSerializer.Serialize(value); |  | ||||||
|                 await _cacheDatabase.StringSetAsync(key, json, expiry); |  | ||||||
|                 _logger.LogInformation($"Cache item set with key: {key}"); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error setting cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task RemoveAsync(string key) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 await _cacheDatabase.KeyDeleteAsync(key); |  | ||||||
|                 _logger.LogInformation($"Cache item removed with key: {key}"); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error removing cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task<bool> ExistsAsync(string key) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var exists = await _cacheDatabase.KeyExistsAsync(key); |  | ||||||
|                 _logger.LogInformation($"Cache item exists check for key: {key} - {exists}"); |  | ||||||
|                 return exists; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error checking existence of cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task RefreshAsync(string key, TimeSpan? expiry = null) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var value = await _cacheDatabase.StringGetAsync(key); |  | ||||||
|                 if (!value.IsNullOrEmpty) |  | ||||||
|                 { |  | ||||||
|                     await _cacheDatabase.StringSetAsync(key, value, expiry); |  | ||||||
|                     _logger.LogInformation($"Cache item refreshed with key: {key}"); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     _logger.LogWarning($"Cache item with key: {key} does not exist, cannot refresh"); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 _logger.LogError(ex, $"Error refreshing cache item with key {key}"); |  | ||||||
|                 throw; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,7 +0,0 @@ | |||||||
| namespace Core.Thalos.Infraestructure.Caching.Configs |  | ||||||
| { |  | ||||||
|     public class CacheSettings |  | ||||||
|     { |  | ||||||
|         public int DefaultCacheDurationInMinutes { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,11 +0,0 @@ | |||||||
| namespace Core.Thalos.Infraestructure.Caching.Contracts |  | ||||||
| { |  | ||||||
|     public interface ICacheService |  | ||||||
|     { |  | ||||||
|         Task<T> GetAsync<T>(string key); |  | ||||||
|         Task SetAsync<T>(string key, T value, TimeSpan? expiry = null); |  | ||||||
|         Task RemoveAsync(string key); |  | ||||||
|         Task<bool> ExistsAsync(string key); |  | ||||||
|         Task RefreshAsync(string key, TimeSpan? expiry = null); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,33 +0,0 @@ | |||||||
| using Microsoft.Extensions.Configuration; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Infraestructure.Contexts.Mongo |  | ||||||
| { |  | ||||||
|     public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider |  | ||||||
|     { |  | ||||||
|         public string ConnectionString { get; set; } = string.Empty; |  | ||||||
|         public string Databasename { get; set; } = string.Empty; |  | ||||||
|         public string Audience { get; set; } = string.Empty; |  | ||||||
|  |  | ||||||
|         public string GetConnectionString() |  | ||||||
|         { |  | ||||||
|             return configuration?.GetConnectionString("DefaultConnection")?.ToString() ?? string.Empty; |  | ||||||
|         } |  | ||||||
|         public string GetDatabasename() |  | ||||||
|         { |  | ||||||
|             return configuration.GetSection("MongoDb:DatabaseName").Value ?? string.Empty; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public string GetAudience() |  | ||||||
|         { |  | ||||||
|             return configuration.GetSection("MongoDb:Audience").Value ?? string.Empty; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     public interface IConnectionStringProvider |  | ||||||
|     { |  | ||||||
|         string GetConnectionString(); |  | ||||||
|         string GetDatabasename(); |  | ||||||
|         string ConnectionString { get; set; } |  | ||||||
|         string Databasename { get; set; } |  | ||||||
|         string Audience { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,14 +0,0 @@ | |||||||
| namespace Core.Thalos.Infraestructure.Contexts.Mongo; |  | ||||||
|  |  | ||||||
| public interface IMongoConnSettings |  | ||||||
| { |  | ||||||
|     string ConnectionString { get; set; } |  | ||||||
|     string Databasename { get; set; } |  | ||||||
|     string Audience { get; set; } |  | ||||||
| } |  | ||||||
| public class MongoConnSettings : IMongoConnSettings |  | ||||||
| { |  | ||||||
|     public string ConnectionString { get; set; } |  | ||||||
|     public string Databasename { get; set; } |  | ||||||
|     public string Audience { get; set; } |  | ||||||
| } |  | ||||||
| @@ -1,15 +0,0 @@ | |||||||
| namespace Core.Thalos.Infraestructure.PerformanceCacheService |  | ||||||
| { |  | ||||||
|     [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] |  | ||||||
|     public class CacheAttribute : Attribute |  | ||||||
|     { |  | ||||||
|         public int CacheDurationInMinutes { get; set; } |  | ||||||
|         public bool EnableCaching { get; set; } |  | ||||||
|  |  | ||||||
|         public CacheAttribute(int cacheDurationInMinutes, bool enableCaching = true) |  | ||||||
|         { |  | ||||||
|             CacheDurationInMinutes = cacheDurationInMinutes; |  | ||||||
|             EnableCaching = enableCaching; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -49,7 +49,7 @@ namespace Core.Thalos.Provider.Contracts | |||||||
|         /// <param name="eamil">The User email.</param> |         /// <param name="eamil">The User email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken); |         ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the user. |         /// Changes the status of the user. | ||||||
|   | |||||||
| @@ -11,15 +11,13 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Blueprint.Mongo" Version="0.0.3" /> |     <PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" /> | ||||||
|     <PackageReference Include="Blueprint.Redis" Version="0.0.1" /> |     <PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" /> | ||||||
|     <PackageReference Include="BuildingBlocks.Library" Version="0.0.1" /> |  | ||||||
|     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> |     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> |     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||||
|     <ProjectReference Include="..\Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj" /> |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -1,16 +0,0 @@ | |||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers |  | ||||||
| { |  | ||||||
|     public class BaseProvider |  | ||||||
|     { |  | ||||||
|         private readonly IMongoDatabase _database; |  | ||||||
|  |  | ||||||
|         public BaseProvider(IMongoDatabase database) |  | ||||||
|         { |  | ||||||
|             _database = database ?? throw new ArgumentNullException(nameof(database)); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         protected IMongoDatabase Database => _database; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,99 +0,0 @@ | |||||||
| using Azure.Core; |  | ||||||
| using Azure.Identity; |  | ||||||
| using Core.Thalos.Adapters.Common.Constants; |  | ||||||
| using MongoDB.Driver.Authentication.Oidc; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers |  | ||||||
| { |  | ||||||
|     public class HeathOidcCallback : IOidcCallback |  | ||||||
|     { |  | ||||||
|         private readonly string _audience; |  | ||||||
|         private readonly string _environment; |  | ||||||
|         public HeathOidcCallback(string audience) |  | ||||||
|         { |  | ||||||
|             _audience = audience; |  | ||||||
|             _environment = Environment.GetEnvironmentVariable(EnvironmentVariables.Stage) ?? string.Empty; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public OidcAccessToken GetOidcAccessToken(OidcCallbackParameters parameters, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 AccessToken token; |  | ||||||
|  |  | ||||||
|                 TokenRequestContext tokenRequestContext = |  | ||||||
|                     new TokenRequestContext( |  | ||||||
|                         new[] { _audience } |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                 if (_environment == "Local") |  | ||||||
|                 { |  | ||||||
|                     token = |  | ||||||
|                     new ChainedTokenCredential( |  | ||||||
|                         new ManagedIdentityCredential(), |  | ||||||
|                         new VisualStudioCredential(), |  | ||||||
|                         new VisualStudioCodeCredential(), |  | ||||||
|                         new SharedTokenCacheCredential() |  | ||||||
|                     ) |  | ||||||
|                     .GetToken( |  | ||||||
|                         tokenRequestContext |  | ||||||
|                     ); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     token = |  | ||||||
|                     new ManagedIdentityCredential() |  | ||||||
|                     .GetToken( |  | ||||||
|                         tokenRequestContext |  | ||||||
|                     ); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 return new(token.Token, expiresIn: null); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|  |  | ||||||
|                 throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public async Task<OidcAccessToken> GetOidcAccessTokenAsync(OidcCallbackParameters parameters, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 TokenRequestContext tokenRequestContext = |  | ||||||
|                     new TokenRequestContext( |  | ||||||
|                         new[] { _audience } |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                 AccessToken token; |  | ||||||
|  |  | ||||||
|                 if (_environment == "Local") |  | ||||||
|                 { |  | ||||||
|                     token = await new ChainedTokenCredential( |  | ||||||
|                         new ManagedIdentityCredential(), |  | ||||||
|                         new VisualStudioCredential(), |  | ||||||
|                         new VisualStudioCodeCredential(), |  | ||||||
|                         new SharedTokenCacheCredential() |  | ||||||
|                     ) |  | ||||||
|                     .GetTokenAsync( |  | ||||||
|                         tokenRequestContext, cancellationToken |  | ||||||
|                     ).ConfigureAwait(false); |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     token = await new ManagedIdentityCredential() |  | ||||||
|                     .GetTokenAsync( |  | ||||||
|                         tokenRequestContext, cancellationToken |  | ||||||
|                     ).ConfigureAwait(false); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 return new(token.Token, expiresIn: null); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -5,13 +5,13 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; |  | ||||||
| using Core.Blueprint.Redis.Helpers; |  | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Blueprint.Redis; | ||||||
|  | using Core.Blueprint.Redis.Helpers; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -25,7 +25,8 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         private readonly IRedisCacheProvider cacheProvider; |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public ModuleProvider(CollectionRepository<ModuleAdapter> repository, |         public ModuleProvider(CollectionRepository<ModuleAdapter> repository, | ||||||
|         IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings) |             IRedisCacheProvider cacheProvider, | ||||||
|  |             IOptions<CacheSettings> cacheSettings) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
| @@ -104,9 +105,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var builder = Builders<ModuleAdapter>.Filter; |             var builder = Builders<ModuleAdapter>.Filter; | ||||||
|             var filters = new List<FilterDefinition<ModuleAdapter>>(); |             var filters = new List<FilterDefinition<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|             if (modules == null || !modules.Any()) |             if (modules != null || !modules.Any()) | ||||||
|             { |             { | ||||||
|                 filters.Add(builder.In(x => x.Id, modules)); |                 filters.Add(builder.In(x => x._Id, modules)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|   | |||||||
| @@ -3,15 +3,15 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; | using MongoDB.Driver; | ||||||
| using Core.Thalos.Provider.Contracts; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -25,7 +25,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         private readonly IRedisCacheProvider cacheProvider; |         private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public PermissionProvider(CollectionRepository<PermissionAdapter> repository, |         public PermissionProvider(CollectionRepository<PermissionAdapter> repository, | ||||||
|         IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings) |             IRedisCacheProvider cacheProvider, | ||||||
|  |             IOptions<CacheSettings> cacheSettings | ||||||
|  |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
| @@ -59,7 +61,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id); | ||||||
|             var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var permission = await repository.FindByIdAsync(_id); |             var permission = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
| @@ -104,9 +106,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var builder = Builders<PermissionAdapter>.Filter; |             var builder = Builders<PermissionAdapter>.Filter; | ||||||
|             var filters = new List<FilterDefinition<PermissionAdapter>>(); |             var filters = new List<FilterDefinition<PermissionAdapter>>(); | ||||||
|  |  | ||||||
|             if (permissions == null || !permissions.Any()) |             if (permissions != null || !permissions.Any()) | ||||||
|             { |             { | ||||||
|                 filters.Add(builder.In(x => x.Id, permissions)); |                 filters.Add(builder.In(x => x._Id, permissions)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|   | |||||||
| @@ -3,21 +3,21 @@ | |||||||
| //     AgileWebs | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Adapters.Common.Enums; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; |  | ||||||
| using Core.Thalos.Provider.Contracts; |  | ||||||
| using MongoDB.Bson; |  | ||||||
| using System.Text.RegularExpressions; |  | ||||||
| using MongoDB.Bson.Serialization; |  | ||||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; |  | ||||||
| using Microsoft.Graph; | using Microsoft.Graph; | ||||||
|  | using MongoDB.Bson; | ||||||
|  | using MongoDB.Bson.Serialization; | ||||||
|  | using MongoDB.Driver; | ||||||
| using System.ComponentModel.Design; | using System.ComponentModel.Design; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -27,17 +27,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     public class RoleProvider : IRoleProvider |     public class RoleProvider : IRoleProvider | ||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<RoleAdapter> repository; |         private readonly CollectionRepository<RoleAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; | 		private readonly CacheSettings cacheSettings; | ||||||
|         private readonly IRedisCacheProvider cacheProvider; | 		private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public RoleProvider(CollectionRepository<RoleAdapter> repository, | 		public RoleProvider(CollectionRepository<RoleAdapter> repository, | ||||||
|         IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings) | 		    IRedisCacheProvider cacheProvider, | ||||||
|  | 			IOptions<CacheSettings> cacheSettings | ||||||
|  | 			) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; | 			this.cacheSettings = cacheSettings.Value; | ||||||
|             this.cacheProvider = cacheProvider; | 			this.cacheProvider = cacheProvider; | ||||||
|         } | 		} | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Role. |         /// Creates a new Role. | ||||||
| @@ -133,7 +135,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) |         public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var role = await repository.FindOneAsync( |             var role = await repository.FindOneAsync( | ||||||
|                 u => u.Id == roleId && |                 u => u._Id == roleId && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             var updatedApplications = role.Applications.Append(application).Distinct().ToArray(); |             var updatedApplications = role.Applications.Append(application).Distinct().ToArray(); | ||||||
| @@ -153,7 +155,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) |         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var role = await repository.FindOneAsync( |             var role = await repository.FindOneAsync( | ||||||
|                 u => u.Id == roleId && |                 u => u._Id == roleId && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             var updatedApplications = role.Applications |             var updatedApplications = role.Applications | ||||||
|   | |||||||
| @@ -4,18 +4,19 @@ | |||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
|  |  | ||||||
| using Core.Thalos.Adapters; |  | ||||||
| using Core.Thalos.Adapters.Common.Enums; |  | ||||||
| using Core.Blueprint.Mongo; | using Core.Blueprint.Mongo; | ||||||
| using Core.Blueprint.Redis; | using Core.Blueprint.Redis; | ||||||
| using Core.Blueprint.Redis.Helpers; | using Core.Blueprint.Redis.Helpers; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
| using Mapster; | using Mapster; | ||||||
| using Microsoft.Extensions.Options; | using Microsoft.Extensions.Options; | ||||||
| using MongoDB.Driver; |  | ||||||
| using Core.Thalos.Provider.Contracts; |  | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using System.Text.RegularExpressions; |  | ||||||
| using MongoDB.Bson.Serialization; | using MongoDB.Bson.Serialization; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using System.Reflection; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider.Providers.Onboarding | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
| { | { | ||||||
| @@ -26,16 +27,18 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|     { |     { | ||||||
|         private readonly CollectionRepository<UserAdapter> repository; |         private readonly CollectionRepository<UserAdapter> repository; | ||||||
|         private readonly CacheSettings cacheSettings; |         private readonly CacheSettings cacheSettings; | ||||||
|         private readonly IRedisCacheProvider cacheProvider; | 		private readonly IRedisCacheProvider cacheProvider; | ||||||
|  |  | ||||||
|         public UserProvider(CollectionRepository<UserAdapter> repository, | 		public UserProvider(CollectionRepository<UserAdapter> repository, | ||||||
|         IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings) |             IRedisCacheProvider cacheProvider, | ||||||
|  | 			IOptions<CacheSettings> cacheSettings | ||||||
|  |             ) | ||||||
|         { |         { | ||||||
|             this.repository = repository; |             this.repository = repository; | ||||||
|             this.repository.CollectionInitialization(); |             this.repository.CollectionInitialization(); | ||||||
|             this.cacheSettings = cacheSettings.Value; | 			this.cacheSettings = cacheSettings.Value; | ||||||
|             this.cacheProvider = cacheProvider; | 			this.cacheProvider = cacheProvider; | ||||||
|         } | 		} | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new User. |         /// Creates a new User. | ||||||
| @@ -63,7 +66,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id); | ||||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var user = await repository.FindByIdAsync(_id); |             var user = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
| @@ -102,7 +105,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Email == email &&  |                 u => u.Email == email &&  | ||||||
| @@ -119,20 +122,24 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         /// <param name="email">The User email.</param> |         /// <param name="email">The User email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         public async ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken) |         public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); |             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Email == email && |                 u => u.Email == email && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             await cacheProvider.SetAsync(cacheKey, user); |             UserExistenceAdapter userExistance = new UserExistenceAdapter(); | ||||||
|  |  | ||||||
|             return user; |             userExistance.Existence = (user != null) ? true : false; | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, userExistance); | ||||||
|  |  | ||||||
|  |             return userExistance; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -213,7 +220,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Id == userId && |                 u => u._Id == userId && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray(); |             var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray(); | ||||||
| @@ -233,7 +240,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Id == userId && |                 u => u._Id == userId && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             var updatedCompanies = user.Companies |             var updatedCompanies = user.Companies | ||||||
| @@ -256,11 +263,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Id == userId && |                 u => u._Id == userId && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray(); |             var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray(); | ||||||
|             user.Companies = updatedProjects; |             user.Projects = updatedProjects; | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
| @@ -276,14 +283,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|         public async ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken) |         public async ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var user = await repository.FindOneAsync( |             var user = await repository.FindOneAsync( | ||||||
|                 u => u.Id == userId && |                 u => u._Id == userId && | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|             var updatedProjects = user.Projects |             var updatedProjects = user.Projects | ||||||
|                     ?.Where(c => c != projectId) |                     ?.Where(c => c != projectId) | ||||||
|                     .ToArray(); |                     .ToArray(); | ||||||
|  |  | ||||||
|             user.Companies = updatedProjects; |             user.Projects = updatedProjects; | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
| @@ -399,53 +406,106 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|                     User = new UserAdapter |                     User = new UserAdapter | ||||||
|                     { |                     { | ||||||
|                         Id = result["_id"]?.ToString() ?? "", |                         Id = result["_id"]?.ToString() ?? "", | ||||||
|                         Guid = result["guid"].AsString, |                         Guid = result.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : "", | ||||||
|                         Email = result["email"].AsString, |                         Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : "", | ||||||
|                         Name = result["name"].AsString, |                         Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : "", | ||||||
|                         MiddleName = result["middleName"].AsString, |                         MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : "", | ||||||
|                         LastName = result["lastName"].AsString, |                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", | ||||||
|                         DisplayName = result["displayName"].AsString, |                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", | ||||||
|                         RoleId = result["roleId"]?.ToString() ?? "", |                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", | ||||||
|                         Companies = result["companies"].AsBsonArray |                         Companies = result.Contains("companies") && result["companies"].IsBsonArray | ||||||
|                             .Select(c => c.AsString) |                             ? result["companies"].AsBsonArray | ||||||
|                             .ToArray(), |                                 .Where(c => c != null && !c.IsBsonNull) | ||||||
|                         Projects = result["projects"].AsBsonArray |                                 .Select(c => c.AsString) | ||||||
|                             .Select(c => c.AsString) |                                 .ToArray() | ||||||
|                             .ToArray(), |                             : Array.Empty<string>(), | ||||||
|                         LastLogIn = result["lastLogIn"].ToUniversalTime(), |                                         Projects = result.Contains("projects") && result["projects"].IsBsonArray | ||||||
|                         LastLogOut = result["lastLogOut"].ToUniversalTime(), |                             ? result["projects"].AsBsonArray | ||||||
|                         CreatedAt = result["createdAt"].ToUniversalTime(), |                                 .Where(p => p != null && !p.IsBsonNull) | ||||||
|                         CreatedBy = result["createdBy"].AsString, |                                 .Select(p => p.AsString) | ||||||
|                         UpdatedAt = result["updatedAt"].ToUniversalTime(), |                                 .ToArray() | ||||||
|                         UpdatedBy = result["updatedBy"].AsString, |                             : Array.Empty<string>(), | ||||||
|                         Status = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString), |                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : "", | ||||||
|  |                         UpdatedAt = result.Contains("updatedAt") && !result["updatedAt"].IsBsonNull ? result["updatedAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : "", | ||||||
|  |                         Status = result.Contains("status") && !result["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Inactive | ||||||
|                     }, |                     }, | ||||||
|                     Role = new RoleAdapter |                     Role = new RoleAdapter | ||||||
|                     { |                     { | ||||||
|                         Id = result["role"]["_id"]?.ToString() ?? "", |                         Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id") | ||||||
|                         Name = result["role"]["name"].AsString, |                             ? result["role"]["_id"]?.ToString() ?? "" | ||||||
|                         Description = result["role"]["description"].AsString, |                             : "", | ||||||
|                         Applications = result["role"]["applications"].AsBsonArray |                         Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name") | ||||||
|                             .Select(c => (ApplicationsEnum)c.AsInt32) |                             ? result["role"]["name"]?.AsString ?? "" | ||||||
|                             .ToArray(), |                             : "", | ||||||
|                         Modules = result["role"]["modules"].AsBsonArray |                         Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description") | ||||||
|                             .Select(c => c.ToString() ?? "") |                             ? result["role"]["description"]?.AsString ?? "" | ||||||
|                             .ToArray(), |                             : "", | ||||||
|                         Permissions = result["role"]["permissions"].AsBsonArray |                         Applications = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|                             .Select(c => c.ToString() ?? "") |                        result["role"].AsBsonDocument.Contains("applications") && | ||||||
|                             .ToArray(), |                        result["role"]["applications"].IsBsonArray | ||||||
|                         Status = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString), |                             ? result["role"]["applications"].AsBsonArray | ||||||
|                         CreatedAt = result["role"]["createdAt"].ToUniversalTime(), |                                 .Where(app => app != null && app.IsInt32) | ||||||
|                         UpdatedAt = result["role"]["updatedAt"].ToUniversalTime(), |                                 .Select(app => (ApplicationsEnum)app.AsInt32) | ||||||
|                         CreatedBy = result["role"]["createdBy"].AsString, |                                 .ToArray() | ||||||
|                         UpdatedBy = result["role"]["updatedBy"].AsString |                             : Array.Empty<ApplicationsEnum>(), | ||||||
|  |                         Modules = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("modules") && | ||||||
|  |                             result["role"]["modules"].IsBsonArray | ||||||
|  |                             ? result["role"]["modules"].AsBsonArray | ||||||
|  |                                 .Where(m => m != null) | ||||||
|  |                                 .Select(m => m.ToString() ?? "") | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         Permissions = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("permissions") && | ||||||
|  |                             result["role"]["permissions"].IsBsonArray | ||||||
|  |                             ? result["role"]["permissions"].AsBsonArray | ||||||
|  |                                 .Where(p => p != null) | ||||||
|  |                                 .Select(p => p.ToString() ?? "") | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         Status = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                              result["role"].AsBsonDocument.Contains("status") && | ||||||
|  |                              !result["role"]["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Inactive, | ||||||
|  |                         CreatedAt = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("createdAt") && | ||||||
|  |                             !result["role"]["createdAt"].IsBsonNull | ||||||
|  |                             ? result["role"]["createdAt"].ToUniversalTime() | ||||||
|  |                             : DateTime.MinValue, | ||||||
|  |                         UpdatedAt = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("updatedAt") && | ||||||
|  |                             !result["role"]["updatedAt"].IsBsonNull | ||||||
|  |                             ? result["role"]["updatedAt"].ToUniversalTime() | ||||||
|  |                             : DateTime.MinValue, | ||||||
|  |                         CreatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("createdBy") && | ||||||
|  |                             !result["role"]["createdBy"].IsBsonNull | ||||||
|  |                             ? result["role"]["createdBy"].AsString | ||||||
|  |                             : "", | ||||||
|  |                         UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("updatedBy") && | ||||||
|  |                             !result["role"]["updatedBy"].IsBsonNull | ||||||
|  |                             ? result["role"]["updatedBy"].AsString | ||||||
|  |                             : "" | ||||||
|                     }, |                     }, | ||||||
|                     Permissions = result["permissions"].AsBsonArray |                     Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray | ||||||
|                         .Select(permission => BsonSerializer.Deserialize<PermissionAdapter>(permission.AsBsonDocument)) |                         ? result["permissions"].AsBsonArray | ||||||
|                         .Where(permission => permission.Status == Core.Blueprint.Mongo.StatusEnum.Active) |                             .Where(p => p != null && p.IsBsonDocument) | ||||||
|                         .ToList() |                             .Select(p => BsonSerializer.Deserialize<PermissionAdapter>(p.AsBsonDocument)) | ||||||
|  |                             .Where(p => p.Status == Core.Blueprint.Mongo.StatusEnum.Active) | ||||||
|  |                             .ToList() | ||||||
|  |                         : new List<PermissionAdapter>() | ||||||
|                 }; |                 }; | ||||||
|  |  | ||||||
|  |  | ||||||
|                 return tokenAdapter; |                 return tokenAdapter; | ||||||
|  |  | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -1,100 +1,28 @@ | |||||||
| using Core.Thalos.Infraestructure.Caching.Contracts; | using Core.Blueprint.Mongo; | ||||||
| using Core.Thalos.Infraestructure.Contexts.Mongo; | using Core.Thalos.Adapters; | ||||||
| using Core.Thalos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Thalos.Provider.Providers; |  | ||||||
| using Core.Thalos.Provider.Providers.Onboarding; | using Core.Thalos.Provider.Providers.Onboarding; | ||||||
| using LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.Extensions.Configuration; | using Microsoft.Extensions.Configuration; | ||||||
| using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Thalos.Provider | namespace Core.Thalos.Provider | ||||||
| { | { | ||||||
|     public static class ServiceCollectionExtensions |     public static class ServiceCollectionExtensions | ||||||
|     { |     { | ||||||
|         public static IServiceCollection AddDALLayer(this IServiceCollection services, IConfiguration configuration) |         public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration) | ||||||
|         { |         { | ||||||
|             var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty; |             //Mongo | ||||||
|  |             services.AddScoped<IModuleProvider, ModuleProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|             var connectionString = configuration.GetSection("ConnectionStrings:MongoDB").Value ?? string.Empty; |             services.AddScoped<IPermissionProvider, PermissionProvider>(); | ||||||
|             var databaseName = configuration.GetSection("MongoDB:DatabaseName").Value ?? string.Empty; |             services.AddScoped<CollectionRepository<PermissionAdapter>>(); | ||||||
|             var audience = (environment == "Local") |  | ||||||
|                 ? configuration.GetSection("MongoDB:LocalAudience").Value |  | ||||||
|                 : configuration.GetSection("MongoDB:Audience").Value; |  | ||||||
|  |  | ||||||
|             if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(databaseName) || string.IsNullOrEmpty(audience)) |             services.AddScoped<IRoleProvider, RoleProvider>(); | ||||||
|             { |             services.AddScoped<CollectionRepository<RoleAdapter>>(); | ||||||
|                 throw new InvalidOperationException("Mongo connection is not configured correctly."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             services.Configure<MongoConnSettings>(options => |  | ||||||
|             { |  | ||||||
|                 options.ConnectionString = connectionString; |  | ||||||
|                 options.Databasename = databaseName; |  | ||||||
|                 options.Audience = audience ?? string.Empty; |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddSingleton<IMongoClient>(serviceProvider => |  | ||||||
|             { |  | ||||||
|                 var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value; |  | ||||||
|                 var mongoClientSettings = MongoClientSettings.FromConnectionString(settings.ConnectionString); |  | ||||||
|                 mongoClientSettings.Credential = MongoCredential.CreateOidcCredential(new HeathOidcCallback(settings.Audience)); |  | ||||||
|                 return new MongoClient(mongoClientSettings); |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddSingleton<IMongoDatabase>(serviceProvider => |  | ||||||
|             { |  | ||||||
|                 var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value; |  | ||||||
|                 var client = serviceProvider.GetRequiredService<IMongoClient>(); |  | ||||||
|                 return client.GetDatabase(settings.Databasename); |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddDALConfigurationLayer(); |  | ||||||
|             services.AddLogs(); |  | ||||||
|             services.AddRedisCacheService(configuration); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddDALConfigurationLayer(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddHttpContextAccessor(); |  | ||||||
|  |  | ||||||
|             services.AddScoped<IUserProvider, UserProvider>(); |             services.AddScoped<IUserProvider, UserProvider>(); | ||||||
|             services.AddScoped<IRoleProvider, RoleProvider>(); |             services.AddScoped<CollectionRepository<UserAdapter>>(); | ||||||
|             services.AddScoped<IPermissionProvider, PermissionProvider>(); |  | ||||||
|             services.AddScoped<IPermissionProvider, PermissionProvider>(); |  | ||||||
|             services.AddScoped<IModuleProvider, ModuleProvider>(); |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddLogs(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddLogging(); |  | ||||||
|             var serviceProvider = services.BuildServiceProvider(); |  | ||||||
|             //var logger = serviceProvider.GetService<ILogger<DashboardDALService>>(); //Add for Markup class later TODO |  | ||||||
|  |  | ||||||
|             //services.AddSingleton(typeof(ILogger), logger); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddRedisCacheService(this IServiceCollection services, IConfiguration configuration) |  | ||||||
|         { |  | ||||||
|             var source = configuration.GetSection("ConnectionStrings"); |  | ||||||
|  |  | ||||||
|             var redisConnectionString = source["Redis"]?.ToString(); |  | ||||||
|  |  | ||||||
|             if (string.IsNullOrEmpty(redisConnectionString)) |  | ||||||
|             { |  | ||||||
|                 throw new InvalidOperationException("Redis connection string is not configured."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             services.AddSingleton<ICacheService>(provider => |  | ||||||
|                 new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>())); |  | ||||||
|  |  | ||||||
|             return services; |             return services; | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user