shennyg / azure-blob-remote-volume

This plugin integrates Craft CMS and Microsoft Azure Storage Blob cloud storage service.
MIT License
1 stars 3 forks source link

Add support for local development using Azure Storage emulators provided by Microsoft #5

Closed sidm1983 closed 3 years ago

sidm1983 commented 3 years ago

Hi,

I am currently setting up my local development environment for Craft CMS using docker. I came across your Azure Blob Remote Volume plugin and was trying to set it up when I realized that there is currently no way for me to specify the BlobEndpoint value in the connection string. I believe the plugin always assumes that people will only be using storage account within the Azure Portal. However, Microsoft also provides storage emulators for local development that have different connection strings / endpoints to the storage accounts in Azure Cloud.

Here are 2 different connection strings that can be used to connect to the Azure Storage Emulators provided by Microsoft:

UseDevelopmentStorage=true

The above connection string is a short-form connection string that tells the Azure Storage Client library to connect to the locally installed storage emulator using default endpoint hostnames, ports, account names and account keys. The above is actually equivalent to the long-form connection string below.

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;

As you can see, there is a BlobEndpoint property at the end of the connection string that allows you to specify the hostname/port of the endpoint to connect to. I know that this plugin only supports the blob endpoint, so you don't need to pass in the QueueEndpoint in the connection string above. It can just be removed. It would be great if the plugin allowed admins/devs to also supply a Blob Hostname/Port during volume creation so that it could be used to connect to properly set up the BlobEndpoint property in the above connection string to allow connections to the local storage emulator. Keep in mind that it is possible for developers to install the storage emulator locally to a non-standard hostname/port. There is probably no need to support the first short-form connection string above. Please note that the above account name and account key are the default, hard-coded values used by local storage emulators.

Would also be good to be able to choose an HTTP or HTTPS connection during volume creation.

The azure-storage-blob package from Microsoft that this plugin uses already supports connecting to the local storage emulators, so hopefully it should be pretty straightforward to support it and allow the additional blob hostname and port values to be specified during volume creation.

More information about Azurite (Microsoft's cross-platform storage emulator) can be found here: https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azurite (scroll down to the Connection Strings section for more connection string examples)

Also, here is a link to the Azurite docker image on docker hub if you need to quickly test on your local machine: https://hub.docker.com/_/microsoft-azure-storage-azurite

Looking forward to hearing from you. Please don't hesitate to let me know if you need help testing the updates on my end.

Thank you πŸ™πŸ™ŒπŸ™‚

sidm1983 commented 3 years ago

@shennyg, I raised the original issue above and since I had time, I thought I would try to solve it and submit a pull request. Please see the pull request above (#6) and let me know what you think.

Thank you.