-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 182: Rel righe asincrono Related work items: #587
- Loading branch information
Showing
14 changed files
with
341 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Services/IRelRigheStorageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Services; | ||
public interface IRelRigheStorageService | ||
{ | ||
string? GetBlobName(string sidtestata, string nomeEnte, string? extension = ".csv"); | ||
string? GetSASToken(string sidtestata, string nomeEnte); | ||
} |
54 changes: 54 additions & 0 deletions
54
...e/PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Services/RelRigheStorageService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Azure.Storage.Sas; | ||
using Azure.Storage; | ||
using PortaleFatture.BE.Core.Entities.SEND.DatiRel; | ||
using Microsoft.Extensions.Localization; | ||
using Microsoft.Extensions.Logging; | ||
using PortaleFatture.BE.Core.Common; | ||
using PortaleFatture.BE.Core.Resources; | ||
using PortaleFatture.BE.Infrastructure.Gateway.Storage; | ||
|
||
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Services; | ||
|
||
public class RelRigheStorageService(IPortaleFattureOptions options, | ||
IStringLocalizer<Localization> localizer, | ||
ILogger<RelStorageService> logger) : IRelRigheStorageService | ||
{ | ||
private readonly IStringLocalizer<Localization> _localizer = localizer; | ||
private readonly ILogger<RelStorageService> _logger = logger; | ||
private readonly IPortaleFattureOptions _options = options; | ||
private string _accountName { get; set; } = options.StorageREL!.StorageRELAccountName!; | ||
private string _accountKey { get; set; } = options.StorageREL!.StorageRELAccountKey!; | ||
private string _blobContainerName { get; set; } = options.StorageREL!.StorageRELBlobContainerName!; | ||
private string _customDNS { get; set; } = options.StorageREL!.StorageRELCustomDns!; | ||
|
||
public string? GetBlobName(string sidtestata, string nomeEnte, string? extension = ".csv") | ||
{ | ||
var idTestata = RelTestataKey.Deserialize(sidtestata); | ||
return $"{idTestata.Anno}/{idTestata.Mese}/{idTestata.TipologiaFattura}/{idTestata.IdEnte}/{idTestata.IdContratto}/Rel_Report di dettaglio_{nomeEnte}_{idTestata.Mese}_{idTestata.Anno}{extension}"; | ||
} | ||
|
||
public string? GetSASToken(string sidtestata, string nomeEnte) | ||
{ | ||
var blobName = GetBlobName(sidtestata, nomeEnte); | ||
var sasToken = GenerateBlobSasToken(_accountName, _accountKey, _blobContainerName, blobName); | ||
return $"{_customDNS}/{_blobContainerName}/{blobName}?{sasToken}"; | ||
} | ||
|
||
static string GenerateBlobSasToken(string accountName, string accountKey, string containerName, string? blobName) | ||
{ | ||
var credential = new StorageSharedKeyCredential(accountName, accountKey); | ||
|
||
var sasBuilder = new BlobSasBuilder() | ||
{ | ||
BlobContainerName = containerName, | ||
BlobName = blobName, | ||
Resource = "b", // "b" for blob-level SAS | ||
ExpiresOn = DateTimeOffset.UtcNow.AddHours(1), | ||
StartsOn = DateTimeOffset.UtcNow.AddHours(-1) | ||
}; | ||
|
||
sasBuilder.SetPermissions(BlobSasPermissions.Read); | ||
|
||
return sasBuilder.ToSasQueryParameters(credential).ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.