Environemnts refactor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user