Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort the results of Get-SecretInfo correctly #219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/code/SecretManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,15 +1092,9 @@ private void WriteResults(SecretInformation[] results)
if (results == null) { return; }

// Ensure each vaults results are sorted by secret name.
var sortedList = new SortedDictionary<string, SecretInformation>(StringComparer.OrdinalIgnoreCase);
foreach (var item in results)
{
sortedList.Add(
key: item.Name,
value: item);
}
Array.Sort(results, new SecretInformationComparer());

foreach (var item in sortedList.Values)
foreach (var item in results)
{
WriteObject(item);
}
Expand Down
11 changes: 11 additions & 0 deletions src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@

#endregion
}

/// <summary>
/// Compares secret information by name.
/// </summary>
public class SecretInformationComparer : IComparer<SecretInformation>
{
public int Compare(SecretInformation x, SecretInformation y)

Check warning on line 333 in src/code/Utils.cs

View workflow job for this annotation

GitHub Actions / pester (windows-latest)

Missing XML comment for publicly visible type or member 'SecretInformationComparer.Compare(SecretInformation, SecretInformation)'

Check warning on line 333 in src/code/Utils.cs

View workflow job for this annotation

GitHub Actions / pester (macos-latest)

Missing XML comment for publicly visible type or member 'SecretInformationComparer.Compare(SecretInformation, SecretInformation)'

Check warning on line 333 in src/code/Utils.cs

View workflow job for this annotation

GitHub Actions / pester (ubuntu-latest)

Missing XML comment for publicly visible type or member 'SecretInformationComparer.Compare(SecretInformation, SecretInformation)'
{
return string.Compare(x.Name, y.Name, StringComparison.Ordinal);
}
}

#endregion

Expand Down