From 202ef5cc54ef2d18fc9b1a3abd6c22521c4767cc Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 9 Jun 2023 09:39:25 +0300 Subject: [PATCH] [#59] Drop sync-tree Signed-off-by: Denis Kirillov --- .forgejo/workflows/tests.yml | 6 - .forgejo/workflows/vulncheck.yml | 3 - .gitignore | 1 - Makefile | 8 +- internal/frostfs/services/tree_client_grpc.go | 114 ------------------ .../services/tree_client_grpc_signature.go | 29 ----- syncTree.sh | 21 ---- 7 files changed, 1 insertion(+), 181 deletions(-) delete mode 100644 internal/frostfs/services/tree_client_grpc.go delete mode 100644 internal/frostfs/services/tree_client_grpc_signature.go delete mode 100755 syncTree.sh diff --git a/.forgejo/workflows/tests.yml b/.forgejo/workflows/tests.yml index f64b816..7a03020 100644 --- a/.forgejo/workflows/tests.yml +++ b/.forgejo/workflows/tests.yml @@ -7,9 +7,6 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Sync tree service - run: make sync-tree - - name: golangci-lint uses: https://github.com/golangci/golangci-lint-action@v2 with: @@ -29,9 +26,6 @@ jobs: uses: actions/setup-go@v3 with: go-version: '${{ matrix.go_versions }}' - - - name: Sync tree service - run: make sync-tree - name: Update Go modules run: make dep diff --git a/.forgejo/workflows/vulncheck.yml b/.forgejo/workflows/vulncheck.yml index 34692c9..0c9e908 100644 --- a/.forgejo/workflows/vulncheck.yml +++ b/.forgejo/workflows/vulncheck.yml @@ -9,9 +9,6 @@ jobs: with: fetch-depth: 0 - - name: Sync tree service - run: make sync-tree - - name: Setup Go uses: actions/setup-go@v3 with: diff --git a/.gitignore b/.gitignore index c1ca465..c4a98d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ bin temp /plugins/ /vendor/ -internal/frostfs/services/tree .test.env *~ diff --git a/Makefile b/Makefile index aeea3a8..a4db526 100755 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ METRICS_DUMP_OUT ?= ./metrics-dump.json BINDIR = bin DIRS = $(BINDIR) BINS = $(BINDIR)/frostfs-http-gw -SYNCDIR = internal/frostfs/services/tree .PHONY: all $(BINS) $(DIRS) dep docker/ test cover fmt image image-push dirty-image lint docker/lint pre-commit unpre-commit version clean @@ -28,7 +27,7 @@ PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \ # Make all binaries all: $(BINS) -$(BINS): sync-tree $(DIRS) dep +$(BINS): $(DIRS) dep @echo "⇒ Build $@" CGO_ENABLED=0 \ go build -v -trimpath \ @@ -39,10 +38,6 @@ $(DIRS): @echo "⇒ Ensure dir: $@" @mkdir -p $@ -# Synchronize tree service -sync-tree: - @./syncTree.sh - # Pull go dependencies dep: @printf "⇒ Download requirements: " @@ -136,7 +131,6 @@ version: clean: rm -rf vendor rm -rf $(BINDIR) - rm -rf $(SYNCDIR) # Package for Debian debpackage: diff --git a/internal/frostfs/services/tree_client_grpc.go b/internal/frostfs/services/tree_client_grpc.go deleted file mode 100644 index f25588a..0000000 --- a/internal/frostfs/services/tree_client_grpc.go +++ /dev/null @@ -1,114 +0,0 @@ -package services - -import ( - "context" - "fmt" - "strings" - - grpcService "git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/frostfs/services/tree" - "git.frostfs.info/TrueCloudLab/frostfs-http-gw/tokens" - "git.frostfs.info/TrueCloudLab/frostfs-http-gw/tree" - "github.com/nspcc-dev/neo-go/pkg/crypto/keys" - "google.golang.org/grpc" -) - -type GetNodeByPathResponseInfoWrapper struct { - response *grpcService.GetNodeByPathResponse_Info -} - -func (n GetNodeByPathResponseInfoWrapper) GetMeta() []tree.Meta { - res := make([]tree.Meta, len(n.response.Meta)) - for i, value := range n.response.Meta { - res[i] = value - } - return res -} - -type GetSubTreeResponseBodyWrapper struct { - response *grpcService.GetSubTreeResponse_Body -} - -func (n GetSubTreeResponseBodyWrapper) GetMeta() []tree.Meta { - res := make([]tree.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 grpcService.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 := grpcService.NewTreeServiceClient(conn) - if _, err = c.Healthcheck(ctx, &grpcService.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 *tree.GetNodesParams) ([]tree.NodeResponse, error) { - request := &grpcService.GetNodeByPathRequest{ - Body: &grpcService.GetNodeByPathRequest_Body{ - ContainerId: p.CnrID[:], - TreeId: p.TreeID, - Path: p.Path, - Attributes: p.Meta, - PathAttribute: tree.FileNameKey, - LatestOnly: p.LatestOnly, - AllAttributes: p.AllAttrs, - BearerToken: getBearer(ctx), - }, - } - - if err := c.signRequest(request.Body, func(key, sign []byte) { - request.Signature = &grpcService.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([]tree.NodeResponse, len(resp.GetBody().GetNodes())) - for i, info := range resp.GetBody().GetNodes() { - res[i] = GetNodeByPathResponseInfoWrapper{info} - } - - return res, nil -} - -func getBearer(ctx context.Context) []byte { - token, err := tokens.LoadBearerToken(ctx) - if err != nil { - return nil - } - return token.Marshal() -} - -func handleError(msg string, err error) error { - if strings.Contains(err.Error(), "not found") { - return fmt.Errorf("%w: %s", tree.ErrNodeNotFound, err.Error()) - } else if strings.Contains(err.Error(), "is denied by") { - return fmt.Errorf("%w: %s", tree.ErrNodeAccessDenied, err.Error()) - } - return fmt.Errorf("%s: %w", msg, err) -} diff --git a/internal/frostfs/services/tree_client_grpc_signature.go b/internal/frostfs/services/tree_client_grpc_signature.go deleted file mode 100644 index 9dd38f9..0000000 --- a/internal/frostfs/services/tree_client_grpc_signature.go +++ /dev/null @@ -1,29 +0,0 @@ -/*REMOVE THIS AFTER SIGNATURE WILL BE AVAILABLE IN TREE CLIENT FROM FROSTFS NODE*/ -package services - -import ( - crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto" - "google.golang.org/protobuf/proto" -) - -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. - sign, err := crypto.Sign(&c.key.PrivateKey, buf) - if err != nil { - return err - } - - f(c.key.PublicKey().Bytes(), sign) - return nil -} - -func (c *ServiceClientGRPC) signRequest(requestBody proto.Message, f func(key, sign []byte)) error { - buf, err := proto.Marshal(requestBody) - if err != nil { - return err - } - - return c.signData(buf, f) -} diff --git a/syncTree.sh b/syncTree.sh deleted file mode 100755 index 98d16a0..0000000 --- a/syncTree.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -mkdir -p internal/frostfs/services/tree 2>/dev/null - -REVISION="f07d4158f50ed5c7f44cc0bc224c3d03edf27f3b" - -echo "tree service revision ${REVISION}" - -# regexp below find all link to source code files which end with ".pb.go" and retrieve the file names -# we use `[^.]*` as non greedy workaround for `.*` -FILES=$(curl -s https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/${REVISION}/pkg/services/tree | sed -n "s,.*\"/TrueCloudLab/frostfs-node/src/commit/${REVISION}/pkg/services/tree/\([^.]*\.pb\.go\)\".*,\1,p") - -for file in $FILES; do - if [[ $file == *"frostfs"* ]]; then - echo "skip '$file'" - continue - else - echo "sync '$file' in tree service" - fi - curl -s "https://git.frostfs.info/TrueCloudLab/frostfs-node/raw/commit/${REVISION}/pkg/services/tree/${file}" -o "./internal/frostfs/services/tree/${file}" -done \ No newline at end of file