Skip to content

Commit 6acb588

Browse files
Merge pull request #266 from Avanade/feat/newcartridges
feat: refactoring AzureStorage adapter.
2 parents e921136 + 5af7854 commit 6acb588

File tree

14 files changed

+320
-150
lines changed

14 files changed

+320
-150
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# CI & CD workflow
2-
name: CI/CD - Liquid.Adapter.AzureStorage component for Liquid Application Framework
2+
name: CI/CD - Liquid.Storage.AzureStorage component for Liquid Application Framework
33

44
on:
55
push:
66
branches: [ main, releases/v2.X.X, releases/v6.X.X ]
77
paths:
8-
- 'src/Liquid.Adapter.AzureStorage/**'
8+
- 'src/Liquid.Storage.AzureStorage/**'
99

1010
pull_request:
1111
branches: [ main, releases/** ]
1212
types: [opened, synchronize, reopened]
1313
paths:
14-
- 'src/Liquid.Adapter.AzureStorage/**'
14+
- 'src/Liquid.Storage.AzureStorage/**'
1515

1616
# Allows you to run this workflow manually from the Actions tab
1717
workflow_dispatch:
@@ -20,7 +20,7 @@ jobs:
2020
call-reusable-build-workflow:
2121
uses: Avanade/Liquid-Application-Framework/.github/workflows/base-liquid-ci-and-cd.yml@main
2222
with:
23-
component_name: Liquid.Adapter.AzureStorage
23+
component_name: Liquid.Storage.AzureStorage
2424
secrets:
2525
sonar_token: ${{ secrets.SONAR_TOKEN_STORAGE }}
2626
nuget_token: ${{ secrets.PUBLISH_TO_NUGET_ORG }}

Liquid.Application.Framework.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.WebApi.Http", "src\L
6161
EndProject
6262
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.WebApi.Http.Tests", "test\Liquid.WebApi.Http.Tests\Liquid.WebApi.Http.Tests.csproj", "{DED98401-EAED-4BE0-84A9-494D77B0E70D}"
6363
EndProject
64-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Adapter.AzureStorage", "src\Liquid.Adapter.AzureStorage\Liquid.Adapter.AzureStorage.csproj", "{F599C512-7224-4A27-A474-3AA9510D2A14}"
64+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Storage.AzureStorage", "src\Liquid.Storage.AzureStorage\Liquid.Storage.AzureStorage.csproj", "{F599C512-7224-4A27-A474-3AA9510D2A14}"
6565
EndProject
6666
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Adapter.Dataverse", "src\Liquid.Adapter.Dataverse\Liquid.Adapter.Dataverse.csproj", "{CD31C6F6-F8DD-4B56-B08C-D9E8D5BA3E73}"
6767
EndProject
6868
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Adapter.Dataverse.Tests", "test\Liquid.Adapter.Dataverse.Tests\Liquid.Adapter.Dataverse.Tests.csproj", "{5B0DC38B-5BC9-4DAC-8527-8D1C33E97247}"
6969
EndProject
70-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Adapter.AzureStorage.Tests", "test\Liquid.Adapter.AzureStorage.Tests\Liquid.Adapter.AzureStorage.Tests.csproj", "{53341B04-6D30-4137-943B-20D8706351E8}"
70+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Storage.AzureStorage.Tests", "test\Liquid.Storage.AzureStorage.Tests\Liquid.Storage.AzureStorage.Tests.csproj", "{53341B04-6D30-4137-943B-20D8706351E8}"
7171
EndProject
7272
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.ChatCompletions.OpenAi", "src\Liquid.ChatCompletions.OpenAi\Liquid.ChatCompletions.OpenAi.csproj", "{CB199ED6-3D1D-4E12-A15F-597B6A0BA564}"
7373
EndProject

src/Liquid.Adapter.AzureStorage/ILiquidBlobStorageAdapter.cs

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

src/Liquid.Adapter.AzureStorage/LiquidBlob.cs

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

src/Liquid.Adapter.AzureStorage/BlobClientFactory.cs renamed to src/Liquid.Storage.AzureStorage/BlobClientFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using Azure.Core;
2-
using Azure.Storage.Blobs;
1+
using Azure.Storage.Blobs;
32
using Microsoft.Extensions.Options;
43

5-
namespace Liquid.Adapter.AzureStorage
4+
namespace Liquid.Storage.AzureStorage
65
{
76
///<inheritdoc/>
87
public class BlobClientFactory : IBlobClientFactory
98
{
109
private readonly StorageSettings _options;
11-
private IList<BlobContainerClient> _clients = new List<BlobContainerClient>();
10+
private readonly List<BlobContainerClient> _clients = new List<BlobContainerClient>();
1211

1312
///<inheritdoc/>
1413
public IList<BlobContainerClient> Clients => _clients;
@@ -26,12 +25,12 @@ public BlobClientFactory(IOptions<StorageSettings>? options)
2625
///<inheritdoc/>
2726
public void SetContainerClients()
2827
{
29-
if(_options.Containers.Count == 0)
30-
throw new ArgumentNullException(nameof(_options));
28+
if (_options.Containers.Count == 0)
29+
throw new ArgumentNullException(nameof(_options));
3130

32-
foreach(var container in _options.Containers)
31+
foreach (var container in _options.Containers)
3332
{
34-
var client = new BlobContainerClient(container.ConnectionString,container.ContainerName);
33+
var client = new BlobContainerClient(container.ConnectionString, container.ContainerName);
3534

3635
_clients.Add(client);
3736
}
@@ -42,8 +41,9 @@ public BlobContainerClient GetContainerClient(string containerName)
4241
{
4342
var client = _clients.FirstOrDefault(x => x.Name == containerName);
4443

45-
if (client == null) {
46-
throw new ArgumentException(nameof(containerName));
44+
if (client == null)
45+
{
46+
throw new ArgumentException($"Container named {containerName} not found.");
4747
}
4848

4949
return client;

src/Liquid.Adapter.AzureStorage/Extensions/IServiceCollectionExtensions.cs renamed to src/Liquid.Storage.AzureStorage/Extensions/IServiceCollectionExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using Microsoft.Extensions.Configuration;
1+
using Liquid.Core.Interfaces;
2+
using Microsoft.Extensions.Configuration;
23
using Microsoft.Extensions.DependencyInjection;
34
using System.Diagnostics.CodeAnalysis;
45

5-
namespace Liquid.Adapter.AzureStorage.Extensions
6+
namespace Liquid.Storage.AzureStorage.Extensions
67
{
78
/// <summary>
89
/// Extension methods of <see cref="IServiceCollection"/>
@@ -12,7 +13,7 @@ namespace Liquid.Adapter.AzureStorage.Extensions
1213
public static class IServiceCollectionExtensions
1314
{
1415
/// <summary>
15-
/// Registers <see cref="BlobStorageAdapter"/> service, it's dependency
16+
/// Registers <see cref="LiquidStorageAzure"/> service, it's dependency
1617
/// <see cref="BlobClientFactory"/>, and also set configuration
1718
/// option <see cref="StorageSettings"/>.
1819
/// </summary>
@@ -28,7 +29,7 @@ public static IServiceCollection AddLiquidAzureStorageAdapter(this IServiceColle
2829

2930
services.AddSingleton<IBlobClientFactory, BlobClientFactory>();
3031

31-
services.AddScoped<ILiquidBlobStorageAdapter, BlobStorageAdapter>();
32+
services.AddScoped<ILiquidStorage, LiquidStorageAzure>();
3233

3334
return services;
3435
}

src/Liquid.Adapter.AzureStorage/IBlobClientFactory.cs renamed to src/Liquid.Storage.AzureStorage/IBlobClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Azure.Storage.Blobs;
22

3-
namespace Liquid.Adapter.AzureStorage
3+
namespace Liquid.Storage.AzureStorage
44
{
55
/// <summary>
66
/// <see cref="BlobContainerClient"/> instances factory.

src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj renamed to src/Liquid.Storage.AzureStorage/Liquid.Storage.AzureStorage.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
30+
<PackageReference Include="Azure.Storage.Blobs" Version="12.24.0" />
31+
<PackageReference Include="Liquid.Core" Version="8.0.0-rc-01" />
3132
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
32-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
33+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
3334
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
3435
</ItemGroup>
3536

src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs renamed to src/Liquid.Storage.AzureStorage/LiquidStorageAzure.cs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
using Azure.Storage.Blobs.Models;
33
using Azure.Storage.Blobs.Specialized;
44
using Azure.Storage.Sas;
5-
using System.Diagnostics.CodeAnalysis;
5+
using Liquid.Core.Entities;
6+
using Liquid.Core.Interfaces;
67
using System.Text;
78

8-
namespace Liquid.Adapter.AzureStorage
9+
namespace Liquid.Storage.AzureStorage
910
{
1011
///<inheritdoc/>
11-
[ExcludeFromCodeCoverage]
12-
public class BlobStorageAdapter : ILiquidBlobStorageAdapter
12+
public class LiquidStorageAzure : ILiquidStorage
1313
{
1414
private readonly IBlobClientFactory _factory;
1515

1616
/// <summary>
17-
/// Initialize a new instance of <see cref="BlobStorageAdapter"/>
17+
/// Initialize a new instance of <see cref="LiquidStorageAzure"/>
1818
/// </summary>
1919
/// <param name="factory"></param>
2020
/// <exception cref="ArgumentNullException"></exception>
21-
public BlobStorageAdapter(IBlobClientFactory factory)
21+
public LiquidStorageAzure(IBlobClientFactory factory)
2222
{
2323
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
2424

@@ -30,21 +30,22 @@ public async Task DeleteByTags(IDictionary<string, string> tags, string containe
3030
{
3131
var client = _factory.GetContainerClient(containerName);
3232

33-
var stringFilter = string.Empty;
34-
33+
var stringFilterBd = new StringBuilder();
3534
foreach (var tag in tags)
3635
{
37-
stringFilter += @$"""{tag.Key}"" = '{tag.Value}' AND ";
36+
stringFilterBd.Append(@$"""{tag.Key}"" = '{tag.Value}' AND ");
3837
}
3938

39+
var stringFilter = stringFilterBd.ToString();
40+
4041
stringFilter = stringFilter.Substring(0, stringFilter.Length - 4);
4142

4243
await foreach (TaggedBlobItem blobItem in client.FindBlobsByTagsAsync(stringFilter))
4344
{
4445
var blockBlob = client.GetBlockBlobClient(blobItem.BlobName);
4546

4647
await blockBlob.DeleteAsync();
47-
};
48+
}
4849
}
4950

5051
///<inheritdoc/>
@@ -58,11 +59,12 @@ public async Task<List<LiquidBlob>> GetAllBlobs(string containerName)
5859
{
5960
var blockBlob = client.GetBlockBlobClient(blobItem.Name);
6061
var blob = await blockBlob.DownloadContentAsync();
62+
var blobTags = await blockBlob.GetTagsAsync();
6163

6264
var item = new LiquidBlob
6365
{
6466
Blob = blob.Value.Content.ToArray(),
65-
Tags = blockBlob.GetTags().Value.Tags,
67+
Tags = blobTags?.Value?.Tags,
6668
Name = blobItem.Name,
6769
AbsoluteUri = blockBlob.Uri.AbsoluteUri
6870
};
@@ -87,22 +89,26 @@ public async Task<List<LiquidBlob>> ReadBlobsByTags(IDictionary<string, string>
8789
{
8890
var client = _factory.GetContainerClient(containerName);
8991

90-
var stringFilter = string.Empty;
92+
var stringFilterBd = new StringBuilder();
9193
foreach (var tag in tags)
9294
{
93-
stringFilter += @$"""{tag.Key}"" = '{tag.Value}' AND ";
95+
stringFilterBd.Append(@$"""{tag.Key}"" = '{tag.Value}' AND ");
9496
}
97+
98+
var stringFilter = stringFilterBd.ToString();
9599
stringFilter = stringFilter.Substring(0, stringFilter.Length - 4);
96100

97101
var results = new List<LiquidBlob>();
98102
await foreach (TaggedBlobItem blobItem in client.FindBlobsByTagsAsync(stringFilter))
99103
{
100104
var blockBlob = client.GetBlockBlobClient(blobItem.BlobName);
101105
var blob = await blockBlob.DownloadContentAsync();
106+
var blobTags = await blockBlob.GetTagsAsync();
107+
102108
var item = new LiquidBlob
103109
{
104110
Blob = blob.Value.Content.ToArray(),
105-
Tags = blockBlob.GetTags().Value.Tags,
111+
Tags = blobTags?.Value?.Tags,
106112
Name = blobItem.BlobName,
107113
AbsoluteUri = blockBlob.Uri.AbsoluteUri
108114
};
@@ -135,10 +141,12 @@ public async Task<LiquidBlob> ReadBlobsByName(string blobName, string containerN
135141
var client = _factory.GetContainerClient(containerName);
136142
var blockBlob = client.GetBlockBlobClient(blobName);
137143
var blob = await blockBlob.DownloadContentAsync();
144+
var tags = await blockBlob.GetTagsAsync();
145+
138146
var item = new LiquidBlob
139147
{
140148
Blob = blob.Value.Content.ToArray(),
141-
Tags = blockBlob.GetTags().Value.Tags,
149+
Tags = tags?.Value?.Tags,
142150
Name = blobName,
143151
AbsoluteUri = blockBlob.Uri.AbsoluteUri
144152
};
@@ -150,15 +158,15 @@ public async Task<LiquidBlob> ReadBlobsByName(string blobName, string containerN
150158
{
151159
return null;
152160
}
153-
catch (Exception)
161+
catch (Exception ex)
154162
{
155-
throw;
163+
throw new ArgumentOutOfRangeException("Error reading blob", ex);
156164
}
157165

158166
}
159167

160168
///<inheritdoc/>
161-
public string? GetBlobSasUri(string blobName, string containerName, DateTimeOffset expiresOn, BlobContainerSasPermissions permissions)
169+
public string? GetBlobSasUri(string blobName, string containerName, DateTimeOffset expiresOn, string permissions)
162170
{
163171
var blobClient = _factory.GetContainerClient(containerName);
164172

@@ -183,5 +191,6 @@ public async Task<LiquidBlob> ReadBlobsByName(string blobName, string containerN
183191

184192
return sasURI.AbsoluteUri;
185193
}
194+
186195
}
187196
}

src/Liquid.Adapter.AzureStorage/StorageSettings.cs renamed to src/Liquid.Storage.AzureStorage/StorageSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Liquid.Adapter.AzureStorage
1+
namespace Liquid.Storage.AzureStorage
22
{
33
/// <summary>
44
/// Set of Azure Storage containers configs.

0 commit comments

Comments
 (0)