Skip to content

Commit 2f0d0b1

Browse files
Remove all location related changes from other providers than Azure for backport
1 parent 320bd9c commit 2f0d0b1

4 files changed

Lines changed: 6 additions & 250 deletions

File tree

gcp.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,8 @@ func (s *gcpStorage) upload(reader io.Reader, storagePath, contentType string) (
118118
return "", 0, err
119119
}
120120

121-
return s.location(storagePath), n, nil
122-
}
123-
124-
func (s *gcpStorage) location(storagePath string) string {
125-
return (&url.URL{
126-
Scheme: "https",
127-
Host: s.conf.Bucket + ".storage.googleapis.com",
128-
Path: storagePath,
129-
}).String()
121+
loc := url.URL{Scheme: "https", Host: s.conf.Bucket + ".storage.googleapis.com", Path: storagePath}
122+
return loc.String(), n, nil
130123
}
131124

132125
func (s *gcpStorage) ListObjects(prefix string) ([]string, error) {

local.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewLocal(conf *LocalConfig) (Storage, error) {
4040
}
4141

4242
func (u *localUploader) UploadFile(localPath, storagePath string, _ string) (string, int64, error) {
43-
storagePath = u.location(storagePath)
43+
storagePath = path.Join(u.StorageDir, storagePath)
4444

4545
local, err := os.Open(localPath)
4646
if err != nil {
@@ -69,7 +69,7 @@ func (u *localUploader) UploadFile(localPath, storagePath string, _ string) (str
6969
}
7070

7171
func (u *localUploader) UploadData(data []byte, storagePath, _ string) (string, int64, error) {
72-
storagePath = u.location(storagePath)
72+
storagePath = path.Join(u.StorageDir, storagePath)
7373

7474
if dir, _ := path.Split(storagePath); dir != "" {
7575
if err := os.MkdirAll(dir, 0755); err != nil {
@@ -91,10 +91,6 @@ func (u *localUploader) UploadData(data []byte, storagePath, _ string) (string,
9191
return storagePath, int64(size), nil
9292
}
9393

94-
func (u *localUploader) location(storagePath string) string {
95-
return path.Join(u.StorageDir, storagePath)
96-
}
97-
9894
func (u *localUploader) ListObjects(prefix string) ([]string, error) {
9995
absPrefix := path.Join(u.StorageDir, prefix)
10096
dir, filenamePrefix := path.Split(absPrefix)

location_test.go

Lines changed: 0 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -21,64 +21,6 @@ import (
2121
"github.com/stretchr/testify/require"
2222
)
2323

24-
func TestAliOSSLocation(t *testing.T) {
25-
cases := []struct {
26-
name string
27-
conf AliOSSConfig
28-
storagePath string
29-
want string
30-
}{
31-
{
32-
name: "normal",
33-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "oss-region.aliyuncs.com"},
34-
storagePath: "foo.mp4",
35-
want: "https://mybucket.oss-region.aliyuncs.com/foo.mp4",
36-
},
37-
{
38-
name: "endpoint with https:// prefix",
39-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "https://oss-region.aliyuncs.com"},
40-
storagePath: "foo.mp4",
41-
want: "https://mybucket.oss-region.aliyuncs.com/foo.mp4",
42-
},
43-
{
44-
name: "endpoint with http:// prefix",
45-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "http://oss-region.aliyuncs.com"},
46-
storagePath: "foo.mp4",
47-
want: "https://mybucket.oss-region.aliyuncs.com/foo.mp4",
48-
},
49-
{
50-
name: "nested path",
51-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "oss-region.aliyuncs.com"},
52-
storagePath: "folder/sub/foo.mp4",
53-
want: "https://mybucket.oss-region.aliyuncs.com/folder/sub/foo.mp4",
54-
},
55-
{
56-
name: "storagePath with leading slash",
57-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "oss-region.aliyuncs.com"},
58-
storagePath: "/foo.mp4",
59-
want: "https://mybucket.oss-region.aliyuncs.com/foo.mp4",
60-
},
61-
{
62-
name: "space in key",
63-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "oss-region.aliyuncs.com"},
64-
storagePath: "folder/my file.mp4",
65-
want: "https://mybucket.oss-region.aliyuncs.com/folder/my%20file.mp4",
66-
},
67-
{
68-
name: "unicode in key",
69-
conf: AliOSSConfig{Bucket: "mybucket", Endpoint: "oss-region.aliyuncs.com"},
70-
storagePath: "café/résumé.mp4",
71-
want: "https://mybucket.oss-region.aliyuncs.com/caf%C3%A9/r%C3%A9sum%C3%A9.mp4",
72-
},
73-
}
74-
for _, tc := range cases {
75-
s := &aliOSSStorage{conf: &tc.conf}
76-
got := s.location(tc.storagePath)
77-
require.Equal(t, tc.want, got, tc.name)
78-
requireWellFormedHTTPLocation(t, got, tc.name)
79-
}
80-
}
81-
8224
func TestAzureLocation(t *testing.T) {
8325
cases := []struct {
8426
name string
@@ -143,178 +85,6 @@ func TestAzureLocation(t *testing.T) {
14385
}
14486
}
14587

146-
func TestGCPLocation(t *testing.T) {
147-
cases := []struct {
148-
name string
149-
conf GCPConfig
150-
storagePath string
151-
want string
152-
}{
153-
{
154-
name: "normal",
155-
conf: GCPConfig{Bucket: "mybucket"},
156-
storagePath: "foo.mp4",
157-
want: "https://mybucket.storage.googleapis.com/foo.mp4",
158-
},
159-
{
160-
name: "nested path",
161-
conf: GCPConfig{Bucket: "mybucket"},
162-
storagePath: "a/b/c.mp4",
163-
want: "https://mybucket.storage.googleapis.com/a/b/c.mp4",
164-
},
165-
{
166-
name: "storagePath with leading slash",
167-
conf: GCPConfig{Bucket: "mybucket"},
168-
storagePath: "/foo.mp4",
169-
want: "https://mybucket.storage.googleapis.com/foo.mp4",
170-
},
171-
{
172-
name: "space in key",
173-
conf: GCPConfig{Bucket: "mybucket"},
174-
storagePath: "folder/my file.mp4",
175-
want: "https://mybucket.storage.googleapis.com/folder/my%20file.mp4",
176-
},
177-
{
178-
name: "unicode in key",
179-
conf: GCPConfig{Bucket: "mybucket"},
180-
storagePath: "café/résumé.mp4",
181-
want: "https://mybucket.storage.googleapis.com/caf%C3%A9/r%C3%A9sum%C3%A9.mp4",
182-
},
183-
}
184-
for _, tc := range cases {
185-
s := &gcpStorage{conf: &tc.conf}
186-
got := s.location(tc.storagePath)
187-
require.Equal(t, tc.want, got, tc.name)
188-
requireWellFormedHTTPLocation(t, got, tc.name)
189-
}
190-
}
191-
192-
func TestS3Location(t *testing.T) {
193-
cases := []struct {
194-
name string
195-
conf S3Config
196-
storagePath string
197-
want string
198-
}{
199-
{
200-
name: "vhost default endpoint",
201-
conf: S3Config{Bucket: "mybucket"},
202-
storagePath: "foo.mp4",
203-
want: "https://mybucket.s3.amazonaws.com/foo.mp4",
204-
},
205-
{
206-
name: "vhost custom endpoint without scheme",
207-
conf: S3Config{Bucket: "mybucket", Endpoint: "s3.example.com"},
208-
storagePath: "foo.mp4",
209-
want: "https://mybucket.s3.example.com/foo.mp4",
210-
},
211-
{
212-
name: "vhost custom endpoint with https://",
213-
conf: S3Config{Bucket: "mybucket", Endpoint: "https://s3.example.com"},
214-
storagePath: "foo.mp4",
215-
want: "https://mybucket.s3.example.com/foo.mp4",
216-
},
217-
{
218-
name: "vhost custom endpoint with http://",
219-
conf: S3Config{Bucket: "mybucket", Endpoint: "http://s3.example.com"},
220-
storagePath: "foo.mp4",
221-
want: "https://mybucket.s3.example.com/foo.mp4",
222-
},
223-
{
224-
name: "vhost nested path",
225-
conf: S3Config{Bucket: "mybucket"},
226-
storagePath: "a/b/c.mp4",
227-
want: "https://mybucket.s3.amazonaws.com/a/b/c.mp4",
228-
},
229-
{
230-
name: "vhost storagePath with leading slash",
231-
conf: S3Config{Bucket: "mybucket"},
232-
storagePath: "/foo.mp4",
233-
want: "https://mybucket.s3.amazonaws.com/foo.mp4",
234-
},
235-
{
236-
name: "vhost space in key",
237-
conf: S3Config{Bucket: "mybucket"},
238-
storagePath: "folder/my file.mp4",
239-
want: "https://mybucket.s3.amazonaws.com/folder/my%20file.mp4",
240-
},
241-
{
242-
name: "vhost unicode in key",
243-
conf: S3Config{Bucket: "mybucket"},
244-
storagePath: "café/résumé.mp4",
245-
want: "https://mybucket.s3.amazonaws.com/caf%C3%A9/r%C3%A9sum%C3%A9.mp4",
246-
},
247-
{
248-
name: "force path style default endpoint",
249-
conf: S3Config{Bucket: "mybucket", ForcePathStyle: true},
250-
storagePath: "foo.mp4",
251-
want: "https://s3.amazonaws.com/mybucket/foo.mp4",
252-
},
253-
{
254-
name: "force path style custom endpoint",
255-
conf: S3Config{Bucket: "mybucket", Endpoint: "https://minio.example.com", ForcePathStyle: true},
256-
storagePath: "foo.mp4",
257-
want: "https://minio.example.com/mybucket/foo.mp4",
258-
},
259-
{
260-
name: "force path style nested",
261-
conf: S3Config{Bucket: "mybucket", ForcePathStyle: true},
262-
storagePath: "a/b/c.mp4",
263-
want: "https://s3.amazonaws.com/mybucket/a/b/c.mp4",
264-
},
265-
{
266-
name: "force path style storagePath with leading slash",
267-
conf: S3Config{Bucket: "mybucket", ForcePathStyle: true},
268-
storagePath: "/foo.mp4",
269-
want: "https://s3.amazonaws.com/mybucket/foo.mp4",
270-
},
271-
}
272-
for _, tc := range cases {
273-
s := &s3Storage{conf: &tc.conf}
274-
got := s.location(tc.storagePath)
275-
require.Equal(t, tc.want, got, tc.name)
276-
requireWellFormedHTTPLocation(t, got, tc.name)
277-
}
278-
}
279-
280-
func TestLocalLocation(t *testing.T) {
281-
cases := []struct {
282-
name string
283-
storageDir string
284-
storagePath string
285-
want string
286-
}{
287-
{
288-
name: "normal",
289-
storageDir: "/var/storage",
290-
storagePath: "foo.mp4",
291-
want: "/var/storage/foo.mp4",
292-
},
293-
{
294-
name: "nested path",
295-
storageDir: "/var/storage",
296-
storagePath: "a/b/c.mp4",
297-
want: "/var/storage/a/b/c.mp4",
298-
},
299-
{
300-
name: "storagePath with leading slash",
301-
storageDir: "/var/storage",
302-
storagePath: "/foo.mp4",
303-
want: "/var/storage/foo.mp4",
304-
},
305-
{
306-
name: "storageDir with trailing slash",
307-
storageDir: "/var/storage/",
308-
storagePath: "foo.mp4",
309-
want: "/var/storage/foo.mp4",
310-
},
311-
}
312-
for _, tc := range cases {
313-
u := &localUploader{StorageDir: tc.storageDir}
314-
require.Equal(t, tc.want, u.location(tc.storagePath))
315-
}
316-
}
317-
31888
// requireWellFormedHTTPLocation verifies an https:// location URL is parseable,
31989
// uses the https scheme, has a non-empty host, and contains no accidental
32090
// double-slashes in its path (the original Azure bug).

s3.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,6 @@ func (s *s3Storage) upload(reader io.Reader, storagePath, contentType string) (s
260260
return "", err
261261
}
262262

263-
return s.location(storagePath), nil
264-
}
265-
266-
func (s *s3Storage) location(storagePath string) string {
267263
endpoint := "s3.amazonaws.com"
268264
if s.conf.Endpoint != "" {
269265
endpoint = s.conf.Endpoint
@@ -279,7 +275,8 @@ func (s *s3Storage) location(storagePath string) string {
279275
loc.Host = s.conf.Bucket + "." + endpoint
280276
loc.Path = storagePath
281277
}
282-
return loc.String()
278+
279+
return loc.String(), nil
283280
}
284281

285282
func (s *s3Storage) ListObjects(prefix string) ([]string, error) {

0 commit comments

Comments
 (0)