31 lines
989 B
C#
31 lines
989 B
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using static StellaOps.Localization.T;
|
|
|
|
namespace StellaOps.Cryptography.Kms;
|
|
|
|
public sealed partial class GcpKmsClient
|
|
{
|
|
private async Task<string> ResolveVersionAsync(string keyId, string? keyVersion, CancellationToken cancellationToken)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(keyVersion))
|
|
{
|
|
return keyVersion!;
|
|
}
|
|
|
|
var snapshot = await GetCachedMetadataAsync(keyId, cancellationToken).ConfigureAwait(false);
|
|
if (!string.IsNullOrWhiteSpace(snapshot.Metadata.PrimaryVersionName))
|
|
{
|
|
return snapshot.Metadata.PrimaryVersionName!;
|
|
}
|
|
|
|
var firstActive = snapshot.Versions.FirstOrDefault(v => v.State == GcpCryptoKeyVersionState.Enabled);
|
|
if (firstActive is not null)
|
|
{
|
|
return firstActive.VersionName;
|
|
}
|
|
|
|
throw new InvalidOperationException(_t("crypto.kms.no_primary_version", keyId));
|
|
}
|
|
} |