-
-
Save RobBlackwell/7547536 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python | |
import sys | |
import datetime | |
import time | |
from datetime import timedelta | |
sys.path.append('/home/reb/local/azure-sdk-for-python/') | |
from azure.storage import * | |
from azure.storage.sharedaccesssignature import * | |
blob_service1 = BlobService(account_name='account1', account_key='key1') | |
blob_service2 = BlobService(account_name='account2', account_key='key2') | |
def format_date_time (t): | |
return t.strftime('%Y-%m-%dT%H:%M:%SZ') | |
def sign (blob_service, container_name, blob_name): | |
sas = SharedAccessSignature(account_name=blob_service.account_name, account_key=blob_service.account_key) | |
start = datetime.now() | |
expiry = start + timedelta(minutes = 10) | |
accss_plcy = AccessPolicy() | |
accss_plcy.start = format_date_time (start) | |
accss_plcy.expiry = format_date_time (expiry) | |
accss_plcy.permission = 'r' | |
sap = SharedAccessPolicy(accss_plcy) | |
qry_str = sas.generate_signed_query_string(container_name + '/' + blob_name, RESOURCE_BLOB, sap) | |
qry_str2 = sas._convert_query_string(qry_str) | |
return blob_service.protocol + '://' + blob_service._get_host() + '/' + container_name + '/' + blob_name + '?' + qry_str2 | |
# copy from source to destination | |
source = sign(blob_service2, 'junk', 'foo.txt') | |
blob_service1.copy_blob('foo', 'foo3.txt', source) |
Hi Rob,
i am having issues while i run this code.
i have pip installed all the latest packages for azure storage account in my system. Everytime i run the above script, i get this issue NameError: name 'SharedAccessPolicy' is not defined
i believe i have everything installed, could you tell me how to fix the SharedAccessPolicy issue.
Thanks! in advance
-Nitin
Hi Rob,
i am having issues while i run this code.
i have pip installed all the latest packages for azure storage account in my system. Everytime i run the above script, i get this issue NameError: name 'SharedAccessPolicy' is not defined
i believe i have everything installed, could you tell me how to fix the SharedAccessPolicy issue.
Thanks! in advance-Nitin
Hi,
I am experiencing the same issue. Do you have the solution yet?
Hi Rob,
i am having issues while i run this code.
i have pip installed all the latest packages for azure storage account in my system. Everytime i run the above script, i get this issue NameError: name 'SharedAccessPolicy' is not defined
i believe i have everything installed, could you tell me how to fix the SharedAccessPolicy issue.
Thanks! in advance
-NitinHi,
I am experiencing the same issue. Do you have the solution yet?
Couldn’t get this working hence created power shell script and used azcopy.
This example was certainly helpful but needed a few changes to work as is. First was setting the value for RESOURCE_BLOB:
Second was using the utc time for expiry date. The documentation suggests not setting a start time for operations that you want to have start immediately. I used:
If I did not use UTC time I got the following error: