Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BlobStorage to use Azure.Storage.Blobs #1564

Merged
merged 21 commits into from
Oct 8, 2021

Conversation

tedvanderveen
Copy link
Contributor

@tedvanderveen tedvanderveen commented Mar 24, 2021

Use the v.12 version of the Azure Storage SDK to replace the now deprecated Microsoft.Azure.Storage.Blob nuget packages

See also #944

/// <param name="naming">How uploaded media files should be named</param>
/// <param name="scope">The optional service scope. Default is singleton</param>
/// <returns>The service collection</returns>
public static IServiceCollection AddPiranhaBlobStorage(
this IServiceCollection services,
StorageCredentials credentials,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constitutes the main breaking change when moving to the v.12 Azure SDK, as the StorageCredentials class is no longer available.

_naming = naming;
_storage.CreateIfNotExists(PublicAccessType.Blob);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this create a request towards Azure? If so I would recommend keeping the async variant as was before.

Copy link
Contributor Author

@tedvanderveen tedvanderveen Mar 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaellindemann this should not be inside the constructor, agree. On the other hand, the method IStorage.OpenAsync() would not be a proper place either. Maybe an idea to add a method IStorage.InitializeAsync() where initial plumbing and checks can be performed?

When using Azure.Storage.Blobs assembly classes, there is no real concept of "sessions".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was that if it does asynchronous operations (IO being one of them) then it should be an asynchronous function. I didn't check what is behind CreateIfNotExists, but since ExistsAsync and CreateAsync was in use before, I guess that CreateIfNotExists is waiting on the asynchronous operation behind the scenes.

Not sure if I encouraged this change you have made, sorry if I did, but now you have introduced a breaking change in the storage extension point of Piranha. Also, you have limited any storage implementation not to be session based.

Wouldn't it make sense to keep the storage and session implementation as was, such that a BlobContainerClient was the underlying session for a BlobStorage? (Tbh. I don't know the details of IStorage, IStorageSession and Azure BlobStorage, so maybe this is a bad suggestion).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaellindemann I reversed most of those breaking changes. Guess I was a bit too enthousiastic. Please take a second look at the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And with regards to that CreateIfNotExists, it's about ensuring the parent Storage Container is available. So this should optimally be part of the App Init chaining.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And with Azure.Storage.Blobs assembly there is no real concept of sessions.
The BlobContainerClient is maintained as a singleton via DI / BlobStorage class. And BlobClient class instances are lightweight and are instantiated from the BlobContainerClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaellindemann I have now reverted any breaking changes to existing interfaces. And reverted all changes to the Piranha.Local.FileStorage source.
What remains now inside this PR:

  1. the move to the Azure SDK v.12 using the recommended Azure.Storage.Blobs Nuget packages
  2. Add the interface IInitializable to optionally indicate that a class implements Init() method, which is then called via App.cs

{
return (IStorageSession)new FileStorageSession(this, _basePath, _baseUrl, _naming);
});
return Task.FromResult<IStorageSession>(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikaellindemann this should make things better scalable.

@sander1095
Copy link

Hello! what is the state of this?

@tidyui
Copy link
Member

tidyui commented Sep 14, 2021

The PR was opened after 9.0 was release, and as it contains breaking changes we cant release it until 10.0 which is scheduled for November with the release of .NET 6

@tedvanderveen
Copy link
Contributor Author

tedvanderveen commented Sep 19, 2021

Other option could be to introduce new Piranha Nuget package with name
Piranha.Azure.StorageBlobs that depends on this new Azure SDK version? And mark existing storage integration packages as deprecated with release of Piranha version 10? So users can move to new package at own pace.

@sander1095
Copy link

What breaking changes does it contain? Do you perhaps mean the InitializeAsync() bit?

If the only breaking changes are related to this package AND we can continue using Piranha 9, why must it wait?

If we increase the MAJOR version of this package to indicate it is a breaking change, and later on increase MINOR (or PATCH) for the 10.0 version bump, we can already release it?

@sander1095
Copy link

@tedvanderveen I like the idea of being able to use the new Azure SDK NOW... But I think creating an extra package for just 2 months would be a bit much.

If you really wanted to, you could try and just put the code from this PR into your project and have it work that way?

  • People might get confused about what package they need (example: The current Azure SDK situation)
  • Docs needs updating, and updating again when v10 is out.
  • When people want to upgrade from the old package to the new one, they need to install a different package. Might be confusing!

@tidyui
Copy link
Member

tidyui commented Oct 8, 2021

I will merge this into master shortly as 9.2 has been released and we're working on 10.0 for .NET6. It's highly likely that we will release an alpha-package soon, but please remember that this will target net6.0 and use the RC1 packages from Microsoft as well, so it won't be compatible with the currently released version of Piranha.

return $"{ _containerUrl }/{ GetResourceName(media, id, true) }";
}
return null;
return string.IsNullOrWhiteSpace(id) ? default : $"{_blobContainerClient.Uri.AbsoluteUri}/{GetResourceName(media, id, true)}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is no longer checking that media != null, and in GetResourceName() there is an access to media.Id without checking for null values either. But I can fix this after merge.

@tidyui tidyui merged commit ad4d354 into PiranhaCMS:master Oct 8, 2021
@tidyui tidyui changed the title Use Azure.Storage.Blobs Nuget package to replace deprecated Microsoft.Azure.Storage.Blob Update BlobStorage to use Azure.Storage.Blobs Oct 8, 2021
@tidyui tidyui added this to the Version 10.0 milestone Oct 8, 2021
@tidyui tidyui added this to In progress in Version 10.0 via automation Oct 8, 2021
@tidyui tidyui moved this from In progress to Done in Version 10.0 Oct 8, 2021
tidyui added a commit that referenced this pull request Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants