Environemnts refactor
All checks were successful
Build Docker Images / test (push) Successful in 1m19s
Build Docker Images / build-and-push (push) Successful in 1m34s

This commit is contained in:
Michał Zieliński
2025-11-12 11:59:11 +01:00
parent f7b9009215
commit fd39b72596
9 changed files with 79 additions and 72 deletions

2
.gitignore vendored
View File

@@ -484,6 +484,8 @@ yarn-error.log
## ##
**/appsettings.Development.json **/appsettings.Development.json
**/appsettings.Local.json **/appsettings.Local.json
**/client_secrets.Development.json
**/client
*.p12 *.p12
*.key *.key
*.pem *.pem

View File

@@ -71,7 +71,7 @@ builder.Services.AddAuthentication(options =>
ValidateAudience = false, ValidateAudience = false,
ValidateLifetime = true, ValidateLifetime = true,
ValidateIssuerSigningKey = true, ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Secret"]!)) IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JwtSettings:SecurityKey"]!))
}; };
}); });

View File

@@ -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"
}
}
}
}

View File

@@ -1,6 +1,5 @@
{ {
"PONG": "#{PING}#",
"app-version": "#{buildId}#",
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
@@ -25,47 +24,9 @@
"Args": { "Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}" "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"] "Enrich": ["FromLogContext", "WithMachineName", "WithThreadId"]
}, },
"AllowedHosts": "*", "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}#"
}
}
}
} }

View File

@@ -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}#"
}

View File

@@ -24,13 +24,15 @@ public class GoogleDriveHelper
} }
private static GoogleCredential GetCredentialsFromFile() private static GoogleCredential GetCredentialsFromFile()
{ {
// ReSharper disable once RedundantAssignment
var fileName = "client_secrets.json";
#if DEBUG #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 #endif
using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
return credential;
} }
} }

View File

@@ -24,12 +24,15 @@ public class GoogleSheetsHelper
} }
private static GoogleCredential GetCredentialsFromFile() private static GoogleCredential GetCredentialsFromFile()
{ {
var fileName = "client_secrets.json";
#if DEBUG #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 #endif
using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
var credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
return credential;
} }
} }

View File

@@ -6,12 +6,6 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"ApiSettings": {
"BaseUrl": "#{api-base-url}#"
},
"GoogleAuth": {
"ClientId": "#{google-auth-client-id}#"
},
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"Http": { "Http": {

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}