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
5 changes: 2 additions & 3 deletions FluentStorage.Azure.Blobs/AzureDataLakeStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Azure.Storage;
Expand All @@ -10,6 +8,7 @@
using FluentStorage.Azure.Blobs.Gen2.Model;
using FluentStorage.Utils.Objects;
using Azure.Core.Pipeline;
using FluentStorage.Azure.Identity;

namespace FluentStorage.Azure.Blobs {
class AzureDataLakeStorage : AzureBlobStorage, IAzureDataLakeStorage {
Expand Down
5 changes: 5 additions & 0 deletions FluentStorage.Azure.Blobs/AzureIdentityTypeForwarding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.CompilerServices;
using FluentStorage.Azure.Identity;

[assembly: TypeForwardedTo(typeof(AzureCloudEnvironment))]
[assembly: TypeForwardedTo(typeof(AzureCloudEndpoints))]
1 change: 1 addition & 0 deletions FluentStorage.Azure.Blobs/ExtendedSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using FluentStorage.Blobs;
using FluentStorage.Azure.Blobs;
using FluentStorage.Azure.Blobs.Gen2.Model;
using FluentStorage.Azure.Identity;
using FluentStorage.Utils.Extensions;

namespace Blobs {
Expand Down
47 changes: 17 additions & 30 deletions FluentStorage.Azure.Blobs/Factory.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using Azure.Core;
using Azure.Identity;
using Azure.Storage;
using Azure.Storage.Blobs;
using Azure.Storage.Sas;
using FluentStorage.ConnectionString;
using FluentStorage.Azure.Blobs;
using FluentStorage.Azure.Identity;

namespace FluentStorage {
/// <summary>
Expand Down Expand Up @@ -203,18 +203,12 @@ public static IAzureBlobStorage AzureBlobStorageWithAzureAd(this IBlobStorageFac
if (applicationSecret is null)
throw new ArgumentNullException(nameof(applicationSecret));

var authorityHost = activeDirectoryAuthEndpoint is not null
? new Uri(activeDirectoryAuthEndpoint)
: AzureCloudEndpoints.GetAuthorityEndpoint(cloudEnvironment);

// Create a token credential that can use our Azure Active
// Directory application to authenticate with Azure Storage
TokenCredential credential =
new ClientSecretCredential(
tenantId,
applicationId,
applicationSecret,
new TokenCredentialOptions { AuthorityHost = authorityHost });
TokenCredential credential = AzureStorageIdentity.CreateClientSecretCredential(
tenantId,
applicationId,
applicationSecret,
activeDirectoryAuthEndpoint,
cloudEnvironment);

// Create a client that can authenticate using our token credential
var client = new BlobServiceClient(GetServiceUri(accountName, cloudEnvironment), credential);
Expand Down Expand Up @@ -284,21 +278,15 @@ public static IAzureDataLakeStorage AzureDataLakeStorageWithAzureAd(this IBlobSt
if (applicationSecret is null)
throw new ArgumentNullException(nameof(applicationSecret));

var authorityHost = activeDirectoryAuthEndpoint is not null
? new Uri(activeDirectoryAuthEndpoint)
: AzureCloudEndpoints.GetAuthorityEndpoint(cloudEnvironment);

// Create a token credential that can use our Azure Active
// Directory application to authenticate with Azure Storage
TokenCredential credential =
new ClientSecretCredential(
tenantId,
applicationId,
applicationSecret,
new TokenCredentialOptions { AuthorityHost = authorityHost });
TokenCredential credential = AzureStorageIdentity.CreateClientSecretCredential(
tenantId,
applicationId,
applicationSecret,
activeDirectoryAuthEndpoint,
cloudEnvironment);

// Create a client that can authenticate using our token credential
var client = new BlobServiceClient(GetServiceUri(accountName), credential);
var client = new BlobServiceClient(GetServiceUri(accountName, cloudEnvironment), credential);

return new AzureDataLakeStorage(client, accountName, azureCloudEnvironment: cloudEnvironment);
}
Expand Down Expand Up @@ -388,7 +376,7 @@ public static IAzureBlobStorage AzureBlobStorageWithMsi(this IBlobStorageFactory
string accountName,
string clientId,
AzureCloudEnvironment azureCloudEnvironment) {
TokenCredential credential = new ManagedIdentityCredential(clientId, null);
TokenCredential credential = AzureStorageIdentity.CreateManagedIdentityCredential(clientId);

var client = new BlobServiceClient(GetServiceUri(accountName, azureCloudEnvironment), credential);

Expand Down Expand Up @@ -443,7 +431,7 @@ public static IAzureDataLakeStorage AzureDataLakeStorageWithMsi(this IBlobStorag
string accountName,
string clientId,
AzureCloudEnvironment azureCloudEnvironment) {
TokenCredential credential = new ManagedIdentityCredential(clientId, null);
TokenCredential credential = AzureStorageIdentity.CreateManagedIdentityCredential(clientId);

var client = new BlobServiceClient(GetServiceUri(accountName, azureCloudEnvironment), credential);

Expand Down Expand Up @@ -521,8 +509,7 @@ public static StorageConnectionString ForAzureDataLakeStorageWithAzureAd(this IC
}

private static Uri GetServiceUri(string accountName, AzureCloudEnvironment cloudEnvironment = default) {
var endpoint = AzureCloudEndpoints.GetBlobEndpoint(cloudEnvironment);
return new Uri($"https://{accountName}.blob.{endpoint}/");
return AzureStorageIdentity.CreateBlobServiceUri(accountName, cloudEnvironment);
}

private static bool TryParseSasUrl(string url, out string accountName, out string containerName, out string sas) {
Expand Down
2 changes: 1 addition & 1 deletion FluentStorage.Azure.Blobs/FluentStorage.Azure.Blobs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.14.2" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
<PackageReference Include="MimeMapping" Version="3.1.0" />
</ItemGroup>
Expand All @@ -39,6 +38,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FluentStorage.Azure.Identity\FluentStorage.Azure.Identity.csproj" />
<ProjectReference Include="..\FluentStorage\FluentStorage.csproj" />
</ItemGroup>

Expand Down
84 changes: 43 additions & 41 deletions FluentStorage.Azure.Files/AzConvert.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
using System;
using Microsoft.Azure.Storage.File;

using Azure.Storage.Files.Shares.Models;
using FluentStorage.Blobs;
using FluentStorage.Utils.Extensions;

namespace FluentStorage.Azure.Files {
static class AzConvert {
public static Blob ToBlob(CloudFileShare share) {
public static Blob ToBlob(ShareItem share) {
var blob = new Blob(share.Name, BlobItemKind.Folder);
blob.TryAddProperties(
"IsSnapshot", share.IsSnapshot.ToString(),
"ETag", share.Properties.ETag,
"ETag", share.Properties.ETag?.ToString(),
"LastModified", share.Properties.LastModified?.ToString(),
"Quota", share.Properties.Quota?.ToString(),
"SnapshotTime", share.SnapshotTime?.ToString(),
"QuotaInGB", share.Properties.QuotaInGB?.ToString(),
"IsShare", "True");
blob.Metadata.MergeRange(share.Metadata);
return blob;
}

public static Blob ToBlob(string path, IListFileItem item) {
if (item is CloudFile file) {
var blob = new Blob(path, file.Name, BlobItemKind.File) {
LastModificationTime = file.Properties.LastWriteTime,
Size = file.Properties.Length,
MD5 = file.Properties.ContentMD5
};
blob.TryAddProperties(
"CopyState", file.CopyState?.ToString(),
"ChangeTime", file.Properties.ChangeTime?.ToString(),
"ContentType", file.Properties.ContentType,
"CreationTime", file.Properties.CreationTime?.ToString(),
"ETag", file.Properties.ETag,
"IsServerEncrypted", file.Properties.IsServerEncrypted.ToString(),
"LastModified", file.Properties.LastModified?.ToString(),
"NtfsAttributes", file.Properties.NtfsAttributes?.ToString());
blob.Metadata.MergeRange(file.Metadata);
return blob;
}
else if (item is CloudFileDirectory dir) {
var blob = new Blob(path, dir.Name, BlobItemKind.Folder) {
LastModificationTime = dir.Properties.LastWriteTime
};
public static Blob ToBlob(string path, ShareFileItem item) {
if (item.IsDirectory) {
var blob = new Blob(path, item.Name, BlobItemKind.Folder);
blob.TryAddProperties(
"ChangeTime", dir.Properties.ChangeTime?.ToString(),
"CreationTime", dir.Properties.CreationTime?.ToString(),
"ETag", dir.Properties.ETag,
"IsServerEncrypted", dir.Properties.IsServerEncrypted.ToString(),
"LastModified", dir.Properties.LastModified?.ToString(),
"NtfsAttributes", dir.Properties.NtfsAttributes?.ToString());
blob.Metadata.MergeRange(dir.Metadata);
"ETag", item.Properties.ETag?.ToString(),
"LastModified", item.Properties.LastModified?.ToString());
return blob;
}
else {
throw new NotSupportedException($"don't know '{item.GetType()}' object type");
}

return ToFileBlob(path, item);
}

public static Blob ToBlob(string path, string name, ShareFileProperties properties) {
return ToBlob(path, name, properties, properties.Metadata);
}

private static Blob ToFileBlob(string path, ShareFileItem item) {
ShareFileItemProperties properties = item.Properties;
var blob = new Blob(path, item.Name, BlobItemKind.File) {
LastModificationTime = properties.LastModified,
Size = item.FileSize
};
blob.TryAddProperties(
"ETag", properties.ETag?.ToString(),
"LastModified", properties.LastModified?.ToString());
return blob;
}

private static Blob ToBlob(string path, string name, ShareFileProperties properties, System.Collections.Generic.IDictionary<string, string> metadata) {
var blob = new Blob(path, name, BlobItemKind.File) {
LastModificationTime = properties.LastModified,
Size = properties.ContentLength,
MD5 = properties.ContentHash == null ? null : Convert.ToBase64String(properties.ContentHash)
};
blob.TryAddProperties(
"CopyStatus", properties.CopyStatus.ToString(),
"ContentType", properties.ContentType,
"ETag", properties.ETag.ToString(),
"IsServerEncrypted", properties.IsServerEncrypted.ToString(),
"LastModified", properties.LastModified.ToString());
blob.Metadata.MergeRange(metadata);
return blob;
}
}
}
Loading