日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

Python存儲空間清單

本文介紹如何添加、查看、批量列舉和刪除存儲空間(Bucket)的清單(Inventory)配置。

注意事項

  • 本文以華東1(杭州)外網Endpoint為例。如果您希望通過與OSS同地域的其他阿里云產品訪問OSS,請使用內網Endpoint。關于OSS支持的Region與Endpoint的對應關系,請參見訪問域名和數據中心

  • 本文以從環境變量讀取訪問憑證為例。如何配置訪問憑證,請參見配置訪問憑證

  • 本文以OSS域名新建OSSClient為例。如果您希望通過自定義域名、STS等方式新建OSSClient,請參見初始化

  • 請確保您擁有調用添加、查看、列舉和刪除存儲空間清單配置的權限。Bucket所有者默認擁有此類權限,如果您無此類權限,請先向Bucket所有者申請對應操作的權限。

  • 單個Bucket最多只能有1000條清單配置。

  • 配置清單的源Bucket與存放導出的清單文件所在的目標Bucket必須位于同一個Region。

添加清單配置

以下代碼用于為某個Bucket添加清單配置:

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
from oss2.models import (InventoryConfiguration,
                         InventoryFilter,
                         InventorySchedule,
                         InventoryDestination,
                         InventoryBucketDestination,
                         INVENTORY_INCLUDED_OBJECT_VERSIONS_CURRENT,
                         INVENTORY_FREQUENCY_DAILY,
                         INVENTORY_FORMAT_CSV,
                         FIELD_SIZE,
                         FIELD_LAST_MODIFIED_DATE,
                         FIELD_STORAG_CLASS,
                         FIELD_ETAG,
                         FIELD_IS_MULTIPART_UPLOADED,
                         FIELD_ENCRYPTION_STATUS)

# 從環境變量中獲取訪問憑證。運行本代碼示例之前,請確保已設置環境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# yourEndpoint填寫Bucket所在地域對應的Endpoint。以華東1(杭州)為例,Endpoint填寫為https://oss-cn-hangzhou.aliyuncs.com。
# 填寫Bucket名稱,例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# 填寫Bucket所有者授予的賬戶ID。例如:1283641033516515
account_id = 'yourtBucketDestinationAccountId'
# 填寫具有讀取源Bucket所有文件和向目標Bucket寫入文件權限的角色名稱。例如:acs:ram::1283641033516515:role/AliyunOSSRole
role_arn = 'yourBucketDestinationRoleArn'
# 填寫存放清單結果的Bucket名稱。
dest_bucket_name = 'yourDestinationBucketName'

# 設置清單規則名稱。
inventory_id = "inventory1"

# 設置清單結果中包含的Object屬性。
optional_fields = [FIELD_SIZE, FIELD_LAST_MODIFIED_DATE, FIELD_STORAG_CLASS,
                   FIELD_ETAG, FIELD_IS_MULTIPART_UPLOADED, FIELD_ENCRYPTION_STATUS]

# 創建存放清單文件的目標Bucket配置。
bucket_destination = InventoryBucketDestination(
    # 目標Bucket的用戶accountId。
    account_id=account_id,
    # 目標Bucket的roleArn。
    role_arn=role_arn,
    # 目標Bucket的名稱。
    bucket=dest_bucket_name,
    # 指定清單格式。
    inventory_format=INVENTORY_FORMAT_CSV,
    # 清單結果的存儲路徑前綴。
    prefix='destination-prefix',
    # 如果需要使用KMS加密清單,請參考如下設置。
    # sse_kms_encryption=InventoryServerSideEncryptionKMS("test-kms-id"),
    # 如果需要使用OSS服務端加密清單,請參考如下設置。
    # sse_oss_encryption=InventoryServerSideEncryptionOSS()
)

# 創建清單配置。
inventory_configuration = InventoryConfiguration(
    # 設置清單的配置id。
    inventory_id=inventory_id,
    # 清單配置是否啟用的標識, true或false。
    is_enabled=True,
    # 設置清單的生成計劃,以下示例為每天一次。其中,WEEKLY對應每周一次,DAILY對應每天一次。
    inventory_schedule=InventorySchedule(frequency=INVENTORY_FREQUENCY_DAILY),
    # 設置清單中包含的object的版本為當前版本。如果設置為INVENTORY_INCLUDED_OBJECT_VERSIONS_ALL則表示object的所有版本,在版本控制狀態下生效。
    included_object_versions=INVENTORY_INCLUDED_OBJECT_VERSIONS_CURRENT,
    # 設置清單清篩選object的前綴。
    # inventory_filter=InventoryFilter(prefix="obj-prefix"),
    # 設置清單清篩選條件。假如篩選文件最后修改時間的起始時間戳為1637883649,
    inventory_filter=InventoryFilter(
        # 篩選規則的匹配前綴。
        "obj-prefix",
        # 篩選文件最后修改時間的起始時間戳,單位為秒。
        1637883649,
        # 篩選文件最后修改時間的終止時間戳,單位為秒。
        1638347592,
        # 篩選文件的最小大小,單位為B。
        1024,
        # 篩選文件的最大大小,單位為B。
        1048576,
        # 篩選文件的存儲類型,支持指定多種存儲類型。
        'Standard,IA'),
    # 設置清單中包含的object屬性。
    optional_fields=optional_fields,    
    inventory_destination=InventoryDestination(bucket_destination=bucket_destination))

# 上傳清單配置。
result = bucket.put_bucket_inventory_configuration(inventory_configuration)
print(result.status)

查看清單配置

以下代碼用于查看某個Bucket的清單配置:

# -*- coding: utf-8 -*-

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
import os

# 從環境變量中獲取訪問憑證。運行本代碼示例之前,請確保已設置環境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# yourEndpoint填寫Bucket所在地域對應的Endpoint。以華東1(杭州)為例,Endpoint填寫為https://oss-cn-hangzhou.aliyuncs.com。
# 填寫Bucket名稱,例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# 填寫清單規則名稱。
inventory_id = "inventory1"

# 獲取清單配置。
result = bucket.get_bucket_inventory_configuration(inventory_id=inventory_id);

# 打印清單配置信息。
print('======inventory configuration======')
print('inventory_id', result.inventory_id)
print('is_enabled', result.is_enabled)
print('frequency', result.inventory_schedule.frequency)
print('included_object_versions', result.included_object_versions)
print('inventory_filter prefix', result.inventory_filter.prefix)
print('fields', result.optional_fields)
bucket_destin = result.inventory_destination.bucket_destination
print('===bucket destination===')
print('account_id', bucket_destin.account_id)
print('role_arn', bucket_destin.role_arn)
print('bucket', bucket_destin.bucket)
print('format', bucket_destin.inventory_format)
print('prefix', bucket_destin.prefix)
if bucket_destin.sse_kms_encryption is not None:
    print('server side encryption by kms, key id:', bucket_destin.sse_kms_encryption.key_id)
elif bucket_destin.sse_oss_encryption is not None:
    print('server side encryption by oss.')

批量列舉清單配置

說明

單次請求最多可獲取100條清單配置項內容。若需獲取超過100條清單配置項,則需發送多次請求,并保留相應的Token,作為下一次請求的參數。

以下代碼用于批量列舉某個Bucket的清單配置:

# -*- coding: utf-8 -*-

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
import os

# 從環境變量中獲取訪問憑證。運行本代碼示例之前,請確保已設置環境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# yourEndpoint填寫Bucket所在地域對應的Endpoint。以華東1(杭州)為例,Endpoint填寫為https://oss-cn-hangzhou.aliyuncs.com。
# 填寫Bucket名稱,例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# 打印清單配置信息。
def print_inventory_configuration(configuration):
    print('======inventory configuration======')
    print('inventory_id', configuration.inventory_id)
    print('is_enabled', configuration.is_enabled)
    print('frequency', configuration.inventory_schedule.frequency)
    print('included_object_versions', configuration.included_object_versions)
    print('inventory_filter prefix', configuration.inventory_filter.prefix)
    print('fields', configuration.optional_fields)
    bucket_destin = configuration.inventory_destination.bucket_destination
    print('===bucket destination===')
    print('account_id', bucket_destin.account_id)
    print('role_arn', bucket_destin.role_arn)
    print('bucket', bucket_destin.bucket)
    print('format', bucket_destin.inventory_format)
    print('prefix', bucket_destin.prefix)
    if bucket_destin.sse_kms_encryption is not None:
        print('server side encryption by kms, key id:', bucket_destin.sse_kms_encryption.key_id)
    elif bucket_destin.sse_oss_encryption is not None:
        print('server side encryption by oss.')

# 列舉所有的清單配置。
# 如果存在超過100條配置,列舉結果將會分頁,分頁信息保存在class: <oss2.models.ListInventoryConfigurationResult>中。
continuation_token = None
while 1:
    result = bucket.list_bucket_inventory_configurations(continuation_token=continuation_token)
    # 本次列舉結果是否分頁。
    print('is truncated', result.is_truncated)
    # 本次列舉攜帶的token。
    print('continuaiton_token', result.continuaiton_token)
    # 下次列舉需要攜帶的token。
    print('next_continuation_token', result.next_continuation_token)

    # 打印清單配置信息。
    for inventory_config in result.inventory_configurations:
        print_inventory_configuration(inventory_config)

    # 如果本次列舉為分頁列舉,則繼續列舉,且需要攜帶分頁token。
    if result.is_truncated:
        continuation_token = result.next_continuation_token
    else:
         break

刪除清單配置

以下代碼用于刪除某個Bucket的清單配置:

# -*- coding: utf-8 -*-

import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
import os

# 從環境變量中獲取訪問憑證。運行本代碼示例之前,請確保已設置環境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
# yourEndpoint填寫Bucket所在地域對應的Endpoint。以華東1(杭州)為例,Endpoint填寫為https://oss-cn-hangzhou.aliyuncs.com。
# 填寫Bucket名稱,例如examplebucket。
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')

# 填寫清單規則名稱。
inventory_id = "inventory1"

# 刪除清單配置。
bucket.delete_bucket_inventory_configuration(inventory_id)

相關文檔