当前位置: 首页>>代码示例>>Python>>正文


Python BlobService.generate_shared_access_signature方法代码示例

本文整理汇总了Python中azure.storage.blob.BlobService.generate_shared_access_signature方法的典型用法代码示例。如果您正苦于以下问题:Python BlobService.generate_shared_access_signature方法的具体用法?Python BlobService.generate_shared_access_signature怎么用?Python BlobService.generate_shared_access_signature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.storage.blob.BlobService的用法示例。


在下文中一共展示了BlobService.generate_shared_access_signature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: copyBlobToBlob

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import generate_shared_access_signature [as 别名]
def copyBlobToBlob(sourceUrl, sourceKey, destUrl, destKey):
    blobservice = BlobService(destUrl, destkey)
    srcblobservice = BlobService(SourceUrl, srckey)
    today = datetime.datetime.utcnow()
    todayPlusMonth = today + datetime.timedelta(1)
    todayPlusMonthISO = todayPlusMonth.replace(microsecond=0).isoformat() + 'Z'
    srcSasParam = srcblobservice.generate_shared_access_signature(container,
            filename, SharedAccessPolicy(AccessPolicy(None, todayPlusMonthISO, "r"), None))
    srcUrl = srcblobservice.make_blob_url(container, filename,
            sas_token=srcSasParam)
    print srcUrl
    blobservice.copy_blob(container, filename, srcUrl)
开发者ID:MSSedusch,项目名称:azcopy-py,代码行数:14,代码来源:azcopy.py

示例2: copyBlobToBlob

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import generate_shared_access_signature [as 别名]
def copyBlobToBlob(sourceUrl, sourceKey, destUrl, destKey):
    sourceParts = split_storage_url(sourceUrl)
    destParts = split_storage_url(destUrl)
    blobservice = BlobService(destParts[0], destKey)
    srcblobservice = BlobService(sourceParts[0], sourceKey)

    today = datetime.datetime.utcnow()
    todayPlusMonth = today + datetime.timedelta(1)
    todayPlusMonthISO = todayPlusMonth.replace(microsecond=0).isoformat() + 'Z'
    srcSasParam = srcblobservice.generate_shared_access_signature(sourceParts[2],
            sourceParts[3], SharedAccessPolicy(AccessPolicy(None, todayPlusMonthISO, "r"), None))
    srcUrl = srcblobservice.make_blob_url(sourceParts[2], sourceParts[3],
            sas_token=srcSasParam)
    print destParts
    blobservice.copy_blob(destParts[2], destParts[3], srcUrl)
开发者ID:ne-msft,项目名称:azcopy-py,代码行数:17,代码来源:azcopy.py

示例3: get_container_details

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import generate_shared_access_signature [as 别名]
def get_container_details(creds, resource_group_name, account_name, container_name):
    keys = _get_storage_account_keys(creds, resource_group_name, account_name)
    blob_service = BlobService(account_name, keys.key1)

    model = StorageAccountContainerDetails()
    model.container_name = container_name
    model.sas_policy = _get_shared_access_policy(BlobSharedAccessPermissions.READ)
    model.blobs = []
    for blob in blob_service.iterate_blobs(container_name, include="metadata"):
        sas_token = blob_service.generate_shared_access_signature(container_name, blob.name, model.sas_policy)
        blob.sas_url = blob_service.make_blob_url(container_name, blob.name, sas_token=sas_token)
        raw_md5 = b64decode(blob.properties.content_md5)
        hex_md5 = "".join([hex(val)[2:] for val in raw_md5])
        blob.properties.content_hex_md5 = hex_md5
        model.blobs.append(blob)

    return model
开发者ID:yunjing,项目名称:azure-sdk-for-python,代码行数:19,代码来源:models.py

示例4: module_impl

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import generate_shared_access_signature [as 别名]

