From bf3d1590dce0b06d21c658cacfb67410a4fb3de8 Mon Sep 17 00:00:00 2001 From: wanyj <2026804718@qq.com> Date: Mon, 9 Feb 2026 13:57:40 +0800 Subject: [PATCH] [refactor][backend] support configurable force_path_style for S3 client Previously, the ForcePathStyle setting was hardcoded based on domain name detection, making it difficult to adapt to different object storage services. This commit refactors the getOssForcePathStyle function to read from the configuration file (infrastructure.yaml) with a fallback to domain-based detection for backward compatibility. Changes: - Modify getOssForcePathStyle to accept componentConfig parameter - Prioritize reading force_path_style from s3_config in infrastructure.yaml - Fallback to domain-based detection when config is not set Benefits: - Flexibility to configure force_path_style for any S3-compatible storage - Easier integration with different object storage backends (MinIO, RustFS, etc.) - Maintains backward compatibility with existing deployments --- backend/cmd/main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 8dedc19252..5c72272c94 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -214,7 +214,7 @@ func newComponent(ctx context.Context) (*component, error) { cfg.AccessKeyID = getOssUser() cfg.SecretAccessKey = getOssPassword() cfg.Bucket = getOssBucket() - cfg.ForcePathStyle = getOssForcePathStyle() + cfg.ForcePathStyle = getOssForcePathStyle(componentConfig) }) objectStorage, err := fileserver.NewS3Client(s3Config) if err != nil { @@ -348,7 +348,13 @@ func getOssBucket() string { return os.Getenv("COZE_LOOP_OSS_BUCKET") } -func getOssForcePathStyle() *bool { +func getOssForcePathStyle(componentConfig *ComponentConfig) *bool { + // 优先从配置文件读取 + if componentConfig != nil && componentConfig.S3Config.ForcePathStyle != nil { + return componentConfig.S3Config.ForcePathStyle + } + + // 配置文件未设置时,回退到域名判断(向后兼容) if getOssDomain() == "coze-loop-minio" { return gptr.Of(true) }