Skip to content

Commit 67abb25

Browse files
committed
feat: Add "GetServiceAccountSheetsServiceProviderFromKeyJson" for CI
1 parent e3dc249 commit 67abb25

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

Assets/Example/Editor/ExampleLocalizationSynchronizationMenu.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal static void PullAllLocalizationTablesWithGoogleServiceAccount()
4848
internal static void PullAllLocalizationTablesFromTempKeyJson()
4949
{
5050
var bundle = Bundle;
51-
var provider = GetServiceAccountSheetsServiceProviderFromTempKeyJson(bundle);
51+
var provider = GetServiceAccountSheetsServiceProviderFromKeyJson(bundle);
5252
bundle.PullAllLocales(provider);
5353
}
5454

@@ -91,23 +91,29 @@ internal static void PushAllLocalizationTablesWithGoogleServiceAccount()
9191
internal static void PushAllLocalizationTablesWithGoogleServiceAccountFromTempKeyJson()
9292
{
9393
var bundle = Bundle;
94-
var provider = GetServiceAccountSheetsServiceProviderFromTempKeyJson(bundle);
94+
var provider = GetServiceAccountSheetsServiceProviderFromKeyJson(bundle);
9595
bundle.PushAllLocales(provider);
9696
}
9797

9898
#endregion
9999

100100
#region Service Account Key from Environment Variable
101101

102-
private const string EnvironmentGoogleServiceAccountKey = "UNITY_LOCALIZATION_GOOGLE_SERVICE_ACCOUNT_KEY";
103-
104102
internal static ServiceAccountSheetsServiceProvider GetServiceAccountSheetsServiceProvider(
105103
StringTableCollectionBundle bundle)
106104
{
107-
var serviceAccountKeyJson = Environment.GetEnvironmentVariable(EnvironmentGoogleServiceAccountKey);
105+
const string EnvironmentGoogleServiceAccountKey = "UNITY_LOCALIZATION_GOOGLE_SERVICE_ACCOUNT_KEY";
106+
return GetServiceAccountSheetsServiceProvider(bundle, EnvironmentGoogleServiceAccountKey);
107+
}
108+
109+
internal static ServiceAccountSheetsServiceProvider GetServiceAccountSheetsServiceProvider(
110+
StringTableCollectionBundle bundle,
111+
string keyEnvironmentVariableName)
112+
{
113+
var serviceAccountKeyJson = Environment.GetEnvironmentVariable(keyEnvironmentVariableName);
108114
if (string.IsNullOrEmpty(serviceAccountKeyJson))
109115
{
110-
throw new InvalidOperationException($"Environment variable \"{EnvironmentGoogleServiceAccountKey}\" is not set.");
116+
throw new InvalidOperationException($"Environment variable \"{keyEnvironmentVariableName}\" is not set.");
111117
}
112118

113119
var provider = new ServiceAccountSheetsServiceProvider(
@@ -118,22 +124,28 @@ internal static ServiceAccountSheetsServiceProvider GetServiceAccountSheetsServi
118124

119125
#endregion
120126

121-
#region Service Account Key from Temp Json
127+
#region Service Account Key from Json File
122128

123-
private const string TempJsonKeyPath = "Temp/UnityLocalizationExtension/service-account-key.json";
124-
125-
internal static ServiceAccountSheetsServiceProvider GetServiceAccountSheetsServiceProviderFromTempKeyJson(
129+
internal static ServiceAccountSheetsServiceProvider GetServiceAccountSheetsServiceProviderFromKeyJson(
126130
StringTableCollectionBundle bundle)
127131
{
128-
if (!File.Exists(TempJsonKeyPath))
132+
const string JsonKeyPath = "SecretCache/UnityLocalizationExtension/service-account-key.json";
133+
return GetServiceAccountSheetsServiceProviderFromKeyJson(bundle, JsonKeyPath);
134+
}
135+
136+
internal static ServiceAccountSheetsServiceProvider GetServiceAccountSheetsServiceProviderFromKeyJson(
137+
StringTableCollectionBundle bundle,
138+
string keyJsonPath)
139+
{
140+
if (!File.Exists(keyJsonPath))
129141
{
130-
throw new InvalidOperationException($"File \"{TempJsonKeyPath}\" is not found.");
142+
throw new InvalidOperationException($"File \"{keyJsonPath}\" is not found.");
131143
}
132144

133-
string serviceAccountKeyJson = File.ReadAllText(TempJsonKeyPath);
145+
string serviceAccountKeyJson = File.ReadAllText(keyJsonPath);
134146
if (string.IsNullOrEmpty(serviceAccountKeyJson))
135147
{
136-
throw new InvalidOperationException($"File \"{TempJsonKeyPath}\" is empty.");
148+
throw new InvalidOperationException($"File \"{keyJsonPath}\" is empty.");
137149
}
138150

139151
var provider = new ServiceAccountSheetsServiceProvider(

0 commit comments

Comments
 (0)