Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
基于 httpx 的阿里云对象存储 Python SDK,支持异步操作并提供类型提示。
[!Note]
- 此版本不包含
osscmd
命令行工具。- 此版本仅支持 Python 3.10 及以上版本。
- 此版本仅支持 V4 签名。
Python 3.10 及以上版本。
通过 PIP 安装官方发布版本:
pip install aliyun-oss-x
如果需要使用阿里云 KMS 加密,请安装 aliyun-kms 扩展包:
pip install aliyun-oss-x[aliyun-kms]
import aliyun_oss_x
endpoint = 'http://oss-cn-hangzhou.aliyuncs.com' # 假设你的存储桶位于杭州地区
auth = aliyun_oss_x.Auth('<你的 AccessKeyID>', '<你的 AccessKeySecret>')
bucket = aliyun_oss_x.Bucket(auth, endpoint, '<你的存储桶名称>')
# 存储桶中的对象键为 story.txt
key = 'story.txt'
# 上传
bucket.put_object(key, 'Ali Baba 是一个快乐的青年。')
# 下载
bucket.get_object(key).read()
# 删除
bucket.delete_object(key)
# 遍历存储桶中的所有对象
for object_info in aliyun_oss_x.ObjectIterator(bucket):
print(object_info.key)
import asyncio
import aliyun_oss_x
endpoint = 'http://oss-cn-hangzhou.aliyuncs.com' # 假设你的存储桶位于杭州地区
auth = aliyun_oss_x.Auth('<你的 AccessKeyID>', '<你的 AccessKeySecret>')
bucket = aliyun_oss_x.AsyncBucket(auth, endpoint, '<你的存储桶名称>', region="cn-hangzhou")
async def main():
# 存储桶中的对象键为 story.txt
key = 'story.txt'
# 上传
await bucket.put_object(key, 'Ali Baba 是一个快乐的青年。')
# 下载
await bucket.get_object(key).read()
# 删除
await bucket.delete_object(key)
# 遍历存储桶中的所有对象
async for object_info in aliyun_oss_x.AsyncObjectIterator(bucket):
print(object_info.key)
asyncio.run(main())
更多示例请参考 "examples" 目录下的代码。
除非另有说明,Python SDK 接口在出错时会抛出异常(参见 aliyun_oss_x.exceptions 子模块)。以下是一个示例:
try:
result = bucket.get_object(key)
print(result.read())
except aliyun_oss_x.exceptions.NoSuchKey as e:
print('{0} 未找到:http_status={1}, request_id={2}'.format(key, e.status, e.request_id))
以下代码可以设置 'aliyun_oss_x' 的日志级别:
import logging
logging.getLogger('aliyun_oss_x').setLevel(logging.WARNING)
首先通过环境变量设置测试所需的 AccessKeyId、AccessKeySecret、endpoint 和 bucket 信息(不要使用生产环境的存储桶)。 以 Linux 系统为例:
export OSS_TEST_ACCESS_KEY_ID=<AccessKeyId>
export OSS_TEST_ACCESS_KEY_SECRET=<AccessKeySecret>
export OSS_TEST_ENDPOINT=<endpoint>
export OSS_TEST_BUCKET=<bucket>
export OSS_TEST_STS_ID=<用于测试 STS 的 AccessKeyId>
export OSS_TEST_STS_KEY=<用于测试 STS 的 AccessKeySecret>
export OSS_TEST_STS_ARN=<用于测试 STS 的角色 ARN>
按以下方式运行测试:
nosetests # 首先安装 nose
FAQs
Aliyun OSS SDK for Python with async support
We found that aliyun-oss-x demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.