#.........这里部分代码省略.........
                    file_path,
                    x_ms_meta_name_values,
                    x_ms_blob_cache_control,
                    x_ms_blob_content_encoding,
                    x_ms_blob_content_language,
                    x_ms_blob_content_type
                )
                results['blob'] = get_blob_facts(bs, container_name, blob_name)
            results['changed'] = True
            results['msg'] = 'Successfully updloaded file.'
            return results

    if mode == 'list':
        container = container_check(bs, container_name)
        response = bs.list_blobs(
            container_name,
            prefix,
            marker,
            max_results
        )
        results['blobs'] = []
        for blob in response.blobs:
            b = dict(
                name = blob.name,
                snapshot = blob.snapshot,
                last_modified = blob.properties.last_modified,
                content_length = blob.properties.content_length,
                blob_type = blob.properties.blob_type,
            )
            results['blobs'].append(b)
        return results

    if mode == 'get':
        if file_path is None:
            raise Exception("Parameter error: file_path cannot be None.")
        
        container = container_check(bs, container_name)
        blob = blob_check(bs, container_name, blob_name)
        path_exists = path_check(file_path)
        
        if not path_exists or overwrite == 'always':
            if not check_mode:
                bs.get_blob_to_path(container_name, blob_name, file_path)
            results['changed'] = True
            results['msg'] = "Blob %s successfully downloaded to %s." % (blob_name, file_path)
            return results

        if path_exists:
            md5_remote = blob['content-md5']
            md5_local = get_md5(file_path)

            if md5_local == md5_remote:
                sum_matches = True
                if overwrite == 'always':
                    if not check_mode:
                        bs.get_blob_to_path(container_name, blob_name, file_path)
                    results['changed'] = True
                    results['msg'] = "Blob %s successfully downloaded to %s." % (blob_name, file_path)
                else:
                    results['msg'] = "Local and remote object are identical, ignoring. Use overwrite parameter to force."
            else:
                sum_matches = False
                if overwrite in ('always', 'different'):
                    if not check_mode:
                        bs.get_blob_to_path(container_name, blob_name, file_path)
                    results['changed'] = True
                    results['msg'] = "Blob %s successfully downloaded to %s." % (blob_name, file_path)
                else:
                    results['msg'] ="WARNING: Checksums do not match. Use overwrite parameter to force download."
        
        if sum_matches is True and overwrite == 'never':
            results['msg'] = "Local and remote object are identical, ignoring. Use overwrite parameter to force."
        
        return results

    if mode == 'get_url':
        if not blob_name:
            raise Exception("Parameter error: blob_name cannot be None.")

        container = container_check(bs, container_name)
        blob = blob_check(bs, container_name, blob_name)

        url = bs.make_blob_url(
            container_name=container_name,
            blob_name=blob_name,
            sas_token=access_token)
        results['url'] = url
        results['msg'] = "Url: %s" % url
        return results

    if mode == 'get_token':
        if hours == 0 and days == 0:
            raise Exception("Parameter error: expecting hours > 0 or days > 0")
        container = container_check(bs, container_name)
        blob = blob_check(bs, container_name, blob_name)
        results['blob_name'] = blob_name
        sap = get_shared_access_policy(permissions, hours=hours, days=days)
        token = bs.generate_shared_access_signature(container_name, blob_name, sap)
        results['access_token'] = token
        return results
开发者ID:catap,项目名称:azurerm,代码行数:104,代码来源:azure_rm_storageblob.py

示例5: identifier

# 需要导入模块: from azure.storage.blob import BlobService [as 别名]
# 或者: from azure.storage.blob.BlobService import generate_shared_access_signature [as 别名]
    example_file_path,
)

# Create a new signed identifier (policy)
si = SignedIdentifier()
# Set the name
si.id = policy_name
# Set the expiration date
si.access_policy.expiry = '2016-01-01'
# Set the permissions. Read and List in this example
si.access_policy.permission = ContainerSharedAccessPermissions.READ + ContainerSharedAccessPermissions.LIST

# Get the existing signed identifiers (policies) for the container
identifiers = blob_service.get_container_acl(storage_container_name)
# And append the new one ot the list
identifiers.signed_identifiers.append(si)

# Set the container to the updated list of signed identifiers (policies)
blob_service.set_container_acl(
    container_name=storage_container_name,
    signed_identifiers=identifiers,
)

# Generate a new Shared Access Signature token using the 
sas_token = blob_service.generate_shared_access_signature(
    container_name=storage_container_name,
    shared_access_policy=SharedAccessPolicy(signed_identifier=policy_name),
)

# Print out the new token
print(sas_token)
开发者ID:hning86,项目名称:hdinsight-dotnet-python-azure-storage-shared-access-signature,代码行数:33,代码来源:SASToken.py


注:本文中的azure.storage.blob.BlobService.generate_shared_access_signature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。