Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Dec 7, 2022
1 parent c18dda1 commit 46971ea
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public override void ExecuteCmdlet()
keyStore?.SaveKey(new ServicePrincipalKey(AzureAccount.Property.CertificatePassword, azureAccount.Id, Tenant), CertificatePassword);
if (GetContextModificationScope() == ContextModificationScope.CurrentUser && !keyStore.IsProtected)
{
WriteWarning(string.Format(Resources.ServicePrincipalWarning, keyStore.FileName, keyStore.Directory));
WriteWarning(string.Format(Resources.ServicePrincipalWarning, AzureSession.Instance.KeyStoreFile, AzureSession.Instance.ARMProfileDirectory));
}
}
}
Expand All @@ -455,7 +455,7 @@ public override void ExecuteCmdlet()
,azureAccount.Id, Tenant), password);
if (GetContextModificationScope() == ContextModificationScope.CurrentUser && !keyStore.IsProtected)
{
WriteWarning(string.Format(Resources.ServicePrincipalWarning, keyStore.FileName, keyStore.Directory));
WriteWarning(string.Format(Resources.ServicePrincipalWarning, AzureSession.Instance.KeyStoreFile, AzureSession.Instance.ARMProfileDirectory));
}
}
if (azureAccount.Type == "ClientAssertion" && FederatedToken != null)
Expand Down Expand Up @@ -714,7 +714,6 @@ public void OnImport()

AzKeyStore keyStore = null;
keyStore = new AzKeyStore(AzureSession.Instance.ARMProfileDirectory, AzureSession.Instance.KeyStoreFile, false, autoSaveEnabled);
AzureSession.Instance.KeyStoreFile = keyStore.FileName;
AzKeyStore.RegisterJsonConverter(typeof(ServicePrincipalKey), typeof(ServicePrincipalKey).Name);
AzKeyStore.RegisterJsonConverter(typeof(SecureString), typeof(SecureString).Name, new SecureStringConverter());
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore);
Expand Down
2 changes: 1 addition & 1 deletion src/Accounts/Authentication/AzureSessionInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static IAzureSession CreateInstance(IDataStore dataStore = null, Action<string>
session.ARMProfileFile = autoSave.ContextFile;
session.TokenCacheDirectory = autoSave.CacheDirectory;
session.TokenCacheFile = autoSave.CacheFile;
session.KeyStoreFile = "azkeystore";
session.KeyStoreFile = "azkeystore.cache";
autoSave.Settings.TryGetValue("InstallationId", out string installationId);
session.ExtendedProperties.Add("InstallationId", installationId);
InitializeConfigs(session, profilePath, writeWarning);
Expand Down
10 changes: 0 additions & 10 deletions src/Accounts/Authentication/KeyStore/AzKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ public bool IsProtected
get => Storage.IsProtected;
}

public string FileName
{
get => Storage.FileName;
}

public string Directory
{
get => Storage.Directory;
}

public AzKeyStore()
{

Expand Down
3 changes: 0 additions & 3 deletions src/Accounts/Authentication/KeyStore/IStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public interface IStorage

Exception GetLastError();

string FileName { get; set; }
string Directory { get; set; }

bool IsProtected
{
get;
Expand Down
18 changes: 7 additions & 11 deletions src/Accounts/Authentication/KeyStore/StorageWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class StorageWrapper : IStorage

private Storage _storage = null;

private bool isProtected;
private bool _protected;
public bool IsProtected
{
get => isProtected;
private set => isProtected = value;
get => _protected;
private set => _protected = value;
}

static ReaderWriterLockSlim storageLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
Expand All @@ -51,32 +51,28 @@ public IStorage Create()
{
throw new InvalidOperationException(Resources.StorageLockConflicts);
}
string tempFileName = null;
try
{
tempFileName = $"{FileName}.cache";
storageProperties = new StorageCreationPropertiesBuilder(tempFileName, Directory)
storageProperties = new StorageCreationPropertiesBuilder(FileName, Directory)
.WithMacKeyChain(KeyChainServiceName + ".other_secrets", FileName)
.WithLinuxKeyring(FileName, "default", "AzKeyStoreCache",
new KeyValuePair<string, string>("AzureClientID", "Microsoft.Developer.Azure.PowerShell"),
new KeyValuePair<string, string>("Microsoft.Developer.Azure.PowerShell", "1.0.0.0"));
_storage = Storage.Create(storageProperties.Build());
VerifyPersistence();
isProtected = true;
_protected = true;
}
catch (Exception e)
{
_lastError = e;
tempFileName = $"{FileName}.json";
storageProperties = new StorageCreationPropertiesBuilder(tempFileName, Directory).WithUnprotectedFile();
storageProperties = new StorageCreationPropertiesBuilder(FileName, Directory).WithUnprotectedFile();
_storage = Storage.Create(storageProperties.Build());
isProtected = false;
_protected = false;
}
finally
{
storageLock.ExitWriteLock();
}
FileName = tempFileName ?? FileName;
return this;
}

Expand Down

0 comments on commit 46971ea

Please sign in to comment.