-
Notifications
You must be signed in to change notification settings - Fork 9.1k
fix: prepend bucket prefix to Azure SPN and SAS storage paths #14185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,9 +69,10 @@ def health(self): | |
| return f.flush_data(len(binary)) | ||
|
|
||
| def put(self, bucket, fnm, binary): | ||
| f_path = f"{bucket}/{fnm}" | ||
| for _ in range(3): | ||
| try: | ||
| f = self.conn.create_file(fnm) | ||
| f = self.conn.create_file(f_path) | ||
| f.append_data(binary, offset=0, length=len(binary)) | ||
| return f.flush_data(len(binary)) | ||
| except Exception: | ||
|
|
@@ -83,14 +84,15 @@ def put(self, bucket, fnm, binary): | |
|
|
||
| def rm(self, bucket, fnm): | ||
| try: | ||
| self.conn.delete_file(fnm) | ||
| self.conn.delete_file(f"{bucket}/{fnm}") | ||
| except Exception: | ||
| logging.exception(f"Fail rm {bucket}/{fnm}") | ||
|
|
||
| def get(self, bucket, fnm): | ||
| f_path = f"{bucket}/{fnm}" | ||
| for _ in range(1): | ||
| try: | ||
| client = self.conn.get_file_client(fnm) | ||
| client = self.conn.get_file_client(f_path) | ||
| r = client.download_file() | ||
| return r.read() | ||
| except Exception: | ||
|
|
@@ -101,16 +103,17 @@ def get(self, bucket, fnm): | |
|
|
||
| def obj_exist(self, bucket, fnm): | ||
| try: | ||
| client = self.conn.get_file_client(fnm) | ||
| client = self.conn.get_file_client(f"{bucket}/{fnm}") | ||
| return client.exists() | ||
| except Exception: | ||
| logging.exception(f"Fail put {bucket}/{fnm}") | ||
| return False | ||
|
|
||
| def get_presigned_url(self, bucket, fnm, expires): | ||
| f_path = f"{bucket}/{fnm}" | ||
| for _ in range(10): | ||
| try: | ||
| return self.conn.get_presigned_url("GET", bucket, fnm, expires) | ||
| return self.conn.get_presigned_url("GET", bucket, f_path, expires) | ||
|
Comment on lines
+113
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 1) Find local wrappers/definitions that may provide get_presigned_url
ast-grep --pattern $'def get_presigned_url($_, $_, $_, $_, $_):\n $$$'
# 2) Inspect call sites and azure client usage context
rg -n -C3 'FileSystemClient|get_presigned_url\s*\('
# 3) Check declared Azure package versions in manifests
rg -n -C2 'azure-storage-file-datalake|azure-storage-blob|azure-identity'Repository: infiniflow/ragflow Length of output: 12360 🏁 Script executed: # Check if there are any tests or usage examples of azure_spn_conn
find . -name "*.py" -type f | xargs grep -l "azure_spn_conn\|AzureSpnConnection" | head -20
# Look for any comments or documentation about this method
rg -n "get_presigned_url" rag/utils/azure_spn_conn.py -B5 -A10
# Check if there are any error messages or logging that might hint at the actual issue
rg -n "fail get\|presigned" rag/utils/azure_spn_conn.py -B2 -A2Repository: infiniflow/ragflow Length of output: 675 🌐 Web query:
💡 Result: The azure-storage-file-datalake Python SDK's FileSystemClient class does not have a get_presigned_url or generate_sas_url method. Unlike JavaScript/TS and .NET SDKs which provide generateSasUrl methods on FileSystemClient equivalents, the Python SDK uses standalone SAS generation functions. To generate a presigned URL (SAS URL) for a FileSystemClient: 1. Use generate_file_system_sas from azure.storage.filedatalake: from azure.storage.filedatalake import generate_file_system_sas, FileSystemSasPermissions from datetime import datetime, timedelta sas_token = generate_file_system_sas( account_name="youraccount", file_system_name="yourfilesystem", credential="youraccountkey", # or UserDelegationKey permission=FileSystemSasPermissions(read=True), # adjust permissions expiry=datetime.utcnow + timedelta(hours=1) ) 2. Construct the URL manually: filesystem_url = f"https://{account_name}.dfs.core.windows.net/{file_system_name}?{sas_token}" This URL provides time-limited access to the filesystem according to the SAS permissions. For sub-resources (directories/files), use generate_directory_sas or generate_file_sas and append their paths to the URL. Example full usage: python from azure.storage.filedatalake import generate_file_system_sas, FileSystemSasPermissions from datetime import datetime, timedelta account_name = "youraccount" file_system_name = "yourfilesystem" account_key = "yourkey" sas_token = generate_file_system_sas( account_name=account_name, file_system_name=file_system_name, credential=account_key, permission=FileSystemSasPermissions(read=True, list=True), expiry=datetime.utcnow + timedelta(hours=1) ) presigned_url = f"https://{account_name}.dfs.core.windows.net/{file_system_name}?{sas_token}" print(presigned_url) Official docs confirm FileSystemClient methods focus on CRUD operations like create_file_system, get_paths, etc., with no SAS generation on the client itself. SAS functions are in _shared_access_signature module. Citations:
Remove Line 116 calls 🤖 Prompt for AI Agents |
||
| except Exception: | ||
| logging.exception(f"fail get {bucket}/{fnm}") | ||
| self.__open__() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: infiniflow/ragflow
Length of output: 11943
Remove or replace invalid
ContainerClient.get_presigned_url()call with Azure SDK–supported SAS generation.Line 93 calls a non-existent method. The Azure Storage Blob SDK (12.28.0) does not expose
get_presigned_url()onContainerClient. Usegenerate_container_sas()orgenerate_account_sas()fromazure.storage.blobinstead, or implement SAS token generation with proper Azure SDK methods.🤖 Prompt for AI Agents