Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krenek committed Jul 27, 2023
2 parents 019ae9d + 4e26cba commit e1682a9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions BusinessLogicTier/Logic/Management/ManagementLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ public SecureShellKey CreateSecureShellKey(string username, string[] accountingS
SecureShellKey secureShellKey = sshGenerator.GetEncryptedSecureShellKey(username, passphrase);
string keyPath = GetUniquePrivateKeyPath(accountingStrings);
//save private key to file
FileInfo file = new FileInfo(keyPath);
file.Directory.Create();
File.WriteAllText(keyPath, secureShellKey.PrivateKeyPEM);

foreach (var project in existingProjects)
Expand Down Expand Up @@ -324,6 +326,7 @@ public string RemoveSecureShellKey(string publicKey)
{
File.Delete(credentials.PrivateKeyFile);
credentials.IsDeleted = true;
credentials.ClusterProjectCredentials.ForEach(cpc => cpc.IsDeleted = true);
_unitOfWork.ClusterAuthenticationCredentialsRepository.Update(credentials);
}
_unitOfWork.Save();
Expand All @@ -339,7 +342,7 @@ public string RemoveSecureShellKey(string publicKey)
private string ComputePublicKeyFingerprint(string publicKey)
{
publicKey = publicKey.Replace("\n", "");
Regex regex = new Regex(@"([A-Za-z0-9+\/=]+==)");
Regex regex = new Regex(@"([A-Za-z0-9+\/=]+=)");
Match match = regex.Match(publicKey);
if (!match.Success)
{
Expand All @@ -360,7 +363,8 @@ private string GetUniquePrivateKeyPath(string[] projectIds)
{
string projectIdsString = string.Join("_", projectIds);
long netxId = _unitOfWork.ClusterAuthenticationCredentialsRepository.GetAll().Max(x => x.Id) + 1;
string keyPath = Path.Combine(_sshKeysDirectory, $"KEY_{projectIdsString}_{netxId}");
string directoryPath = Path.Combine(_sshKeysDirectory, projectIdsString.ToUpper());
string keyPath = Path.Combine(directoryPath, $"KEY_{projectIdsString}_{netxId}");
return keyPath;
}
}
Expand Down

0 comments on commit e1682a9

Please sign in to comment.