Skip to content

Commit 1868116

Browse files
authored
[Bugfix] [Platform] Proper Path handler in StorageV2 (#1793)
1 parent e69ad33 commit 1868116

File tree

6 files changed

+47
-39
lines changed

6 files changed

+47
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
- (Maintenance) Switch License to 2025
4444
- (Feature) Migrate Storage V1 to CE
4545
- (Feature) Improve Helm Chart Manager
46+
- (Bugfix) (Platform) Proper Path handler in StorageV2
4647

4748
## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
4849
- (Feature) ArangoRoute CRD

integrations/storage/v2/definition/helpers.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -83,3 +83,25 @@ func Receive(ctx context.Context, client StorageV2Client, key string, out io.Wri
8383

8484
return bytes, nil
8585
}
86+
87+
func List(ctx context.Context, client StorageV2Client, prefix string) ([]*StorageV2Object, error) {
88+
var r []*StorageV2Object
89+
90+
res, err := client.ListObjects(ctx, &StorageV2ListObjectsRequest{
91+
Path: &StorageV2Path{
92+
Path: prefix,
93+
},
94+
})
95+
if err != nil {
96+
return nil, err
97+
}
98+
99+
if err := ugrpc.Recv[*StorageV2ListObjectsResponse](res, func(response *StorageV2ListObjectsResponse) error {
100+
r = append(r, response.GetFiles()...)
101+
return nil
102+
}); err != nil {
103+
return nil, err
104+
}
105+
106+
return r, nil
107+
}

integrations/storage/v2/shared/s3/io.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -22,7 +22,8 @@ package s3
2222

2323
import (
2424
"context"
25-
"fmt"
25+
"path"
26+
"strings"
2627

2728
"github.com/aws/aws-sdk-go/service/s3"
2829
"github.com/aws/aws-sdk-go/service/s3/s3iface"
@@ -39,8 +40,12 @@ type ios struct {
3940
downloader *s3manager.Downloader
4041
}
4142

42-
func (i *ios) key(key string) string {
43-
return fmt.Sprintf("%s%s", i.config.BucketPrefix, key)
43+
func (i *ios) key(keys ...string) string {
44+
return path.Join(strings.TrimPrefix(i.config.BucketPrefix, "/"), path.Join(keys...))
45+
}
46+
47+
func (i *ios) clean(key string) string {
48+
return strings.TrimPrefix(strings.TrimPrefix(key, i.key()), "/")
4449
}
4550

4651
func (i *ios) Write(ctx context.Context, key string) (pbImplStorageV2Shared.Writer, error) {

integrations/storage/v2/shared/s3/list.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ package s3
2323
import (
2424
"context"
2525
"io"
26-
"strings"
2726
"sync"
2827

2928
"github.com/aws/aws-sdk-go/service/s3"
@@ -86,7 +85,7 @@ func (l *listIterator) Next(ctx context.Context) ([]pbImplStorageV2Shared.File,
8685
info.LastUpdatedAt = util.TypeOrDefault(obj.LastModified)
8786

8887
results = append(results, pbImplStorageV2Shared.File{
89-
Key: strings.TrimPrefix(*obj.Key, l.parent.key(l.key)),
88+
Key: l.parent.clean(*obj.Key),
9089
Info: info,
9190
})
9291

integrations/storage/v2/storage.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -235,9 +235,6 @@ func (i *implementation) ListObjects(req *pbStorageV2.StorageV2ListObjectsReques
235235
log := logger.Str("func", "ReadObject").Str("path", req.GetPath().GetPath())
236236
ctx := server.Context()
237237
path := req.GetPath().GetPath()
238-
if path == "" {
239-
return status.Errorf(codes.InvalidArgument, "path missing")
240-
}
241238

242239
lister, err := i.io.List(ctx, path)
243240
if err != nil {

integrations/storage/v2/storage_test.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2024-2025 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@ import (
2626
"crypto/rand"
2727
"fmt"
2828
"sort"
29-
"strings"
3029
"testing"
3130

3231
"github.com/stretchr/testify/require"
@@ -36,27 +35,8 @@ import (
3635
pbStorageV2 "github.com/arangodb/kube-arangodb/integrations/storage/v2/definition"
3736
"github.com/arangodb/kube-arangodb/pkg/util"
3837
"github.com/arangodb/kube-arangodb/pkg/util/errors"
39-
ugrpc "github.com/arangodb/kube-arangodb/pkg/util/grpc"
4038
)
4139

42-
func listAllFilesHelper(t *testing.T, ctx context.Context, h pbStorageV2.StorageV2Client, prefix string) []*pbStorageV2.StorageV2Object {
43-
var r []*pbStorageV2.StorageV2Object
44-
45-
res, err := h.ListObjects(ctx, &pbStorageV2.StorageV2ListObjectsRequest{
46-
Path: &pbStorageV2.StorageV2Path{
47-
Path: prefix,
48-
},
49-
})
50-
require.NoError(t, err)
51-
52-
require.NoError(t, ugrpc.Recv[*pbStorageV2.StorageV2ListObjectsResponse](res, func(response *pbStorageV2.StorageV2ListObjectsResponse) error {
53-
r = append(r, response.GetFiles()...)
54-
return nil
55-
}))
56-
57-
return r
58-
}
59-
6040
func Test_List(t *testing.T) {
6141
ctx, c := context.WithCancel(context.Background())
6242
defer c()
@@ -163,27 +143,30 @@ func testFileListing(t *testing.T, ctx context.Context, h pbStorageV2.StorageV2C
163143
})
164144

165145
t.Run("List", func(t *testing.T) {
166-
revcFiles := listAllFilesHelper(t, ctx, h, prefix)
146+
revcFiles, err := pbStorageV2.List(ctx, h, prefix)
147+
require.NoError(t, err)
167148

168149
require.Len(t, revcFiles, len(files))
169150

170151
for id := range files {
171-
require.EqualValues(t, strings.TrimPrefix(files[id], prefix), revcFiles[id].GetPath().GetPath())
152+
require.EqualValues(t, files[id], revcFiles[id].GetPath().GetPath())
172153
require.EqualValues(t, revcFiles[id].GetInfo().GetSize(), len(data))
173154
}
174155
})
175156

176157
t.Run("ListSubFolder", func(t *testing.T) {
177-
revcFiles := listAllFilesHelper(t, ctx, h, fmt.Sprintf("%spath0000/", prefix))
158+
revcFiles, err := pbStorageV2.List(ctx, h, fmt.Sprintf("%spath0000/", prefix))
159+
require.NoError(t, err)
178160

179161
require.Len(t, revcFiles, 1)
180162

181-
require.EqualValues(t, "file", revcFiles[0].GetPath().GetPath())
163+
require.EqualValues(t, fmt.Sprintf("%spath0000/file", prefix), revcFiles[0].GetPath().GetPath())
182164
require.EqualValues(t, len(data), revcFiles[0].GetInfo().GetSize())
183165
})
184166

185167
t.Run("ListMisSubFolder", func(t *testing.T) {
186-
revcFiles := listAllFilesHelper(t, ctx, h, fmt.Sprintf("%snon-existent/", prefix))
168+
revcFiles, err := pbStorageV2.List(ctx, h, fmt.Sprintf("%snon-existent/", prefix))
169+
require.NoError(t, err)
187170

188171
require.Len(t, revcFiles, 0)
189172
})
@@ -281,7 +264,8 @@ func testS3BucketFileHandling(t *testing.T, ctx context.Context, h pbStorageV2.S
281264
})
282265

283266
t.Run("List Objects", func(t *testing.T) {
284-
revcFiles := listAllFilesHelper(t, ctx, h, prefix)
267+
revcFiles, err := pbStorageV2.List(ctx, h, "/")
268+
require.NoError(t, err)
285269

286270
t.Logf("Size: %d", len(revcFiles))
287271
})

0 commit comments

Comments
 (0)