Skip to content

Commit 46971ea

Browse files
author
msJinLei
committed
Address review comments
1 parent c18dda1 commit 46971ea

File tree

5 files changed

+10
-28
lines changed

5 files changed

+10
-28
lines changed

src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public override void ExecuteCmdlet()
428428
keyStore?.SaveKey(new ServicePrincipalKey(AzureAccount.Property.CertificatePassword, azureAccount.Id, Tenant), CertificatePassword);
429429
if (GetContextModificationScope() == ContextModificationScope.CurrentUser && !keyStore.IsProtected)
430430
{
431-
WriteWarning(string.Format(Resources.ServicePrincipalWarning, keyStore.FileName, keyStore.Directory));
431+
WriteWarning(string.Format(Resources.ServicePrincipalWarning, AzureSession.Instance.KeyStoreFile, AzureSession.Instance.ARMProfileDirectory));
432432
}
433433
}
434434
}
@@ -455,7 +455,7 @@ public override void ExecuteCmdlet()
455455
,azureAccount.Id, Tenant), password);
456456
if (GetContextModificationScope() == ContextModificationScope.CurrentUser && !keyStore.IsProtected)
457457
{
458-
WriteWarning(string.Format(Resources.ServicePrincipalWarning, keyStore.FileName, keyStore.Directory));
458+
WriteWarning(string.Format(Resources.ServicePrincipalWarning, AzureSession.Instance.KeyStoreFile, AzureSession.Instance.ARMProfileDirectory));
459459
}
460460
}
461461
if (azureAccount.Type == "ClientAssertion" && FederatedToken != null)
@@ -714,7 +714,6 @@ public void OnImport()
714714

715715
AzKeyStore keyStore = null;
716716
keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, AzureSession.Instance.KeyStoreFile, false, autoSaveEnabled);
717-
AzureSession.Instance.KeyStoreFile = keyStore.FileName;
718717
AzKeyStore.RegisterJsonConverter(typeof(ServicePrincipalKey), typeof(ServicePrincipalKey).Name);
719718
AzKeyStore.RegisterJsonConverter(typeof(SecureString), typeof(SecureString).Name, new SecureStringConverter());
720719
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore);

src/Accounts/Authentication/AzureSessionInitializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static IAzureSession CreateInstance(IDataStore dataStore = null, Action<string>
268268
session.ARMProfileFile = autoSave.ContextFile;
269269
session.TokenCacheDirectory = autoSave.CacheDirectory;
270270
session.TokenCacheFile = autoSave.CacheFile;
271-
session.KeyStoreFile = "azkeystore";
271+
session.KeyStoreFile = "azkeystore.cache";
272272
autoSave.Settings.TryGetValue("InstallationId", out string installationId);
273273
session.ExtendedProperties.Add("InstallationId", installationId);
274274
InitializeConfigs(session, profilePath, writeWarning);

src/Accounts/Authentication/KeyStore/AzKeyStore.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ public bool IsProtected
7676
get => Storage.IsProtected;
7777
}
7878

79-
public string FileName
80-
{
81-
get => Storage.FileName;
82-
}
83-
84-
public string Directory
85-
{
86-
get => Storage.Directory;
87-
}
88-
8979
public AzKeyStore()
9080
{
9181

src/Accounts/Authentication/KeyStore/IStorage.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public interface IStorage
2929

3030
Exception GetLastError();
3131

32-
string FileName { get; set; }
33-
string Directory { get; set; }
34-
3532
bool IsProtected
3633
{
3734
get;

src/Accounts/Authentication/KeyStore/StorageWrapper.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class StorageWrapper : IStorage
3030

3131
private Storage _storage = null;
3232

33-
private bool isProtected;
33+
private bool _protected;
3434
public bool IsProtected
3535
{
36-
get => isProtected;
37-
private set => isProtected = value;
36+
get => _protected;
37+
private set => _protected = value;
3838
}
3939

4040
static ReaderWriterLockSlim storageLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
@@ -51,32 +51,28 @@ public IStorage Create()
5151
{
5252
throw new InvalidOperationException(Resources.StorageLockConflicts);
5353
}
54-
string tempFileName = null;
5554
try
5655
{
57-
tempFileName = $"{FileName}.cache";
58-
storageProperties = new StorageCreationPropertiesBuilder(tempFileName, Directory)
56+
storageProperties = new StorageCreationPropertiesBuilder(FileName, Directory)
5957
.WithMacKeyChain(KeyChainServiceName + ".other_secrets", FileName)
6058
.WithLinuxKeyring(FileName, "default", "AzKeyStoreCache",
6159
new KeyValuePair<string, string>("AzureClientID", "Microsoft.Developer.Azure.PowerShell"),
6260
new KeyValuePair<string, string>("Microsoft.Developer.Azure.PowerShell", "1.0.0.0"));
6361
_storage = Storage.Create(storageProperties.Build());
6462
VerifyPersistence();
65-
isProtected = true;
63+
_protected = true;
6664
}
6765
catch (Exception e)
6866
{
6967
_lastError = e;
70-
tempFileName = $"{FileName}.json";
71-
storageProperties = new StorageCreationPropertiesBuilder(tempFileName, Directory).WithUnprotectedFile();
68+
storageProperties = new StorageCreationPropertiesBuilder(FileName, Directory).WithUnprotectedFile();
7269
_storage = Storage.Create(storageProperties.Build());
73-
isProtected = false;
70+
_protected = false;
7471
}
7572
finally
7673
{
7774
storageLock.ExitWriteLock();
7875
}
79-
FileName = tempFileName ?? FileName;
8076
return this;
8177
}
8278

0 commit comments

Comments
 (0)