From 9f0558c2825578eeffe95536a664744696cf27a6 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Thu, 17 Jul 2025 13:39:09 +0200 Subject: [PATCH 01/14] Target main for github-workflow-parts --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 50abd6d..7cd7ab5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,7 +31,7 @@ jobs: uses: actions/checkout@v4 with: repository: devpro/github-workflow-parts - ref: feature/sonar-login-deprecation + ref: main path: workflow-parts - name: Start MongoDB uses: ./workflow-parts/mongodb/start @@ -62,7 +62,7 @@ jobs: uses: actions/checkout@v3 with: repository: devpro/github-workflow-parts - ref: feature/sonar-login-deprecation + ref: main path: workflow-parts - name: Create and scan container image uses: ./workflow-parts/docker/build-scan From e9ad5ddcab3aed2d3e9a06787f007c32bce63b02 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Thu, 17 Jul 2025 17:54:55 +0200 Subject: [PATCH 02/14] Rename Devpro with Farseer in namespaces --- ...formBackend.sln => Farseer.TerraformBackend.sln | 0 compose.yaml | 4 ++-- .../Authentication/BasicAuthenticationClient.cs | 2 +- .../Authentication/BasicAuthenticationDefaults.cs | 2 +- .../Authentication/BasicAuthorizationAttribute.cs | 2 +- .../Builder/PolicyBuilderExtensions.cs | 4 ++-- .../Builder/SwaggerBuilderExtensions.cs | 4 ++-- .../Common.AspNetCore.WebApi.csproj | 4 ++-- .../Configuration/WebApiConfiguration.cs | 2 +- .../SwaggerServiceCollectionExtensions.cs | 4 ++-- src/Common.AspNetCore/Common.AspNetCore.csproj | 4 ++-- .../BehaviorServiceCollectionExtensions.cs | 2 +- .../Formatters/RawRequestBodyFormatter.cs | 2 +- src/Common.MongoDb/Common.MongoDb.csproj | 4 ++-- src/Common.MongoDb/DefaultMongoClientFactory.cs | 2 +- src/Common.MongoDb/IMongoClientFactory.cs | 2 +- src/Common.MongoDb/MongoDbConfiguration.cs | 2 +- src/Common.MongoDb/RepositoryBase.cs | 2 +- src/Domain/Domain.csproj | 4 ++-- src/Domain/Models/StateLockModel.cs | 2 +- src/Domain/Models/StateModel.cs | 2 +- src/Domain/Models/StateValueModel.cs | 2 +- src/Domain/Models/UserModel.cs | 2 +- src/Domain/Repositories/IStateLockRepository.cs | 4 ++-- src/Domain/Repositories/IStateRepository.cs | 2 +- src/Domain/Repositories/IUserRepository.cs | 4 ++-- .../Infrastructure.MongoDb.csproj | 4 ++-- .../Repositories/StateLockRepository.cs | 8 ++++---- .../Repositories/StateRepository.cs | 6 +++--- .../Repositories/UserRepository.cs | 8 ++++---- src/WebApi/ApplicationConfiguration.cs | 4 ++-- .../Authentication/BasicAuthenticationHandler.cs | 6 +++--- .../Authentication/ClaimsPrincipalExtensions.cs | 2 +- src/WebApi/Controllers/StateController.cs | 8 ++++---- .../AuthenticationServiceCollectionExtensions.cs | 6 +++--- .../InfrastructureServiceCollectionExtensions.cs | 2 +- src/WebApi/Dockerfile | 2 +- src/WebApi/Filters/TenantAuthorizationFilter.cs | 4 ++-- src/WebApi/ImplicitUsings.cs | 14 +++++++------- src/WebApi/Properties/launchSettings.json | 4 ++-- src/WebApi/WebApi.csproj | 8 ++------ src/WebApi/appsettings.json | 4 ++-- .../Behaviors/InvalidModelStateBehaviorTest.cs | 4 ++-- .../Http/HttpResponseMessageExtensions.cs | 2 +- .../WebApi.IntegrationTests/IntegrationTestBase.cs | 4 ++-- .../Resources/HealthCheckResourceTest.cs | 4 ++-- .../Resources/StateControllerResourceTest.cs | 4 ++-- .../Resources/SwaggerResourceTest.cs | 4 ++-- .../WebApi.IntegrationTests.csproj | 4 ++-- 49 files changed, 91 insertions(+), 95 deletions(-) rename Devpro.TerraformBackend.sln => Farseer.TerraformBackend.sln (100%) diff --git a/Devpro.TerraformBackend.sln b/Farseer.TerraformBackend.sln similarity index 100% rename from Devpro.TerraformBackend.sln rename to Farseer.TerraformBackend.sln diff --git a/compose.yaml b/compose.yaml index fe34055..b56061b 100644 --- a/compose.yaml +++ b/compose.yaml @@ -9,10 +9,10 @@ services: - Application__IsHttpsRedirectionEnabled=false - Application__IsOpenTelemetryEnabled=false - Application__IsSwaggerEnabled=true - - ConnectionStrings__MongoDbLocal=mongodb://mongodb:27017/?readPreference=primary&appname=DevproTerraformBackendWebApi&directConnection=true&ssl=false + - ConnectionStrings__MongoDbLocal=mongodb://mongodb:27017/?readPreference=primary&appname=FarseerTerraformBackendWebApi&directConnection=true&ssl=false - Logging__LogLevel__Default=Debug - Logging__LogLevel__Microsoft__AspNetCore=Information - - Logging__LogLevel__Devpro=Debug + - Logging__LogLevel__Farseer=Debug - MongoDb__ConnectionStringName=MongoDbLocal - MongoDb__DatabaseName=terraform_backend_dev ports: diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs index cb608c7..cfe8e59 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs @@ -1,6 +1,6 @@ using System.Security.Principal; -namespace Devpro.Common.AspNetCore.WebApi.Authentication; +namespace Farseer.Common.AspNetCore.WebApi.Authentication; public class BasicAuthenticationClient : IIdentity { diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs index 2310fab..627f8f6 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs @@ -1,4 +1,4 @@ -namespace Devpro.Common.AspNetCore.WebApi.Authentication; +namespace Farseer.Common.AspNetCore.WebApi.Authentication; public class BasicAuthenticationDefaults { diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs index 55f884e..e1f0e78 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Authorization; -namespace Devpro.Common.AspNetCore.WebApi.Authentication; +namespace Farseer.Common.AspNetCore.WebApi.Authentication; public class BasicAuthorizationAttribute : AuthorizeAttribute { diff --git a/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs b/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs index b5780c4..3fc53a1 100644 --- a/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs +++ b/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs @@ -1,7 +1,7 @@ -using Devpro.Common.AspNetCore.WebApi.Configuration; +using Farseer.Common.AspNetCore.WebApi.Configuration; using Microsoft.AspNetCore.Builder; -namespace Devpro.Common.AspNetCore.WebApi.Builder; +namespace Farseer.Common.AspNetCore.WebApi.Builder; public static class PolicyBuilderExtensions { diff --git a/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs b/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs index 9bd4b27..16a6724 100644 --- a/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs +++ b/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs @@ -1,7 +1,7 @@ -using Devpro.Common.AspNetCore.WebApi.Configuration; +using Farseer.Common.AspNetCore.WebApi.Configuration; using Microsoft.AspNetCore.Builder; -namespace Devpro.Common.AspNetCore.WebApi.Builder; +namespace Farseer.Common.AspNetCore.WebApi.Builder; public static class SwaggerBuilderExtensions { diff --git a/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj b/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj index eebeae5..379d16a 100644 --- a/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj +++ b/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj @@ -2,8 +2,8 @@ net8.0 - Devpro.Common.AspNetCore.WebApi - Devpro.Common.AspNetCore.WebApi + Farseer.Common.AspNetCore.WebApi + Farseer.Common.AspNetCore.WebApi {19336002-C959-4E76-B112-861F93CF6423} enable enable diff --git a/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs b/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs index eee1be5..c2d06ce 100644 --- a/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs +++ b/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.OpenApi.Models; -namespace Devpro.Common.AspNetCore.WebApi.Configuration; +namespace Farseer.Common.AspNetCore.WebApi.Configuration; public class WebApiConfiguration(IConfigurationRoot configurationRoot) { diff --git a/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs b/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs index 212d532..5984bee 100644 --- a/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs +++ b/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using Devpro.Common.AspNetCore.WebApi.Configuration; +using Farseer.Common.AspNetCore.WebApi.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; -namespace Devpro.Common.AspNetCore.WebApi.DependencyInjection; +namespace Farseer.Common.AspNetCore.WebApi.DependencyInjection; public static class SwaggerServiceCollectionExtensions { diff --git a/src/Common.AspNetCore/Common.AspNetCore.csproj b/src/Common.AspNetCore/Common.AspNetCore.csproj index 7c7b11e..e0a48e0 100644 --- a/src/Common.AspNetCore/Common.AspNetCore.csproj +++ b/src/Common.AspNetCore/Common.AspNetCore.csproj @@ -2,8 +2,8 @@ net8.0 - Devpro.Common.AspNetCore - Devpro.Common.AspNetCore + Farseer.Common.AspNetCore + Farseer.Common.AspNetCore {F23098F5-355B-46F0-BABE-3D6E23D8EED7} enable diff --git a/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs b/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs index 1c04a40..2325645 100644 --- a/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs +++ b/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -namespace Devpro.Common.AspNetCore.DependencyInjection; +namespace Farseer.Common.AspNetCore.DependencyInjection; public static class BehaviorServiceCollectionExtensions { diff --git a/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs b/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs index 3e88cce..ce73aa0 100644 --- a/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs +++ b/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Net.Http.Headers; -namespace Devpro.Common.AspNetCore.Formatters; +namespace Farseer.Common.AspNetCore.Formatters; /// /// ASP.NET Core input formatter to manage raw request bodies. diff --git a/src/Common.MongoDb/Common.MongoDb.csproj b/src/Common.MongoDb/Common.MongoDb.csproj index 9711fa2..6e15124 100644 --- a/src/Common.MongoDb/Common.MongoDb.csproj +++ b/src/Common.MongoDb/Common.MongoDb.csproj @@ -2,8 +2,8 @@ net8.0 - Devpro.Common.MongoDb - Devpro.Common.MongoDb + Farseer.Common.MongoDb + Farseer.Common.MongoDb {49BF313A-4ED3-4BD2-9AEE-E44A5ED19C0C} enable diff --git a/src/Common.MongoDb/DefaultMongoClientFactory.cs b/src/Common.MongoDb/DefaultMongoClientFactory.cs index 5db07c5..a8984eb 100644 --- a/src/Common.MongoDb/DefaultMongoClientFactory.cs +++ b/src/Common.MongoDb/DefaultMongoClientFactory.cs @@ -2,7 +2,7 @@ using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; -namespace Devpro.Common.MongoDb; +namespace Farseer.Common.MongoDb; public class DefaultMongoClientFactory : IMongoClientFactory { diff --git a/src/Common.MongoDb/IMongoClientFactory.cs b/src/Common.MongoDb/IMongoClientFactory.cs index a6c282d..428ec87 100644 --- a/src/Common.MongoDb/IMongoClientFactory.cs +++ b/src/Common.MongoDb/IMongoClientFactory.cs @@ -1,6 +1,6 @@ using MongoDB.Driver; -namespace Devpro.Common.MongoDb; +namespace Farseer.Common.MongoDb; /// /// Avoids calling "new" in application code. diff --git a/src/Common.MongoDb/MongoDbConfiguration.cs b/src/Common.MongoDb/MongoDbConfiguration.cs index 6236c43..4e4c66f 100644 --- a/src/Common.MongoDb/MongoDbConfiguration.cs +++ b/src/Common.MongoDb/MongoDbConfiguration.cs @@ -1,4 +1,4 @@ -namespace Devpro.Common.MongoDb; +namespace Farseer.Common.MongoDb; public class MongoDbConfiguration { diff --git a/src/Common.MongoDb/RepositoryBase.cs b/src/Common.MongoDb/RepositoryBase.cs index f0dc8c1..e7e162d 100644 --- a/src/Common.MongoDb/RepositoryBase.cs +++ b/src/Common.MongoDb/RepositoryBase.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace Devpro.Common.MongoDb; +namespace Farseer.Common.MongoDb; public abstract class RepositoryBase { diff --git a/src/Domain/Domain.csproj b/src/Domain/Domain.csproj index ae3da51..25457ca 100644 --- a/src/Domain/Domain.csproj +++ b/src/Domain/Domain.csproj @@ -2,8 +2,8 @@ net8.0 - Devpro.TerraformBackend.Domain - Devpro.TerraformBackend.Domain + Farseer.TerraformBackend.Domain + Farseer.TerraformBackend.Domain {A5CAD112-C1E6-442B-BE0E-37C697030636} enable diff --git a/src/Domain/Models/StateLockModel.cs b/src/Domain/Models/StateLockModel.cs index 1fd6e35..6a46717 100644 --- a/src/Domain/Models/StateLockModel.cs +++ b/src/Domain/Models/StateLockModel.cs @@ -2,7 +2,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -namespace Devpro.TerraformBackend.Domain.Models; +namespace Farseer.TerraformBackend.Domain.Models; public class StateLockModel { diff --git a/src/Domain/Models/StateModel.cs b/src/Domain/Models/StateModel.cs index 7ed19b2..7e9318b 100644 --- a/src/Domain/Models/StateModel.cs +++ b/src/Domain/Models/StateModel.cs @@ -2,7 +2,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -namespace Devpro.TerraformBackend.Domain.Models; +namespace Farseer.TerraformBackend.Domain.Models; public class StateModel { diff --git a/src/Domain/Models/StateValueModel.cs b/src/Domain/Models/StateValueModel.cs index cb97ed6..7a2e486 100644 --- a/src/Domain/Models/StateValueModel.cs +++ b/src/Domain/Models/StateValueModel.cs @@ -1,6 +1,6 @@ using MongoDB.Bson.Serialization.Attributes; -namespace Devpro.TerraformBackend.Domain.Models; +namespace Farseer.TerraformBackend.Domain.Models; public class StateValueModel { diff --git a/src/Domain/Models/UserModel.cs b/src/Domain/Models/UserModel.cs index 89a2a5e..1b51295 100644 --- a/src/Domain/Models/UserModel.cs +++ b/src/Domain/Models/UserModel.cs @@ -1,7 +1,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -namespace Devpro.TerraformBackend.Domain.Models; +namespace Farseer.TerraformBackend.Domain.Models; public class UserModel { diff --git a/src/Domain/Repositories/IStateLockRepository.cs b/src/Domain/Repositories/IStateLockRepository.cs index 9059e31..b1404f8 100644 --- a/src/Domain/Repositories/IStateLockRepository.cs +++ b/src/Domain/Repositories/IStateLockRepository.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -using Devpro.TerraformBackend.Domain.Models; +using Farseer.TerraformBackend.Domain.Models; -namespace Devpro.TerraformBackend.Domain.Repositories; +namespace Farseer.TerraformBackend.Domain.Repositories; public interface IStateLockRepository { diff --git a/src/Domain/Repositories/IStateRepository.cs b/src/Domain/Repositories/IStateRepository.cs index c45f919..ab4e42f 100644 --- a/src/Domain/Repositories/IStateRepository.cs +++ b/src/Domain/Repositories/IStateRepository.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Devpro.TerraformBackend.Domain.Repositories; +namespace Farseer.TerraformBackend.Domain.Repositories; public interface IStateRepository { diff --git a/src/Domain/Repositories/IUserRepository.cs b/src/Domain/Repositories/IUserRepository.cs index 8cbe7e7..5e7f2bf 100644 --- a/src/Domain/Repositories/IUserRepository.cs +++ b/src/Domain/Repositories/IUserRepository.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -using Devpro.TerraformBackend.Domain.Models; +using Farseer.TerraformBackend.Domain.Models; -namespace Devpro.TerraformBackend.Domain.Repositories; +namespace Farseer.TerraformBackend.Domain.Repositories; public interface IUserRepository { diff --git a/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj b/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj index 23796c6..3a1a43c 100644 --- a/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj +++ b/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj @@ -2,8 +2,8 @@ net8.0 - Devpro.TerraformBackend.Infrastructure.MongoDb - Devpro.TerraformBackend.Infrastructure.MongoDb + Farseer.TerraformBackend.Infrastructure.MongoDb + Farseer.TerraformBackend.Infrastructure.MongoDb {0429A41A-2D3A-42D4-8736-5FC0F6F0FF0C} enable diff --git a/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs b/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs index 9584e2d..b0909f6 100644 --- a/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs +++ b/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs @@ -1,11 +1,11 @@ using System.Threading.Tasks; -using Devpro.Common.MongoDb; -using Devpro.TerraformBackend.Domain.Models; -using Devpro.TerraformBackend.Domain.Repositories; +using Farseer.Common.MongoDb; +using Farseer.TerraformBackend.Domain.Models; +using Farseer.TerraformBackend.Domain.Repositories; using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace Devpro.TerraformBackend.Infrastructure.MongoDb.Repositories; +namespace Farseer.TerraformBackend.Infrastructure.MongoDb.Repositories; public class StateLockRepository : RepositoryBase, IStateLockRepository { diff --git a/src/Infrastructure.MongoDb/Repositories/StateRepository.cs b/src/Infrastructure.MongoDb/Repositories/StateRepository.cs index a7e423f..d523605 100644 --- a/src/Infrastructure.MongoDb/Repositories/StateRepository.cs +++ b/src/Infrastructure.MongoDb/Repositories/StateRepository.cs @@ -1,12 +1,12 @@ using System; using System.Threading.Tasks; -using Devpro.Common.MongoDb; -using Devpro.TerraformBackend.Domain.Repositories; +using Farseer.Common.MongoDb; +using Farseer.TerraformBackend.Domain.Repositories; using Microsoft.Extensions.Logging; using MongoDB.Bson; using MongoDB.Driver; -namespace Devpro.TerraformBackend.Infrastructure.MongoDb.Repositories; +namespace Farseer.TerraformBackend.Infrastructure.MongoDb.Repositories; public class StateRepository : RepositoryBase, IStateRepository { diff --git a/src/Infrastructure.MongoDb/Repositories/UserRepository.cs b/src/Infrastructure.MongoDb/Repositories/UserRepository.cs index 0066234..d6555f9 100644 --- a/src/Infrastructure.MongoDb/Repositories/UserRepository.cs +++ b/src/Infrastructure.MongoDb/Repositories/UserRepository.cs @@ -1,11 +1,11 @@ using System.Threading.Tasks; -using Devpro.Common.MongoDb; -using Devpro.TerraformBackend.Domain.Models; -using Devpro.TerraformBackend.Domain.Repositories; +using Farseer.Common.MongoDb; +using Farseer.TerraformBackend.Domain.Models; +using Farseer.TerraformBackend.Domain.Repositories; using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace Devpro.TerraformBackend.Infrastructure.MongoDb.Repositories; +namespace Farseer.TerraformBackend.Infrastructure.MongoDb.Repositories; public class UserRepository : RepositoryBase, IUserRepository { diff --git a/src/WebApi/ApplicationConfiguration.cs b/src/WebApi/ApplicationConfiguration.cs index bc58750..00faad6 100644 --- a/src/WebApi/ApplicationConfiguration.cs +++ b/src/WebApi/ApplicationConfiguration.cs @@ -1,6 +1,6 @@ -using Devpro.Common.MongoDb; +using Farseer.Common.MongoDb; -namespace Devpro.TerraformBackend.WebApi; +namespace Farseer.TerraformBackend.WebApi; public class ApplicationConfiguration(IConfigurationRoot configurationRoot) : WebApiConfiguration(configurationRoot) diff --git a/src/WebApi/Authentication/BasicAuthenticationHandler.cs b/src/WebApi/Authentication/BasicAuthenticationHandler.cs index 48a0d22..049d922 100644 --- a/src/WebApi/Authentication/BasicAuthenticationHandler.cs +++ b/src/WebApi/Authentication/BasicAuthenticationHandler.cs @@ -1,12 +1,12 @@ using System.Security.Claims; using System.Text; using System.Text.Encodings.Web; -using Devpro.Common.AspNetCore.WebApi.Authentication; -using Devpro.TerraformBackend.Domain.Repositories; +using Farseer.Common.AspNetCore.WebApi.Authentication; +using Farseer.TerraformBackend.Domain.Repositories; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Options; -namespace Devpro.TerraformBackend.WebApi.Authentication; +namespace Farseer.TerraformBackend.WebApi.Authentication; public class BasicAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, IUserRepository userRepository) : AuthenticationHandler(options, logger, encoder) diff --git a/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs b/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs index d654273..c907201 100644 --- a/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs +++ b/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs @@ -1,6 +1,6 @@ using System.Security.Claims; -namespace Devpro.TerraformBackend.WebApi.Authentication; +namespace Farseer.TerraformBackend.WebApi.Authentication; public static class ClaimsPrincipalExtensions { diff --git a/src/WebApi/Controllers/StateController.cs b/src/WebApi/Controllers/StateController.cs index b796fa0..920e591 100644 --- a/src/WebApi/Controllers/StateController.cs +++ b/src/WebApi/Controllers/StateController.cs @@ -1,11 +1,11 @@ using System.Text.Json; -using Devpro.TerraformBackend.Domain.Models; -using Devpro.TerraformBackend.Domain.Repositories; -using Devpro.TerraformBackend.WebApi.Filters; +using Farseer.TerraformBackend.Domain.Models; +using Farseer.TerraformBackend.Domain.Repositories; +using Farseer.TerraformBackend.WebApi.Filters; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -namespace Devpro.TerraformBackend.WebApi.Controllers; +namespace Farseer.TerraformBackend.WebApi.Controllers; [Authorize] [ApiController] diff --git a/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs b/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs index 97937e8..bf6b562 100644 --- a/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs +++ b/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using Devpro.Common.AspNetCore.WebApi.Authentication; -using Devpro.TerraformBackend.WebApi.Authentication; +using Farseer.Common.AspNetCore.WebApi.Authentication; +using Farseer.TerraformBackend.WebApi.Authentication; using Microsoft.AspNetCore.Authentication; -namespace Devpro.TerraformBackend.WebApi.DependencyInjection; +namespace Farseer.TerraformBackend.WebApi.DependencyInjection; public static class AuthenticationServiceCollectionExtensions { diff --git a/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs b/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs index 8105f3a..f7501f7 100644 --- a/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs +++ b/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; -namespace Devpro.TerraformBackend.WebApi.DependencyInjection; +namespace Farseer.TerraformBackend.WebApi.DependencyInjection; internal static class InfrastructureServiceCollectionExtensions { diff --git a/src/WebApi/Dockerfile b/src/WebApi/Dockerfile index daa926c..c8c1025 100644 --- a/src/WebApi/Dockerfile +++ b/src/WebApi/Dockerfile @@ -20,4 +20,4 @@ RUN dotnet publish "WebApi.csproj" -c "$BUILD_CONFIGURATION" -o /app/publish /p: FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Devpro.TerraformBackend.WebApi.dll"] +ENTRYPOINT ["dotnet", "Farseer.TerraformBackend.WebApi.dll"] diff --git a/src/WebApi/Filters/TenantAuthorizationFilter.cs b/src/WebApi/Filters/TenantAuthorizationFilter.cs index f6caf1a..da09358 100644 --- a/src/WebApi/Filters/TenantAuthorizationFilter.cs +++ b/src/WebApi/Filters/TenantAuthorizationFilter.cs @@ -1,8 +1,8 @@ -using Devpro.TerraformBackend.WebApi.Authentication; +using Farseer.TerraformBackend.WebApi.Authentication; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -namespace Devpro.TerraformBackend.WebApi.Filters; +namespace Farseer.TerraformBackend.WebApi.Filters; public class TenantAuthorizationFilter : IActionFilter { diff --git a/src/WebApi/ImplicitUsings.cs b/src/WebApi/ImplicitUsings.cs index d116536..3e2f66c 100644 --- a/src/WebApi/ImplicitUsings.cs +++ b/src/WebApi/ImplicitUsings.cs @@ -1,7 +1,7 @@ -global using Devpro.Common.AspNetCore.DependencyInjection; -global using Devpro.Common.AspNetCore.Formatters; -global using Devpro.Common.AspNetCore.WebApi.Builder; -global using Devpro.Common.AspNetCore.WebApi.Configuration; -global using Devpro.Common.AspNetCore.WebApi.DependencyInjection; -global using Devpro.TerraformBackend.WebApi; -global using Devpro.TerraformBackend.WebApi.DependencyInjection; +global using Farseer.Common.AspNetCore.DependencyInjection; +global using Farseer.Common.AspNetCore.Formatters; +global using Farseer.Common.AspNetCore.WebApi.Builder; +global using Farseer.Common.AspNetCore.WebApi.Configuration; +global using Farseer.Common.AspNetCore.WebApi.DependencyInjection; +global using Farseer.TerraformBackend.WebApi; +global using Farseer.TerraformBackend.WebApi.DependencyInjection; diff --git a/src/WebApi/Properties/launchSettings.json b/src/WebApi/Properties/launchSettings.json index 1057a39..1ace3bd 100644 --- a/src/WebApi/Properties/launchSettings.json +++ b/src/WebApi/Properties/launchSettings.json @@ -9,7 +9,7 @@ "ASPNETCORE_ENVIRONMENT": "Development", "Application__IsHttpsRedirectionEnabled": "false", "Application__IsSwaggerEnabled": "true", - "Logging__LogLevel__Devpro": "Debug" + "Logging__LogLevel__Farseer": "Debug" }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:5293" @@ -22,7 +22,7 @@ "ASPNETCORE_ENVIRONMENT": "Development", "Application__IsHttpsRedirectionEnabled": "true", "Application__IsSwaggerEnabled": "true", - "Logging__LogLevel__Devpro": "Debug" + "Logging__LogLevel__Farseer": "Debug" }, "dotnetRunMessages": true, "applicationUrl": "https://localhost:7293;http://localhost:5293" diff --git a/src/WebApi/WebApi.csproj b/src/WebApi/WebApi.csproj index 2ea7686..a647438 100644 --- a/src/WebApi/WebApi.csproj +++ b/src/WebApi/WebApi.csproj @@ -2,18 +2,14 @@ net8.0 - Devpro.TerraformBackend.WebApi - Devpro.TerraformBackend.WebApi + Farseer.TerraformBackend.WebApi + Farseer.TerraformBackend.WebApi {5CD7A689-5ADB-4207-972E-6FA881AF1B1C} enable enable 78fb2134-a177-45da-a7e1-5800154c5f5b - - - - diff --git a/src/WebApi/appsettings.json b/src/WebApi/appsettings.json index e8a6552..c3ad226 100644 --- a/src/WebApi/appsettings.json +++ b/src/WebApi/appsettings.json @@ -5,13 +5,13 @@ "IsHttpsRedirectionEnabled": true }, "ConnectionStrings": { - "MongoDbLocal": "mongodb://localhost:27017/?readPreference=primary&appname=DevproTerraformBackendWebApi&directConnection=true&ssl=false" + "MongoDbLocal": "mongodb://localhost:27017/?readPreference=primary&appname=FarseerTerraformBackendWebApi&directConnection=true&ssl=false" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning", - "Devpro": "Information" + "Farseer": "Information" } }, "MongoDb": { diff --git a/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs b/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs index e5f763b..1220f24 100644 --- a/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs +++ b/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs @@ -1,9 +1,9 @@ -using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; +using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Moq; -namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Behaviors; +namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Behaviors; [Trait("Category", "IntegrationTests")] public class InvalidModelStateBehaviorTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs b/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs index dfa4df1..9ce2de6 100644 --- a/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs +++ b/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs @@ -1,6 +1,6 @@ using System.Net; -namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Http; +namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Http; internal static class HttpResponseMessageExtensions { diff --git a/test/WebApi.IntegrationTests/IntegrationTestBase.cs b/test/WebApi.IntegrationTests/IntegrationTestBase.cs index b54caa7..a85cf23 100644 --- a/test/WebApi.IntegrationTests/IntegrationTestBase.cs +++ b/test/WebApi.IntegrationTests/IntegrationTestBase.cs @@ -1,8 +1,8 @@ using System.Net.Http.Headers; -using Devpro.TerraformBackend.Domain.Models; +using Farseer.TerraformBackend.Domain.Models; using Microsoft.AspNetCore.Hosting; -namespace Devpro.TerraformBackend.WebApi.IntegrationTests; +namespace Farseer.TerraformBackend.WebApi.IntegrationTests; /// /// Ref. https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests diff --git a/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs b/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs index 7dcd555..b2359b0 100644 --- a/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs +++ b/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs @@ -1,6 +1,6 @@ -using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; +using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; -namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources; +namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Resources; [Trait("Category", "IntegrationTests")] public class HealthCheckResourceTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs b/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs index 6670ed8..06e80cc 100644 --- a/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs +++ b/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs @@ -1,7 +1,7 @@ using System.Net; -using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; +using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; -namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources; +namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Resources; [Trait("Category", "IntegrationTests")] public class StateControllerResourceTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs b/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs index b9980bf..f6faf32 100644 --- a/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs +++ b/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs @@ -1,6 +1,6 @@ -using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; +using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; -namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources; +namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Resources; [Trait("Category", "IntegrationTests")] public class SwaggerResourceTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj b/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj index bd05c3f..f3fcbac 100644 --- a/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj +++ b/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj @@ -2,8 +2,8 @@ net8.0 - Devpro.TerraformBackend.WebApi.IntegrationTests - Devpro.TerraformBackend.WebApi.IntegrationTests + Farseer.TerraformBackend.WebApi.IntegrationTests + Farseer.TerraformBackend.WebApi.IntegrationTests {B055FFAF-8261-43B1-866A-12E289D5D7DC} enable enable From 92ef5a50d33ed23e2b226def7c22c37c2724dc8e Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Wed, 23 Jul 2025 08:29:11 +0200 Subject: [PATCH 03/14] Update in appsettings and CONTRIBUTING --- CONTRIBUTING.md | 3 ++- src/WebApi/appsettings.json | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 53a0106..1d7b655 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,13 +32,14 @@ Name | Description * [HTTP backend](https://developer.hashicorp.com/terraform/language/backend/http) * [Remote state backend](https://github.com/hashicorp/terraform/tree/main/internal/backend/remote-state). -### References of other implementations +### Other community implementations * [GitLab](https://gitlab.com/gitlab-org/manage/import/gitlab/-/blob/master/doc/user/infrastructure/terraform_state.md) * [lib/api/terraform/state.rb](https://gitlab.com/gitlab-org/manage/import/gitlab/-/blob/master/lib/api/terraform/state.rb) * HTTP * [akshay/terraform-http-backend-pass](https://git.coop/akshay/terraform-http-backend-pass) * [bhoriuchi/terraform-backend-http](https://github.com/bhoriuchi/terraform-backend-http) + * [nimbolus/terraform-backend](https://github.com/nimbolus/terraform-backend) * git * [plumber-cd/terraform-backend-git](https://github.com/plumber-cd/terraform-backend-git) diff --git a/src/WebApi/appsettings.json b/src/WebApi/appsettings.json index c3ad226..10fa873 100644 --- a/src/WebApi/appsettings.json +++ b/src/WebApi/appsettings.json @@ -19,7 +19,7 @@ "DatabaseName": "terraform_backend_dev" }, "OpenApi": { - "Title": "Terraform Backend (REST API)", - "Version": "v1.0" + "Title": "Terraform Backend MongoDB", + "Version": "v1.1" } } From 1d433b29b1e0db43a648df7900b178e5be06707f Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Wed, 23 Jul 2025 10:50:36 +0200 Subject: [PATCH 04/14] Add docs for mkdocs site --- .markdownlint.yml | 5 ++++ .yamllint.yaml | 10 ++++++++ CONTRIBUTING.md | 45 ++++++++++++++++++++-------------- docs/.gitkeep | 0 docs/index.md | 11 +++++++++ docs/project.md | 10 ++++++++ docs/quickstart.md | 15 ++++++++++++ docs/setup.md | 44 +++++++++++++++++++++++++++++++++ docs/usage.md | 35 ++++++++++++++++++++++++++ mkdocs.yml | 42 +++++++++++++++++++++++++++++++ samples/docker-nginx/README.md | 2 +- 11 files changed, 199 insertions(+), 20 deletions(-) create mode 100644 .markdownlint.yml create mode 100644 .yamllint.yaml delete mode 100644 docs/.gitkeep create mode 100644 docs/index.md create mode 100644 docs/project.md create mode 100644 docs/quickstart.md create mode 100644 docs/setup.md create mode 100644 docs/usage.md create mode 100644 mkdocs.yml diff --git a/.markdownlint.yml b/.markdownlint.yml new file mode 100644 index 0000000..7c78c5f --- /dev/null +++ b/.markdownlint.yml @@ -0,0 +1,5 @@ +# ref. https://github.com/DavidAnson/markdownlint +default: true +MD013: + line_length: 180 +MD046: false diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..f8ef3a1 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,10 @@ +# ref. https://yamllint.readthedocs.io/en/stable/configuration.html +extends: default +rules: + document-start: disable + line-length: + level: warning + max: 120 + truthy: disable + tags: + disable: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d7b655..b7593ca 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,8 @@ # Project development guide -## Design +## Application -The application is entirely based on open-source, cross-platform (Linux/Windows), highly performant, free, object-oriented technologies: .NET / C#. +The code is entirely based on open-source, cross-platform (Linux/Windows), highly performant, free, object-oriented technologies: .NET / C#. ### Projects @@ -24,24 +24,27 @@ Name | Description `Swashbuckle.AspNetCore` | OpenAPI / Swagger generation `System.Text.Json` | JSON support -### Documentation +### Clients -* [OpenTofu](https://opentofu.org/) -* [MongoDB](https://www.mongodb.com/) -* [Terraform](https://www.terraform.io) - * [HTTP backend](https://developer.hashicorp.com/terraform/language/backend/http) - * [Remote state backend](https://github.com/hashicorp/terraform/tree/main/internal/backend/remote-state). +- [OpenTofu](https://opentofu.org/) +- [Terraform](https://www.terraform.io) + - [HTTP backend](https://developer.hashicorp.com/terraform/language/backend/http) + - [Remote state backend](https://github.com/hashicorp/terraform/tree/main/internal/backend/remote-state) + +### Backing services + +- [MongoDB](https://www.mongodb.com/) ### Other community implementations -* [GitLab](https://gitlab.com/gitlab-org/manage/import/gitlab/-/blob/master/doc/user/infrastructure/terraform_state.md) - * [lib/api/terraform/state.rb](https://gitlab.com/gitlab-org/manage/import/gitlab/-/blob/master/lib/api/terraform/state.rb) -* HTTP - * [akshay/terraform-http-backend-pass](https://git.coop/akshay/terraform-http-backend-pass) - * [bhoriuchi/terraform-backend-http](https://github.com/bhoriuchi/terraform-backend-http) - * [nimbolus/terraform-backend](https://github.com/nimbolus/terraform-backend) -* git - * [plumber-cd/terraform-backend-git](https://github.com/plumber-cd/terraform-backend-git) +- [GitLab](https://gitlab.com/gitlab-org/manage/import/gitlab/-/blob/master/doc/user/infrastructure/terraform_state.md) + - [lib/api/terraform/state.rb](https://gitlab.com/gitlab-org/manage/import/gitlab/-/blob/master/lib/api/terraform/state.rb) +- HTTP + - [akshay/terraform-http-backend-pass](https://git.coop/akshay/terraform-http-backend-pass) + - [bhoriuchi/terraform-backend-http](https://github.com/bhoriuchi/terraform-backend-http) + - [nimbolus/terraform-backend](https://github.com/nimbolus/terraform-backend) +- git + - [plumber-cd/terraform-backend-git](https://github.com/plumber-cd/terraform-backend-git) ## Automation @@ -89,8 +92,12 @@ dotnet run --project src/WebApi Open Swagger in a browser: [localhost:5293/swagger](http://localhost:5293/swagger). -## Backlog +## Documentation + +The documentation is a static website built with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/). -### New features +Run locally with: -* Store only one version of the state in tf_state and save the others in tf_state_revision +```bash +docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material +``` diff --git a/docs/.gitkeep b/docs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..266c3ef --- /dev/null +++ b/docs/index.md @@ -0,0 +1,11 @@ +# Welcome + +This project provides an HTTP backend for Terraform and OpenTofu that will save and manage state data from a MongoDB database. + +As the state is a JSON content, it makes sense to use the best-in-class database technology to work with it. + +The goal is to: + +- provide an highly available storage +- secure sensitive data +- query the data without an infrastructure automation tool diff --git a/docs/project.md b/docs/project.md new file mode 100644 index 0000000..7f64e6f --- /dev/null +++ b/docs/project.md @@ -0,0 +1,10 @@ +# Project + +## Backlog + +### V2.0 + +New features: + +- :material-square: Store in the database only one version of the state in tf_state (the latest) and save the others in tf_state_revision +- :material-square: Send traces, logs, metrics to OpenTelemetry Collector diff --git a/docs/quickstart.md b/docs/quickstart.md new file mode 100644 index 0000000..4609b65 --- /dev/null +++ b/docs/quickstart.md @@ -0,0 +1,15 @@ +# Quickstart + +Before looking at all the options, let's do a quick demonstration of the application. + +=== "Docker Compose" + + ```bash + docker compose + ``` + +=== "Docker" + + ```bash + docker ... + ``` diff --git a/docs/setup.md b/docs/setup.md new file mode 100644 index 0000000..a60d419 --- /dev/null +++ b/docs/setup.md @@ -0,0 +1,44 @@ +# Setup + +## Requirements + +### Database server + +Make sure you have access to a MongoDB database (with a connection string containing a user that have admin permissions). + +The MongoDB server can run: + +- On a machine from the binary +- On multiple machines from the binary +- In a container +- In a Kubernetes cluster +- In MongoDB Atlas (free tier available!) + +!!! warning + + Double check any network/security restrictions such as MongoDB IP access list as the application needs to access the MongoDB server + +### Database indexes + +Add indexes for optimal performances: + +```bash +docker run --rm --link mongodb \ + -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ + bash -c "mongosh mongodb://:/ /home/scripts/mongo-create-index.js" +``` + +## Installation + +### Kubernetes + +Use the official Helm chart: + +```bash +# adds the chart repository +helm repo add devpro https://devpro.github.io/helm-charts +helm repo update + +# installs the chart +helm upgrade --install tfbackend devpro/terraform-backend-mongodb --create-namespace --namespace tfbackend +``` diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 0000000..8b29c44 --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,35 @@ +# Usage + +## Tenant authentication + +API calls are secured through tenant isolation and user authentication, which are stored in the MongoDB database. + +You can add a user with the following script (replace the parameters): + +```bash +./scripts/mongo-create-user.sh myusername mypassword mytenant +docker run --rm --link mongodb \ + -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ + bash -c "mongosh mongodb://:/ /home/scripts/add-user.js" +``` + +## Client configuration + +In the tf file, configure the backend to use the REST API: + +```tf +terraform { + backend "http" { + address = "http:////state/" + lock_address = "http:////state//lock" + unlock_address = "http:////state//lock" + lock_method = "POST" + unlock_method = "DELETE" + username = "" + password = "" + #skip_cert_verification = "true" + } +} +``` + +And now, you can take advantage of a MongoDB backend for your Terraform/OpenTofu actions! diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..84ee1d9 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,42 @@ +site_name: Terraform Backend MongoDB +theme: + name: material + # logo: assets/logo.png + # favicon: images/favicon.png + language: en + features: + - navigation.footer + - content.tabs.link + - navigation.tabs + - navigation.path + - toc.integrate + palette: + - media: "(prefers-color-scheme: dark)" + scheme: slate + toggle: + icon: material/brightness-4 + name: Switch to light mode + - media: "(prefers-color-scheme: light)" + scheme: default + toggle: + icon: material/brightness-7 + name: Switch to dark mode +repo_url: https://github.com/devpro/terraform-backend-mongodb +extra: + generator: false +nav: + - index.md + - quickstart.md + - setup.md + - usage.md + - project.md +markdown_extensions: + - admonition + - pymdownx.details + - pymdownx.superfences + - pymdownx.tabbed: + alternate_style: true + - attr_list + - pymdownx.emoji: + emoji_index: !!python/name:material.extensions.emoji.twemoji + emoji_generator: !!python/name:material.extensions.emoji.to_svg diff --git a/samples/docker-nginx/README.md b/samples/docker-nginx/README.md index 8c1fba6..ef52b1e 100644 --- a/samples/docker-nginx/README.md +++ b/samples/docker-nginx/README.md @@ -10,7 +10,7 @@ The following tools must be available from the command line: - [.NET](https://dotnet.microsoft.com/download) or an IDE (Visual Studio or Rider) - [Terraform](https://developer.hashicorp.com/terraform/install) or [OpenTofu](https://opentofu.org/docs/intro/install/) - Docker - + ## Workflow Run the application (example given for information but feel free to start from the IDE): From 74d77749e3b4c064b5f6d36f17938d2c5b840f7c Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Thu, 24 Jul 2025 10:07:49 +0200 Subject: [PATCH 05/14] Add GitHub Action for Pages --- .github/workflows/ci.yaml | 12 +++++++----- .github/workflows/pages.yaml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/pkg.yaml | 8 ++++---- CONTRIBUTING.md | 18 ------------------ docs/project.md | 19 +++++++++++++++++++ 5 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/pages.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7cd7ab5..a21427b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,14 +1,16 @@ # purpose: run Continuous Integration (build, unit test, lint, scan) -# variables: [ SONAR_HOST_URL, SONAR_ORG, SONAR_PROJECT_KEY ] -# secrets: [ SONAR_TOKEN ] +# variables: [SONAR_HOST_URL, SONAR_ORG, SONAR_PROJECT_KEY] +# secrets: [SONAR_TOKEN] name: CI on: push: - branches: ["main"] + branches: + - main pull_request: - branches: ["main"] + branches: + - main workflow_dispatch: {} concurrency: @@ -35,7 +37,7 @@ jobs: path: workflow-parts - name: Start MongoDB uses: ./workflow-parts/mongodb/start - - name: Initialize database + - name: Initialize database (indexes, tenants & users) run: | mongosh mongodb://localhost:27017/terraform_backend_dev scripts/mongo-create-index.js sudo apt-get -y install apache2-utils diff --git a/.github/workflows/pages.yaml b/.github/workflows/pages.yaml new file mode 100644 index 0000000..c3fbadc --- /dev/null +++ b/.github/workflows/pages.yaml @@ -0,0 +1,32 @@ +name: Pages + +on: + push: + branches: + - main + workflow_dispatch: {} + +permissions: + contents: write + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Configure Git Credentials + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + - uses: actions/cache@v4 + with: + key: mkdocs-material-${{ env.cache_id }} + path: ~/.cache + restore-keys: | + mkdocs-material- + - run: pip install mkdocs-material + - run: mkdocs gh-deploy --force diff --git a/.github/workflows/pkg.yaml b/.github/workflows/pkg.yaml index cd9a3b0..6f8fc46 100644 --- a/.github/workflows/pkg.yaml +++ b/.github/workflows/pkg.yaml @@ -1,13 +1,13 @@ # purpose: run Continuous Delivery / Packaging (package) # variables: [] -# secrets: [ DOCKERHUB_USERNAME, DOCKERHUB_TOKEN ] - +# secrets: [DOCKERHUB_USERNAME, DOCKERHUB_TOKEN] + name: PKG on: push: - branches: ["main"] - # tags: [ 'v*.*.*' ] + branches: + - main workflow_dispatch: {} jobs: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b7593ca..003123a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,24 +46,6 @@ Name | Description - git - [plumber-cd/terraform-backend-git](https://github.com/plumber-cd/terraform-backend-git) -## Automation - -### Build (CI/CD pipelines) - -GitHub Actions are triggered to automate the integration and delivery of the application: - -- [CI](.github/workflows/ci.yaml) -- [PKG](.github/workflows/pkg.yaml) - -GitHub project has been configured, in **General** / **Security** / **Secrets and Variables** / **Actions**: - -- DOCKERHUB_TOKEN -- DOCKERHUB_USERNAME -- SONAR_HOST_URL -- SONAR_ORG -- SONAR_PROJECT_KEY -- SONAR_TOKEN - ## Procedures ### Run locally the application diff --git a/docs/project.md b/docs/project.md index 7f64e6f..630019c 100644 --- a/docs/project.md +++ b/docs/project.md @@ -1,5 +1,24 @@ # Project +## Automation + +### CI/CD pipelines + +GitHub Actions are triggered to automate the integration and delivery of the application: + +- [CI](../.github/workflows/ci.yaml) +- [Pages](../.github/workflows/pages.yaml) +- [PKG](../.github/workflows/pkg.yaml) + +GitHub configuration (**General** / **Security** / **Secrets and Variables** / **Actions**): + +- DOCKERHUB_TOKEN +- DOCKERHUB_USERNAME +- SONAR_HOST_URL +- SONAR_ORG +- SONAR_PROJECT_KEY +- SONAR_TOKEN + ## Backlog ### V2.0 From 1490c6e442ea896c9a0b43edc956170215201b09 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Thu, 24 Jul 2025 10:16:30 +0200 Subject: [PATCH 06/14] Update README --- README.md | 36 +++++------------------------------- docs/quickstart.md | 11 +++++++++-- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index fc24a94..8d99242 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,17 @@ # MongoDB HTTP backend for Terraform/OpenTofu state [![CI](https://github.com/devpro/terraform-backend-mongodb/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/devpro/terraform-backend-mongodb/actions/workflows/ci.yaml) +[![Pages](https://github.com/devpro/terraform-backend-mongodb/actions/workflows/pages.yaml/badge.svg?branch=main)](https://github.com/devpro/terraform-backend-mongodb/actions/workflows/pages.yaml) [![PKG](https://github.com/devpro/terraform-backend-mongodb/actions/workflows/pkg.yaml/badge.svg?branch=main)](https://github.com/devpro/terraform-backend-mongodb/actions/workflows/pkg.yaml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=devpro_terraform-backend-mongodb&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=devpro_terraform-backend-mongodb) [![Docker Image Version](https://img.shields.io/docker/v/devprofr/terraform-backend-mongodb?label=Image&logo=docker)](https://hub.docker.com/r/devprofr/terraform-backend-mongodb) Manage Terraform/OpenTofu state through a secured REST API and take advatange of MongoDB greatness! -The [project development guide](CONTRIBUTING.md) provides the implementation details. +## Getting started -## Quick start +Best place to start is the [documentation](https://devpro.github.io/terraform-backend-mongodb/). -1. Make sure a you have access to a MongoDB database +## Going further -2. Configure the application with the MongoDB database connection information - -2. Run the web API - -3. Update the Terraform file - -```tf -terraform { - backend "http" { - address = "//state/" - lock_address = "//state//lock" - unlock_address = "//state//lock" - lock_method = "POST" - unlock_method = "DELETE" - username = "" - password = "" - # uncomment if HTTPS certificate is not valid - # skip_cert_verification = "true" - } -} -``` - -4. Execute usual Terraform command lines - -## Samples - -* [Make local actions on files](samples/local-files/README.md) -* [Run NGINX container with Docker](samples/docker-nginx/README.md) +Technical implementation is described in the [project development guide](CONTRIBUTING.md). diff --git a/docs/quickstart.md b/docs/quickstart.md index 4609b65..964f18b 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -1,15 +1,22 @@ # Quickstart +## Demo + Before looking at all the options, let's do a quick demonstration of the application. -=== "Docker Compose" +=== "Containers (Docker Compose)" ```bash docker compose ``` -=== "Docker" +=== "Kubernetes (Helm)" ```bash docker ... ``` + +## Samples + +* [Make local actions on files](samples/local-files/README.md) +* [Run NGINX container with Docker](samples/docker-nginx/README.md) From 182e35c8ea5b629aa398a158958cd211e8ece70b Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Fri, 25 Jul 2025 15:12:27 +0200 Subject: [PATCH 07/14] Updated docs --- .markdownlint.yml | 2 +- CONTRIBUTING.md | 2 +- README.md | 4 ++-- docs/index.md | 8 ++++---- docs/quickstart.md | 2 +- docs/setup.md | 22 +++++++++++++++------- docs/usage.md | 23 ++++++++++++++++------- 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/.markdownlint.yml b/.markdownlint.yml index 7c78c5f..03c928b 100644 --- a/.markdownlint.yml +++ b/.markdownlint.yml @@ -1,5 +1,5 @@ # ref. https://github.com/DavidAnson/markdownlint default: true MD013: - line_length: 180 + line_length: 240 MD046: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 003123a..9bbd0e8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Project development guide +# Contribution guide ## Application diff --git a/README.md b/README.md index 8d99242..d43226e 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ Manage Terraform/OpenTofu state through a secured REST API and take advatange of ## Getting started -Best place to start is the [documentation](https://devpro.github.io/terraform-backend-mongodb/). +Best place to start is the [documentation website](https://devpro.github.io/terraform-backend-mongodb/). ## Going further -Technical implementation is described in the [project development guide](CONTRIBUTING.md). +Technical implementation is described in the [contribution guide](CONTRIBUTING.md). diff --git a/docs/index.md b/docs/index.md index 266c3ef..0f313b9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,11 +1,11 @@ # Welcome -This project provides an HTTP backend for Terraform and OpenTofu that will save and manage state data from a MongoDB database. +This project provides an HTTP backend for Terraform and OpenTofu that will save and manage state data in a MongoDB database. As the state is a JSON content, it makes sense to use the best-in-class database technology to work with it. The goal is to: -- provide an highly available storage -- secure sensitive data -- query the data without an infrastructure automation tool +- provide an highly available, and performant, storage +- share a secured access to sensitive information +- value the infrastructure data diff --git a/docs/quickstart.md b/docs/quickstart.md index 964f18b..c7c3de5 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -13,7 +13,7 @@ Before looking at all the options, let's do a quick demonstration of the applica === "Kubernetes (Helm)" ```bash - docker ... + helm upgrade --install tfbackend https://github.com/devpro/helm-charts/releases/download/terraform-backend-mongodb-0.1.0/terraform-backend-mongodb-0.1.0.tgz --create-namespace --namespace tfbackend ``` ## Samples diff --git a/docs/setup.md b/docs/setup.md index a60d419..af8c6d8 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -8,8 +8,8 @@ Make sure you have access to a MongoDB database (with a connection string contai The MongoDB server can run: -- On a machine from the binary -- On multiple machines from the binary +- On a machine from binaries +- On multiple machines binaries - In a container - In a Kubernetes cluster - In MongoDB Atlas (free tier available!) @@ -22,11 +22,19 @@ The MongoDB server can run: Add indexes for optimal performances: -```bash -docker run --rm --link mongodb \ - -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ - bash -c "mongosh mongodb://:/ /home/scripts/mongo-create-index.js" -``` +=== "Container (Docker)" + + ```bash + docker run --rm --link mongodb \ + -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ + bash -c "mongosh mongodb://:/ /home/scripts/mongo-create-index.js" + ``` + +=== "Client (mongosh)" + + ```bash + mongosh mongodb://:/ ./scripts/mongo-create-index.js + ``` ## Installation diff --git a/docs/usage.md b/docs/usage.md index 8b29c44..a989709 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -4,14 +4,23 @@ API calls are secured through tenant isolation and user authentication, which are stored in the MongoDB database. -You can add a user with the following script (replace the parameters): +You can add a user with the following commands (replace the parameters): -```bash -./scripts/mongo-create-user.sh myusername mypassword mytenant -docker run --rm --link mongodb \ - -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ - bash -c "mongosh mongodb://:/ /home/scripts/add-user.js" -``` +=== "Container (Docker)" + + ```bash + ./scripts/mongo-create-user.sh myusername mypassword mytenant + docker run --rm --link mongodb \ + -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ + bash -c "mongosh mongodb://:/ /home/scripts/add-user.js" + ``` + +=== "Client (mongosh)" + + ```bash + ./scripts/mongo-create-user.sh myusername mypassword mytenant + mongosh mongodb://:/ ./scripts/add-user.js + ``` ## Client configuration From 1d4aaa266c9cd56b1954b6a6f9b951782ed6fcd5 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Fri, 25 Jul 2025 15:12:46 +0200 Subject: [PATCH 08/14] Change license to AGPL3 --- LICENSE | 149 ++++++++++++++++++++++++++------------------------------ 1 file changed, 68 insertions(+), 81 deletions(-) diff --git a/LICENSE b/LICENSE index f288702..0ad25db 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies @@ -7,17 +7,15 @@ Preamble - The GNU General Public License is a free, copyleft license for -software and other kinds of works. + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to +our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. +software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you @@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. The precise terms and conditions for copying, distribution and modification follow. @@ -72,7 +60,7 @@ modification follow. 0. Definitions. - "This License" refers to version 3 of the GNU General Public License. + "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. @@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. - 13. Use with the GNU Affero General Public License. + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single +under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General +Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published +GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's +versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. @@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Affero General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see +For more information on this, and how to apply and follow the GNU AGPL, see . - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. From dbd65f770ca5a340dd7e2419643df37fc464f4a3 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Fri, 25 Jul 2025 15:13:56 +0200 Subject: [PATCH 09/14] Rollback rename of Devpro to Farseer --- ...er.TerraformBackend.sln => TerraformBackend.sln | 0 compose.yaml | 4 ++-- .../Authentication/BasicAuthenticationClient.cs | 2 +- .../Authentication/BasicAuthenticationDefaults.cs | 2 +- .../Authentication/BasicAuthorizationAttribute.cs | 2 +- .../Builder/PolicyBuilderExtensions.cs | 4 ++-- .../Builder/SwaggerBuilderExtensions.cs | 4 ++-- .../Common.AspNetCore.WebApi.csproj | 4 ++-- .../Configuration/WebApiConfiguration.cs | 2 +- .../SwaggerServiceCollectionExtensions.cs | 4 ++-- src/Common.AspNetCore/Common.AspNetCore.csproj | 4 ++-- .../BehaviorServiceCollectionExtensions.cs | 2 +- .../Formatters/RawRequestBodyFormatter.cs | 2 +- src/Common.MongoDb/Common.MongoDb.csproj | 4 ++-- src/Common.MongoDb/DefaultMongoClientFactory.cs | 2 +- src/Common.MongoDb/IMongoClientFactory.cs | 2 +- src/Common.MongoDb/MongoDbConfiguration.cs | 2 +- src/Common.MongoDb/RepositoryBase.cs | 2 +- src/Domain/Domain.csproj | 4 ++-- src/Domain/Models/StateLockModel.cs | 4 ++-- src/Domain/Models/StateModel.cs | 2 +- src/Domain/Models/StateValueModel.cs | 2 +- src/Domain/Models/UserModel.cs | 2 +- src/Domain/Repositories/IStateLockRepository.cs | 4 ++-- src/Domain/Repositories/IStateRepository.cs | 2 +- src/Domain/Repositories/IUserRepository.cs | 4 ++-- .../Infrastructure.MongoDb.csproj | 4 ++-- .../Repositories/StateLockRepository.cs | 8 ++++---- .../Repositories/StateRepository.cs | 6 +++--- .../Repositories/UserRepository.cs | 8 ++++---- src/WebApi/ApplicationConfiguration.cs | 4 ++-- .../Authentication/BasicAuthenticationHandler.cs | 6 +++--- .../Authentication/ClaimsPrincipalExtensions.cs | 2 +- src/WebApi/Controllers/StateController.cs | 8 ++++---- .../AuthenticationServiceCollectionExtensions.cs | 6 +++--- .../InfrastructureServiceCollectionExtensions.cs | 2 +- src/WebApi/Dockerfile | 2 +- src/WebApi/Filters/TenantAuthorizationFilter.cs | 4 ++-- src/WebApi/ImplicitUsings.cs | 14 +++++++------- src/WebApi/Properties/launchSettings.json | 4 ++-- src/WebApi/WebApi.csproj | 4 ++-- src/WebApi/appsettings.json | 4 ++-- .../Behaviors/InvalidModelStateBehaviorTest.cs | 4 ++-- .../Http/HttpResponseMessageExtensions.cs | 2 +- .../WebApi.IntegrationTests/IntegrationTestBase.cs | 4 ++-- .../Resources/HealthCheckResourceTest.cs | 4 ++-- .../Resources/StateControllerResourceTest.cs | 4 ++-- .../Resources/SwaggerResourceTest.cs | 4 ++-- .../WebApi.IntegrationTests.csproj | 4 ++-- 49 files changed, 92 insertions(+), 92 deletions(-) rename Farseer.TerraformBackend.sln => TerraformBackend.sln (100%) diff --git a/Farseer.TerraformBackend.sln b/TerraformBackend.sln similarity index 100% rename from Farseer.TerraformBackend.sln rename to TerraformBackend.sln diff --git a/compose.yaml b/compose.yaml index b56061b..fe34055 100644 --- a/compose.yaml +++ b/compose.yaml @@ -9,10 +9,10 @@ services: - Application__IsHttpsRedirectionEnabled=false - Application__IsOpenTelemetryEnabled=false - Application__IsSwaggerEnabled=true - - ConnectionStrings__MongoDbLocal=mongodb://mongodb:27017/?readPreference=primary&appname=FarseerTerraformBackendWebApi&directConnection=true&ssl=false + - ConnectionStrings__MongoDbLocal=mongodb://mongodb:27017/?readPreference=primary&appname=DevproTerraformBackendWebApi&directConnection=true&ssl=false - Logging__LogLevel__Default=Debug - Logging__LogLevel__Microsoft__AspNetCore=Information - - Logging__LogLevel__Farseer=Debug + - Logging__LogLevel__Devpro=Debug - MongoDb__ConnectionStringName=MongoDbLocal - MongoDb__DatabaseName=terraform_backend_dev ports: diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs index cfe8e59..cb608c7 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationClient.cs @@ -1,6 +1,6 @@ using System.Security.Principal; -namespace Farseer.Common.AspNetCore.WebApi.Authentication; +namespace Devpro.Common.AspNetCore.WebApi.Authentication; public class BasicAuthenticationClient : IIdentity { diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs index 627f8f6..2310fab 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs @@ -1,4 +1,4 @@ -namespace Farseer.Common.AspNetCore.WebApi.Authentication; +namespace Devpro.Common.AspNetCore.WebApi.Authentication; public class BasicAuthenticationDefaults { diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs index e1f0e78..55f884e 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthorizationAttribute.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Authorization; -namespace Farseer.Common.AspNetCore.WebApi.Authentication; +namespace Devpro.Common.AspNetCore.WebApi.Authentication; public class BasicAuthorizationAttribute : AuthorizeAttribute { diff --git a/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs b/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs index 3fc53a1..b5780c4 100644 --- a/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs +++ b/src/Common.AspNetCore.WebApi/Builder/PolicyBuilderExtensions.cs @@ -1,7 +1,7 @@ -using Farseer.Common.AspNetCore.WebApi.Configuration; +using Devpro.Common.AspNetCore.WebApi.Configuration; using Microsoft.AspNetCore.Builder; -namespace Farseer.Common.AspNetCore.WebApi.Builder; +namespace Devpro.Common.AspNetCore.WebApi.Builder; public static class PolicyBuilderExtensions { diff --git a/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs b/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs index 16a6724..9bd4b27 100644 --- a/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs +++ b/src/Common.AspNetCore.WebApi/Builder/SwaggerBuilderExtensions.cs @@ -1,7 +1,7 @@ -using Farseer.Common.AspNetCore.WebApi.Configuration; +using Devpro.Common.AspNetCore.WebApi.Configuration; using Microsoft.AspNetCore.Builder; -namespace Farseer.Common.AspNetCore.WebApi.Builder; +namespace Devpro.Common.AspNetCore.WebApi.Builder; public static class SwaggerBuilderExtensions { diff --git a/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj b/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj index 379d16a..eebeae5 100644 --- a/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj +++ b/src/Common.AspNetCore.WebApi/Common.AspNetCore.WebApi.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.Common.AspNetCore.WebApi - Farseer.Common.AspNetCore.WebApi + Devpro.Common.AspNetCore.WebApi + Devpro.Common.AspNetCore.WebApi {19336002-C959-4E76-B112-861F93CF6423} enable enable diff --git a/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs b/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs index c2d06ce..eee1be5 100644 --- a/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs +++ b/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.OpenApi.Models; -namespace Farseer.Common.AspNetCore.WebApi.Configuration; +namespace Devpro.Common.AspNetCore.WebApi.Configuration; public class WebApiConfiguration(IConfigurationRoot configurationRoot) { diff --git a/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs b/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs index 5984bee..212d532 100644 --- a/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs +++ b/src/Common.AspNetCore.WebApi/DependencyInjection/SwaggerServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using Farseer.Common.AspNetCore.WebApi.Configuration; +using Devpro.Common.AspNetCore.WebApi.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; -namespace Farseer.Common.AspNetCore.WebApi.DependencyInjection; +namespace Devpro.Common.AspNetCore.WebApi.DependencyInjection; public static class SwaggerServiceCollectionExtensions { diff --git a/src/Common.AspNetCore/Common.AspNetCore.csproj b/src/Common.AspNetCore/Common.AspNetCore.csproj index e0a48e0..7c7b11e 100644 --- a/src/Common.AspNetCore/Common.AspNetCore.csproj +++ b/src/Common.AspNetCore/Common.AspNetCore.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.Common.AspNetCore - Farseer.Common.AspNetCore + Devpro.Common.AspNetCore + Devpro.Common.AspNetCore {F23098F5-355B-46F0-BABE-3D6E23D8EED7} enable diff --git a/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs b/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs index 2325645..1c04a40 100644 --- a/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs +++ b/src/Common.AspNetCore/DependencyInjection/BehaviorServiceCollectionExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -namespace Farseer.Common.AspNetCore.DependencyInjection; +namespace Devpro.Common.AspNetCore.DependencyInjection; public static class BehaviorServiceCollectionExtensions { diff --git a/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs b/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs index ce73aa0..3e88cce 100644 --- a/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs +++ b/src/Common.AspNetCore/Formatters/RawRequestBodyFormatter.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Net.Http.Headers; -namespace Farseer.Common.AspNetCore.Formatters; +namespace Devpro.Common.AspNetCore.Formatters; /// /// ASP.NET Core input formatter to manage raw request bodies. diff --git a/src/Common.MongoDb/Common.MongoDb.csproj b/src/Common.MongoDb/Common.MongoDb.csproj index 6e15124..9711fa2 100644 --- a/src/Common.MongoDb/Common.MongoDb.csproj +++ b/src/Common.MongoDb/Common.MongoDb.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.Common.MongoDb - Farseer.Common.MongoDb + Devpro.Common.MongoDb + Devpro.Common.MongoDb {49BF313A-4ED3-4BD2-9AEE-E44A5ED19C0C} enable diff --git a/src/Common.MongoDb/DefaultMongoClientFactory.cs b/src/Common.MongoDb/DefaultMongoClientFactory.cs index a8984eb..5db07c5 100644 --- a/src/Common.MongoDb/DefaultMongoClientFactory.cs +++ b/src/Common.MongoDb/DefaultMongoClientFactory.cs @@ -2,7 +2,7 @@ using MongoDB.Bson.Serialization.Conventions; using MongoDB.Driver; -namespace Farseer.Common.MongoDb; +namespace Devpro.Common.MongoDb; public class DefaultMongoClientFactory : IMongoClientFactory { diff --git a/src/Common.MongoDb/IMongoClientFactory.cs b/src/Common.MongoDb/IMongoClientFactory.cs index 428ec87..a6c282d 100644 --- a/src/Common.MongoDb/IMongoClientFactory.cs +++ b/src/Common.MongoDb/IMongoClientFactory.cs @@ -1,6 +1,6 @@ using MongoDB.Driver; -namespace Farseer.Common.MongoDb; +namespace Devpro.Common.MongoDb; /// /// Avoids calling "new" in application code. diff --git a/src/Common.MongoDb/MongoDbConfiguration.cs b/src/Common.MongoDb/MongoDbConfiguration.cs index 4e4c66f..6236c43 100644 --- a/src/Common.MongoDb/MongoDbConfiguration.cs +++ b/src/Common.MongoDb/MongoDbConfiguration.cs @@ -1,4 +1,4 @@ -namespace Farseer.Common.MongoDb; +namespace Devpro.Common.MongoDb; public class MongoDbConfiguration { diff --git a/src/Common.MongoDb/RepositoryBase.cs b/src/Common.MongoDb/RepositoryBase.cs index e7e162d..f0dc8c1 100644 --- a/src/Common.MongoDb/RepositoryBase.cs +++ b/src/Common.MongoDb/RepositoryBase.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace Farseer.Common.MongoDb; +namespace Devpro.Common.MongoDb; public abstract class RepositoryBase { diff --git a/src/Domain/Domain.csproj b/src/Domain/Domain.csproj index 25457ca..ae3da51 100644 --- a/src/Domain/Domain.csproj +++ b/src/Domain/Domain.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.TerraformBackend.Domain - Farseer.TerraformBackend.Domain + Devpro.TerraformBackend.Domain + Devpro.TerraformBackend.Domain {A5CAD112-C1E6-442B-BE0E-37C697030636} enable diff --git a/src/Domain/Models/StateLockModel.cs b/src/Domain/Models/StateLockModel.cs index 6a46717..af0be9b 100644 --- a/src/Domain/Models/StateLockModel.cs +++ b/src/Domain/Models/StateLockModel.cs @@ -2,7 +2,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -namespace Farseer.TerraformBackend.Domain.Models; +namespace Devpro.TerraformBackend.Domain.Models; public class StateLockModel { @@ -15,7 +15,7 @@ public class StateLockModel public string Id { get; set; } = null!; /// - /// + /// /// public string Tenant { get; set; } = string.Empty; diff --git a/src/Domain/Models/StateModel.cs b/src/Domain/Models/StateModel.cs index 7e9318b..7ed19b2 100644 --- a/src/Domain/Models/StateModel.cs +++ b/src/Domain/Models/StateModel.cs @@ -2,7 +2,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -namespace Farseer.TerraformBackend.Domain.Models; +namespace Devpro.TerraformBackend.Domain.Models; public class StateModel { diff --git a/src/Domain/Models/StateValueModel.cs b/src/Domain/Models/StateValueModel.cs index 7a2e486..cb97ed6 100644 --- a/src/Domain/Models/StateValueModel.cs +++ b/src/Domain/Models/StateValueModel.cs @@ -1,6 +1,6 @@ using MongoDB.Bson.Serialization.Attributes; -namespace Farseer.TerraformBackend.Domain.Models; +namespace Devpro.TerraformBackend.Domain.Models; public class StateValueModel { diff --git a/src/Domain/Models/UserModel.cs b/src/Domain/Models/UserModel.cs index 1b51295..89a2a5e 100644 --- a/src/Domain/Models/UserModel.cs +++ b/src/Domain/Models/UserModel.cs @@ -1,7 +1,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -namespace Farseer.TerraformBackend.Domain.Models; +namespace Devpro.TerraformBackend.Domain.Models; public class UserModel { diff --git a/src/Domain/Repositories/IStateLockRepository.cs b/src/Domain/Repositories/IStateLockRepository.cs index b1404f8..9059e31 100644 --- a/src/Domain/Repositories/IStateLockRepository.cs +++ b/src/Domain/Repositories/IStateLockRepository.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -using Farseer.TerraformBackend.Domain.Models; +using Devpro.TerraformBackend.Domain.Models; -namespace Farseer.TerraformBackend.Domain.Repositories; +namespace Devpro.TerraformBackend.Domain.Repositories; public interface IStateLockRepository { diff --git a/src/Domain/Repositories/IStateRepository.cs b/src/Domain/Repositories/IStateRepository.cs index ab4e42f..c45f919 100644 --- a/src/Domain/Repositories/IStateRepository.cs +++ b/src/Domain/Repositories/IStateRepository.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Farseer.TerraformBackend.Domain.Repositories; +namespace Devpro.TerraformBackend.Domain.Repositories; public interface IStateRepository { diff --git a/src/Domain/Repositories/IUserRepository.cs b/src/Domain/Repositories/IUserRepository.cs index 5e7f2bf..8cbe7e7 100644 --- a/src/Domain/Repositories/IUserRepository.cs +++ b/src/Domain/Repositories/IUserRepository.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; -using Farseer.TerraformBackend.Domain.Models; +using Devpro.TerraformBackend.Domain.Models; -namespace Farseer.TerraformBackend.Domain.Repositories; +namespace Devpro.TerraformBackend.Domain.Repositories; public interface IUserRepository { diff --git a/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj b/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj index 3a1a43c..23796c6 100644 --- a/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj +++ b/src/Infrastructure.MongoDb/Infrastructure.MongoDb.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.TerraformBackend.Infrastructure.MongoDb - Farseer.TerraformBackend.Infrastructure.MongoDb + Devpro.TerraformBackend.Infrastructure.MongoDb + Devpro.TerraformBackend.Infrastructure.MongoDb {0429A41A-2D3A-42D4-8736-5FC0F6F0FF0C} enable diff --git a/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs b/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs index b0909f6..9584e2d 100644 --- a/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs +++ b/src/Infrastructure.MongoDb/Repositories/StateLockRepository.cs @@ -1,11 +1,11 @@ using System.Threading.Tasks; -using Farseer.Common.MongoDb; -using Farseer.TerraformBackend.Domain.Models; -using Farseer.TerraformBackend.Domain.Repositories; +using Devpro.Common.MongoDb; +using Devpro.TerraformBackend.Domain.Models; +using Devpro.TerraformBackend.Domain.Repositories; using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace Farseer.TerraformBackend.Infrastructure.MongoDb.Repositories; +namespace Devpro.TerraformBackend.Infrastructure.MongoDb.Repositories; public class StateLockRepository : RepositoryBase, IStateLockRepository { diff --git a/src/Infrastructure.MongoDb/Repositories/StateRepository.cs b/src/Infrastructure.MongoDb/Repositories/StateRepository.cs index d523605..a7e423f 100644 --- a/src/Infrastructure.MongoDb/Repositories/StateRepository.cs +++ b/src/Infrastructure.MongoDb/Repositories/StateRepository.cs @@ -1,12 +1,12 @@ using System; using System.Threading.Tasks; -using Farseer.Common.MongoDb; -using Farseer.TerraformBackend.Domain.Repositories; +using Devpro.Common.MongoDb; +using Devpro.TerraformBackend.Domain.Repositories; using Microsoft.Extensions.Logging; using MongoDB.Bson; using MongoDB.Driver; -namespace Farseer.TerraformBackend.Infrastructure.MongoDb.Repositories; +namespace Devpro.TerraformBackend.Infrastructure.MongoDb.Repositories; public class StateRepository : RepositoryBase, IStateRepository { diff --git a/src/Infrastructure.MongoDb/Repositories/UserRepository.cs b/src/Infrastructure.MongoDb/Repositories/UserRepository.cs index d6555f9..0066234 100644 --- a/src/Infrastructure.MongoDb/Repositories/UserRepository.cs +++ b/src/Infrastructure.MongoDb/Repositories/UserRepository.cs @@ -1,11 +1,11 @@ using System.Threading.Tasks; -using Farseer.Common.MongoDb; -using Farseer.TerraformBackend.Domain.Models; -using Farseer.TerraformBackend.Domain.Repositories; +using Devpro.Common.MongoDb; +using Devpro.TerraformBackend.Domain.Models; +using Devpro.TerraformBackend.Domain.Repositories; using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace Farseer.TerraformBackend.Infrastructure.MongoDb.Repositories; +namespace Devpro.TerraformBackend.Infrastructure.MongoDb.Repositories; public class UserRepository : RepositoryBase, IUserRepository { diff --git a/src/WebApi/ApplicationConfiguration.cs b/src/WebApi/ApplicationConfiguration.cs index 00faad6..bc58750 100644 --- a/src/WebApi/ApplicationConfiguration.cs +++ b/src/WebApi/ApplicationConfiguration.cs @@ -1,6 +1,6 @@ -using Farseer.Common.MongoDb; +using Devpro.Common.MongoDb; -namespace Farseer.TerraformBackend.WebApi; +namespace Devpro.TerraformBackend.WebApi; public class ApplicationConfiguration(IConfigurationRoot configurationRoot) : WebApiConfiguration(configurationRoot) diff --git a/src/WebApi/Authentication/BasicAuthenticationHandler.cs b/src/WebApi/Authentication/BasicAuthenticationHandler.cs index 049d922..48a0d22 100644 --- a/src/WebApi/Authentication/BasicAuthenticationHandler.cs +++ b/src/WebApi/Authentication/BasicAuthenticationHandler.cs @@ -1,12 +1,12 @@ using System.Security.Claims; using System.Text; using System.Text.Encodings.Web; -using Farseer.Common.AspNetCore.WebApi.Authentication; -using Farseer.TerraformBackend.Domain.Repositories; +using Devpro.Common.AspNetCore.WebApi.Authentication; +using Devpro.TerraformBackend.Domain.Repositories; using Microsoft.AspNetCore.Authentication; using Microsoft.Extensions.Options; -namespace Farseer.TerraformBackend.WebApi.Authentication; +namespace Devpro.TerraformBackend.WebApi.Authentication; public class BasicAuthenticationHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, IUserRepository userRepository) : AuthenticationHandler(options, logger, encoder) diff --git a/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs b/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs index c907201..d654273 100644 --- a/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs +++ b/src/WebApi/Authentication/ClaimsPrincipalExtensions.cs @@ -1,6 +1,6 @@ using System.Security.Claims; -namespace Farseer.TerraformBackend.WebApi.Authentication; +namespace Devpro.TerraformBackend.WebApi.Authentication; public static class ClaimsPrincipalExtensions { diff --git a/src/WebApi/Controllers/StateController.cs b/src/WebApi/Controllers/StateController.cs index 920e591..b796fa0 100644 --- a/src/WebApi/Controllers/StateController.cs +++ b/src/WebApi/Controllers/StateController.cs @@ -1,11 +1,11 @@ using System.Text.Json; -using Farseer.TerraformBackend.Domain.Models; -using Farseer.TerraformBackend.Domain.Repositories; -using Farseer.TerraformBackend.WebApi.Filters; +using Devpro.TerraformBackend.Domain.Models; +using Devpro.TerraformBackend.Domain.Repositories; +using Devpro.TerraformBackend.WebApi.Filters; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -namespace Farseer.TerraformBackend.WebApi.Controllers; +namespace Devpro.TerraformBackend.WebApi.Controllers; [Authorize] [ApiController] diff --git a/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs b/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs index bf6b562..97937e8 100644 --- a/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs +++ b/src/WebApi/DependencyInjection/AuthenticationServiceCollectionExtensions.cs @@ -1,8 +1,8 @@ -using Farseer.Common.AspNetCore.WebApi.Authentication; -using Farseer.TerraformBackend.WebApi.Authentication; +using Devpro.Common.AspNetCore.WebApi.Authentication; +using Devpro.TerraformBackend.WebApi.Authentication; using Microsoft.AspNetCore.Authentication; -namespace Farseer.TerraformBackend.WebApi.DependencyInjection; +namespace Devpro.TerraformBackend.WebApi.DependencyInjection; public static class AuthenticationServiceCollectionExtensions { diff --git a/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs b/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs index f7501f7..8105f3a 100644 --- a/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs +++ b/src/WebApi/DependencyInjection/InfrastructureServiceCollectionExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; -namespace Farseer.TerraformBackend.WebApi.DependencyInjection; +namespace Devpro.TerraformBackend.WebApi.DependencyInjection; internal static class InfrastructureServiceCollectionExtensions { diff --git a/src/WebApi/Dockerfile b/src/WebApi/Dockerfile index c8c1025..daa926c 100644 --- a/src/WebApi/Dockerfile +++ b/src/WebApi/Dockerfile @@ -20,4 +20,4 @@ RUN dotnet publish "WebApi.csproj" -c "$BUILD_CONFIGURATION" -o /app/publish /p: FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Farseer.TerraformBackend.WebApi.dll"] +ENTRYPOINT ["dotnet", "Devpro.TerraformBackend.WebApi.dll"] diff --git a/src/WebApi/Filters/TenantAuthorizationFilter.cs b/src/WebApi/Filters/TenantAuthorizationFilter.cs index da09358..f6caf1a 100644 --- a/src/WebApi/Filters/TenantAuthorizationFilter.cs +++ b/src/WebApi/Filters/TenantAuthorizationFilter.cs @@ -1,8 +1,8 @@ -using Farseer.TerraformBackend.WebApi.Authentication; +using Devpro.TerraformBackend.WebApi.Authentication; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -namespace Farseer.TerraformBackend.WebApi.Filters; +namespace Devpro.TerraformBackend.WebApi.Filters; public class TenantAuthorizationFilter : IActionFilter { diff --git a/src/WebApi/ImplicitUsings.cs b/src/WebApi/ImplicitUsings.cs index 3e2f66c..d116536 100644 --- a/src/WebApi/ImplicitUsings.cs +++ b/src/WebApi/ImplicitUsings.cs @@ -1,7 +1,7 @@ -global using Farseer.Common.AspNetCore.DependencyInjection; -global using Farseer.Common.AspNetCore.Formatters; -global using Farseer.Common.AspNetCore.WebApi.Builder; -global using Farseer.Common.AspNetCore.WebApi.Configuration; -global using Farseer.Common.AspNetCore.WebApi.DependencyInjection; -global using Farseer.TerraformBackend.WebApi; -global using Farseer.TerraformBackend.WebApi.DependencyInjection; +global using Devpro.Common.AspNetCore.DependencyInjection; +global using Devpro.Common.AspNetCore.Formatters; +global using Devpro.Common.AspNetCore.WebApi.Builder; +global using Devpro.Common.AspNetCore.WebApi.Configuration; +global using Devpro.Common.AspNetCore.WebApi.DependencyInjection; +global using Devpro.TerraformBackend.WebApi; +global using Devpro.TerraformBackend.WebApi.DependencyInjection; diff --git a/src/WebApi/Properties/launchSettings.json b/src/WebApi/Properties/launchSettings.json index 1ace3bd..1057a39 100644 --- a/src/WebApi/Properties/launchSettings.json +++ b/src/WebApi/Properties/launchSettings.json @@ -9,7 +9,7 @@ "ASPNETCORE_ENVIRONMENT": "Development", "Application__IsHttpsRedirectionEnabled": "false", "Application__IsSwaggerEnabled": "true", - "Logging__LogLevel__Farseer": "Debug" + "Logging__LogLevel__Devpro": "Debug" }, "dotnetRunMessages": true, "applicationUrl": "http://localhost:5293" @@ -22,7 +22,7 @@ "ASPNETCORE_ENVIRONMENT": "Development", "Application__IsHttpsRedirectionEnabled": "true", "Application__IsSwaggerEnabled": "true", - "Logging__LogLevel__Farseer": "Debug" + "Logging__LogLevel__Devpro": "Debug" }, "dotnetRunMessages": true, "applicationUrl": "https://localhost:7293;http://localhost:5293" diff --git a/src/WebApi/WebApi.csproj b/src/WebApi/WebApi.csproj index a647438..ddf1ad0 100644 --- a/src/WebApi/WebApi.csproj +++ b/src/WebApi/WebApi.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.TerraformBackend.WebApi - Farseer.TerraformBackend.WebApi + Devpro.TerraformBackend.WebApi + Devpro.TerraformBackend.WebApi {5CD7A689-5ADB-4207-972E-6FA881AF1B1C} enable enable diff --git a/src/WebApi/appsettings.json b/src/WebApi/appsettings.json index 10fa873..2e90252 100644 --- a/src/WebApi/appsettings.json +++ b/src/WebApi/appsettings.json @@ -5,13 +5,13 @@ "IsHttpsRedirectionEnabled": true }, "ConnectionStrings": { - "MongoDbLocal": "mongodb://localhost:27017/?readPreference=primary&appname=FarseerTerraformBackendWebApi&directConnection=true&ssl=false" + "MongoDbLocal": "mongodb://localhost:27017/?readPreference=primary&appname=DevproTerraformBackendWebApi&directConnection=true&ssl=false" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning", - "Farseer": "Information" + "Devpro": "Information" } }, "MongoDb": { diff --git a/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs b/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs index 1220f24..e5f763b 100644 --- a/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs +++ b/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs @@ -1,9 +1,9 @@ -using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; +using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Moq; -namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Behaviors; +namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Behaviors; [Trait("Category", "IntegrationTests")] public class InvalidModelStateBehaviorTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs b/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs index 9ce2de6..dfa4df1 100644 --- a/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs +++ b/test/WebApi.IntegrationTests/Http/HttpResponseMessageExtensions.cs @@ -1,6 +1,6 @@ using System.Net; -namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Http; +namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Http; internal static class HttpResponseMessageExtensions { diff --git a/test/WebApi.IntegrationTests/IntegrationTestBase.cs b/test/WebApi.IntegrationTests/IntegrationTestBase.cs index a85cf23..b54caa7 100644 --- a/test/WebApi.IntegrationTests/IntegrationTestBase.cs +++ b/test/WebApi.IntegrationTests/IntegrationTestBase.cs @@ -1,8 +1,8 @@ using System.Net.Http.Headers; -using Farseer.TerraformBackend.Domain.Models; +using Devpro.TerraformBackend.Domain.Models; using Microsoft.AspNetCore.Hosting; -namespace Farseer.TerraformBackend.WebApi.IntegrationTests; +namespace Devpro.TerraformBackend.WebApi.IntegrationTests; /// /// Ref. https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests diff --git a/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs b/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs index b2359b0..7dcd555 100644 --- a/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs +++ b/test/WebApi.IntegrationTests/Resources/HealthCheckResourceTest.cs @@ -1,6 +1,6 @@ -using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; +using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; -namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Resources; +namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources; [Trait("Category", "IntegrationTests")] public class HealthCheckResourceTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs b/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs index 06e80cc..6670ed8 100644 --- a/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs +++ b/test/WebApi.IntegrationTests/Resources/StateControllerResourceTest.cs @@ -1,7 +1,7 @@ using System.Net; -using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; +using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; -namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Resources; +namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources; [Trait("Category", "IntegrationTests")] public class StateControllerResourceTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs b/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs index f6faf32..b9980bf 100644 --- a/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs +++ b/test/WebApi.IntegrationTests/Resources/SwaggerResourceTest.cs @@ -1,6 +1,6 @@ -using Farseer.TerraformBackend.WebApi.IntegrationTests.Http; +using Devpro.TerraformBackend.WebApi.IntegrationTests.Http; -namespace Farseer.TerraformBackend.WebApi.IntegrationTests.Resources; +namespace Devpro.TerraformBackend.WebApi.IntegrationTests.Resources; [Trait("Category", "IntegrationTests")] public class SwaggerResourceTest(WebApplicationFactory factory) diff --git a/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj b/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj index f3fcbac..bd05c3f 100644 --- a/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj +++ b/test/WebApi.IntegrationTests/WebApi.IntegrationTests.csproj @@ -2,8 +2,8 @@ net8.0 - Farseer.TerraformBackend.WebApi.IntegrationTests - Farseer.TerraformBackend.WebApi.IntegrationTests + Devpro.TerraformBackend.WebApi.IntegrationTests + Devpro.TerraformBackend.WebApi.IntegrationTests {B055FFAF-8261-43B1-866A-12E289D5D7DC} enable enable From 1256cd574dbdfa60ab24030b9f0d430788c952b9 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Fri, 25 Jul 2025 15:42:20 +0200 Subject: [PATCH 10/14] Fix build warnings --- .../BasicAuthenticationDefaults.cs | 2 +- .../Configuration/WebApiConfiguration.cs | 20 ++++++++++--------- src/WebApi/ApplicationConfiguration.cs | 4 ++-- src/WebApi/Program.cs | 2 +- .../InvalidModelStateBehaviorTest.cs | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs index 2310fab..776ab72 100644 --- a/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs +++ b/src/Common.AspNetCore.WebApi/Authentication/BasicAuthenticationDefaults.cs @@ -1,6 +1,6 @@ namespace Devpro.Common.AspNetCore.WebApi.Authentication; -public class BasicAuthenticationDefaults +public static class BasicAuthenticationDefaults { public const string AuthenticationScheme = "Basic"; } diff --git a/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs b/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs index eee1be5..5ffbb7f 100644 --- a/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs +++ b/src/Common.AspNetCore.WebApi/Configuration/WebApiConfiguration.cs @@ -9,30 +9,32 @@ public class WebApiConfiguration(IConfigurationRoot configurationRoot) // flags - public bool IsOpenTelemetryEnabled => TryGetSection("Application:IsOpenTelemetryEnabled").Get(); + public bool IsOpenTelemetryEnabled => TryGetSection("Application:IsOpenTelemetryEnabled"); - public bool IsHttpsRedirectionEnabled => TryGetSection("Application:IsHttpsRedirectionEnabled").Get(); + public bool IsHttpsRedirectionEnabled => TryGetSection("Application:IsHttpsRedirectionEnabled"); - public bool IsSwaggerEnabled => TryGetSection("Application:IsSwaggerEnabled").Get(); + public bool IsSwaggerEnabled => TryGetSection("Application:IsSwaggerEnabled"); // definitions public static string HealthCheckEndpoint => "/health"; - public OpenApiInfo OpenApi => TryGetSection("OpenApi").Get() ?? throw new Exception(""); + public OpenApiInfo OpenApi => TryGetSection("OpenApi"); - public string OpenTelemetryService => TryGetSection("OpenTelemetry:ServiceName").Get() ?? ""; + public string OpenTelemetryService => TryGetSection("OpenTelemetry:ServiceName"); // infrastructure - public string OpenTelemetryCollectorEndpoint => TryGetSection("OpenTelemetry:CollectorEndpoint").Get() ?? ""; + public string OpenTelemetryCollectorEndpoint => TryGetSection("OpenTelemetry:CollectorEndpoint"); // protected methods - protected IConfigurationSection TryGetSection(string sectionKey) + protected T TryGetSection(string sectionKey) { - return ConfigurationRoot.GetSection(sectionKey) - ?? throw new ArgumentException("Missing section \"" + sectionKey + "\" in configuration", nameof(sectionKey)); + var section = ConfigurationRoot.GetSection(sectionKey) + ?? throw new ArgumentException($"Missing section \"{sectionKey}\" in configuration", nameof(sectionKey)); + return section.Get() + ?? throw new ArgumentException($"Section \"{sectionKey}\" value cannot be read as \"{nameof(T)}\"", nameof(sectionKey)); } } diff --git a/src/WebApi/ApplicationConfiguration.cs b/src/WebApi/ApplicationConfiguration.cs index bc58750..2985dc8 100644 --- a/src/WebApi/ApplicationConfiguration.cs +++ b/src/WebApi/ApplicationConfiguration.cs @@ -8,7 +8,7 @@ public class ApplicationConfiguration(IConfigurationRoot configurationRoot) public MongoDbConfiguration MongoDbConfiguration => new() { - ConnectionString = ConfigurationRoot.GetConnectionString(TryGetSection("MongoDb:ConnectionStringName")?.Get() ?? string.Empty) ?? string.Empty, - DatabaseName = TryGetSection("MongoDb:DatabaseName").Get() ?? string.Empty + ConnectionString = ConfigurationRoot.GetConnectionString(TryGetSection("MongoDb:ConnectionStringName")) ?? string.Empty, + DatabaseName = TryGetSection("MongoDb:DatabaseName") }; } diff --git a/src/WebApi/Program.cs b/src/WebApi/Program.cs index 62ae714..4e8f7eb 100644 --- a/src/WebApi/Program.cs +++ b/src/WebApi/Program.cs @@ -21,5 +21,5 @@ // runs the application app.Run(); -// adds explicit class definition for integration test project +[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "S1118:Utility classes should not have public constructors", Justification = "Explicit class definition needed for integration test project")] public partial class Program { } diff --git a/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs b/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs index e5f763b..5745b9f 100644 --- a/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs +++ b/test/WebApi.IntegrationTests/Behaviors/InvalidModelStateBehaviorTest.cs @@ -26,7 +26,7 @@ public async Task InvalidModelStateBehavior_OnInvalidModelState_LogsWarning() }); }); var invalidModel = new { Name = (string?)null }; - var name = Faker.Random.Word(); + var name = Faker.Random.AlphaNumeric(8); // Act var response = await client.PostAsync($"/dummy/state/{name}/lock", Serialize(invalidModel)); From 08d08a30dabc5509641266d61ba9a9a877e54e10 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Sat, 26 Jul 2025 16:19:36 +0200 Subject: [PATCH 11/14] Add scripts/tfbackend-cli --- .gitignore | 3 - CONTRIBUTING.md | 22 ++-- docs/index.md | 2 +- docs/project.md | 6 ++ scripts/mongo-create-index.js | 2 - scripts/mongo-create-user.sh | 39 ------- scripts/tfbackend-cli | 184 ++++++++++++++++++++++++++++++++++ 7 files changed, 198 insertions(+), 60 deletions(-) delete mode 100644 scripts/mongo-create-index.js delete mode 100755 scripts/mongo-create-user.sh create mode 100755 scripts/tfbackend-cli diff --git a/.gitignore b/.gitignore index 056db93..d7c48f7 100644 --- a/.gitignore +++ b/.gitignore @@ -356,6 +356,3 @@ appsettings.Development.json .terraform/ .terraform.lock.hcl errored.tfstate - -# temp script files -scripts/add-user.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9bbd0e8..675d20a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,8 @@ # Contribution guide -## Application +## Application codebase -The code is entirely based on open-source, cross-platform (Linux/Windows), highly performant, free, object-oriented technologies: .NET / C#. - -### Projects +### .NET projects Project name | Technology | Project type ---------------------------|------------|--------------------------- @@ -15,7 +13,7 @@ Project name | Technology | Project type `Infrastructure.MongoDb` | .NET 8 | Library `WebApi` | ASP.NET 8 | Web application (REST API) -### Packages (NuGet) +### .NET packages (NuGet) Name | Description -------------------------|----------------------------- @@ -24,16 +22,10 @@ Name | Description `Swashbuckle.AspNetCore` | OpenAPI / Swagger generation `System.Text.Json` | JSON support -### Clients - -- [OpenTofu](https://opentofu.org/) -- [Terraform](https://www.terraform.io) - - [HTTP backend](https://developer.hashicorp.com/terraform/language/backend/http) - - [Remote state backend](https://github.com/hashicorp/terraform/tree/main/internal/backend/remote-state) - -### Backing services +### Terraform specifications -- [MongoDB](https://www.mongodb.com/) +- [HTTP backend](https://developer.hashicorp.com/terraform/language/backend/http) +- [Remote state backend](https://github.com/hashicorp/terraform/tree/main/internal/backend/remote-state) ### Other community implementations @@ -74,7 +66,7 @@ dotnet run --project src/WebApi Open Swagger in a browser: [localhost:5293/swagger](http://localhost:5293/swagger). -## Documentation +## Documentation codebase The documentation is a static website built with [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/). diff --git a/docs/index.md b/docs/index.md index 0f313b9..d89c9e8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ # Welcome -This project provides an HTTP backend for Terraform and OpenTofu that will save and manage state data in a MongoDB database. +This project provides an HTTP backend for [Terraform](https://www.terraform.io) and [OpenTofu](https://opentofu.org/) that will save and manage state data in a [MongoDB](https://www.mongodb.com/) database. As the state is a JSON content, it makes sense to use the best-in-class database technology to work with it. diff --git a/docs/project.md b/docs/project.md index 630019c..0aa0065 100644 --- a/docs/project.md +++ b/docs/project.md @@ -27,3 +27,9 @@ New features: - :material-square: Store in the database only one version of the state in tf_state (the latest) and save the others in tf_state_revision - :material-square: Send traces, logs, metrics to OpenTelemetry Collector + +## Design + +### Programming languages + +The code is mainly written in C# / .NET: open-source, cross-platform (Linux/Windows), highly performant, object-oriented. diff --git a/scripts/mongo-create-index.js b/scripts/mongo-create-index.js deleted file mode 100644 index a9d2879..0000000 --- a/scripts/mongo-create-index.js +++ /dev/null @@ -1,2 +0,0 @@ -db.tf_state.createIndex({ "tenant": 1, "name": 1 }); -db.tf_state_lock.createIndex({ "tenant": 1, "name": 1 }); diff --git a/scripts/mongo-create-user.sh b/scripts/mongo-create-user.sh deleted file mode 100755 index 9f2ca5b..0000000 --- a/scripts/mongo-create-user.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -if [ "$#" -ne 3 ]; then - echo "Usage: $0 " - exit 1 -fi - -USERNAME="$1" -PASSWORD="$2" -TENANT="$3" - -if ! command -v htpasswd &> /dev/null; then - echo "Error: htpasswd is not installed." - echo "Please install apache2-utils (on Debian/Ubuntu) or httpd-tools (on CentOS/RHEL)." - echo "Installation commands:" - echo " Debian/Ubuntu: sudo apt-get install apache2-utils" - echo " CentOS/RHEL: sudo yum install httpd-tools" - exit 1 -fi - -SCRIPT_DIR=$(dirname "$(realpath "$0")") -JS_FILE="$SCRIPT_DIR/add-user.js" - -HASH=$(htpasswd -bnBC 10 "" "$PASSWORD" | tr -d ':\n') -if [ $? -ne 0 ] || [ -z "$HASH" ]; then - echo "Error: Failed to generate BCrypt hash." - exit 1 -fi - -cat > "$JS_FILE" << EOF -db.user.insertOne({ - username: '$USERNAME', - password_hash: '$HASH', - tenant: '$TENANT' -}); -db.user.createIndex({ "username": 1 }, { unique: true }); -EOF - -echo "Generated "$JS_FILE" successfully" diff --git a/scripts/tfbackend-cli b/scripts/tfbackend-cli new file mode 100755 index 0000000..48e885f --- /dev/null +++ b/scripts/tfbackend-cli @@ -0,0 +1,184 @@ +#!/bin/bash + +# tfbackend-cli create-index +# tfbackend-cli create-user myusername mypassword mytenant + +MONGODB_URI="${MONGODB_URI:-mongodb://mongodb:27017}" +MONGODB_DB="${MONGODB_DB:-test}" +MONGODB_CONTAINERNAME="${MONGODB_CONTAINERNAME:-mongodb}" + +MONGODB_INDEX_COMMANDS=( + 'db.tf_state.createIndex({"tenant": 1, "name": 1})' + 'db.tf_state_lock.createIndex({"tenant": 1, "name": 1})' +) + +log_info() { + local message="$1" + echo -e "$message" +} + +log_header() { + local message="$1" + echo -e "\033[1;34m$message\033[0m" # blue +} + +log_success() { + local message="$1" + echo -e "\033[1;32m$message\033[0m" # green +} + +log_warn() { + local message="$1" + echo -e "\033[1;33mWarn: $message\033[0m" # yello +} + +log_error() { + local message="$1" + echo -e "\033[1;31mError: $message\033[0m" # red +} + +usage() { + echo -e "\033[1;34mUsage:\033[0m $0 [command] [arguments...]" + echo -e "\033[1;34mCommands:\033[0m" + echo " create-index : Create indexes in database" + echo " create-user : Create user in database" + echo " help : Show this help message" + # echo " (no arguments) : Run in interactive mode" + exit 1 +} + +check_command() { + local cmd=$1 + if command -v "$cmd" &> /dev/null; then + return 0 + else + return 1 + fi +} + +check_htpasswd() { + if ! command -v htpasswd &> /dev/null; then + log_error "htpasswd is not installed." + log_info "Please install apache2-utils (on Debian/Ubuntu) or httpd-tools (on CentOS/RHEL)." + log_info "Installation commands:" + log_info " Debian/Ubuntu: sudo apt-get install apache2-utils" + log_info " CentOS/RHEL: sudo yum install httpd-tools" + exit 1 + fi +} + +execute_mongosh() { + local mongo_cmd="$1" + if check_command "mongosh"; then + execute_mongosh_package "$mongo_cmd" || exit 1 + else + if check_command "docker"; then + execute_mongosh_docker "$mongo_cmd" || exit 1 + else + echo "Error: Neither mongosh nor Docker is installed. Please install one to proceed." + exit 1 + fi + fi +} + +execute_mongosh_package() { + local mongo_cmd="$1" + log_info "Executing MongoDB command in the shell: $mongo_cmd" + if output=$(mongosh "$MONGODB_URI/$MONGODB_DB" --quiet --eval "$mongo_cmd" 2>&1); then + log_info "Output:\n$output" + else + log_warn "$output" + return 1 + fi +} + +execute_mongosh_docker() { + local mongo_cmd="$1" + log_info "Executing MongoDB command in a container: $mongo_cmd" + if output=$(docker run --rm --link "$MONGODB_CONTAINERNAME" mongo:8.0 bash -c "mongosh \"$MONGODB_URI/$MONGODB_DB\" --quiet --eval \"$mongo_cmd\"" 2>&1); then + log_info "Output:\n$output" + else + log_warn "$output" + return 1 + fi +} + +create_mongodb_indexes() { + local status=0 + log_header "Creating predefined MongoDB indexes" + for cmd in "${MONGODB_INDEX_COMMANDS[@]}"; do + execute_mongosh "$cmd" || status=1 + done + if [ $status -eq 0 ]; then + log_success "All indexes created successfully" + else + log_error "One or more index creations failed" + fi + return $status +} + +create_user() { + local username=$1 + local password=$2 + local tenant=$3 + + hash=$(htpasswd -bnBC 10 "" "$password" | tr -d ':\n') + if [ $? -ne 0 ] || [ -z "$hash" ]; then + log_error "Failed to generate BCrypt hash" + exit 1 + fi + + creation_command=$(cat < Date: Sat, 26 Jul 2025 17:07:20 +0200 Subject: [PATCH 12/14] Update and rename script --- scripts/{tfbackend-cli => tfbeadm} | 64 +++++++++++++++++++----------- 1 file changed, 41 insertions(+), 23 deletions(-) rename scripts/{tfbackend-cli => tfbeadm} (66%) diff --git a/scripts/tfbackend-cli b/scripts/tfbeadm similarity index 66% rename from scripts/tfbackend-cli rename to scripts/tfbeadm index 48e885f..491c9e4 100755 --- a/scripts/tfbackend-cli +++ b/scripts/tfbeadm @@ -1,15 +1,13 @@ #!/bin/bash -# tfbackend-cli create-index -# tfbackend-cli create-user myusername mypassword mytenant - -MONGODB_URI="${MONGODB_URI:-mongodb://mongodb:27017}" -MONGODB_DB="${MONGODB_DB:-test}" -MONGODB_CONTAINERNAME="${MONGODB_CONTAINERNAME:-mongodb}" +MONGODB_URI="${MONGODB_URI:-mongodb://mongodb:27017/test}" +#MONGODB_CONTAINERNAME +MONGODB_VERSION="${MONGODB_VERSION:-8.0}" MONGODB_INDEX_COMMANDS=( 'db.tf_state.createIndex({"tenant": 1, "name": 1})' - 'db.tf_state_lock.createIndex({"tenant": 1, "name": 1})' + 'db.tf_state_lock.createIndex({"tenant": 1, "name": 1}, {unique: true})' + 'db.user.createIndex({"username": 1}, {unique: true})' ) log_info() { @@ -40,7 +38,7 @@ log_error() { usage() { echo -e "\033[1;34mUsage:\033[0m $0 [command] [arguments...]" echo -e "\033[1;34mCommands:\033[0m" - echo " create-index : Create indexes in database" + echo " create-indexes : Create indexes in database" echo " create-user : Create user in database" echo " help : Show this help message" # echo " (no arguments) : Run in interactive mode" @@ -68,23 +66,27 @@ check_htpasswd() { } execute_mongosh() { - local mongo_cmd="$1" + local mongodb_cmd="$1" if check_command "mongosh"; then - execute_mongosh_package "$mongo_cmd" || exit 1 + execute_mongosh_package "$mongodb_cmd" || return 1 else if check_command "docker"; then - execute_mongosh_docker "$mongo_cmd" || exit 1 + if [[ -n "$MONGODB_CONTAINERNAME" ]]; then + execute_mongosh_docker_link "$mongodb_cmd" || return 1 + else + execute_mongosh_docker "$mongodb_cmd" || return 1 + fi else echo "Error: Neither mongosh nor Docker is installed. Please install one to proceed." - exit 1 + return 1 fi fi } execute_mongosh_package() { - local mongo_cmd="$1" - log_info "Executing MongoDB command in the shell: $mongo_cmd" - if output=$(mongosh "$MONGODB_URI/$MONGODB_DB" --quiet --eval "$mongo_cmd" 2>&1); then + local mongodb_cmd="$1" + log_info "Executing MongoDB command in the shell: $mongodb_cmd" + if output=$(mongosh "$MONGODB_URI" --quiet --eval "$mongodb_cmd" 2>&1); then log_info "Output:\n$output" else log_warn "$output" @@ -93,9 +95,9 @@ execute_mongosh_package() { } execute_mongosh_docker() { - local mongo_cmd="$1" - log_info "Executing MongoDB command in a container: $mongo_cmd" - if output=$(docker run --rm --link "$MONGODB_CONTAINERNAME" mongo:8.0 bash -c "mongosh \"$MONGODB_URI/$MONGODB_DB\" --quiet --eval \"$mongo_cmd\"" 2>&1); then + local mongodb_cmd="$1" + log_info "Executing MongoDB command in a container: $mongodb_cmd" + if output=$(docker run --rm "mongo:$MONGODB_VERSION" bash -c "mongosh \"$MONGODB_URI\" --quiet --eval \"$mongodb_cmd\"" 2>&1); then log_info "Output:\n$output" else log_warn "$output" @@ -103,7 +105,18 @@ execute_mongosh_docker() { fi } -create_mongodb_indexes() { +execute_mongosh_docker_link() { + local mongodb_cmd="$1" + log_info "Executing MongoDB command in a container with a link: $mongodb_cmd" + if output=$(docker run --rm --link "$MONGODB_CONTAINERNAME" "mongo:$MONGODB_VERSION" bash -c "mongosh \"$MONGODB_URI\" --quiet --eval \"$mongodb_cmd\"" 2>&1); then + log_info "Output:\n$output" + else + log_warn "$output" + return 1 + fi +} + +create_indexes() { local status=0 log_header "Creating predefined MongoDB indexes" for cmd in "${MONGODB_INDEX_COMMANDS[@]}"; do @@ -121,6 +134,7 @@ create_user() { local username=$1 local password=$2 local tenant=$3 + log_header "Creating user" hash=$(htpasswd -bnBC 10 "" "$password" | tr -d ':\n') if [ $? -ne 0 ] || [ -z "$hash" ]; then @@ -137,15 +151,19 @@ db.user.insertOne({ EOF ) - execute_mongosh "$creation_command" || return 1 - execute_mongosh "db.user.createIndex({\"username\": 1}, {unique: true})" || return 1 + if execute_mongosh "$creation_command"; then + log_success "User created successfully" + else + log_error "User created failed" + exit 1 + fi } # checks for command-line arguments if [ $# -gt 0 ]; then case "$1" in - "create-index") - create_mongodb_indexes + "create-indexes") + create_indexes exit $? ;; "create-user") From fc9d26718844ddba0faf20285dc6fcde274aa733 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Sat, 26 Jul 2025 17:42:49 +0200 Subject: [PATCH 13/14] Update documentation --- .github/workflows/ci.yaml | 8 +++--- CONTRIBUTING.md | 15 +++-------- docs/project.md | 8 +++--- docs/quickstart.md | 4 +-- docs/setup.md | 56 ++++++++++++++++++++++++++++++--------- docs/usage.md | 20 ++++---------- 6 files changed, 65 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a21427b..727175b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,11 +39,13 @@ jobs: uses: ./workflow-parts/mongodb/start - name: Initialize database (indexes, tenants & users) run: | - mongosh mongodb://localhost:27017/terraform_backend_dev scripts/mongo-create-index.js sudo apt-get -y install apache2-utils - ./scripts/mongo-create-user.sh admin admin123 dummy - mongosh mongodb://localhost:27017/terraform_backend_dev scripts/add-user.js + docker run --name mongodb -d -p 27017:27017 mongo:8.0 + ./scripts/tfbeadm create-indexes + ./scripts/tfbeadm create-user admin admin123 dummy shell: bash + env: + MONGODB_URI: mongodb://localhost:27017/terraform_backend_dev - name: Build, lint & test uses: ./workflow-parts/dotnet/build-lint-test with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 675d20a..2f50bea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,20 +42,13 @@ Name | Description ### Run locally the application -Create/have a MongoDB database (example with a local container but you can provision a cluster in MongoDB Atlas): +Run MongoDB in a database and add the indexes and test tenant/user: ```bash -# creates a container docker run --name mongodb -d -p 27017:27017 mongo:8.0 -# (optional) adds indexes for optimal performances -docker run --rm --link mongodb \ - -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ - bash -c "mongosh mongodb://mongodb:27017/terraform_backend_dev /home/scripts/mongo-create-index.js" -# creates one user -./scripts/mongo-create-user.sh admin admin123 dummy -docker run --rm --link mongodb \ - -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ - bash -c "mongosh mongodb://mongodb:27017/terraform_backend_dev /home/scripts/add-user.js" +MONGODB_CONTAINERNAME=mongodb +./scripts/tfbeadm create-indexes +./scripts/tfbeadm create-user admin admin123 dummy ``` Run the web API (example with the command line but an IDE like Visual Studio or Rider would be nice to be able to debug): diff --git a/docs/project.md b/docs/project.md index 0aa0065..4a70c93 100644 --- a/docs/project.md +++ b/docs/project.md @@ -6,9 +6,11 @@ GitHub Actions are triggered to automate the integration and delivery of the application: -- [CI](../.github/workflows/ci.yaml) -- [Pages](../.github/workflows/pages.yaml) -- [PKG](../.github/workflows/pkg.yaml) +Role | Definition file +----------|------------------------------- +**CI** | `.github/workflows/ci.yaml` +**Pages** | `.github/workflows/pages.yaml` +**PKG** | `.github/workflows/pkg.yaml` GitHub configuration (**General** / **Security** / **Secrets and Variables** / **Actions**): diff --git a/docs/quickstart.md b/docs/quickstart.md index c7c3de5..1668a1a 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -18,5 +18,5 @@ Before looking at all the options, let's do a quick demonstration of the applica ## Samples -* [Make local actions on files](samples/local-files/README.md) -* [Run NGINX container with Docker](samples/docker-nginx/README.md) +* Make local actions on files: `samples/local-files/README.md` +* Run NGINX container with Docker: `samples/docker-nginx/README.md` diff --git a/docs/setup.md b/docs/setup.md index af8c6d8..7fc4dd3 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -22,19 +22,15 @@ The MongoDB server can run: Add indexes for optimal performances: -=== "Container (Docker)" - - ```bash - docker run --rm --link mongodb \ - -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ - bash -c "mongosh mongodb://:/ /home/scripts/mongo-create-index.js" - ``` +```bash +MONGODB_URI=mongodb://:27017/ +curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/scripts/tfbeadm +tfbeadm create-indexes +``` -=== "Client (mongosh)" +!!! warning - ```bash - mongosh mongodb://:/ ./scripts/mongo-create-index.js - ``` + `mongosh` or `Docker` packages must be available on the machine running the commands ## Installation @@ -48,5 +44,41 @@ helm repo add devpro https://devpro.github.io/helm-charts helm repo update # installs the chart -helm upgrade --install tfbackend devpro/terraform-backend-mongodb --create-namespace --namespace tfbackend +helm upgrade --install tfbackend devpro/terraform-backend-mongodb [-f values.yaml] --create-namespace --namespace tfbackend ``` + +Values file examples: + +=== "Embedded MongoDB chart" + + ```yaml + mongodb: + enabled: true + auth: + rootPassword: admin + webapi: + db: + connectionString: mongodb://root:admin@tfbackend-mongodb:27017/terraform_backend_beta?authSource=admin + databaseName: terraform_backend_beta + ``` + +=== "Traefik Ingress with Let's Encrypt cert-manager issuer" + + ```yaml + webapi: + host: tfbackend.mydomain + ingress: + enabled: true + className: traefik + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod + ``` + +=== "Development environment with Swagger" + + ```yaml + dotnet: + environment: Development + enableSwagger: true + enableOpenTelemetry: false + ``` diff --git a/docs/usage.md b/docs/usage.md index a989709..b57bab8 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -6,21 +6,11 @@ API calls are secured through tenant isolation and user authentication, which ar You can add a user with the following commands (replace the parameters): -=== "Container (Docker)" - - ```bash - ./scripts/mongo-create-user.sh myusername mypassword mytenant - docker run --rm --link mongodb \ - -v "$(pwd)/scripts":/home/scripts mongo:8.0 \ - bash -c "mongosh mongodb://:/ /home/scripts/add-user.js" - ``` - -=== "Client (mongosh)" - - ```bash - ./scripts/mongo-create-user.sh myusername mypassword mytenant - mongosh mongodb://:/ ./scripts/add-user.js - ``` +```bash +MONGODB_URI=mongodb://:27017/ +curl -O https://raw.githubusercontent.com/devpro/terraform-backend-mongodb/refs/heads/main/scripts/tfbeadm +tfbeadm create-user +``` ## Client configuration From 5ae7e6b00c376565131a51de221b67efd99916f0 Mon Sep 17 00:00:00 2001 From: Bertrand Thomas Date: Sat, 26 Jul 2025 17:46:06 +0200 Subject: [PATCH 14/14] Update CI --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 727175b..e65ef75 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,8 +39,6 @@ jobs: uses: ./workflow-parts/mongodb/start - name: Initialize database (indexes, tenants & users) run: | - sudo apt-get -y install apache2-utils - docker run --name mongodb -d -p 27017:27017 mongo:8.0 ./scripts/tfbeadm create-indexes ./scripts/tfbeadm create-user admin admin123 dummy shell: bash