Skip to content

Commit

Permalink
feat: support aliyun oss auth v4
Browse files Browse the repository at this point in the history
  • Loading branch information
owen committed Apr 26, 2024
1 parent 2e454c7 commit 3ac8d5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ ALIYUN_OSS_BUCKET_NAME=your-bucket-name
ALIYUN_OSS_ACCESS_KEY=your-access-key
ALIYUN_OSS_SECRET_KEY=your-secret-key
ALIYUN_OSS_ENDPOINT=your-endpoint
ALIYUN_OSS_AUTH_VERSION=v1
ALIYUN_OSS_REGION=your-region

# CORS configuration
WEB_API_CORS_ALLOW_ORIGINS=http://127.0.0.1:3000,*
Expand Down
2 changes: 2 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def __init__(self):
self.ALIYUN_OSS_ACCESS_KEY=get_env('ALIYUN_OSS_ACCESS_KEY')
self.ALIYUN_OSS_SECRET_KEY=get_env('ALIYUN_OSS_SECRET_KEY')
self.ALIYUN_OSS_ENDPOINT=get_env('ALIYUN_OSS_ENDPOINT')
self.ALIYUN_OSS_REGION=get_env('ALIYUN_OSS_REGION')
self.ALIYUN_OSS_AUTH_VERSION=get_env('ALIYUN_OSS_AUTH_VERSION')

# ------------------------
# Vector Store Configurations.
Expand Down
9 changes: 8 additions & 1 deletion api/extensions/ext_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ def init_app(self, app: Flask):
credential=sas_token)
elif self.storage_type == 'aliyun-oss':
self.bucket_name = app.config.get('ALIYUN_OSS_BUCKET_NAME')
oss_auth_method = aliyun_s3.Auth
region = None
if app.config.get('ALIYUN_OSS_AUTH_VERSION') == 'v4':
oss_auth_method = aliyun_s3.AuthV4
region = app.config.get('ALIYUN_OSS_REGION')
oss_auth = oss_auth_method(app.config.get('ALIYUN_OSS_ACCESS_KEY'), app.config.get('ALIYUN_OSS_SECRET_KEY'))
self.client = aliyun_s3.Bucket(
aliyun_s3.Auth(app.config.get('ALIYUN_OSS_ACCESS_KEY'), app.config.get('ALIYUN_OSS_SECRET_KEY')),
oss_auth,
app.config.get('ALIYUN_OSS_ENDPOINT'),
self.bucket_name,
region=region,
connect_timeout=30
)
else:
Expand Down

0 comments on commit 3ac8d5b

Please sign in to comment.