From 7308c333ccc994f3be1767315fe26e6e922e4f17 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 29 Apr 2022 19:57:31 +0300 Subject: [PATCH] [#1365] cli: Add `SyncContainerSettings` func to internal client Signed-off-by: Pavel Karpy --- cmd/neofs-cli/internal/client/client.go | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-cli/internal/client/client.go b/cmd/neofs-cli/internal/client/client.go index bb46ec2e..de16962e 100644 --- a/cmd/neofs-cli/internal/client/client.go +++ b/cmd/neofs-cli/internal/client/client.go @@ -9,7 +9,7 @@ import ( "github.com/nspcc-dev/neofs-sdk-go/accounting" "github.com/nspcc-dev/neofs-sdk-go/client" - "github.com/nspcc-dev/neofs-sdk-go/container" + containerSDK "github.com/nspcc-dev/neofs-sdk-go/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/eacl" "github.com/nspcc-dev/neofs-sdk-go/netmap" @@ -123,7 +123,7 @@ type GetContainerRes struct { } // Container returns structured of the requested container. -func (x GetContainerRes) Container() container.Container { +func (x GetContainerRes) Container() containerSDK.Container { return x.cliRes.Container() } @@ -833,3 +833,37 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) { return new(PayloadRangeRes), nil } + +// SyncContainerPrm groups parameters of SyncContainerSettings operation. +type SyncContainerPrm struct { + commonPrm + c *containerSDK.Container +} + +// SetContainer sets a container that is required to be synced. +func (s *SyncContainerPrm) SetContainer(c *containerSDK.Container) { + s.c = c +} + +// SyncContainerRes groups resulting values of SyncContainerSettings +// operation. +type SyncContainerRes struct{} + +// SyncContainerSettings reads global network config from NeoFS and +// syncs container settings with it. +// +// Interrupts on any writer error. +// +// Panics if a container passed as a parameter is nil. +func SyncContainerSettings(prm SyncContainerPrm) (*SyncContainerRes, error) { + if prm.c == nil { + panic("sync container settings with the network: nil container") + } + + err := client.SyncContainerWithNetwork(context.Background(), prm.c, prm.cli) + if err != nil { + return nil, err + } + + return new(SyncContainerRes), nil +}