การใช้ Python azure-storage
API ฉันคาดว่าจะสามารถสร้างโทเค็นบัญชี SAS ซึ่งช่วยให้ฉันสามารถอ่านและเขียน blobs ในคอนเทนเนอร์ใดก็ได้ในบัญชีที่เก็บข้อมูลของฉัน
การสร้างโทเค็น SAS ดำเนินไปโดยไม่มีข้อยกเว้น แต่เมื่อฉันพยายามสร้าง BlockBlobService
โดยใช้โทเค็น SAS นั้นและแสดงรายการ blobs บางส่วนสำหรับคอนเทนเนอร์ที่กำหนด ฉันได้รับข้อผิดพลาด AuthorizationPermissionMismatch
จาก Azure
ฉันเข้าใจแนวคิดของโทเค็นบัญชี SAS ถูกต้องหรือไม่
ฉันได้ดูเอกสารจำนวนมากเกี่ยวกับเอกสาร "การเริ่มต้นใช้งาน" ของ Azure สำหรับ Python Storage API และฉันได้ดู https://azure-storage.readthedocs.io/ref/azure.storageแล้วblob.sharedaccesssignature.html ค่อนข้างน้อย
ฉันได้ลองใช้ azure.storage.blob.BlockBlobService.generate_account_shared_access_signature()
ด้วยการอนุญาตที่อนุญาตอย่างมาก และยังคงได้รับข้อยกเว้นอยู่
ฉันสามารถยืนยันได้ว่า azure.storage.blob.BlockBlobService.generate_container_shared_access_signature()
ทำงานได้ดี แต่ข้อกำหนดของฉันคือการสร้าง SAS Token โดยไม่คำนึงถึงคอนเทนเนอร์นั้น
from azure.storage.blob import BlockBlobService
from azure.storage.models import AccountPermissions, ResourceTypes
bbs = BlockBlobService("myaccountname", "myaccountkey")
sas_token = bbs.generate_account_shared_access_signature(
ResourceTypes.CONTAINER + ResourceTypes.OBJECT + ResourceTypes.SERVICE,
AccountPermissions.READ + AccountPermissions.WRITE + AccountPermissions.LIST + AccountPermissions.CREATE,
datetime.utcnow() + timedelta(hours=1)
)
BlockBlobService(account_name="myaccountname", sas_token=sas_token).list_blobs("containername")
azure.common.AzureHttpError: This request is not authorized to perform this operation using this permission.
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthorizationPermissionMismatch</Code><Message>This request is not authorized to perform this operation using this permission.
RequestId:6a06b32e-f01e-005a-44e7-430c8b000000
Time:2019-07-26T19:22:02.7337249Z</Message></Error>
ฉันคาดว่าจะสามารถโทร list_blobs()
ที่นี่ได้ไม่มีปัญหา ฉันจะทำสิ่งนี้ให้สำเร็จโดยไม่ต้องสร้างคอนเทนเนอร์ SAS Token ตามคอนเทนเนอร์ได้อย่างไร