azure-storage

Azure Blob Storage client for Kit

Files

FileDescription
kit.tomlPackage manifest with metadata and dependencies
src/storage.kitBlob and container operations (get, put, list, delete)
tests/azure-storage.test.kitTests for client creation, error types, and blob info
examples/basic.kitList containers and blobs from environment credentials
examples/upload-download.kitUpload, verify metadata, download, and delete a blob
LICENSEMIT license file

Dependencies

  • azure-core

Installation

kit add gitlab.com/kit-lang/packages/kit-azure-storage.git

Usage

import Kit.AzureStorage

License

MIT License - see LICENSE for details.

Exported Functions & Types

AzureStorageError

Azure Storage error type with specific variants for different failure modes.

Variants

AzureStorageBlobError {message}
Blob-related error (get, put, delete, head, copy operations).
AzureStorageContainerError {message}
Container-related error (list, create, delete container operations).

StorageClient

Azure Storage client configuration.

Fields: - azure: Underlying Azure client for authentication and signing - base-url: Base URL for blob storage (https://{account}.blob.core.windows.net)

Variants

StorageClient {azure, base-url}

BlobInfo

Metadata for an Azure blob.

Fields: - name: The blob's name (path) within the container - container: Container name containing this blob - size: Size of the blob in bytes - content-type: MIME type of the blob content - etag: Entity tag (version identifier) of the blob - last-modified: ISO 8601 timestamp of last modification

Variants

BlobInfo {name, container, size, content-type, etag, last-modified}

ContainerInfo

Metadata for an Azure container.

Fields: - name: Container name - last-modified: ISO 8601 timestamp of last modification

Variants

ContainerInfo {name, last-modified}

ListBlobsResponse

Response from listing blobs in a container.

Fields: - blobs: List of blobs matching the query - prefixes: List of common prefixes (for hierarchical listing with delimiter) - next-marker: Marker for fetching next page (empty if none)

Variants

ListBlobsResponse {blobs, prefixes, next-marker}

ListContainersResponse

Response from listing containers in a storage account.

Fields: - containers: List of containers - next-marker: Marker for fetching next page (empty if none)

Variants

ListContainersResponse {containers, next-marker}

client

Create storage client from Azure client.

Wraps an existing Azure client for blob storage operations.

Parameters:

Returns:

Azure.AzureClient -> StorageClient

azure = Azure.client creds
storage = Storage.client azure

client-from-connection-string

Create client from Azure connection string.

Parses an Azure Storage connection string and creates a client. Connection string format: "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...;EndpointSuffix=core.windows.net"

Parameters:

Returns:

String -> Result StorageClient String

conn-str = "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=...;"
match Storage.client-from-connection-string conn-str
  | Ok client -> print "Client created"
  | Err err -> print "Error: ${err}"

client-from-env

Create client from environment variables.

Reads credentials from AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_KEY environment variables.

Returns:

() -> Result StorageClient String

match Storage.client-from-env()
  | Ok client -> print "Client created from environment"
  | Err err -> print "Error: ${err}"

client-from-managed-identity

Create client with managed identity.

Creates a client using Azure Managed Identity for authentication. Useful for applications running in Azure VMs, App Service, or AKS.

Parameters:

Returns:

String -> Result StorageClient String

match Storage.client-from-managed-identity "mystorageaccount"
  | Ok client -> print "Using managed identity"
  | Err err -> print "Error: ${err}"

client-with-credentials

Create client with explicit credentials.

Creates a client with shared key authentication using explicit account credentials.

Parameters:

Returns:

String -> String -> StorageClient

storage = Storage.client-with-credentials "myaccount" "base64encodedkey=="

get-blob

Get blob content.

Downloads the content of a blob from an Azure container.

Parameters:

Returns:

StorageClient -> String -> String -> Result String AzureStorageError

match Storage.get-blob client "my-container" "data/file.txt"
  | Ok content -> print content
  | Err err -> print "Error: ${err}"

put-blob

Upload blob with default content type.

Uploads content to an Azure container with default content type (application/octet-stream).

Parameters:

Returns:

StorageClient -> String -> String -> String -> Result () AzureStorageError

match Storage.put-blob client "my-container" "data.txt" "Hello, Azure!"
  | Ok _ -> print "Upload successful"
  | Err err -> print "Error: ${err}"

put-blob-with-type

Upload blob with specific content type.

Uploads content to an Azure container with a custom content type. Creates a BlockBlob in Azure Storage.

Parameters:

Returns:

StorageClient -> String -> String -> String -> String -> Result () AzureStorageError

json = "{\"name\": \"example\"}"
match Storage.put-blob-with-type client "my-container" "data.json" json "application/json"
  | Ok _ -> print "Upload successful"
  | Err err -> print "Error: ${err}"

delete-blob

Delete blob.

Deletes a blob from an Azure container.

Parameters:

Returns:

StorageClient -> String -> String -> Result () AzureStorageError

match Storage.delete-blob client "my-container" "old-file.txt"
  | Ok _ -> print "Deleted successfully"
  | Err err -> print "Error: ${err}"

exists?

Check if blob exists (convenience function).

Simplified wrapper around head-blob that returns a boolean.

Parameters:

Returns:

StorageClient -> String -> String -> Bool

if Storage.exists? client "my-container" "test.txt" then
  print "Blob exists"
else
  print "Blob not found"

head-blob

Get blob metadata using HEAD request.

Retrieves blob metadata without downloading the content.

Parameters:

Returns:

StorageClient -> String -> String -> Result BlobInfo AzureStorageError

match Storage.head-blob client "my-container" "test.txt"
  | Ok info ->
    print "Size: ${Int.to-string info.size} bytes"
    print "Content-Type: ${info.content-type}"
  | Err err -> print "Error: ${err}"

copy-blob

Copy blob within Azure Storage.

Copies a blob from one location to another within Azure Storage. The source and destination can be in the same or different containers. This is a server-side operation that doesn't download the blob.

Parameters:

Returns:

StorageClient -> String -> String -> String -> String -> Result () AzureStorageError

match Storage.copy-blob client "src-container" "old/file.txt" "dest-container" "new/file.txt"
  | Ok _ -> print "Blob copied"
  | Err err -> print "Error: ${err}"

list-blobs

List blobs in container.

Retrieves a list of blobs from an Azure container with optional prefix filtering.

Parameters:

Returns:

StorageClient -> String -> String -> Int -> Result ListBlobsResponse AzureStorageError

match Storage.list-blobs client "my-container" "logs/" 100
  | Ok response ->
    print "Found ${List.length response.blobs} blobs"
    if String.length response.next-marker > 0 then
      print "More results available"
  | Err err -> print "Error: ${err}"

list-blobs-with-marker

List blobs with pagination marker.

Continues a previous list-blobs call using a pagination marker.

Parameters:

Returns:

StorageClient -> String -> String -> Int -> String -> Result ListBlobsResponse AzureStorageError

# Get first page
match Storage.list-blobs client "my-container" "" 1000
  | Ok response ->
    if String.length response.next-marker > 0 then
      # Get next page
      match Storage.list-blobs-with-marker client "my-container" "" 1000 response.next-marker
        | Ok next-page -> print "Got next page"
        | Err err -> print "Error: ${err}"
  | Err err -> print "Error: ${err}"

list-blobs-delimiter

List blobs with delimiter (hierarchical listing).

Lists blobs using a delimiter to simulate a directory structure. Common prefixes (directory-like paths) are returned separately from blobs.

Parameters:

Returns:

StorageClient -> String -> String -> String -> Int -> Result ListBlobsResponse AzureStorageError

# List "directories" and files in root
match Storage.list-blobs-delimiter client "my-container" "" "/" 100
  | Ok response ->
    print "Directories: ${List.length response.prefixes}"
    print "Files: ${List.length response.blobs}"
  | Err err -> print "Error: ${err}"

list-containers

List containers in storage account.

Retrieves a list of all containers in the storage account.

Parameters:

Returns:

StorageClient -> Result ListContainersResponse AzureStorageError

match Storage.list-containers client
  | Ok response ->
    print "Found ${List.length response.containers} containers"
  | Err err -> print "Error: ${err}"

list-containers-with-marker

List containers with pagination marker.

Continues a previous list-containers call using a pagination marker.

Parameters:

Returns:

StorageClient -> String -> Result ListContainersResponse AzureStorageError

match Storage.list-containers client
  | Ok response ->
    if String.length response.next-marker > 0 then
      match Storage.list-containers-with-marker client response.next-marker
        | Ok next-page -> print "Got next page"
        | Err err -> print "Error: ${err}"
  | Err err -> print "Error: ${err}"

create-container

Create container.

Creates a new container in the storage account. Container names must be lowercase and follow DNS naming rules.

Parameters:

Returns:

StorageClient -> String -> Result () AzureStorageError

match Storage.create-container client "my-new-container"
  | Ok _ -> print "Container created"
  | Err "Container already exists" -> print "Container exists"
  | Err err -> print "Error: ${err}"

delete-container

Delete container.

Deletes a container from the storage account. The container must be empty before deletion.

Parameters:

Returns:

StorageClient -> String -> Result () AzureStorageError

match Storage.delete-container client "old-container"
  | Ok _ -> print "Container deleted"
  | Err "Container is not empty" -> print "Delete blobs first"
  | Err err -> print "Error: ${err}"

upload-file

Upload file from local filesystem to Azure Storage.

Reads a file from the local filesystem and uploads it to Azure Storage. Automatically detects content type based on file extension.

Parameters:

Returns:

StorageClient -> String -> String -> String -> Result () AzureStorageError

match Storage.upload-file client "my-container" "reports/data.pdf" "/tmp/report.pdf"
  | Ok _ -> print "File uploaded"
  | Err err -> print "Error: ${err}"

download-file

Download blob from Azure Storage to local filesystem.

Downloads a blob from Azure Storage and writes it to the local filesystem.

Parameters:

Returns:

StorageClient -> String -> String -> String -> Result () AzureStorageError

match Storage.download-file client "my-container" "reports/data.pdf" "/tmp/report.pdf"
  | Ok _ -> print "File downloaded"
  | Err err -> print "Error: ${err}"