Skip to content

Latest commit

 

History

History
97 lines (72 loc) · 3.43 KB

File metadata and controls

97 lines (72 loc) · 3.43 KB

Azure Blob Storage Client

Azure Blob Storage client implementation for the unified storage-cli tool. This module provides Azure Blob Storage operations through the main storage-cli binary.

Note: This is not a standalone CLI. Use the main storage-cli binary with -s azurebs flag to access Azure Blob Storage functionality.

For general usage and build instructions, see the main README.

Azure-Specific Configuration

The Azure client requires a JSON configuration file with the following structure:

{
  "account_name":                 "<string> (required)",
  "account_key":                  "<string> (required)",
  "container_name":               "<string> (required)",
  "environment":                  "<string> (optional, default: 'AzureCloud')",
  "put_timeout_in_seconds":       "<string> (optional; put/upload operation timeout in whole seconds)",
  "http_request_timeout":         "<string> (optional; Go duration, e.g. '30s', '2m')",
  "http_response_header_timeout": "<string> (optional; Go duration, e.g. '10s', '1m')"
}

Timeout Configuration

  • put_timeout_in_seconds: Applies to upload/put operations and is interpreted as seconds.
  • http_request_timeout: Sets the underlying HTTP client timeout for Azure SDK requests.
  • http_response_header_timeout: Sets how long to wait for response headers from the server.

Usage examples:

# Upload a blob
storage-cli -s azurebs -c azure-config.json put local-file.txt remote-blob

# Fetch a blob (destination file will be overwritten if exists)
storage-cli -s azurebs -c azure-config.json get remote-blob local-file.txt

# Delete a blob
storage-cli -s azurebs -c azure-config.json delete remote-blob

# Check if blob exists
storage-cli -s azurebs -c azure-config.json exists remote-blob

# Generate a signed URL (e.g., GET for 3600 seconds)
storage-cli -s azurebs -c azure-config.json sign remote-blob get 3600s

Using Signed URLs with curl

# Uploading a blob:
curl -X PUT -H "x-ms-blob-type: blockblob" -F 'fileX=<path/to/file>' <signed-url>

# Downloading a blob:
curl -X GET <signed-url>

Testing

Unit Tests

Run from the repository root directory:

ginkgo --skip-package=integration --randomize-all --cover -v -r ./azurebs/...

Or using go test:

go test $(go list ./azurebs/... | grep -v integration)

Integration Tests

  • To run the integration tests with your existing container

    1. Export the following variables into your environment.

      export ACCOUNT_NAME=<your Azure accounnt name>
      export ACCOUNT_KEY=<your Azure account key>
      export CONTAINER_NAME=<the target container name>
    2. Navigate to project's root folder and run the command below:

      go test ./azurebs/integration/...
  • To run it from scratch; create a new container, run tests, delete the container

    1. Create a storage account in your azure subscription.
    2. Get account name and access key from you storage account.
    3. Export account name with command export azure_storage_account=<account name>.
    4. Export access key with command export azure_storage_key=<access key>.
    5. Navigate to project's root folder.
    6. Run environment setup script to create container ./.github/scripts/azurebs/setup.sh.
    7. Run tests ./.github/scripts/azurebs/run-int.sh.
    8. Run environment teardown script to delete test resources ./.github/scripts/azurebs/teardown.sh.