diff --git a/src/TesApi.Tests/TerraStorageAccessProviderTests.cs b/src/TesApi.Tests/TerraStorageAccessProviderTests.cs index dbb7552d3..d7250ff79 100644 --- a/src/TesApi.Tests/TerraStorageAccessProviderTests.cs +++ b/src/TesApi.Tests/TerraStorageAccessProviderTests.cs @@ -146,10 +146,11 @@ public async Task GetInternalTesBlobUrlAsync_BlobPathIsProvided_ReturnsValidURLW } [TestMethod] - [DataRow("script/foo.sh")] - [DataRow("/script/foo.sh")] + [DataRow("script/foo.sh", "/script/foo.sh")] + [DataRow("/script/foo.sh", "/script/foo.sh")] + [DataRow("", "")] public async Task GetInternalTesTaskBlobUrlAsync_BlobPathIsProvided_ReturnsValidURLWithWsmContainerTaskIdAndTesPrefixAppended( - string blobName) + string blobName, string expectedBlobName) { SetUpTerraApiClient(); var task = new TesTask { Name = "taskName", Id = Guid.NewGuid().ToString() }; @@ -157,14 +158,15 @@ public async Task GetInternalTesTaskBlobUrlAsync_BlobPathIsProvided_ReturnsValid Assert.IsNotNull(url); var uri = new Uri(url); - Assert.AreEqual($"/{TerraApiStubData.WorkspaceStorageContainerName}/{batchSchedulingOptions.Prefix}{StorageAccessProvider.TesExecutionsPathPrefix}/{task.Id}/{blobName.TrimStart('/')}", uri.AbsolutePath); + Assert.AreEqual($"/{TerraApiStubData.WorkspaceStorageContainerName}/{batchSchedulingOptions.Prefix}{StorageAccessProvider.TesExecutionsPathPrefix}/{task.Id}{expectedBlobName}", uri.AbsolutePath); } [TestMethod] - [DataRow("script/foo.sh")] - [DataRow("/script/foo.sh")] + [DataRow("script/foo.sh", "/script/foo.sh")] + [DataRow("/script/foo.sh", "/script/foo.sh")] + [DataRow("", "")] public async Task GetInternalTesTaskBlobUrlAsync_BlobPathAndInternalPathPrefixIsProvided_ReturnsValidURLWithWsmContainerTaskIdAndInternalPathPrefixAppended( - string blobName) + string blobName, string expectedBlobName) { var internalPathPrefix = "internalPathPrefix"; @@ -179,7 +181,7 @@ public async Task GetInternalTesTaskBlobUrlAsync_BlobPathAndInternalPathPrefixIs Assert.IsNotNull(url); var uri = new Uri(url); - Assert.AreEqual($"/{TerraApiStubData.WorkspaceStorageContainerName}/{internalPathPrefix}/{blobName.TrimStart('/')}", uri.AbsolutePath); + Assert.AreEqual($"/{TerraApiStubData.WorkspaceStorageContainerName}/{internalPathPrefix}{expectedBlobName}", uri.AbsolutePath); } } } diff --git a/src/TesApi.Web/Storage/TerraStorageAccessProvider.cs b/src/TesApi.Web/Storage/TerraStorageAccessProvider.cs index aed4a483e..464a02315 100644 --- a/src/TesApi.Web/Storage/TerraStorageAccessProvider.cs +++ b/src/TesApi.Web/Storage/TerraStorageAccessProvider.cs @@ -102,19 +102,44 @@ public override async Task MapLocalPathToSasUrlAsync(string path, Cancel return await GetMappedSasUrlFromWsmAsync(terraBlobInfo, cancellationToken); } - /// + /// + /// Returns a URL with a SAS token for the provided blobPath.The resulting URL contains the TES internal segments as a prefix to the blobPath. + /// If the blobPath is not provided(empty), a container SAS token is generated. + /// If the blobPath is provided, a SAS token to the blobPath prefixed with the TES internal segments is generated. + /// + /// + /// + /// public override async Task GetInternalTesBlobUrlAsync(string blobPath, CancellationToken cancellationToken) { var blobInfo = GetTerraBlobInfoForInternalTes(blobPath); + if (string.IsNullOrEmpty(blobPath)) + { + return await GetMappedSasContainerUrlFromWsmAsync(blobInfo, cancellationToken); + } + return await GetMappedSasUrlFromWsmAsync(blobInfo, cancellationToken); } - /// + /// + /// Returns a URL with a SAS token for the provided blobPath.The resulting URL contains the TES task internal segments as a prefix to the blobPath. + /// If the blobPath is not provided(empty), a container SAS token is generated. + /// If the blobPath is provided, a SAS token to the blobPath prefixed with the TES task internal segments is generated. + /// + /// + /// + /// + /// public override async Task GetInternalTesTaskBlobUrlAsync(TesTask task, string blobPath, CancellationToken cancellationToken) { var blobInfo = GetTerraBlobInfoForInternalTesTask(task, blobPath); + if (string.IsNullOrEmpty(blobPath)) + { + return await GetMappedSasContainerUrlFromWsmAsync(blobInfo, cancellationToken); + } + return await GetMappedSasUrlFromWsmAsync(blobInfo, cancellationToken); } @@ -225,14 +250,13 @@ private Guid ToWorkspaceId(string segmentsContainerName) private async Task GetMappedSasContainerUrlFromWsmAsync(TerraBlobInfo blobInfo, CancellationToken cancellationToken) { - //an empty blob name gets a container Sas token var tokenInfo = await GetWorkspaceContainerSasTokenFromWsmAsync(blobInfo, cancellationToken); var urlBuilder = new UriBuilder(tokenInfo.Url); if (!string.IsNullOrEmpty(blobInfo.BlobName)) { - urlBuilder.Path += $"/{blobInfo.BlobName}"; + urlBuilder.Path += $"/{blobInfo.BlobName.TrimStart('/')}"; } return urlBuilder.Uri.ToString();