azure_sas_conn.py


Overview

The azure_sas_conn.py file provides a singleton class RAGFlowAzureSasBlob that encapsulates interaction with an Azure Blob Storage container using Shared Access Signature (SAS) authentication. It enables uploading, downloading, deleting blobs, checking blob existence, and health checking the connection. The class handles connection management, automatic retries on failures, and logging for robust and convenient Azure Blob Storage operations within the application.

This file serves as a utility component within the InfiniFlow system, abstracting away the details of Azure Blob Storage SAS connectivity and providing a clean API for managing blob objects.


Class: RAGFlowAzureSasBlob

A singleton class that manages connection and operations with an Azure Blob Storage container using SAS tokens.

Purpose

Initialization

RAGFlowAzureSasBlob()

Attributes

Attribute

Type

Description

conn

ContainerClient

The Azure Blob Storage container client object.

container_url

str

URL of the Azure Blob container.

sas_token

str

SAS token string for authentication.


Methods


__open__()

def __open__(self) -> None

__close__()

def __close__(self) -> None

health()

def health(self) -> None

Usage example:

azure_blob = RAGFlowAzureSasBlob()
azure_blob.health()

put(bucket: str, fnm: str, binary: bytes)

def put(self, bucket: str, fnm: str, binary: bytes) -> Any

Parameters:

Name

Type

Description

bucket

str

Target bucket name (not used internally)

fnm

str

Blob name (filename)

binary

bytes

Data to upload

Returns:

Usage example:

data = b"Hello Azure!"
azure_blob.put("mybucket", "greeting.txt", data)

rm(bucket: str, fnm: str)

def rm(self, bucket: str, fnm: str) -> None

Parameters:

Name

Type

Description

bucket

str

Bucket name (unused)

fnm

str

Blob name to remove

Usage example:

azure_blob.rm("mybucket", "old_file.txt")

get(bucket: str, fnm: str)

def get(self, bucket: str, fnm: str) -> Optional[bytes]

Parameters:

Name

Type

Description

bucket

str

Bucket name (unused)

fnm

str

Blob name to download

Returns:

Usage example:

content = azure_blob.get("mybucket", "data.json")
if content:
    print(content.decode("utf-8"))

obj_exist(bucket: str, fnm: str)

def obj_exist(self, bucket: str, fnm: str) -> bool

Parameters:

Name

Type

Description

bucket

str

Bucket name (unused)

fnm

str

Blob name to check

Returns:

Usage example:

exists = azure_blob.obj_exist("mybucket", "file.txt")
print(f"Blob exists? {exists}")

get_presigned_url(bucket: str, fnm: str, expires: int)

def get_presigned_url(self, bucket: str, fnm: str, expires: int) -> Optional[str]

Parameters:

Name

Type

Description

bucket

str

Bucket name (unused)

fnm

str

Blob name

expires

int

Expiration time in seconds for URL validity

Returns:

Usage example:

url = azure_blob.get_presigned_url("mybucket", "private_file.txt", 3600)
if url:
    print("Access URL:", url)

Important Implementation Details


Interaction with Other Parts of the System


Diagram: Class Diagram of RAGFlowAzureSasBlob

classDiagram
    class RAGFlowAzureSasBlob {
        -conn: ContainerClient
        -container_url: str
        -sas_token: str
        +__init__()
        +__open__()
        +__close__()
        +health()
        +put(bucket: str, fnm: str, binary: bytes)
        +rm(bucket: str, fnm: str)
        +get(bucket: str, fnm: str) bytes
        +obj_exist(bucket: str, fnm: str) bool
        +get_presigned_url(bucket: str, fnm: str, expires: int) str
    }

Summary

azure_sas_conn.py is a core utility file providing a singleton class for managing Azure Blob Storage access using SAS tokens. It abstracts connection setup, blob operations, and error handling with retry logic. This makes it a reliable and reusable component for Azure blob storage interactions within the InfiniFlow application ecosystem.