forked from TrueCloudLab/frostfs-s3-gw
Compare commits
4 commits
master
...
test-27704
Author | SHA1 | Date | |
---|---|---|---|
f72d9ecf2a | |||
6c68e21777 | |||
a025f2e9c5 | |||
bd3164c57f |
34 changed files with 1353 additions and 792 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -28,4 +28,3 @@ debian/files
|
|||
debian/*.log
|
||||
debian/*.substvars
|
||||
debian/frostfs-s3-gw/
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/resolver"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/service/tree"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||
|
@ -88,7 +89,7 @@ func prepareHandlerContext(t *testing.T) *handlerContext {
|
|||
Caches: layer.DefaultCachesConfigs(zap.NewExample()),
|
||||
AnonKey: layer.AnonymousKey{Key: key},
|
||||
Resolver: testResolver,
|
||||
TreeService: layer.NewTreeService(),
|
||||
TreeService: NewTreeServiceMock(t),
|
||||
}
|
||||
|
||||
var pp netmap.PlacementPolicy
|
||||
|
@ -113,6 +114,12 @@ func prepareHandlerContext(t *testing.T) *handlerContext {
|
|||
}
|
||||
}
|
||||
|
||||
func NewTreeServiceMock(t *testing.T) *tree.Tree {
|
||||
memCli, err := tree.NewTreeServiceClientMemory()
|
||||
require.NoError(t, err)
|
||||
return tree.NewTree(memCli)
|
||||
}
|
||||
|
||||
func createTestBucket(hc *handlerContext, bktName string) *data.BucketInfo {
|
||||
_, err := hc.MockedPool().CreateContainer(hc.Context(), layer.PrmContainerCreate{
|
||||
Creator: hc.owner,
|
||||
|
|
|
@ -753,12 +753,3 @@ func periodicXMLWriter(w io.Writer, dur time.Duration) (stop func() bool) {
|
|||
|
||||
return stop
|
||||
}
|
||||
|
||||
// periodicWriterErrorSender returns handler function to send error. If header is
|
||||
// alreay written by periodic XML writer, do not send HTTP and XML headers.
|
||||
func (h *handler) periodicWriterErrorSender(headerWritten bool) func(http.ResponseWriter, string, *api.ReqInfo, error, ...zap.Field) {
|
||||
if headerWritten {
|
||||
return h.logAndSendErrorNoHeader
|
||||
}
|
||||
return h.logAndSendError
|
||||
}
|
||||
|
|
|
@ -25,12 +25,15 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/wallet"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/xml"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/metrics"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/service/tree"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -110,10 +113,12 @@ func (a *App) initLayer(ctx context.Context) {
|
|||
a.initResolver()
|
||||
|
||||
treeServiceEndpoint := a.cfg.GetString(cfgTreeServiceEndpoint)
|
||||
treeService, err := frostfs.NewTreeClient(ctx, treeServiceEndpoint, a.key)
|
||||
grpcDialOpt := grpc.WithTransportCredentials(insecure.NewCredentials())
|
||||
treeGRPCClient, err := tree.NewTreeServiceClientGRPC(ctx, treeServiceEndpoint, a.key, grpcDialOpt)
|
||||
if err != nil {
|
||||
a.log.Fatal("failed to create tree service", zap.Error(err))
|
||||
}
|
||||
treeService := tree.NewTree(treeGRPCClient)
|
||||
a.log.Info("init tree service", zap.String("endpoint", treeServiceEndpoint))
|
||||
|
||||
// prepare random key for anonymous requests
|
||||
|
|
|
@ -27,4 +27,3 @@ message Tokens {
|
|||
bytes bearerToken = 2 [json_name = "bearerToken"];
|
||||
repeated bytes sessionTokens = 3 [json_name = "sessionTokens"];
|
||||
}
|
||||
|
||||
|
|
2
debian/frostfs-s3-gw.install
vendored
2
debian/frostfs-s3-gw.install
vendored
|
@ -1,4 +1,4 @@
|
|||
config/config.yaml etc/frostfs/s3
|
||||
config/config.yml etc/frostfs/s3
|
||||
config/rules.json var/lib/frostfs/s3
|
||||
bin/frostfs-s3-gw usr/bin
|
||||
bin/frostfs-s3-authmate usr/bin
|
||||
|
|
10
debian/frostfs-s3-gw.postinst
vendored
Normal file → Executable file
10
debian/frostfs-s3-gw.postinst
vendored
Normal file → Executable file
|
@ -24,14 +24,14 @@ case "$1" in
|
|||
id -u frostfs-$USERNAME >/dev/null 2>&1 || useradd -s /usr/sbin/nologin -d /var/lib/frostfs/s3 --system -M -U -c "FrostFS S3 gateway" frostfs-$USERNAME
|
||||
if ! dpkg-statoverride --list /etc/frostfs/$USERNAME >/dev/null; then
|
||||
chown -f -R root:frostfs-$USERNAME /etc/frostfs/$USERNAME
|
||||
chown -f root:frostfs-$USERNAME /etc/frostfs/$USERNAME/config.yaml || true
|
||||
chown -f root:frostfs-$USERNAME /etc/frostfs/$USERNAME/config.yml || true
|
||||
chmod -f 0750 /etc/frostfs/$USERNAME
|
||||
chmod -f 0640 /etc/frostfs/$USERNAME/config.yaml || true
|
||||
chmod -f 0640 /etc/frostfs/$USERNAME/config.yml || true
|
||||
fi
|
||||
USERDIR=$(getent passwd "frostfs-$USERNAME" | cut -d: -f6)
|
||||
if ! dpkg-statoverride --list frostfs-$USERDIR >/dev/null; then
|
||||
chown -f frostfs-$USERNAME: $USERDIR
|
||||
chown -f frostfs-$USERNAME: $USERDIR/rules.json
|
||||
if ! dpkg-statoverride --list frostfs-"$USERDIR" >/dev/null; then
|
||||
chown -f frostfs-$USERNAME: "$USERDIR"
|
||||
chown -f frostfs-$USERNAME: "$USERDIR"/rules.json
|
||||
fi
|
||||
;;
|
||||
|
||||
|
|
0
debian/frostfs-s3-gw.postrm
vendored
Normal file → Executable file
0
debian/frostfs-s3-gw.postrm
vendored
Normal file → Executable file
0
debian/frostfs-s3-gw.preinst
vendored
Normal file → Executable file
0
debian/frostfs-s3-gw.preinst
vendored
Normal file → Executable file
0
debian/frostfs-s3-gw.prerm
vendored
Normal file → Executable file
0
debian/frostfs-s3-gw.prerm
vendored
Normal file → Executable file
2
debian/frostfs-s3-gw.service
vendored
2
debian/frostfs-s3-gw.service
vendored
|
@ -4,7 +4,7 @@ Requires=network.target
|
|||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/frostfs-s3-gw --config /etc/frostfs/s3/config.yaml
|
||||
ExecStart=/usr/bin/frostfs-s3-gw --config /etc/frostfs/s3/config.yml
|
||||
User=frostfs-s3
|
||||
Group=frostfs-s3
|
||||
WorkingDirectory=/var/lib/frostfs/s3
|
||||
|
|
2
debian/rules
vendored
2
debian/rules
vendored
|
@ -12,5 +12,3 @@ override_dh_installsystemd:
|
|||
|
||||
override_dh_installchangelogs:
|
||||
dh_installchangelogs -k CHANGELOG.md
|
||||
|
||||
|
||||
|
|
|
@ -101,13 +101,13 @@ Pprof and Prometheus are integrated into the gateway. To enable them, use `--ppr
|
|||
|
||||
## YAML file and environment variables
|
||||
|
||||
Example of a YAML configuration file: [yaml-example](/config/config.yaml)
|
||||
Example of a YAML configuration file: [yaml-example](/config/config.yml)
|
||||
Examples of environment variables: [env-example](/config/config.env).
|
||||
|
||||
A path to a configuration file can be specified with `--config` parameter:
|
||||
|
||||
```shell
|
||||
$ frostfs-s3-gw --config your-config.yaml
|
||||
$ frostfs-s3-gw --config your-config.yml
|
||||
```
|
||||
|
||||
### Multiple configs
|
||||
|
@ -118,13 +118,13 @@ You can either provide several files with repeating `--config` flag or provide p
|
|||
Also, you can combine these flags:
|
||||
|
||||
```shell
|
||||
$ frostfs-s3-gw --config ./config/config.yaml --config /your/partial/config.yaml --config-dir ./config/dir
|
||||
$ frostfs-s3-gw --config ./config/config.yml --config /your/partial/config.yml --config-dir ./config/dir
|
||||
```
|
||||
|
||||
**Note:** next file in `--config` flag overwrites values from the previous one.
|
||||
Files from `--config-dir` directory overwrite values from `--config` files.
|
||||
So the command above run `frostfs-s3-gw` to listen on `0.0.0.0:8080` address (value from `./config/config.yaml`),
|
||||
applies parameters from `/your/partial/config.yaml`,
|
||||
So the command above run `frostfs-s3-gw` to listen on `0.0.0.0:8080` address (value from `./config/config.yml`),
|
||||
applies parameters from `/your/partial/config.yml`,
|
||||
enable pprof (value from `./config/dir/pprof.yaml`) and prometheus (value from `./config/dir/prometheus.yaml`).
|
||||
|
||||
### Reload on SIGHUP
|
||||
|
@ -141,7 +141,7 @@ $ kill -s SIGHUP <app_pid>
|
|||
Example:
|
||||
|
||||
```shell
|
||||
$ ./bin/frostfs-s3-gw --config config.yaml &> s3.log &
|
||||
$ ./bin/frostfs-s3-gw --config config.yml &> s3.log &
|
||||
[1] 998346
|
||||
|
||||
$ cat s3.log
|
||||
|
|
|
@ -78,7 +78,7 @@ Compatibility: 30/25/29 out of 33
|
|||
Compatibility: 33/43/37 out of 64
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|------------------------------------------------------------------------------------------------|-------------|-------|--------|
|
||||
|-----|------------------------------------------------------------------------------------------------|-------------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_put_object_ifmatch_good | ok | ok | ERROR |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_put_object_ifmatch_failed | FAIL | FAIL | FAIL |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_put_object_ifmatch_overwrite_existed_good | ok | ok | ERROR |
|
||||
|
@ -343,7 +343,7 @@ Compatibility: 4/5/29 out of 29
|
|||
Compatibility: 19/15/19 out of 22
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|----------------------------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|----------------------------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_multipart_upload_empty | ok | FAIL | FAIL |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_multipart_upload_small | ERROR | ERROR | ok |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_multipart_copy_small | ok | ok | ok |
|
||||
|
@ -374,7 +374,7 @@ Comments: in [PR](https://github.com/nspcc-dev/s3-tests/pull/5)
|
|||
Compatibility: 9/6/8 out of 11
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_set_bucket_tagging | FAIL | FAIL | FAIL |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_get_obj_tagging | ok | ok | ok |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_get_obj_head_tagging | ok | ok | ok |
|
||||
|
@ -392,7 +392,7 @@ Compatibility: 9/6/8 out of 11
|
|||
Compatibility: 23/19/24 out of 26
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|---------------------------------------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|---------------------------------------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_versioning_bucket_create_suspend | ok | ok | ok |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_versioning_obj_create_read_remove | ok | ok | ok |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_versioning_obj_create_read_remove_head | ok | ok | ok |
|
||||
|
@ -425,7 +425,7 @@ Compatibility: 23/19/24 out of 26
|
|||
Compatibility: 38/38/45 out of 59
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|----------------------------------------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|----------------------------------------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_headers.test_bucket_create_bad_authorization_invalid_aws2 | FAIL | FAIL | FAIL |
|
||||
| 2 | s3tests_boto3.functional.test_headers.test_bucket_create_bad_ua_empty_aws2 | ERROR | ok | ok |
|
||||
| 3 | s3tests_boto3.functional.test_headers.test_bucket_create_bad_ua_none_aws2 | ERROR | ok | ok |
|
||||
|
@ -582,7 +582,7 @@ Compatibility: 0/10/18 out of 29
|
|||
This group is not explicitly supported by s3-gw, but some tests may pass.
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|---------------------------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|---------------------------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_lifecycle_set | ERROR | ok | ok |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_lifecycle_get | ERROR | FAIL | ok |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_lifecycle_get_no_id | ERROR | ERROR | ok |
|
||||
|
@ -619,7 +619,7 @@ Compatibility: 0/7/20 out of 35
|
|||
This group is not explicitly supported by s3-gw, but some tests may pass.
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|----|-------------------------------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|-------------------------------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_bucket_policy | ERROR | ok | ok |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_bucketv2_policy | ERROR | ok | ok |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_bucket_policy_acl | ERROR | ERROR | ok |
|
||||
|
@ -661,7 +661,7 @@ This group is not explicitly supported by s3-gw, but some tests may pass.
|
|||
Compatibility: 2/2/3 out of 6
|
||||
|
||||
| | Test | s3-gw | minio | aws s3 |
|
||||
|---|-------------------------------------------------------------|-------|-------|--------|
|
||||
|-----|-------------------------------------------------------------|-------|-------|--------|
|
||||
| 1 | s3tests_boto3.functional.test_s3.test_100_continue | FAIL | ERROR | ok |
|
||||
| 2 | s3tests_boto3.functional.test_s3.test_account_usage | ERROR | ERROR | ERROR |
|
||||
| 3 | s3tests_boto3.functional.test_s3.test_head_bucket_usage | ERROR | ERROR | ERROR |
|
||||
|
|
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.18
|
|||
require (
|
||||
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.11.2-0.20230315095236-9dc375346703
|
||||
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230316081442-bec77f280a85
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230329125804-552219b8e130
|
||||
github.com/aws/aws-sdk-go v1.44.6
|
||||
github.com/bluele/gcache v0.0.2
|
||||
github.com/google/uuid v1.3.0
|
||||
|
|
4
go.sum
4
go.sum
|
@ -42,8 +42,8 @@ git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02f
|
|||
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb/go.mod h1:nkR5gaGeez3Zv2SE7aceP0YwxG2FzIB5cGKpQO2vV2o=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSVCB8JNSfPG7Uk4r2oSk=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0/go.mod h1:RUIKZATQLJ+TaYQa60X2fTDwfuhMfm8Ar60bQ5fr+vU=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230316081442-bec77f280a85 h1:TUcJ5A0C1gWi3bAhw4b+V+iVM3E9mbBOdJIWWkAPNxo=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230316081442-bec77f280a85/go.mod h1:23fUGlEv/ImaOi3vck6vZj0v0b4hteOhLLPnVWHSQeA=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230329125804-552219b8e130 h1:V+3dGwEXwEvvSvseMKn8S6ZEMNhxBBYrcyx+F7VaptM=
|
||||
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230329125804-552219b8e130/go.mod h1:23fUGlEv/ImaOi3vck6vZj0v0b4hteOhLLPnVWHSQeA=
|
||||
git.frostfs.info/TrueCloudLab/hrw v1.2.0 h1:KvAES7xIqmQBGd2q8KanNosD9+4BhU/zqD5Kt5KSflk=
|
||||
git.frostfs.info/TrueCloudLab/hrw v1.2.0/go.mod h1:mq2sbvYfO+BB6iFZwYBkgC0yc6mJNx+qZi4jW918m+Y=
|
||||
git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 h1:M2KR3iBj7WpY3hP10IevfIB9MURr4O9mwVfJ+SjT3HA=
|
||||
|
|
File diff suppressed because it is too large
Load diff
311
pkg/service/tree/tree_client_grpc.go
Normal file
311
pkg/service/tree/tree_client_grpc.go
Normal file
|
@ -0,0 +1,311 @@
|
|||
package tree
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/frostfs/services/tree"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type GetNodeByPathResponseInfoWrapper struct {
|
||||
response *tree.GetNodeByPathResponse_Info
|
||||
}
|
||||
|
||||
func (n GetNodeByPathResponseInfoWrapper) GetNodeID() uint64 {
|
||||
return n.response.GetNodeId()
|
||||
}
|
||||
|
||||
func (n GetNodeByPathResponseInfoWrapper) GetParentID() uint64 {
|
||||
return n.response.GetParentId()
|
||||
}
|
||||
|
||||
func (n GetNodeByPathResponseInfoWrapper) GetTimestamp() uint64 {
|
||||
return n.response.GetTimestamp()
|
||||
}
|
||||
|
||||
func (n GetNodeByPathResponseInfoWrapper) GetMeta() []Meta {
|
||||
res := make([]Meta, len(n.response.Meta))
|
||||
for i, value := range n.response.Meta {
|
||||
res[i] = value
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
type GetSubTreeResponseBodyWrapper struct {
|
||||
response *tree.GetSubTreeResponse_Body
|
||||
}
|
||||
|
||||
func (n GetSubTreeResponseBodyWrapper) GetNodeID() uint64 {
|
||||
return n.response.GetNodeId()
|
||||
}
|
||||
|
||||
func (n GetSubTreeResponseBodyWrapper) GetParentID() uint64 {
|
||||
return n.response.GetParentId()
|
||||
}
|
||||
|
||||
func (n GetSubTreeResponseBodyWrapper) GetTimestamp() uint64 {
|
||||
return n.response.GetTimestamp()
|
||||
}
|
||||
|
||||
func (n GetSubTreeResponseBodyWrapper) GetMeta() []Meta {
|
||||
res := make([]Meta, len(n.response.Meta))
|
||||
for i, value := range n.response.Meta {
|
||||
res[i] = value
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
type ServiceClientGRPC struct {
|
||||
key *keys.PrivateKey
|
||||
conn *grpc.ClientConn
|
||||
service tree.TreeServiceClient
|
||||
}
|
||||
|
||||
func NewTreeServiceClientGRPC(ctx context.Context, addr string, key *keys.PrivateKey, grpcOpts ...grpc.DialOption) (*ServiceClientGRPC, error) {
|
||||
conn, err := grpc.Dial(addr, grpcOpts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("did not connect: %v", err)
|
||||
}
|
||||
|
||||
c := tree.NewTreeServiceClient(conn)
|
||||
if _, err = c.Healthcheck(ctx, &tree.HealthcheckRequest{}); err != nil {
|
||||
return nil, fmt.Errorf("healthcheck: %w", err)
|
||||
}
|
||||
|
||||
return &ServiceClientGRPC{
|
||||
key: key,
|
||||
conn: conn,
|
||||
service: c,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientGRPC) GetNodes(ctx context.Context, p *GetNodesParams) ([]NodeResponse, error) {
|
||||
request := &tree.GetNodeByPathRequest{
|
||||
Body: &tree.GetNodeByPathRequest_Body{
|
||||
ContainerId: p.BktInfo.CID[:],
|
||||
TreeId: p.TreeID,
|
||||
Path: p.Path,
|
||||
Attributes: p.Meta,
|
||||
PathAttribute: FileNameKey,
|
||||
LatestOnly: p.LatestOnly,
|
||||
AllAttributes: p.AllAttrs,
|
||||
BearerToken: getBearer(ctx, p.BktInfo),
|
||||
},
|
||||
}
|
||||
|
||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||
request.Signature = &tree.Signature{
|
||||
Key: key,
|
||||
Sign: sign,
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.service.GetNodeByPath(ctx, request)
|
||||
if err != nil {
|
||||
return nil, handleError("failed to get node by path", err)
|
||||
}
|
||||
|
||||
res := make([]NodeResponse, len(resp.GetBody().GetNodes()))
|
||||
for i, info := range resp.GetBody().GetNodes() {
|
||||
res[i] = GetNodeByPathResponseInfoWrapper{info}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientGRPC) GetSubTree(ctx context.Context, bktInfo *data.BucketInfo, treeID string, rootID uint64, depth uint32) ([]NodeResponse, error) {
|
||||
request := &tree.GetSubTreeRequest{
|
||||
Body: &tree.GetSubTreeRequest_Body{
|
||||
ContainerId: bktInfo.CID[:],
|
||||
TreeId: treeID,
|
||||
RootId: rootID,
|
||||
Depth: depth,
|
||||
BearerToken: getBearer(ctx, bktInfo),
|
||||
},
|
||||
}
|
||||
|
||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||
request.Signature = &tree.Signature{
|
||||
Key: key,
|
||||
Sign: sign,
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cli, err := c.service.GetSubTree(ctx, request)
|
||||
if err != nil {
|
||||
return nil, handleError("failed to get sub tree client", err)
|
||||
}
|
||||
|
||||
var subtree []NodeResponse
|
||||
for {
|
||||
resp, err := cli.Recv()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
return nil, handleError("failed to get sub tree", err)
|
||||
}
|
||||
subtree = append(subtree, GetSubTreeResponseBodyWrapper{resp.Body})
|
||||
}
|
||||
|
||||
return subtree, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientGRPC) AddNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, parent uint64, meta map[string]string) (uint64, error) {
|
||||
request := &tree.AddRequest{
|
||||
Body: &tree.AddRequest_Body{
|
||||
ContainerId: bktInfo.CID[:],
|
||||
TreeId: treeID,
|
||||
ParentId: parent,
|
||||
Meta: metaToKV(meta),
|
||||
BearerToken: getBearer(ctx, bktInfo),
|
||||
},
|
||||
}
|
||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||
request.Signature = &tree.Signature{
|
||||
Key: key,
|
||||
Sign: sign,
|
||||
}
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp, err := c.service.Add(ctx, request)
|
||||
if err != nil {
|
||||
return 0, handleError("failed to add node", err)
|
||||
}
|
||||
|
||||
return resp.GetBody().GetNodeId(), nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientGRPC) AddNodeByPath(ctx context.Context, bktInfo *data.BucketInfo, treeID string, path []string, meta map[string]string) (uint64, error) {
|
||||
request := &tree.AddByPathRequest{
|
||||
Body: &tree.AddByPathRequest_Body{
|
||||
ContainerId: bktInfo.CID[:],
|
||||
TreeId: treeID,
|
||||
Path: path,
|
||||
Meta: metaToKV(meta),
|
||||
PathAttribute: FileNameKey,
|
||||
BearerToken: getBearer(ctx, bktInfo),
|
||||
},
|
||||
}
|
||||
|
||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||
request.Signature = &tree.Signature{
|
||||
Key: key,
|
||||
Sign: sign,
|
||||
}
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp, err := c.service.AddByPath(ctx, request)
|
||||
if err != nil {
|
||||
return 0, handleError("failed to add node by path", err)
|
||||
}
|
||||
|
||||
body := resp.GetBody()
|
||||
if body == nil {
|
||||
return 0, errors.New("nil body in tree service response")
|
||||
} else if len(body.Nodes) == 0 {
|
||||
return 0, errors.New("empty list of added nodes in tree service response")
|
||||
}
|
||||
|
||||
// The first node is the leaf that we add, according to tree service docs.
|
||||
return body.Nodes[0], nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientGRPC) MoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID, parentID uint64, meta map[string]string) error {
|
||||
request := &tree.MoveRequest{
|
||||
Body: &tree.MoveRequest_Body{
|
||||
ContainerId: bktInfo.CID[:],
|
||||
TreeId: treeID,
|
||||
NodeId: nodeID,
|
||||
ParentId: parentID,
|
||||
Meta: metaToKV(meta),
|
||||
BearerToken: getBearer(ctx, bktInfo),
|
||||
},
|
||||
}
|
||||
|
||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||
request.Signature = &tree.Signature{
|
||||
Key: key,
|
||||
Sign: sign,
|
||||
}
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := c.service.Move(ctx, request); err != nil {
|
||||
return handleError("failed to move node", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientGRPC) RemoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID uint64) error {
|
||||
request := &tree.RemoveRequest{
|
||||
Body: &tree.RemoveRequest_Body{
|
||||
ContainerId: bktInfo.CID[:],
|
||||
TreeId: treeID,
|
||||
NodeId: nodeID,
|
||||
BearerToken: getBearer(ctx, bktInfo),
|
||||
},
|
||||
}
|
||||
if err := c.signRequest(request.Body, func(key, sign []byte) {
|
||||
request.Signature = &tree.Signature{
|
||||
Key: key,
|
||||
Sign: sign,
|
||||
}
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := c.service.Remove(ctx, request); err != nil {
|
||||
return handleError("failed to remove node", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func metaToKV(meta map[string]string) []*tree.KeyValue {
|
||||
result := make([]*tree.KeyValue, 0, len(meta))
|
||||
|
||||
for key, value := range meta {
|
||||
result = append(result, &tree.KeyValue{Key: key, Value: []byte(value)})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func getBearer(ctx context.Context, bktInfo *data.BucketInfo) []byte {
|
||||
if bd, ok := ctx.Value(api.BoxData).(*accessbox.Box); ok && bd != nil && bd.Gate != nil {
|
||||
if bd.Gate.BearerToken != nil {
|
||||
if bktInfo.Owner.Equals(bearer.ResolveIssuer(*bd.Gate.BearerToken)) {
|
||||
return bd.Gate.BearerToken.Marshal()
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleError(msg string, err error) error {
|
||||
if strings.Contains(err.Error(), "not found") {
|
||||
return fmt.Errorf("%w: %s", ErrNodeNotFound, err.Error())
|
||||
} else if strings.Contains(err.Error(), "is denied by") {
|
||||
return fmt.Errorf("%w: %s", ErrNodeAccessDenied, err.Error())
|
||||
}
|
||||
return fmt.Errorf("%s: %w", msg, err)
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/*REMOVE THIS AFTER SIGNATURE WILL BE AVAILABLE IN TREE CLIENT FROM FROSTFS NODE*/
|
||||
package frostfs
|
||||
package tree
|
||||
|
||||
import (
|
||||
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *TreeClient) signData(buf []byte, f func(key, sign []byte)) error {
|
||||
func (c *ServiceClientGRPC) signData(buf []byte, f func(key, sign []byte)) error {
|
||||
// crypto package should not be used outside of API libraries (see neofs-node#491).
|
||||
// For now tree service does not include into SDK Client nor SDK Pool, so there is no choice.
|
||||
// When SDK library adopts Tree service client, this should be dropped.
|
||||
|
@ -19,7 +19,7 @@ func (c *TreeClient) signData(buf []byte, f func(key, sign []byte)) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *TreeClient) signRequest(requestBody proto.Message, f func(key, sign []byte)) error {
|
||||
func (c *ServiceClientGRPC) signRequest(requestBody proto.Message, f func(key, sign []byte)) error {
|
||||
buf, err := proto.Marshal(requestBody)
|
||||
if err != nil {
|
||||
return err
|
35
pkg/service/tree/tree_client_grpc_test.go
Normal file
35
pkg/service/tree/tree_client_grpc_test.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package tree
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHandleError(t *testing.T) {
|
||||
defaultError := errors.New("default error")
|
||||
for _, tc := range []struct {
|
||||
err error
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
err: defaultError,
|
||||
expectedError: defaultError,
|
||||
},
|
||||
{
|
||||
err: errors.New("something not found"),
|
||||
expectedError: layer.ErrNodeNotFound,
|
||||
},
|
||||
{
|
||||
err: errors.New("something is denied by some acl rule"),
|
||||
expectedError: layer.ErrNodeAccessDenied,
|
||||
},
|
||||
} {
|
||||
t.Run("", func(t *testing.T) {
|
||||
err := handleError("err message", tc.err)
|
||||
require.True(t, errors.Is(err, tc.expectedError))
|
||||
})
|
||||
}
|
||||
}
|
393
pkg/service/tree/tree_client_in_memory.go
Normal file
393
pkg/service/tree/tree_client_in_memory.go
Normal file
|
@ -0,0 +1,393 @@
|
|||
package tree
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
||||
)
|
||||
|
||||
type nodeMeta struct {
|
||||
key string
|
||||
value []byte
|
||||
}
|
||||
|
||||
func (m nodeMeta) GetKey() string {
|
||||
return m.key
|
||||
}
|
||||
|
||||
func (m nodeMeta) GetValue() []byte {
|
||||
return m.value
|
||||
}
|
||||
|
||||
type nodeResponse struct {
|
||||
meta []nodeMeta
|
||||
nodeID uint64
|
||||
parentID uint64
|
||||
timestamp uint64
|
||||
}
|
||||
|
||||
func (n nodeResponse) GetNodeID() uint64 {
|
||||
return n.nodeID
|
||||
}
|
||||
|
||||
func (n nodeResponse) GetParentID() uint64 {
|
||||
return n.parentID
|
||||
}
|
||||
|
||||
func (n nodeResponse) GetTimestamp() uint64 {
|
||||
return n.timestamp
|
||||
}
|
||||
|
||||
func (n nodeResponse) GetMeta() []Meta {
|
||||
res := make([]Meta, len(n.meta))
|
||||
for i, value := range n.meta {
|
||||
res[i] = value
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (n nodeResponse) getValue(key string) string {
|
||||
for _, value := range n.meta {
|
||||
if value.key == key {
|
||||
return string(value.value)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ServiceClientMemory struct {
|
||||
containers map[string]containerInfo
|
||||
}
|
||||
|
||||
type containerInfo struct {
|
||||
bkt *data.BucketInfo
|
||||
trees map[string]memoryTree
|
||||
}
|
||||
|
||||
type memoryTree struct {
|
||||
idCounter uint64
|
||||
treeData *treeNodeMemory
|
||||
}
|
||||
|
||||
type treeNodeMemory struct {
|
||||
data nodeResponse
|
||||
parent *treeNodeMemory
|
||||
children []*treeNodeMemory
|
||||
}
|
||||
|
||||
func (t *treeNodeMemory) getNode(nodeID uint64) *treeNodeMemory {
|
||||
if t.data.nodeID == nodeID {
|
||||
return t
|
||||
}
|
||||
|
||||
for _, child := range t.children {
|
||||
if node := child.getNode(nodeID); node != nil {
|
||||
return node
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *memoryTree) getNodesByPath(path []string) []nodeResponse {
|
||||
if len(path) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var res []nodeResponse
|
||||
for _, child := range t.treeData.children {
|
||||
res = child.listNodesByPath(res, path)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func (t *treeNodeMemory) listNodesByPath(res []nodeResponse, path []string) []nodeResponse {
|
||||
if len(path) == 0 || t.data.getValue(FileNameKey) != path[0] {
|
||||
return res
|
||||
}
|
||||
|
||||
if len(path) == 1 {
|
||||
return append(res, t.data)
|
||||
}
|
||||
|
||||
for _, ch := range t.children {
|
||||
res = ch.listNodesByPath(res, path[1:])
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func (t *memoryTree) createPathIfNotExist(parent *treeNodeMemory, path []string) *treeNodeMemory {
|
||||
if len(path) == 0 {
|
||||
return parent
|
||||
}
|
||||
|
||||
var node *treeNodeMemory
|
||||
for _, child := range parent.children {
|
||||
if len(child.data.meta) == 1 && child.data.getValue(FileNameKey) == path[0] {
|
||||
node = child
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if node == nil {
|
||||
node = &treeNodeMemory{
|
||||
data: nodeResponse{
|
||||
meta: []nodeMeta{{key: FileNameKey, value: []byte(path[0])}},
|
||||
nodeID: t.idCounter,
|
||||
parentID: parent.data.nodeID,
|
||||
timestamp: uint64(time.Now().UnixMicro()),
|
||||
},
|
||||
parent: parent,
|
||||
}
|
||||
t.idCounter++
|
||||
parent.children = append(parent.children, node)
|
||||
}
|
||||
|
||||
return t.createPathIfNotExist(node, path[1:])
|
||||
}
|
||||
|
||||
func (t *treeNodeMemory) removeChild(nodeID uint64) {
|
||||
ind := -1
|
||||
for i, ch := range t.children {
|
||||
if ch.data.nodeID == nodeID {
|
||||
ind = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if ind != -1 {
|
||||
t.children = append(t.children[:ind], t.children[ind+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *treeNodeMemory) listNodes(res []NodeResponse, depth uint32) []NodeResponse {
|
||||
res = append(res, t.data)
|
||||
|
||||
if depth == 0 {
|
||||
return res
|
||||
}
|
||||
|
||||
for _, ch := range t.children {
|
||||
res = ch.listNodes(res, depth-1)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func NewTreeServiceClientMemory() (*ServiceClientMemory, error) {
|
||||
return &ServiceClientMemory{
|
||||
containers: make(map[string]containerInfo),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientMemory) GetNodes(ctx context.Context, p *GetNodesParams) ([]NodeResponse, error) {
|
||||
cnr, ok := c.containers[p.BktInfo.CID.EncodeToString()]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
tr, ok := cnr.trees[p.TreeID]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
res := tr.getNodesByPath(p.Path)
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i].timestamp < res[j].timestamp
|
||||
})
|
||||
|
||||
if p.LatestOnly && len(res) != 0 {
|
||||
res = res[len(res)-1:]
|
||||
}
|
||||
|
||||
res2 := make([]NodeResponse, len(res))
|
||||
for i, n := range res {
|
||||
res2[i] = n
|
||||
}
|
||||
|
||||
return res2, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientMemory) GetSubTree(ctx context.Context, bktInfo *data.BucketInfo, treeID string, rootID uint64, depth uint32) ([]NodeResponse, error) {
|
||||
cnr, ok := c.containers[bktInfo.CID.EncodeToString()]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
tr, ok := cnr.trees[treeID]
|
||||
if !ok {
|
||||
return nil, ErrNodeNotFound
|
||||
}
|
||||
|
||||
node := tr.treeData.getNode(rootID)
|
||||
if node == nil {
|
||||
return nil, ErrNodeNotFound
|
||||
}
|
||||
|
||||
return node.listNodes(nil, depth-1), nil
|
||||
}
|
||||
|
||||
func newContainerInfo(bktInfo *data.BucketInfo, treeID string) containerInfo {
|
||||
return containerInfo{
|
||||
bkt: bktInfo,
|
||||
trees: map[string]memoryTree{
|
||||
treeID: {
|
||||
idCounter: 1,
|
||||
treeData: &treeNodeMemory{
|
||||
data: nodeResponse{
|
||||
timestamp: uint64(time.Now().UnixMicro()),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newMemoryTree() memoryTree {
|
||||
return memoryTree{
|
||||
idCounter: 1,
|
||||
treeData: &treeNodeMemory{
|
||||
data: nodeResponse{
|
||||
timestamp: uint64(time.Now().UnixMicro()),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ServiceClientMemory) AddNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, parent uint64, meta map[string]string) (uint64, error) {
|
||||
cnr, ok := c.containers[bktInfo.CID.EncodeToString()]
|
||||
if !ok {
|
||||
cnr = newContainerInfo(bktInfo, treeID)
|
||||
c.containers[bktInfo.CID.EncodeToString()] = cnr
|
||||
}
|
||||
|
||||
tr, ok := cnr.trees[treeID]
|
||||
if !ok {
|
||||
tr = newMemoryTree()
|
||||
cnr.trees[treeID] = tr
|
||||
}
|
||||
|
||||
parentNode := tr.treeData.getNode(parent)
|
||||
if parentNode == nil {
|
||||
return 0, ErrNodeNotFound
|
||||
}
|
||||
|
||||
newID := tr.idCounter
|
||||
tr.idCounter++
|
||||
|
||||
tn := &treeNodeMemory{
|
||||
data: nodeResponse{
|
||||
meta: metaToNodeMeta(meta),
|
||||
nodeID: newID,
|
||||
parentID: parent,
|
||||
timestamp: uint64(time.Now().UnixMicro()),
|
||||
},
|
||||
parent: parentNode,
|
||||
}
|
||||
|
||||
parentNode.children = append(parentNode.children, tn)
|
||||
cnr.trees[treeID] = tr
|
||||
|
||||
return newID, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientMemory) AddNodeByPath(ctx context.Context, bktInfo *data.BucketInfo, treeID string, path []string, meta map[string]string) (uint64, error) {
|
||||
cnr, ok := c.containers[bktInfo.CID.EncodeToString()]
|
||||
if !ok {
|
||||
cnr = newContainerInfo(bktInfo, treeID)
|
||||
c.containers[bktInfo.CID.EncodeToString()] = cnr
|
||||
}
|
||||
|
||||
tr, ok := cnr.trees[treeID]
|
||||
if !ok {
|
||||
tr = newMemoryTree()
|
||||
cnr.trees[treeID] = tr
|
||||
}
|
||||
|
||||
parentNode := tr.createPathIfNotExist(tr.treeData, path)
|
||||
if parentNode == nil {
|
||||
return 0, fmt.Errorf("create path '%s'", path)
|
||||
}
|
||||
|
||||
newID := tr.idCounter
|
||||
tr.idCounter++
|
||||
|
||||
tn := &treeNodeMemory{
|
||||
data: nodeResponse{
|
||||
meta: metaToNodeMeta(meta),
|
||||
nodeID: newID,
|
||||
parentID: parentNode.data.nodeID,
|
||||
timestamp: uint64(time.Now().UnixMicro()),
|
||||
},
|
||||
parent: parentNode,
|
||||
}
|
||||
|
||||
parentNode.children = append(parentNode.children, tn)
|
||||
cnr.trees[treeID] = tr
|
||||
|
||||
return newID, nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientMemory) MoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID, parentID uint64, meta map[string]string) error {
|
||||
cnr, ok := c.containers[bktInfo.CID.EncodeToString()]
|
||||
if !ok {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
tr, ok := cnr.trees[treeID]
|
||||
if !ok {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
node := tr.treeData.getNode(nodeID)
|
||||
if node == nil {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
newParent := tr.treeData.getNode(parentID)
|
||||
if newParent == nil {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
node.data.meta = metaToNodeMeta(meta)
|
||||
node.data.parentID = parentID
|
||||
|
||||
newParent.children = append(newParent.children, node)
|
||||
node.parent.removeChild(nodeID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ServiceClientMemory) RemoveNode(ctx context.Context, bktInfo *data.BucketInfo, treeID string, nodeID uint64) error {
|
||||
cnr, ok := c.containers[bktInfo.CID.EncodeToString()]
|
||||
if !ok {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
tr, ok := cnr.trees[treeID]
|
||||
if !ok {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
node := tr.treeData.getNode(nodeID)
|
||||
if node == nil {
|
||||
return ErrNodeNotFound
|
||||
}
|
||||
|
||||
node.parent.removeChild(nodeID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func metaToNodeMeta(m map[string]string) []nodeMeta {
|
||||
result := make([]nodeMeta, 0, len(m))
|
||||
|
||||
for key, value := range m {
|
||||
result = append(result, nodeMeta{key: key, value: []byte(value)})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
package frostfs
|
||||
package tree
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -96,28 +97,73 @@ func TestLockConfigurationEncoding(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHandleError(t *testing.T) {
|
||||
defaultError := errors.New("default error")
|
||||
for _, tc := range []struct {
|
||||
err error
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
err: defaultError,
|
||||
expectedError: defaultError,
|
||||
},
|
||||
{
|
||||
err: errors.New("something not found"),
|
||||
expectedError: layer.ErrNodeNotFound,
|
||||
},
|
||||
{
|
||||
err: errors.New("something is denied by some acl rule"),
|
||||
expectedError: layer.ErrNodeAccessDenied,
|
||||
},
|
||||
} {
|
||||
t.Run("", func(t *testing.T) {
|
||||
err := handleError("err message", tc.err)
|
||||
require.True(t, errors.Is(err, tc.expectedError))
|
||||
})
|
||||
func TestTreeServiceSettings(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
memCli, err := NewTreeServiceClientMemory()
|
||||
require.NoError(t, err)
|
||||
treeService := NewTree(memCli)
|
||||
|
||||
bktInfo := &data.BucketInfo{
|
||||
CID: cidtest.ID(),
|
||||
}
|
||||
|
||||
settings := &data.BucketSettings{
|
||||
Versioning: "Versioning",
|
||||
LockConfiguration: &data.ObjectLockConfiguration{
|
||||
ObjectLockEnabled: "Enabled",
|
||||
Rule: &data.ObjectLockRule{
|
||||
DefaultRetention: &data.DefaultRetention{
|
||||
Days: 1,
|
||||
Mode: "mode",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err = treeService.PutSettingsNode(ctx, bktInfo, settings)
|
||||
require.NoError(t, err)
|
||||
|
||||
storedSettings, err := treeService.GetSettingsNode(ctx, bktInfo)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, settings, storedSettings)
|
||||
}
|
||||
|
||||
func TestTreeServiceAddVersion(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
memCli, err := NewTreeServiceClientMemory()
|
||||
require.NoError(t, err)
|
||||
treeService := NewTree(memCli)
|
||||
|
||||
bktInfo := &data.BucketInfo{
|
||||
CID: cidtest.ID(),
|
||||
}
|
||||
|
||||
version := &data.NodeVersion{
|
||||
BaseNodeVersion: data.BaseNodeVersion{
|
||||
OID: oidtest.ID(),
|
||||
Size: 10,
|
||||
ETag: "etag",
|
||||
FilePath: "path/to/version",
|
||||
},
|
||||
IsUnversioned: true,
|
||||
}
|
||||
|
||||
nodeID, err := treeService.AddVersion(ctx, bktInfo, version)
|
||||
require.NoError(t, err)
|
||||
|
||||
storedNode, err := treeService.GetUnversioned(ctx, bktInfo, "path/to/version")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nodeID, storedNode.ID)
|
||||
require.Equal(t, version.BaseNodeVersion.Size, storedNode.Size)
|
||||
require.Equal(t, version.BaseNodeVersion.ETag, storedNode.ETag)
|
||||
require.Equal(t, version.BaseNodeVersion.ETag, storedNode.ETag)
|
||||
require.Equal(t, version.BaseNodeVersion.FilePath, storedNode.FilePath)
|
||||
require.Equal(t, version.BaseNodeVersion.OID, storedNode.OID)
|
||||
|
||||
versions, err := treeService.GetVersions(ctx, bktInfo, "path/to/version")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, versions, 1)
|
||||
require.Equal(t, storedNode, versions[0])
|
||||
}
|
|
@ -23,13 +23,11 @@ get_adjusted_result () {
|
|||
printf "%s%*s" "$NEW_RESULT" $ADDITIONAL_SPACES ''
|
||||
}
|
||||
|
||||
while read -r line;
|
||||
do
|
||||
while read -r line; do
|
||||
RES_LINE=$(echo "$line" | sed -nE '/^s3tests_boto3/p')
|
||||
if [ -n "$RES_LINE" ]
|
||||
then
|
||||
TEST=$(echo "$RES_LINE" | sed -e 's/[[:space:]]*\.\.\..*//')
|
||||
RESULT=$(echo "$RES_LINE" | sed -e 's/^.*\.\.\.[[:space:]]*//')
|
||||
if [ -n "$RES_LINE" ]; then
|
||||
TEST=${RES_LINE%%[[:space:]]*}
|
||||
RESULT=${RES_LINE##*[[:space:]]}
|
||||
|
||||
# beautify trailing spaces
|
||||
OLD_RESULT_S3GW=$(sed -n "s/^.*${TEST}[[:space:]]*|[[:space:]]\(.*\)[[:space:]]|.*|.*|$/\1/p" "$RESULT_FILE" | head -1)
|
||||
|
|
Loading…
Reference in a new issue