-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Substitute PolicyRepository with PolicyFactory and add CancellationTo…
…ken (#777)
- Loading branch information
1 parent
dddaf53
commit 52e27b5
Showing
44 changed files
with
647 additions
and
549 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/Altinn.AccessManagement.Core/Enums/PolicyAccountType.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,14 @@ | ||
namespace Altinn.AccessManagement.Core.Enums | ||
{ | ||
/// <summary> | ||
/// Storage Account | ||
/// </summary> | ||
public enum PolicyAccountType | ||
{ | ||
ResourceRegister, | ||
|
||
Delegations, | ||
|
||
Metadata, | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Altinn.AccessManagement.Core/Repositories/Interfaces/IPolicyFactory.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,24 @@ | ||
using Altinn.AccessManagement.Core.Enums; | ||
|
||
namespace Altinn.AccessManagement.Core.Repositories.Interfaces; | ||
|
||
/// <summary> | ||
/// Create clients for interacting with files | ||
/// </summary> | ||
public interface IPolicyFactory | ||
{ | ||
/// <summary> | ||
/// Creates a client for interacting with storage | ||
/// </summary> | ||
/// <param name="account">which storage account to write blob</param> | ||
/// <param name="filepath">path of the file</param> | ||
/// <returns></returns> | ||
IPolicyRepository Create(PolicyAccountType account, string filepath); | ||
|
||
/// <summary> | ||
/// Creates a client for interacting with storage. assuming storage accoutn based on filename. | ||
/// </summary> | ||
/// <param name="filepath">path of the file</param> | ||
/// <returns></returns> | ||
IPolicyRepository Create(string filepath); | ||
} |
117 changes: 58 additions & 59 deletions
117
src/Altinn.AccessManagement.Core/Repositories/Interfaces/IPolicyRepository.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 |
---|---|---|
@@ -1,72 +1,71 @@ | ||
using Azure; | ||
using Azure.Storage.Blobs.Models; | ||
|
||
namespace Altinn.AccessManagement.Core.Repositories.Interfaces | ||
namespace Altinn.AccessManagement.Core.Repositories.Interfaces; | ||
|
||
/// <summary> | ||
/// Interface for operations on policy files. | ||
/// </summary> | ||
public interface IPolicyRepository | ||
{ | ||
/// <summary> | ||
/// Interface for operations on policy files. | ||
/// Gets file stream for the policy file from blob storage, if it exists at the specified path. | ||
/// </summary> | ||
public interface IPolicyRepository | ||
{ | ||
/// <summary> | ||
/// Gets file stream for the policy file from blob storage, if it exists at the specified path. | ||
/// </summary> | ||
/// <param name="filepath">The file path.</param> | ||
/// <returns>File stream of the policy file</returns> | ||
Task<Stream> GetPolicyAsync(string filepath); | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>File stream of the policy file</returns> | ||
Task<Stream> GetPolicyAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Gets file stream for the specified version of a policy file from blob storage, if it exists at the specified path. | ||
/// </summary> | ||
/// <param name="filepath">The file path.</param> | ||
/// <param name="version">The blob storage version</param> | ||
/// <returns>File stream of the policy file</returns> | ||
Task<Stream> GetPolicyVersionAsync(string filepath, string version); | ||
/// <summary> | ||
/// Gets file stream for the specified version of a policy file from blob storage, if it exists at the specified path. | ||
/// </summary> | ||
/// <param name="version">The blob storage version</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>File stream of the policy file</returns> | ||
Task<Stream> GetPolicyVersionAsync(string version, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Writes a file stream to blobstorage to the specified path. | ||
/// </summary> | ||
/// <param name="filepath">The file path.</param> | ||
/// <param name="fileStream">File stream of the policy file to be written</param> | ||
/// <returns>Azure response BlobContentInfo</returns> | ||
Task<Response<BlobContentInfo>> WritePolicyAsync(string filepath, Stream fileStream); | ||
/// <summary> | ||
/// Writes a file stream to blobstorage to the specified path. | ||
/// </summary> | ||
/// <param name="fileStream">File stream of the policy file to be written</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>Azure response BlobContentInfo</returns> | ||
Task<Response<BlobContentInfo>> WritePolicyAsync(Stream fileStream, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Writes a file stream to blobstorage to the specified path, including the conditional check that the provided blob lease id is valid. | ||
/// </summary> | ||
/// <param name="filepath">The file path.</param> | ||
/// <param name="fileStream">File stream of the policy file to be written</param> | ||
/// <param name="blobLeaseId">The blob lease id, required to be able to write after a lock</param> | ||
/// <returns>Azure response BlobContentInfo</returns> | ||
Task<Response<BlobContentInfo>> WritePolicyConditionallyAsync(string filepath, Stream fileStream, string blobLeaseId); | ||
/// <summary> | ||
/// Writes a file stream to blobstorage to the specified path, including the conditional check that the provided blob lease id is valid. | ||
/// </summary> | ||
/// <param name="fileStream">File stream of the policy file to be written</param> | ||
/// <param name="blobLeaseId">The blob lease id, required to be able to write after a lock</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>Azure response BlobContentInfo</returns> | ||
Task<Response<BlobContentInfo>> WritePolicyConditionallyAsync(Stream fileStream, string blobLeaseId, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Deletes a specific version of a blob storage file if it exits on the specified path. | ||
/// </summary> | ||
/// <param name="filepath">The file path.</param> | ||
/// <param name="version">The blob storage version</param> | ||
/// <returns></returns> | ||
Task<Response> DeletePolicyVersionAsync(string filepath, string version); | ||
/// <summary> | ||
/// Deletes a specific version of a blob storage file if it exits on the specified path. | ||
/// </summary> | ||
/// <param name="version">The blob storage version</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns></returns> | ||
Task<Response> DeletePolicyVersionAsync(string version, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Tries to acquire a blob lease on the base blob for the provided filepath. | ||
/// </summary> | ||
/// <param name="filepath">The file path of the base blob to aquire a blob lease on</param> | ||
/// <returns>The LeaseId if a release was possible, otherwise null</returns> | ||
Task<string> TryAcquireBlobLease(string filepath); | ||
/// <summary> | ||
/// Tries to acquire a blob lease on the base blob for the provided filepath. | ||
/// </summary> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>The LeaseId if a release was possible, otherwise null</returns> | ||
Task<string> TryAcquireBlobLease(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Releases a blob lease on the base blob for the provided filepath using the provided leaseId. | ||
/// </summary> | ||
/// <param name="filepath">The file path of the base blob to release</param> | ||
/// <param name="leaseId">The lease id from to release</param> | ||
void ReleaseBlobLease(string filepath, string leaseId); | ||
/// <summary> | ||
/// Releases a blob lease on the base blob for the provided filepath using the provided leaseId. | ||
/// </summary> | ||
/// <param name="leaseId">The lease id from to release</param> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
void ReleaseBlobLease(string leaseId, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Checks whether there exists a blob at the specified path | ||
/// </summary> | ||
/// <param name="filepath">The file path to check if a blob exists</param> | ||
/// <returns>Bool whether the blob exists or not</returns> | ||
Task<bool> PolicyExistsAsync(string filepath); | ||
} | ||
} | ||
/// <summary> | ||
/// Checks whether there exists a blob at the specified path | ||
/// </summary> | ||
/// <param name="cancellationToken">cancellation token</param> | ||
/// <returns>Bool whether the blob exists or not</returns> | ||
Task<bool> PolicyExistsAsync(CancellationToken cancellationToken = default); | ||
} |
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.