From 8f4c94f1342ccec95b7ad3080a212a02d4422f6e Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 21 Jul 2022 18:04:11 +0300 Subject: [PATCH] [#25] Add computing container version Signed-off-by: Denis Kirillov --- cmd/neofs-rest-gw/integration_test.go | 1 + handlers/containers.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cmd/neofs-rest-gw/integration_test.go b/cmd/neofs-rest-gw/integration_test.go index ff63817..15e8862 100644 --- a/cmd/neofs-rest-gw/integration_test.go +++ b/cmd/neofs-rest-gw/integration_test.go @@ -693,6 +693,7 @@ func restContainerGet(ctx context.Context, t *testing.T, owner user.ID, cnrID ci require.Equal(t, cnrID.EncodeToString(), *cnrInfo.ContainerID) require.Equal(t, owner.EncodeToString(), *cnrInfo.OwnerID) require.Equal(t, containerName, *cnrInfo.ContainerName) + require.NotEmpty(t, *cnrInfo.Version) } func restContainerDelete(ctx context.Context, t *testing.T, clientPool *pool.Pool, owner user.ID) { diff --git a/handlers/containers.go b/handlers/containers.go index 89f0c06..d91f81c 100644 --- a/handlers/containers.go +++ b/handlers/containers.go @@ -24,6 +24,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/pool" "github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/user" + "github.com/nspcc-dev/neofs-sdk-go/version" "go.uber.org/zap" ) @@ -240,9 +241,23 @@ func getContainerInfo(ctx context.Context, p *pool.Pool, cnrID cid.ID) (*models. BasicACL: util.NewString(cnr.BasicACL().EncodeToString()), PlacementPolicy: util.NewString(sb.String()), Attributes: attrs, + Version: util.NewString(getContainerVersion(cnr).String()), }, nil } +func getContainerVersion(cnr *container.Container) version.Version { + var v2cnr containerv2.Container + cnr.WriteToV2(&v2cnr) + + var cnrVersion version.Version + v2version := v2cnr.GetVersion() + if v2version != nil { + cnrVersion = version.Version(*v2version) + } + + return cnrVersion +} + func parseContainerID(containerID string) (cid.ID, error) { var cnrID cid.ID if err := cnrID.DecodeString(containerID); err != nil {