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

View File

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