Add flag of S3ForcePathStyle (#1802)

This commit is contained in:
Lan 2021-11-17 07:03:03 +08:00 committed by Aliaksandr Valialkin
parent 273fbc2e8a
commit 6662714c6c
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 12 additions and 7 deletions

View file

@ -21,6 +21,7 @@ var (
configProfile = flag.String("configProfile", "", "Profile name for S3 configs. If no set, the value of the environment variable will be loaded (AWS_PROFILE or AWS_DEFAULT_PROFILE), "+ configProfile = flag.String("configProfile", "", "Profile name for S3 configs. If no set, the value of the environment variable will be loaded (AWS_PROFILE or AWS_DEFAULT_PROFILE), "+
"or if both not set, DefaultSharedConfigProfile is used") "or if both not set, DefaultSharedConfigProfile is used")
customS3Endpoint = flag.String("customS3Endpoint", "", "Custom S3 endpoint for use with S3-compatible storages (e.g. MinIO). S3 is used if not set") customS3Endpoint = flag.String("customS3Endpoint", "", "Custom S3 endpoint for use with S3-compatible storages (e.g. MinIO). S3 is used if not set")
s3ForcePathStyle = flag.Bool("s3ForcePathStyle", true, "Prefixing endpoint with bucket name when set false, true by default.")
) )
func runParallel(concurrency int, parts []common.Part, f func(p common.Part) error, progress func(elapsed time.Duration)) error { func runParallel(concurrency int, parts []common.Part, f func(p common.Part) error, progress func(elapsed time.Duration)) error {
@ -222,6 +223,7 @@ func NewRemoteFS(path string) (common.RemoteFS, error) {
CredsFilePath: *credsFilePath, CredsFilePath: *credsFilePath,
ConfigFilePath: *configFilePath, ConfigFilePath: *configFilePath,
CustomEndpoint: *customS3Endpoint, CustomEndpoint: *customS3Endpoint,
S3ForcePathStyle: *s3ForcePathStyle,
ProfileName: *configProfile, ProfileName: *configProfile,
Bucket: bucket, Bucket: bucket,
Dir: dir, Dir: dir,

View file

@ -37,6 +37,9 @@ type FS struct {
// Set for using S3-compatible enpoint such as MinIO etc. // Set for using S3-compatible enpoint such as MinIO etc.
CustomEndpoint string CustomEndpoint string
// Force to use path style for s3, true by default.
S3ForcePathStyle bool
// The name of S3 config profile to use. // The name of S3 config profile to use.
ProfileName string ProfileName string
@ -83,7 +86,7 @@ func (fs *FS) Init() error {
sess.Config.WithEndpoint(fs.CustomEndpoint) sess.Config.WithEndpoint(fs.CustomEndpoint)
// Disable prefixing endpoint with bucket name // Disable prefixing endpoint with bucket name
sess.Config.WithS3ForcePathStyle(true) sess.Config.WithS3ForcePathStyle(fs.S3ForcePathStyle)
} else { } else {
// Determine bucket region. // Determine bucket region.
ctx := context.Background() ctx := context.Background()