Skip to content

Commit f290a2e

Browse files
committed
Add support for URIs that contain an API key.
1 parent e6921c3 commit f290a2e

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0
1+
3.1.1

src/VirtualClient/VirtualClient.Core/EndpointUtility.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,24 @@ public static DependencyProfileReference CreateProfileReference(string endpoint,
260260
return profile;
261261
}
262262

263+
/// <summary>
264+
/// Returns true/false whether the value is a URI containing an 'api-key' query string parameter.
265+
/// </summary>
266+
/// <param name="value">The value to evaluate.</param>
267+
/// <returns>True if the value is a URI containing an 'api-key' query string parameter. False if not.</returns>
268+
public static bool IsApiKeyUri(string value)
269+
{
270+
if (Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
271+
{
272+
if (!string.IsNullOrWhiteSpace(uri.Query) && Regex.IsMatch(uri.Query, "api-key"))
273+
{
274+
return true;
275+
}
276+
}
277+
278+
return false;
279+
}
280+
263281
/// <summary>
264282
/// Returns true/false whether the value is a custom Virtual Client connection string
265283
/// (e.g. EndpointUrl=https://any.blob.core.windows.net;ManagedIdentityId=307591a4-abb2-4559-af59-b47177d140cf).

src/VirtualClient/VirtualClient.Main/OptionFactory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,10 @@ private static DependencyStore ParseBlobStore(ArgumentResult parsedResult, strin
16991699
{
17001700
store = new DependencyFileStore(storeName, Path.GetFullPath(endpoint));
17011701
}
1702+
else if (EndpointUtility.IsApiKeyUri(endpoint))
1703+
{
1704+
store = new DependencyBlobStore(DependencyBlobStore.Packages, new Uri(endpoint));
1705+
}
17021706
else
17031707
{
17041708
store = EndpointUtility.CreateBlobStoreReference(storeName, endpoint, certificateManager);

src/VirtualClient/VirtualClient.UnitTests/OptionFactoryTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,17 @@ public void PackageStoreOptionSupportsUrisWithMicrosoftEntraIdAndCertificateRefe
12581258
Assert.IsFalse(result.Errors.Any());
12591259
}
12601260

1261+
[Test]
1262+
[TestCase("https://any.azure-api.net?api-key=12345")]
1263+
[TestCase("https://any.azure-api.net/packages-other?api-key=12345")]
1264+
public void PackageStoreOptionSupportsUrisWithApiKeys(string uri)
1265+
{
1266+
Option option = OptionFactory.CreatePackageStoreOption();
1267+
ParseResult result = option.Parse($"--package-store={uri}");
1268+
Assert.IsFalse(result.Errors.Any());
1269+
Assert.AreEqual(uri.ToString(), result.Tokens[1].Value);
1270+
}
1271+
12611272
[Test]
12621273
public void PackageStoreOptionValidatesTheConnectionTokenProvided()
12631274
{

0 commit comments

Comments
 (0)