Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ManagedCode.Storage.Aws/AWSStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,14 @@ private async Task UploadStreamInternalAsync(string blobName, Stream dataStream,
}

#endregion

#region CreateContainer

public async Task CreateContainerAsync()
{
await _s3Client.EnsureBucketExistsAsync(_bucket);
}

#endregion

}
25 changes: 22 additions & 3 deletions ManagedCode.Storage.Azure/AzureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ namespace ManagedCode.Storage.Azure;

public class AzureStorage : IAzureStorage
{
private readonly BlobContainerClient _blobContainerClient;
private BlobContainerClient _blobContainerClient;
private readonly AzureStorageOptions _options;

public AzureStorage(AzureStorageOptions options)
{
_options = options;
_blobContainerClient = new BlobContainerClient(
options.ConnectionString,
options.Container,
options.OriginalOptions
);

if (options.ShouldCreateIfNotExists)

if (_options.ShouldCreateIfNotExists)
{
_blobContainerClient.CreateIfNotExists(PublicAccessType.BlobContainer);
}

_blobContainerClient.SetAccessPolicy(options.PublicAccessType);
_blobContainerClient.SetAccessPolicy(_options.PublicAccessType);
}

public void Dispose()
Expand Down Expand Up @@ -246,4 +249,20 @@ public async Task<string> UploadAsync(Stream dataStream, CancellationToken cance
}

#endregion

#region CreateContainer

public async Task CreateContainerAsync()
{

if (_options.ShouldCreateIfNotExists)
{
await _blobContainerClient.CreateIfNotExistsAsync(PublicAccessType.BlobContainer);
}

await _blobContainerClient.SetAccessPolicyAsync(_options.PublicAccessType);
}

#endregion

}
2 changes: 2 additions & 0 deletions ManagedCode.Storage.Core/IStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface IStorage : IDisposable
Task<bool> ExistsAsync(BlobMetadata blobMetadata, CancellationToken cancellationToken = default);
IAsyncEnumerable<bool> ExistsAsync(IEnumerable<string> blobNames, CancellationToken cancellationToken = default);
IAsyncEnumerable<bool> ExistsAsync(IEnumerable<BlobMetadata> blobs, CancellationToken cancellationToken = default);

Task CreateContainerAsync();
}
15 changes: 15 additions & 0 deletions ManagedCode.Storage.FileSystem/FileSystemStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,19 @@ public async Task<string> UploadAsync(Stream dataStream, CancellationToken cance
}

#endregion

#region CreateContainer

public async Task CreateContainerAsync()
{
await Task.Yield();

if (!Directory.Exists(_path))
{
Directory.CreateDirectory(_path);
}
}

#endregion

}
37 changes: 30 additions & 7 deletions ManagedCode.Storage.Gcp/GCPStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@ public class GCPStorage : IGCPStorage
{
private readonly string _bucket;
private readonly StorageClient _storageClient;
private readonly GCPStorageOptions _gcpStorageOptions;

public GCPStorage(GCPStorageOptions gcpStorageOptions)
{
_bucket = gcpStorageOptions.BucketOptions.Bucket;
_gcpStorageOptions = gcpStorageOptions;

if (gcpStorageOptions.StorageClientBuilder != null)
_bucket = _gcpStorageOptions.BucketOptions.Bucket;

if (_gcpStorageOptions.StorageClientBuilder != null)
{
_storageClient = gcpStorageOptions.StorageClientBuilder.Build();
_storageClient = _gcpStorageOptions.StorageClientBuilder.Build();
}
else if (gcpStorageOptions.GoogleCredential != null)
else if (_gcpStorageOptions.GoogleCredential != null)
{
_storageClient = StorageClient.Create(gcpStorageOptions.GoogleCredential);
}

try
{
if (gcpStorageOptions.OriginalOptions != null)
if (_gcpStorageOptions.OriginalOptions != null)
{
_storageClient.CreateBucket(gcpStorageOptions.BucketOptions.ProjectId, _bucket, gcpStorageOptions.OriginalOptions);
_storageClient.CreateBucket(_gcpStorageOptions.BucketOptions.ProjectId, _bucket, _gcpStorageOptions.OriginalOptions);
}
else
{
_storageClient.CreateBucket(gcpStorageOptions.BucketOptions.ProjectId, _bucket);
_storageClient.CreateBucket(_gcpStorageOptions.BucketOptions.ProjectId, _bucket);
}
}
catch
Expand Down Expand Up @@ -263,4 +266,24 @@ private async Task UploadStreamInternalAsync(string blobName, Stream dataStream,
}

#endregion

#region CreateContainer
public async Task CreateContainerAsync()
{
try
{
if (_gcpStorageOptions.OriginalOptions != null)
{
await _storageClient.CreateBucketAsync(_gcpStorageOptions.BucketOptions.ProjectId, _bucket, _gcpStorageOptions.OriginalOptions);
}
else
{
await _storageClient.CreateBucketAsync(_gcpStorageOptions.BucketOptions.ProjectId, _bucket);
}
}
catch
{
}
}
#endregion
}
Loading