forked from TrueCloudLab/frostfs-node
[#505] morph/container: Change get container API
Make `Get` method of the wrapper over Container contract's client to accept binary container ID. Create `Get` function similar to the previous `Get` variation. Use this function in Container service server in the place where `Get` method was used. Additionally implement `AsContainerSource` function which allows to simply compose container Source interface from the wrapper. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
6310535b3c
commit
83c27f6e8a
6 changed files with 33 additions and 19 deletions
|
@ -67,24 +67,34 @@ func (w *Wrapper) Put(cnr, key, sig []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Get reads the container from NeoFS system by identifier
|
||||
type containerSource Wrapper
|
||||
|
||||
func (x *containerSource) Get(cid *container.ID) (*container.Container, error) {
|
||||
return Get((*Wrapper)(x), cid)
|
||||
}
|
||||
|
||||
// AsContainerSource provides container Source interface
|
||||
// from Wrapper instance.
|
||||
func AsContainerSource(w *Wrapper) core.Source {
|
||||
return (*containerSource)(w)
|
||||
}
|
||||
|
||||
// Get marshals container ID, and passes it to Wrapper's Get method.
|
||||
//
|
||||
// Returns error if cid is nil.
|
||||
func Get(w *Wrapper, cid *container.ID) (*container.Container, error) {
|
||||
return w.Get(cid.ToV2().GetValue())
|
||||
}
|
||||
|
||||
// Get reads the container from NeoFS system by binary identifier
|
||||
// through Container contract call.
|
||||
//
|
||||
// If an empty slice is returned for the requested identifier,
|
||||
// storage.ErrNotFound error is returned.
|
||||
func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) {
|
||||
if cid == nil {
|
||||
return nil, errNilArgument
|
||||
}
|
||||
func (w *Wrapper) Get(cid []byte) (*container.Container, error) {
|
||||
var args client.GetArgs
|
||||
|
||||
args := client.GetArgs{}
|
||||
|
||||
v2 := cid.ToV2()
|
||||
if v2 == nil {
|
||||
return nil, errUnsupported // use other major version if there any
|
||||
}
|
||||
|
||||
args.SetCID(v2.GetValue())
|
||||
args.SetCID(cid)
|
||||
|
||||
// ask RPC neo node to get serialized container
|
||||
rpcAnswer, err := w.client.Get(args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue