Skip to content

Commit d1728a5

Browse files
authored
Merge pull request #368 from databacker/standardize-s3-endpoint-resolution
standardize S3 endpoint handling and add option for path-style
2 parents 7f52980 + 82fceb3 commit d1728a5

File tree

8 files changed

+44
-79
lines changed

8 files changed

+44
-79
lines changed

cmd/root.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ func rootCmd(execs execs) (*cobra.Command, error) {
5151
Short: "backup or restore one or more mysql-compatible databases",
5252
Long: `Backup or restore one or more mysql-compatible databases.
5353
In addition to the provided command-line flag options and environment variables,
54-
when using s3-storage, supports the standard AWS options:
54+
when using s3-storage, supports the following AWS options:
5555
5656
AWS_ACCESS_KEY_ID: AWS Key ID
5757
AWS_SECRET_ACCESS_KEY: AWS Secret Access Key
5858
AWS_REGION: Region in which the bucket resides
59+
AWS_ENDPOINT_URL: Endpoint URL to use instead of default s3.<region>.amazonaws.com
60+
AWS_PATH_STYLE: Use path-style URLs for S3 requests instead of virtual-hosted-style URLs
5961
`,
6062
PersistentPreRunE: func(c *cobra.Command, args []string) error {
6163
bindFlags(cmd, v)
@@ -146,6 +148,7 @@ func rootCmd(execs execs) (*cobra.Command, error) {
146148
cmdConfig.creds = credentials.Creds{
147149
AWS: credentials.AWSCreds{
148150
Endpoint: v.GetString("aws-endpoint-url"),
151+
PathStyle: v.GetBool("aws-path-style"),
149152
AccessKeyID: v.GetString("aws-access-key-id"),
150153
SecretAccessKey: v.GetString("aws-secret-access-key"),
151154
Region: v.GetString("aws-region"),
@@ -187,6 +190,7 @@ func rootCmd(execs execs) (*cobra.Command, error) {
187190

188191
// aws options
189192
pflags.String("aws-endpoint-url", "", "Specify an alternative endpoint for s3 interoperable systems e.g. Digitalocean; ignored if not using s3.")
193+
pflags.Bool("aws-path-style", false, "Use path-style addressing of buckets instead of default virtual-host-style; ignored if not using s3.")
190194
pflags.String("aws-access-key-id", "", "Access Key for s3 and s3 interoperable systems; ignored if not using s3.")
191195
pflags.String("aws-secret-access-key", "", "Secret Access Key for s3 and s3 interoperable systems; ignored if not using s3.")
192196
pflags.String("aws-region", "", "Region for s3 and s3 interoperable systems; ignored if not using s3.")

docs/configuration.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The following are the environment variables, CLI flags and configuration file op
8484
| AWS secret access key, used only if a target does not have one | BRP | `aws-secret-access-key` | `AWS_SECRET_ACCESS_KEY` | `dump.targets[s3-target].secretAccessKey` | |
8585
| AWS default region, used only if a target does not have one | BRP | `aws-region` | `AWS_REGION` | `dump.targets[s3-target].region` | |
8686
| alternative endpoint URL for S3-interoperable systems, used only if a target does not have one | BR | `aws-endpoint-url` | `AWS_ENDPOINT_URL` | `dump.targets[s3-target].endpoint` | |
87+
| path-style addressing for S3 bucket instead of default virtual-host-style addressing | BR | `aws-path-style` | `AWS_PATH_STYLE` | `dump.targets[s3-target].pathStyle` | |
8788
| SMB username, used only if a target does not have one | BRP | `smb-user` | `SMB_USER` | `dump.targets[smb-target].username` | |
8889
| SMB password, used only if a target does not have one | BRP | `smb-pass` | `SMB_PASS` | `dump.targets[smb-target].password` | |
8990
| compression to use, one of: `bzip2`, `gzip` | BP | `compression` | `DB_DUMP_COMPRESSION` | `dump.compression` | `gzip` |
@@ -159,12 +160,13 @@ for details of each.
159160
* Type s3:
160161
* `region`: the region
161162
* `endpoint`: the endpoint
162-
* `accessKeyId`: the access key ID (s3)
163-
* `secretAccessKey`: the secret access key (s3)
163+
* `pathStyle` (boolean): use path-style bucket addressing instead of virtual-host style bucket addressing, see [AWS docs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html)
164+
* `accessKeyId`: the access key ID
165+
* `secretAccessKey`: the secret access key
164166
* Type smb:
165-
* `domain`: the domain (smb)
166-
* `username`: the username (smb)
167-
* `password`: the password (smb)
167+
* `domain`: the domain
168+
* `username`: the username
169+
* `password`: the password
168170
* `logging`: the log level, one of: error,warning,info,debug,trace; default is info
169171
* `telemetry`: configuration for sending telemetry data (optional)
170172
* `url`: URL to telemetry service

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ require (
3434
github.com/felixge/httpsnoop v1.0.3 // indirect
3535
github.com/go-logr/logr v1.2.4 // indirect
3636
github.com/go-logr/stdr v1.2.2 // indirect
37-
github.com/jmespath/go-jmespath v0.4.0 // indirect
3837
github.com/moby/docker-image-spec v1.3.1 // indirect
3938
github.com/moby/sys/user v0.2.0 // indirect
4039
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
@@ -59,7 +58,7 @@ require (
5958
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 // indirect
6059
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 // indirect
6160
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3 // indirect
62-
github.com/aws/smithy-go v1.22.0
61+
github.com/aws/smithy-go v1.22.0 // indirect
6362
github.com/containerd/containerd v1.7.11 // indirect
6463
github.com/davecgh/go-spew v1.1.1 // indirect
6564
github.com/docker/go-units v0.5.0 // indirect

go.sum

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,80 +14,42 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
1414
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
1515
github.com/aws/aws-sdk-go v1.44.256 h1:O8VH+bJqgLDguqkH/xQBFz5o/YheeZqgcOYIgsTVWY4=
1616
github.com/aws/aws-sdk-go v1.44.256/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
17-
github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
18-
github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc=
1917
github.com/aws/aws-sdk-go-v2 v1.32.3 h1:T0dRlFBKcdaUPGNtkBSwHZxrtis8CQU17UpNBZYd0wk=
2018
github.com/aws/aws-sdk-go-v2 v1.32.3/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo=
21-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 h1:tW1/Rkad38LA15X4UQtjXZXNKsCgkshC3EbmcUmghTg=
22-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3/go.mod h1:UbnqO+zjqk3uIt9yCACHJ9IVNhyhOCnYk8yA19SAWrM=
2319
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 h1:pT3hpW0cOHRJx8Y0DfJUEQuqPild8jRGmSFmBgvydr0=
2420
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6/go.mod h1:j/I2++U0xX+cr44QjHay4Cvxj6FUbnxrgmqN3H1jTZA=
25-
github.com/aws/aws-sdk-go-v2/config v1.27.27 h1:HdqgGt1OAP0HkEDDShEl0oSYa9ZZBSOmKpdpsDMdO90=
26-
github.com/aws/aws-sdk-go-v2/config v1.27.27/go.mod h1:MVYamCg76dFNINkZFu4n4RjDixhVr51HLj4ErWzrVwg=
2721
github.com/aws/aws-sdk-go-v2/config v1.28.1 h1:oxIvOUXy8x0U3fR//0eq+RdCKimWI900+SV+10xsCBw=
2822
github.com/aws/aws-sdk-go-v2/config v1.28.1/go.mod h1:bRQcttQJiARbd5JZxw6wG0yIK3eLeSCPdg6uqmmlIiI=
29-
github.com/aws/aws-sdk-go-v2/credentials v1.17.27 h1:2raNba6gr2IfA0eqqiP2XiQ0UVOpGPgDSi0I9iAP+UI=
30-
github.com/aws/aws-sdk-go-v2/credentials v1.17.27/go.mod h1:gniiwbGahQByxan6YjQUMcW4Aov6bLC3m+evgcoN4r4=
3123
github.com/aws/aws-sdk-go-v2/credentials v1.17.42 h1:sBP0RPjBU4neGpIYyx8mkU2QqLPl5u9cmdTWVzIpHkM=
3224
github.com/aws/aws-sdk-go-v2/credentials v1.17.42/go.mod h1:FwZBfU530dJ26rv9saAbxa9Ej3eF/AK0OAY86k13n4M=
33-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 h1:KreluoV8FZDEtI6Co2xuNk/UqI9iwMrOx/87PBNIKqw=
34-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11/go.mod h1:SeSUYBLsMYFoRvHE0Tjvn7kbxaUhl75CJi1sbfhMxkU=
3525
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 h1:68jFVtt3NulEzojFesM/WVarlFpCaXLKaBxDpzkQ9OQ=
3626
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18/go.mod h1:Fjnn5jQVIo6VyedMc0/EhPpfNlPl7dHV916O6B+49aE=
37-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.9 h1:TC2vjvaAv1VNl9A0rm+SeuBjrzXnrlwk6Yop+gKRi38=
38-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.9/go.mod h1:WPv2FRnkIOoDv/8j2gSUsI4qDc7392w5anFB/I89GZ8=
3927
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.35 h1:ihPPdcCVSN0IvBByXwqVp28/l4VosBZ6sDulcvU2J7w=
4028
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.35/go.mod h1:JkgEhs3SVF51Dj3m1Bj+yL8IznpxzkwlA3jLg3x7Kls=
41-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 h1:SoNJ4RlFEQEbtDcCEt+QG56MY4fm4W8rYirAmq+/DdU=
42-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15/go.mod h1:U9ke74k1n2bf+RIgoX1SXFed1HLs51OgUSs+Ph0KJP8=
4329
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 h1:Jw50LwEkVjuVzE1NzkhNKkBf9cRN7MtE1F/b2cOKTUM=
4430
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22/go.mod h1:Y/SmAyPcOTmpeVaWSzSKiILfXTVJwrGmYZhcRbhWuEY=
45-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 h1:C6WHdGnTDIYETAm5iErQUiVNsclNx9qbJVPIt03B6bI=
46-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15/go.mod h1:ZQLZqhcu+JhSrA9/NXRm8SkDvsycE+JkV3WGY41e+IM=
4731
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 h1:981MHwBaRZM7+9QSR6XamDzF/o7ouUGxFzr+nVSIhrs=
4832
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22/go.mod h1:1RA1+aBEfn+CAB/Mh0MB6LsdCYCnjZm7tKXtnk499ZQ=
49-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
50-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
5133
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 h1:VaRN3TlFdd6KxX1x3ILT5ynH6HvKgqdiXoTxAF4HQcQ=
5234
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1/go.mod h1:FbtygfRFze9usAadmnGJNc8KsP346kEe+y2/oyhGAGc=
53-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.15 h1:Z5r7SycxmSllHYmaAZPpmN8GviDrSGhMS6bldqtXZPw=
54-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.15/go.mod h1:CetW7bDE00QoGEmPUoZuRog07SGVAUVW6LFpNP0YfIg=
5535
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.22 h1:yV+hCAHZZYJQcwAaszoBNwLbPItHvApxT0kVIw6jRgs=
5636
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.22/go.mod h1:kbR1TL8llqB1eGnVbybcA4/wgScxdylOdyAd51yxPdw=
57-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 h1:dT3MqvGhSoaIhRseqw2I0yH81l7wiR2vjs57O51EAm8=
58-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3/go.mod h1:GlAeCkHwugxdHaueRr4nhPuY+WW+gR8UjlcqzPr1SPI=
5937
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 h1:TToQNkvGguu209puTojY/ozlqy2d/SFNcoLIqTFi42g=
6038
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0/go.mod h1:0jp+ltwkf+SwG2fm/PKo8t4y8pJSgOCO4D8Lz3k0aHQ=
61-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.17 h1:YPYe6ZmvUfDDDELqEKtAd6bo8zxhkm+XEFEzQisqUIE=
62-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.17/go.mod h1:oBtcnYua/CgzCWYN7NZ5j7PotFDaFSUjCYVTtfyn7vw=
6339
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.3 h1:kT6BcZsmMtNkP/iYMcRG+mIEA/IbeiUimXtGmqF39y0=
6440
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.3/go.mod h1:Z8uGua2k4PPaGOYn66pK02rhMrot3Xk3tpBuUFPomZU=
65-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 h1:HGErhhrxZlQ044RiM+WdoZxp0p+EGM62y3L6pwA4olE=
66-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17/go.mod h1:RkZEx4l0EHYDJpWppMJ3nD9wZJAa8/0lq9aVC+r2UII=
6741
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 h1:qcxX0JYlgWH3hpPUnd6U0ikcl6LLA9sLkXE2w1fpMvY=
6842
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3/go.mod h1:cLSNEmI45soc+Ef8K/L+8sEA3A3pYFEYf5B5UI+6bH4=
69-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15 h1:246A4lSTXWJw/rmlQI+TT2OcqeDMKBdyjEQrafMaQdA=
70-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15/go.mod h1:haVfg3761/WF7YPuJOER2MP0k4UAXyHaLclKXB6usDg=
7143
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.3 h1:ZC7Y/XgKUxwqcdhO5LE8P6oGP1eh6xlQReWNKfhvJno=
7244
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.3/go.mod h1:WqfO7M9l9yUAw0HcHaikwRd/H6gzYdz7vjejCA5e2oY=
73-
github.com/aws/aws-sdk-go-v2/service/s3 v1.58.2 h1:sZXIzO38GZOU+O0C+INqbH7C2yALwfMWpd64tONS/NE=
74-
github.com/aws/aws-sdk-go-v2/service/s3 v1.58.2/go.mod h1:Lcxzg5rojyVPU/0eFwLtcyTaek/6Mtic5B1gJo7e/zE=
7545
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2 h1:p9TNFL8bFUMd+38YIpTAXpoxyz0MxC7FlbFEH4P4E1U=
7646
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2/go.mod h1:fNjyo0Coen9QTwQLWeV6WO2Nytwiu+cCcWaTdKCAqqE=
77-
github.com/aws/aws-sdk-go-v2/service/sso v1.22.4 h1:BXx0ZIxvrJdSgSvKTZ+yRBeSqqgPM89VPlulEcl37tM=
78-
github.com/aws/aws-sdk-go-v2/service/sso v1.22.4/go.mod h1:ooyCOXjvJEsUw7x+ZDHeISPMhtwI3ZCB7ggFMcFfWLU=
7947
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 h1:UTpsIf0loCIWEbrqdLb+0RxnTXfWh2vhw4nQmFi4nPc=
8048
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3/go.mod h1:FZ9j3PFHHAR+w0BSEjK955w5YD2UwB/l/H0yAK3MJvI=
81-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 h1:yiwVzJW2ZxZTurVbYWA7QOrAaCYQR72t0wrSBfoesUE=
82-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4/go.mod h1:0oxfLkpz3rQ/CHlx5hB7H69YUpFiI1tql6Q6Ne+1bCw=
8349
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 h1:2YCmIXv3tmiItw0LlYf6v7gEHebLY45kBEnPezbUKyU=
8450
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3/go.mod h1:u19stRyNPxGhj6dRm+Cdgu6N75qnbW7+QN0q0dsAk58=
85-
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 h1:ZsDKRLXGWHk8WdtyYMoGNO7bTudrvuKpDKgMVRlepGE=
86-
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3/go.mod h1:zwySh8fpFyXp9yOr/KVzxOl8SRqgf/IDw5aUt9UKFcQ=
8751
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3 h1:wVnQ6tigGsRqSWDEEyH6lSAJ9OyFUsSnbaUWChuSGzs=
8852
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3/go.mod h1:VZa9yTFyj4o10YGsmDO4gbQJUvvhY72fhumT8W4LqsE=
89-
github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE=
90-
github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
9153
github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM=
9254
github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
9355
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=

pkg/config/local.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type S3Target struct {
133133
URL string `yaml:"url"`
134134
Region string `yaml:"region"`
135135
Endpoint string `yaml:"endpoint"`
136+
PathStyle bool `yaml:"pathStyle"`
136137
Credentials AWSCredentials `yaml:"credentials"`
137138
}
138139

@@ -148,6 +149,9 @@ func (s S3Target) Storage() (storage.Storage, error) {
148149
if s.Endpoint != "" {
149150
opts = append(opts, s3.WithEndpoint(s.Endpoint))
150151
}
152+
if s.PathStyle {
153+
opts = append(opts, s3.WithPathStyle())
154+
}
151155
if s.Credentials.AccessKeyId != "" {
152156
opts = append(opts, s3.WithAccessKeyId(s.Credentials.AccessKeyId))
153157
}

pkg/storage/credentials/creds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ type AWSCreds struct {
1515
AccessKeyID string
1616
SecretAccessKey string
1717
Endpoint string
18+
PathStyle bool
1819
Region string
1920
}

pkg/storage/parse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func ParseURL(url string, creds credentials.Creds) (Storage, error) {
4848
if creds.AWS.SecretAccessKey != "" {
4949
opts = append(opts, s3.WithSecretAccessKey(creds.AWS.SecretAccessKey))
5050
}
51+
if creds.AWS.PathStyle {
52+
opts = append(opts, s3.WithPathStyle())
53+
}
5154
store = s3.New(*u, opts...)
5255
default:
5356
return nil, fmt.Errorf("unknown url protocol: %s", u.Scheme)

pkg/storage/s3/s3.go

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/credentials"
1616
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1717
"github.com/aws/aws-sdk-go-v2/service/s3"
18-
smithyendpoints "github.com/aws/smithy-go/endpoints"
1918
log "github.com/sirupsen/logrus"
2019
)
2120

@@ -190,36 +189,45 @@ func (s *S3) Remove(target string, logger *log.Entry) error {
190189

191190
func (s *S3) getClient(logger *log.Entry) (*s3.Client, error) {
192191
// Get the AWS config
193-
var (
194-
opts []func(*config.LoadOptions) error // global client options
195-
s3opts []func(*s3.Options) // s3 client options
196-
)
197-
if s.endpoint != "" {
198-
cleanEndpoint := getEndpoint(s.endpoint)
199-
s3opts = append(s3opts,
200-
s3.WithEndpointResolverV2(&staticResolver{endpoint: cleanEndpoint}),
201-
)
202-
}
192+
var configOpts []func(*config.LoadOptions) error // global client options
203193
if logger.Level == log.TraceLevel {
204-
opts = append(opts, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponse))
194+
configOpts = append(configOpts, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponse))
205195
}
206196
if s.region != "" {
207-
opts = append(opts, config.WithRegion(s.region))
197+
configOpts = append(configOpts, config.WithRegion(s.region))
208198
}
209199
if s.accessKeyId != "" {
210-
opts = append(opts, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
200+
configOpts = append(configOpts, config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
211201
s.accessKeyId,
212202
s.secretAccessKey,
213203
"",
214204
)))
215205
}
216206
cfg, err := config.LoadDefaultConfig(context.TODO(),
217-
opts...,
207+
configOpts...,
218208
)
219209
if err != nil {
220210
return nil, fmt.Errorf("failed to load AWS config: %v", err)
221211
}
222212

213+
// Get the S3 client
214+
var s3opts []func(*s3.Options) // s3 client options
215+
if s.endpoint != "" {
216+
cleanEndpoint := getEndpoint(s.endpoint)
217+
s3opts = append(s3opts,
218+
func(o *s3.Options) {
219+
o.BaseEndpoint = &cleanEndpoint
220+
},
221+
)
222+
}
223+
if s.pathStyle {
224+
s3opts = append(s3opts,
225+
func(o *s3.Options) {
226+
o.UsePathStyle = true
227+
},
228+
)
229+
}
230+
223231
// Create a new S3 service client
224232
return s3.NewFromConfig(cfg, s3opts...), nil
225233
}
@@ -243,24 +251,6 @@ func getEndpoint(endpoint string) string {
243251
return e
244252
}
245253

246-
// endpointResolver is a custom endpoint resolver that always returns the same endpoint.
247-
type staticResolver struct {
248-
endpoint string
249-
}
250-
251-
func (s *staticResolver) ResolveEndpoint(ctx context.Context, params s3.EndpointParameters) (
252-
smithyendpoints.Endpoint, error,
253-
) {
254-
// This value will be used as-is when making the request.
255-
u, err := url.Parse(s.endpoint)
256-
if err != nil {
257-
return smithyendpoints.Endpoint{}, err
258-
}
259-
return smithyendpoints.Endpoint{
260-
URI: *u,
261-
}, nil
262-
}
263-
264254
type s3FileInfo struct {
265255
name string
266256
lastModified time.Time

0 commit comments

Comments
 (0)