Skip to content

Commit db755ab

Browse files
author
Aditya Abhishek
committed
working solution
1 parent 4f13458 commit db755ab

3 files changed

Lines changed: 25 additions & 131 deletions

File tree

src/VirtualClient/VirtualClient.Contracts/KeyVaultDescriptor.cs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,37 @@ public KeyVaultDescriptor(DependencyDescriptor descriptor)
4545
/// </summary>
4646
/// <param name="vaultUri">URI of Azure Key Vault.</param>
4747
/// <param name="objectName">Name of the Secret, key or Certificate as applicable.</param>
48-
public KeyVaultDescriptor(string vaultUri, string objectName)
48+
/// <param name="objectType">Type: Secret, key or Certificate as applicable.</param>
49+
public KeyVaultDescriptor(KeyVaultObjectType objectType, string objectName, string? vaultUri = null)
4950
: base()
5051
{
51-
vaultUri.ThrowIfNullOrWhiteSpace(nameof(vaultUri));
5252
objectName.ThrowIfNullOrWhiteSpace(nameof(objectName));
5353

5454
this.VaultUri = vaultUri;
55-
this.ObjectName = objectName;
55+
this.Name = objectName;
56+
this.ObjectType = objectType;
5657
}
5758

5859
/// <summary>
59-
/// Gets or sets the URI of the Azure Key Vault.
60-
/// </summary>
61-
public string VaultUri
62-
{
63-
get => this.GetValue<string>(nameof(this.VaultUri));
64-
set => this[nameof(this.VaultUri)] = value;
65-
}
66-
67-
/// <summary>
68-
/// Gets or sets the name of the secret, key, or certificate.
60+
/// Gets or sets the type of the Key Vault object (e.g. "Secret", "Key", "Certificate").
6961
/// </summary>
70-
public string ObjectName
62+
public KeyVaultObjectType ObjectType
7163
{
72-
get => this.GetValue<string>(nameof(this.ObjectName));
73-
set => this[nameof(this.ObjectName)] = value;
64+
get => this.GetValue<KeyVaultObjectType>(nameof(this.ObjectType));
65+
set => this[nameof(this.ObjectType)] = value;
7466
}
7567

7668
/// <summary>
77-
/// Gets or sets the type of the Key Vault object (e.g. "Secret", "Key", "Certificate").
69+
/// Gets or sets the URI of the Azure Key Vault.
7870
/// </summary>
79-
public KeyVaultObjectType ObjectType
71+
public string VaultUri
8072
{
81-
get => this.GetValue<KeyVaultObjectType>(nameof(this.ObjectType));
82-
set => this[nameof(this.ObjectType)] = value;
73+
get
74+
{
75+
this.TryGetValue(nameof(this.VaultUri), out IConvertible vaultUri);
76+
return vaultUri?.ToString();
77+
}
78+
set => this[nameof(this.VaultUri)] = value;
8379
}
8480

8581
/// <summary>

src/VirtualClient/VirtualClient.Core/KeyVaultManager.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public async Task<KeyVaultDescriptor> GetSecretAsync(
7070
{
7171
this.ValidateKeyVaultStore();
7272
this.StoreDescription.ThrowIfNull(nameof(this.StoreDescription));
73-
KeyVaultManager.ValidateDescriptor(descriptor, nameof(descriptor.ObjectName));
73+
KeyVaultManager.ValidateDescriptor(descriptor, nameof(descriptor.Name));
7474

7575
// Use descriptor.VaultUri if set, otherwise use the store's EndpointUri
7676
Uri vaultUri = !string.IsNullOrWhiteSpace(descriptor.VaultUri)
7777
? new Uri(descriptor.VaultUri)
7878
: ((DependencyKeyVaultStore)this.StoreDescription).EndpointUri;
7979

80-
string secretName = descriptor.ObjectName;
80+
string secretName = descriptor.Name;
8181

8282
SecretClient client = new SecretClient(vaultUri, ((DependencyKeyVaultStore)this.StoreDescription).Credentials);
8383

@@ -90,7 +90,7 @@ public async Task<KeyVaultDescriptor> GetSecretAsync(
9090
{
9191
Value = secret.Value,
9292
Version = secret.Properties.Version,
93-
ObjectName = secretName,
93+
Name = secretName,
9494
VaultUri = vaultUri.ToString(),
9595
ObjectId = secret.Id.ToString(),
9696
ObjectType = KeyVaultObjectType.Secret
@@ -146,14 +146,14 @@ public async Task<KeyVaultDescriptor> GetKeyAsync(
146146
IAsyncPolicy retryPolicy = null)
147147
{
148148
this.ValidateKeyVaultStore();
149-
KeyVaultManager.ValidateDescriptor(descriptor, nameof(descriptor.ObjectName));
149+
KeyVaultManager.ValidateDescriptor(descriptor, nameof(descriptor.Name));
150150

151151
// Use descriptor.VaultUri if set, otherwise use the store's EndpointUri
152152
Uri vaultUri = !string.IsNullOrWhiteSpace(descriptor.VaultUri)
153153
? new Uri(descriptor.VaultUri)
154154
: ((DependencyKeyVaultStore)this.StoreDescription).EndpointUri;
155155

156-
string keyName = descriptor.ObjectName;
156+
string keyName = descriptor.Name;
157157

158158
KeyClient client = new KeyClient(vaultUri, ((DependencyKeyVaultStore)this.StoreDescription).Credentials);
159159

@@ -165,7 +165,7 @@ public async Task<KeyVaultDescriptor> GetKeyAsync(
165165
KeyVaultDescriptor result = new KeyVaultDescriptor(descriptor)
166166
{
167167
ObjectType = KeyVaultObjectType.Key,
168-
ObjectName = keyName,
168+
Name = keyName,
169169
VaultUri = vaultUri.ToString(),
170170
Version = key.Properties.Version,
171171
ObjectId = key.Id.ToString()
@@ -221,14 +221,14 @@ public async Task<KeyVaultDescriptor> GetCertificateAsync(
221221
IAsyncPolicy retryPolicy = null)
222222
{
223223
this.ValidateKeyVaultStore();
224-
KeyVaultManager.ValidateDescriptor(descriptor, nameof(descriptor.ObjectName));
224+
KeyVaultManager.ValidateDescriptor(descriptor, nameof(descriptor.Name));
225225

226226
// Use descriptor.VaultUri if set, otherwise use the store's EndpointUri
227227
Uri vaultUri = !string.IsNullOrWhiteSpace(descriptor.VaultUri)
228228
? new Uri(descriptor.VaultUri)
229229
: ((DependencyKeyVaultStore)this.StoreDescription).EndpointUri;
230230

231-
string certName = descriptor.ObjectName;
231+
string certName = descriptor.Name;
232232

233233
CertificateClient client = new CertificateClient(vaultUri, ((DependencyKeyVaultStore)this.StoreDescription).Credentials);
234234

@@ -240,7 +240,7 @@ public async Task<KeyVaultDescriptor> GetCertificateAsync(
240240
KeyVaultDescriptor result = new KeyVaultDescriptor(descriptor)
241241
{
242242
ObjectType = KeyVaultObjectType.Certificate,
243-
ObjectName = certName,
243+
Name = certName,
244244
VaultUri = vaultUri.ToString(),
245245
Version = cert.Properties.Version,
246246
ObjectId = cert.Id.ToString(),

src/VirtualClient/VirtualClient.Dependencies/DependencySecretResolution.cs

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)