From fd39b72596291dfc4ee44e3ee2e72b7aaed52e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Wed, 12 Nov 2025 11:59:11 +0100 Subject: [PATCH] Environemnts refactor --- .gitignore | 2 + src/Backend/DiunaBI.API/Program.cs | 2 +- .../DiunaBI.API/appsettings.Production.json | 47 +++++++++++++++++++ src/Backend/DiunaBI.API/appsettings.json | 45 ++---------------- src/Backend/DiunaBI.API/client_secrets.json | 12 ----- .../Services/GoogleDriveHelper.cs | 14 +++--- .../Services/GoogleSheetsHelper.cs | 13 +++-- .../appsettings.Production.json | 6 --- src/Backend/DiunaBI.UI.Web/appsettings.json | 10 ++++ 9 files changed, 79 insertions(+), 72 deletions(-) create mode 100644 src/Backend/DiunaBI.API/appsettings.Production.json delete mode 100644 src/Backend/DiunaBI.API/client_secrets.json create mode 100644 src/Backend/DiunaBI.UI.Web/appsettings.json diff --git a/.gitignore b/.gitignore index 2a914ba..bf4dfc4 100644 --- a/.gitignore +++ b/.gitignore @@ -484,6 +484,8 @@ yarn-error.log ## **/appsettings.Development.json **/appsettings.Local.json +**/client_secrets.Development.json +**/client *.p12 *.key *.pem diff --git a/src/Backend/DiunaBI.API/Program.cs b/src/Backend/DiunaBI.API/Program.cs index 9b861bf..5ec7685 100644 --- a/src/Backend/DiunaBI.API/Program.cs +++ b/src/Backend/DiunaBI.API/Program.cs @@ -71,7 +71,7 @@ builder.Services.AddAuthentication(options => ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Secret"]!)) + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JwtSettings:SecurityKey"]!)) }; }); diff --git a/src/Backend/DiunaBI.API/appsettings.Production.json b/src/Backend/DiunaBI.API/appsettings.Production.json new file mode 100644 index 0000000..633fc00 --- /dev/null +++ b/src/Backend/DiunaBI.API/appsettings.Production.json @@ -0,0 +1,47 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "Serilog": { + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore.Database.Command": "Warning", + "Microsoft.EntityFrameworkCore.Infrastructure": "Warning", + "System.Net.Http.HttpClient": "Warning", + "Google.Apis": "Warning", + "DiunaBI.Core.Services.PluginManager": "Information" + } + }, + "WriteTo": [ + { + "Name": "Console", + "Args": { + "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}" + } + }, + { + "Name": "File", + "Args": { + "path": "/var/log/diunabi/app-.log", + "rollingInterval": "Day", + "retainedFileCountLimit": 30, + "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext} {Message:lj} {Properties:j}{NewLine}{Exception}" + } + } + ], + "Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"] + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "Http": { + "Url": "http://0.0.0.0:7143" + } + } + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.API/appsettings.json b/src/Backend/DiunaBI.API/appsettings.json index 241213c..62d8ffa 100644 --- a/src/Backend/DiunaBI.API/appsettings.json +++ b/src/Backend/DiunaBI.API/appsettings.json @@ -1,6 +1,5 @@ + { - "PONG": "#{PING}#", - "app-version": "#{buildId}#", "Logging": { "LogLevel": { "Default": "Information", @@ -25,47 +24,9 @@ "Args": { "outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}" } - }, - { - "Name": "File", - "Args": { - "path": "/var/log/diunabi/app-.log", - "rollingInterval": "Day", - "retainedFileCountLimit": 30, - "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext} {Message:lj} {Properties:j}{NewLine}{Exception}" - } - }, - { - "Name": "Seq", - "Args": { - "serverUrl": "http://localhost:5341", - "restrictedToMinimumLevel": "Information" - } } ], "Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"] }, - "AllowedHosts": "*", - "ConnectionStrings": { - "SQLDatabase": "#{db-connection-string}#" - }, - "InstanceName": "#{app-environment}#", - "GoogleAuth": { - "ClientId": "#{google-backend-login-client-id}#" - }, - "Secret": "#{google-backend-login-secret}#", - "apiKey": "#{api-key}#", - "powerBI-user": "#{powerBI-user}#", - "powerBI-pass": "#{powerBI-pass}#", - "morska-user": "#{morska-user}#", - "morska-pass": "#{morska-pass}#", - "exportDirectory": "#{export-directory}#", - "apiLocalUrl": "#{api-local-url}#", - "Kestrel": { - "Endpoints": { - "Http": { - "Url": "http://#{api-local-url}#" - } - } - } -} + "AllowedHosts": "*" +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.API/client_secrets.json b/src/Backend/DiunaBI.API/client_secrets.json deleted file mode 100644 index f4f3207..0000000 --- a/src/Backend/DiunaBI.API/client_secrets.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "type": "service_account", - "project_id": "#{google-backend-project-id}#", - "private_key_id": "#{google-backend-private-key-id}#", - "private_key": "#{google-backend-private-key}#", - "client_email": "#{google-backend-client-email}#", - "client_id": "#{google-backend-client-id}#", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "#{google-backend-client-cert-url}#" -} diff --git a/src/Backend/DiunaBI.Infrastructure/Services/GoogleDriveHelper.cs b/src/Backend/DiunaBI.Infrastructure/Services/GoogleDriveHelper.cs index e027c15..a550538 100644 --- a/src/Backend/DiunaBI.Infrastructure/Services/GoogleDriveHelper.cs +++ b/src/Backend/DiunaBI.Infrastructure/Services/GoogleDriveHelper.cs @@ -24,13 +24,15 @@ public class GoogleDriveHelper } private static GoogleCredential GetCredentialsFromFile() { - // ReSharper disable once RedundantAssignment - var fileName = "client_secrets.json"; #if DEBUG - fileName = "client_secrets.Development.json"; + using var stream = new FileStream("client_secrets.Development.json", FileMode.Open, FileAccess.Read); + return GoogleCredential.FromStream(stream).CreateScoped(Scopes); +#else + var json = Environment.GetEnvironmentVariable("GOOGLE_SERVICE_ACCOUNT_JSON"); + if (string.IsNullOrWhiteSpace(json)) + throw new InvalidOperationException("GOOGLE_SERVICE_ACCOUNT_JSON environment variable is not set."); + json = json.Replace("\\n", "\n"); + return GoogleCredential.FromJson(json).CreateScoped(Scopes); #endif - using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes); - return credential; } } \ No newline at end of file diff --git a/src/Backend/DiunaBI.Infrastructure/Services/GoogleSheetsHelper.cs b/src/Backend/DiunaBI.Infrastructure/Services/GoogleSheetsHelper.cs index e6bc21c..935d5f9 100644 --- a/src/Backend/DiunaBI.Infrastructure/Services/GoogleSheetsHelper.cs +++ b/src/Backend/DiunaBI.Infrastructure/Services/GoogleSheetsHelper.cs @@ -24,12 +24,15 @@ public class GoogleSheetsHelper } private static GoogleCredential GetCredentialsFromFile() { - var fileName = "client_secrets.json"; #if DEBUG - fileName = "client_secrets.Development.json"; + using var stream = new FileStream("client_secrets.Development.json", FileMode.Open, FileAccess.Read); + return GoogleCredential.FromStream(stream).CreateScoped(Scopes); +#else + var json = Environment.GetEnvironmentVariable("GOOGLE_SERVICE_ACCOUNT_JSON"); + if (string.IsNullOrWhiteSpace(json)) + throw new InvalidOperationException("GOOGLE_SERVICE_ACCOUNT_JSON environment variable is not set."); + json = json.Replace("\\n", "\n"); + return GoogleCredential.FromJson(json).CreateScoped(Scopes); #endif - using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes); - return credential; } } \ No newline at end of file diff --git a/src/Backend/DiunaBI.UI.Web/appsettings.Production.json b/src/Backend/DiunaBI.UI.Web/appsettings.Production.json index b2c34ee..43538aa 100644 --- a/src/Backend/DiunaBI.UI.Web/appsettings.Production.json +++ b/src/Backend/DiunaBI.UI.Web/appsettings.Production.json @@ -6,12 +6,6 @@ } }, "AllowedHosts": "*", - "ApiSettings": { - "BaseUrl": "#{api-base-url}#" - }, - "GoogleAuth": { - "ClientId": "#{google-auth-client-id}#" - }, "Kestrel": { "Endpoints": { "Http": { diff --git a/src/Backend/DiunaBI.UI.Web/appsettings.json b/src/Backend/DiunaBI.UI.Web/appsettings.json new file mode 100644 index 0000000..0b4b50d --- /dev/null +++ b/src/Backend/DiunaBI.UI.Web/appsettings.json @@ -0,0 +1,10 @@ + +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} \ No newline at end of file