@@ -119,8 +119,11 @@ public interface IConfigurationStore : IRunnerService
119
119
CredentialData GetCredentials ( ) ;
120
120
CredentialData GetMigratedCredentials ( ) ;
121
121
RunnerSettings GetSettings ( ) ;
122
+ RunnerSettings GetMigratedSettings ( ) ;
122
123
void SaveCredential ( CredentialData credential ) ;
124
+ void SaveMigratedCredential ( CredentialData credential ) ;
123
125
void SaveSettings ( RunnerSettings settings ) ;
126
+ void SaveMigratedSettings ( RunnerSettings settings ) ;
124
127
void DeleteCredential ( ) ;
125
128
void DeleteMigratedCredential ( ) ;
126
129
void DeleteSettings ( ) ;
@@ -130,13 +133,15 @@ public sealed class ConfigurationStore : RunnerService, IConfigurationStore
130
133
{
131
134
private string _binPath ;
132
135
private string _configFilePath ;
136
+ private string _migratedConfigFilePath ;
133
137
private string _credFilePath ;
134
138
private string _migratedCredFilePath ;
135
139
private string _serviceConfigFilePath ;
136
140
137
141
private CredentialData _creds ;
138
142
private CredentialData _migratedCreds ;
139
143
private RunnerSettings _settings ;
144
+ private RunnerSettings _migratedSettings ;
140
145
141
146
public override void Initialize ( IHostContext hostContext )
142
147
{
@@ -154,6 +159,9 @@ public override void Initialize(IHostContext hostContext)
154
159
_configFilePath = hostContext . GetConfigFile ( WellKnownConfigFile . Runner ) ;
155
160
Trace . Info ( "ConfigFilePath: {0}" , _configFilePath ) ;
156
161
162
+ _migratedConfigFilePath = hostContext . GetConfigFile ( WellKnownConfigFile . MigratedRunner ) ;
163
+ Trace . Info ( "MigratedConfigFilePath: {0}" , _migratedConfigFilePath ) ;
164
+
157
165
_credFilePath = hostContext . GetConfigFile ( WellKnownConfigFile . Credentials ) ;
158
166
Trace . Info ( "CredFilePath: {0}" , _credFilePath ) ;
159
167
@@ -169,23 +177,23 @@ public override void Initialize(IHostContext hostContext)
169
177
public bool HasCredentials ( )
170
178
{
171
179
Trace . Info ( "HasCredentials()" ) ;
172
- bool credsStored = ( new FileInfo ( _credFilePath ) ) . Exists || ( new FileInfo ( _migratedCredFilePath ) ) . Exists ;
180
+ bool credsStored = new FileInfo ( _credFilePath ) . Exists || new FileInfo ( _migratedCredFilePath ) . Exists ;
173
181
Trace . Info ( "stored {0}" , credsStored ) ;
174
182
return credsStored ;
175
183
}
176
184
177
185
public bool IsConfigured ( )
178
186
{
179
187
Trace . Info ( "IsConfigured()" ) ;
180
- bool configured = new FileInfo ( _configFilePath ) . Exists ;
188
+ bool configured = new FileInfo ( _configFilePath ) . Exists || new FileInfo ( _migratedConfigFilePath ) . Exists ;
181
189
Trace . Info ( "IsConfigured: {0}" , configured ) ;
182
190
return configured ;
183
191
}
184
192
185
193
public bool IsServiceConfigured ( )
186
194
{
187
195
Trace . Info ( "IsServiceConfigured()" ) ;
188
- bool serviceConfigured = ( new FileInfo ( _serviceConfigFilePath ) ) . Exists ;
196
+ bool serviceConfigured = new FileInfo ( _serviceConfigFilePath ) . Exists ;
189
197
Trace . Info ( $ "IsServiceConfigured: { serviceConfigured } ") ;
190
198
return serviceConfigured ;
191
199
}
@@ -229,6 +237,25 @@ public RunnerSettings GetSettings()
229
237
return _settings ;
230
238
}
231
239
240
+ public RunnerSettings GetMigratedSettings ( )
241
+ {
242
+ if ( _migratedSettings == null )
243
+ {
244
+ RunnerSettings configuredSettings = null ;
245
+ if ( File . Exists ( _migratedConfigFilePath ) )
246
+ {
247
+ string json = File . ReadAllText ( _migratedConfigFilePath , Encoding . UTF8 ) ;
248
+ Trace . Info ( $ "Read migrated setting file: { json . Length } chars") ;
249
+ configuredSettings = StringUtil . ConvertFromJson < RunnerSettings > ( json ) ;
250
+ }
251
+
252
+ ArgUtil . NotNull ( configuredSettings , nameof ( configuredSettings ) ) ;
253
+ _migratedSettings = configuredSettings ;
254
+ }
255
+
256
+ return _migratedSettings ;
257
+ }
258
+
232
259
public void SaveCredential ( CredentialData credential )
233
260
{
234
261
Trace . Info ( "Saving {0} credential @ {1}" , credential . Scheme , _credFilePath ) ;
@@ -244,6 +271,21 @@ public void SaveCredential(CredentialData credential)
244
271
File . SetAttributes ( _credFilePath , File . GetAttributes ( _credFilePath ) | FileAttributes . Hidden ) ;
245
272
}
246
273
274
+ public void SaveMigratedCredential ( CredentialData credential )
275
+ {
276
+ Trace . Info ( "Saving {0} migrated credential @ {1}" , credential . Scheme , _migratedCredFilePath ) ;
277
+ if ( File . Exists ( _migratedCredFilePath ) )
278
+ {
279
+ // Delete existing credential file first, since the file is hidden and not able to overwrite.
280
+ Trace . Info ( "Delete exist runner migrated credential file." ) ;
281
+ IOUtil . DeleteFile ( _migratedCredFilePath ) ;
282
+ }
283
+
284
+ IOUtil . SaveObject ( credential , _migratedCredFilePath ) ;
285
+ Trace . Info ( "Migrated Credentials Saved." ) ;
286
+ File . SetAttributes ( _migratedCredFilePath , File . GetAttributes ( _migratedCredFilePath ) | FileAttributes . Hidden ) ;
287
+ }
288
+
247
289
public void SaveSettings ( RunnerSettings settings )
248
290
{
249
291
Trace . Info ( "Saving runner settings." ) ;
@@ -259,6 +301,21 @@ public void SaveSettings(RunnerSettings settings)
259
301
File . SetAttributes ( _configFilePath , File . GetAttributes ( _configFilePath ) | FileAttributes . Hidden ) ;
260
302
}
261
303
304
+ public void SaveMigratedSettings ( RunnerSettings settings )
305
+ {
306
+ Trace . Info ( "Saving runner migrated settings" ) ;
307
+ if ( File . Exists ( _migratedConfigFilePath ) )
308
+ {
309
+ // Delete existing settings file first, since the file is hidden and not able to overwrite.
310
+ Trace . Info ( "Delete exist runner migrated settings file." ) ;
311
+ IOUtil . DeleteFile ( _migratedConfigFilePath ) ;
312
+ }
313
+
314
+ IOUtil . SaveObject ( settings , _migratedConfigFilePath ) ;
315
+ Trace . Info ( "Migrated Settings Saved." ) ;
316
+ File . SetAttributes ( _migratedConfigFilePath , File . GetAttributes ( _migratedConfigFilePath ) | FileAttributes . Hidden ) ;
317
+ }
318
+
262
319
public void DeleteCredential ( )
263
320
{
264
321
IOUtil . Delete ( _credFilePath , default ( CancellationToken ) ) ;
@@ -273,6 +330,12 @@ public void DeleteMigratedCredential()
273
330
public void DeleteSettings ( )
274
331
{
275
332
IOUtil . Delete ( _configFilePath , default ( CancellationToken ) ) ;
333
+ IOUtil . Delete ( _migratedConfigFilePath , default ( CancellationToken ) ) ;
334
+ }
335
+
336
+ public void DeleteMigratedSettings ( )
337
+ {
338
+ IOUtil . Delete ( _migratedConfigFilePath , default ( CancellationToken ) ) ;
276
339
}
277
340
}
278
341
}
0 commit comments