Just wanted to share something I was working on lately, well at least the interesting part. So I have been dealing with some Azure blob storage related projects/challenges and unfortunately running into some PowerShell API shortcomings. I think this happens to many of us Azure developers; we start with the convenient PowerShell API and later discover that many of the REST API calls haven’t been implemented (Yes, sometimes I do consider to just go with the REST API from the start…). Therefore, I basically had to write a lightweight wrapper.
JAABAW was born
My requirements were pretty simple – Based on existing metadata, the application categorizes Blobs, by altering/adding metadata or moving the Blob to a different container. Therefore we need to be able to;
- Iterate though Blob containers and Blobs
- Read, add and alter Blob Metadata and properties.
- Create and delete Blob containers
- Move and delete Blobs
- Can run within Azure Automation
There weren’t any Snapshots present, which simplified the initial implementation.
I generally create my prototypes and tooling directly within PowerShell because don’t want to be bothered starting a heavy-duty IDE and having endless compilation cycles. PowerShell ICE is an excellent editor and I’m often surprised how well it works (start working on some PowerShell workflow code and you will understand). Due to this, I was quickly able to find out that I needed to produce something to fill the gaps.
One important condition was to make sure the solution can run within Azure Automation, which makes all a bit more complex. Writing a lot of code within the context of a workflow just isn’t that simple without things getting hairy, due to all the restrictions/limitations. The good thing is that this actually forces you to implement something that is at least somewhat structured (PowerShell modules). However I’ve seen Azure runbooks containing hundreds of lines of code already. So there’s always a way to get around…
How things are glued together
This is a wrapper on top of the REST API and therefore just building a proper request based on the specifications. The documentation is very detailed (http://msdn.microsoft.com/en-us/library/azure/dd135733.aspx) so there wasn’t really much to it. There are two main helper functions;
InvokeRequest is responsible for invoking the request and
GetSignatureString which specifies the authentication scheme, account name, and signature.
All exported module members have the verb-noun naming convention. I’ve created a base call for all function for future changes (better error handling and retry option). For example Remove-Blob calls RemoveBlob, Below I’ve included some API samples and the functions available as today.
The API includes the operations listed in the following table.
|Get-Containers||Lists all of the containers in a storage account.|
|Get-BlobServiceProperties||Gets the properties of the Blob service, including logging and metrics settings, and the default service version.|
|New-Container||Creates a new container in a storage account.|
|Get-ContainerProperties||Returns all user-defined metadata and system properties of a container.|
|Get-ContainerMetadata||Returns only user-defined metadata of a container.|
|Set-ContainerMetadata||Sets user-defined metadata of a container.|
|Get-ContainerACL||Gets the public access policy and any stored access policies for the container.|
|Remove-Container||Deletes the container and any blobs that it contains.|
|Get-Blobs||Lists all of the blobs in a container.|
|Set-BlobProperties||Sets system properties defined for an existing blob.|
|Set-BlobMetaData||Sets user-defined metadata of an existing blob.|
|Get-BlobMetaData||Retrieves all user-defined metadata of an existing blob or snapshot.|
|Remove-Blob||Marks a blob for deletion.|
|Get-BlobProperties||Returns all system properties and user-defined metadata on the blob.|
|Get-Blob||Reads or downloads a blob from the Blob service, including its user-defined metadata and system properties.|
Just keep in mind that the project is far from complete, but will keep adding features as soon as I will need them or have some time at hand. The module can be downloaded here and the code can be found on GitHub https://github.com/Kevin-Bronsdijk/JAABAW-Just-Another-Azure-Blob-API-Wrapper/
If you’re interested in creating Powershell Modules for Microsoft Azure Automation, make sure to read the following article.