Skip to content

A command line tool to generate a Shared Access Signature (SAS) URLs for a given blob file within Azure Blog storage

License

Notifications You must be signed in to change notification settings

mskadu/generate-azure-blob-sas-urls

Repository files navigation

Azure Generate Blob Storage SAS URL

Description

This tool generates a Shared Access Signature (SAS) URLs for a given blob file within Azure Blog storage.

This tool has been intentionally designed to work on a single file at time. This makes it amenable for use in scripting for mass usage.

Usage

python generate-blob-sas-url.py <blobname>

for example,

python generate-blob-sas-url.py filename.dat

Setup

Pre-requisites:

  • Python (developed on 3.10.xx)
  • Poetry (developed on 1.6.1)
  • This git repository in a dedicated directory
  • The following detail from the Azure admin portal
    • Storage Account Name
    • Storage Account Connection String (from Azure account)
    • Storage Account Key (from Azure account)
    • Container name

Setup

The following steps are only necessary the first time this tool is set up

  1. Open a terminal session and execute the following commands
cd <git repository directory>
poetry config virtualenvs.in-project true
poetry install
  1. If there are no errors displayed, execute the command
poetry shell
  1. In a new browser window, navigate to the Azure Portal and login
  2. Navigate to the relevant storage account
  3. Under Security + Networking --> Access Keys, locate and note value for the field storage account name.
  4. Within the same screen for key 1, locate and note values for the fields key and connection string
  5. Copy/ rename 'config-template.json' to 'config.json'
  6. Edit 'config.json' to add in the values noted above

Configuration file

The tool requires a file named 'config.json' to be present in the root of the git repository. It's format is as follows

{
"storage_account_name": "<Azure storage account name>",
"storage_account_connection_string": "<Azure storage account connection string>",
"storage_account_key": "<Azure storage account key>",
"container_name": "<Name of the container within the above storage account>" 
}

Running the tool

Note - Skip to step 4 to follow on from the setup process

  1. Open a terminal session and execute the following commands
cd <git repository directory>
poetry shell
  1. To generate the SAS URL run the command
python generate-blob-sas-url.py my_blob_filename
  1. If the blob does not exist, an error message will be displayed
  2. If the blob exists, the SAS-enabled URL will be displayed on the screen

TIP: To run this command for multiple files, create a text file listing the blob names. And execute the following command

cat blobs.list | xargs -I {} python generate-blob-sas-url.py {}

About

A command line tool to generate a Shared Access Signature (SAS) URLs for a given blob file within Azure Blog storage

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages