使用 boto3 进行 GCP 保留设置

发布于 2025-01-12 00:44:33 字数 1480 浏览 0 评论 0原文

我正在使用 python boto3 包访问 AWS S3 和 GCP 存储桶。 这些存储桶已为其各自的存储桶设置了对象锁定/保留。 是否有一个通用的包/SDK 可以获取锁定/保留详细信息。

        session = boto3.session.Session(aws_access_key_id=access_key,
                                        aws_secret_access_key=secret_key,
                                        region_name=region_name)
        s3_client = session.client('s3', endpoint_url=endpoint)
        head = s3_client.head_bucket(Bucket=bucket_name)
        result = s3_client.get_object_lock_configuration(Bucket=bucket_name)

此代码块适用于 AWS S3,但会引发 GCP 存储桶异常。 抛出异常:

[DEBUG] Response body: b"<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code>
<Message>Invalid argument.</Message><Details>Invalid query parameter(s): [object-lock]</Details></Error>" 2022-03-03 20:16:37,111 botocore.hooks 
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <botocore.retryhandler.RetryHandler object at 0x7f518264a310> 2022-03-03 20:16:37,112 botocore.retryhandler 
[DEBUG] No retry needed. 2022-03-03 20:16:37,113 botocore.hooks 
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f518264a370>> 
An error occurred (InvalidArgument) when calling the GetObjectLockConfiguration operation: Invalid argument.

谢谢!!

I am using the python boto3 package to access AWS S3 and GCP buckets.
These buckets have object lock/retention set to their respective buckets.
Is there a common packge/SDK that would fetch the lock/retention details.

        session = boto3.session.Session(aws_access_key_id=access_key,
                                        aws_secret_access_key=secret_key,
                                        region_name=region_name)
        s3_client = session.client('s3', endpoint_url=endpoint)
        head = s3_client.head_bucket(Bucket=bucket_name)
        result = s3_client.get_object_lock_configuration(Bucket=bucket_name)

This code block works for AWS S3 but throws exception for GCP buckets.
Exception thrown:

[DEBUG] Response body: b"<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code>
<Message>Invalid argument.</Message><Details>Invalid query parameter(s): [object-lock]</Details></Error>" 2022-03-03 20:16:37,111 botocore.hooks 
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <botocore.retryhandler.RetryHandler object at 0x7f518264a310> 2022-03-03 20:16:37,112 botocore.retryhandler 
[DEBUG] No retry needed. 2022-03-03 20:16:37,113 botocore.hooks 
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f518264a370>> 
An error occurred (InvalidArgument) when calling the GetObjectLockConfiguration operation: Invalid argument.

Thank you!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潇烟暮雨 2025-01-19 00:44:33

Google 云存储在 SDK 中有一组单独的命令 - gsutil
您可以使用 retention 命令获取详细信息。

还有一个 API,允许从 存储桶 获取多个信息和对象
fields 参数中发送 retentionPolicyretentionPeriodeffectiveTime 以仅过滤您感兴趣的值。

Google Cloud storage has a separate set of commands within the SDK - gsutil.
You can use retention command to obtain the details.

There is also an API that allows fetching multiple information from buckets and objects.
Send retentionPolicy, retentionPeriod or effectiveTime in fields parameter to filter only the values you are interested in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文