forked from TrueCloudLab/frostfs-api-go
[#208] pkg/client: Add function to get container and verify ID
GetContainer method reads container structure by identifier from the network. In some cases it is required to additionally check the correspondence of the container structure to the identifier as a hash from the binary representation. To do this, a new function GetVerifiedContainerStructure is defined to execute the check after receiving the container. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
84839b09c2
commit
5395988efc
1 changed files with 17 additions and 0 deletions
|
@ -64,6 +64,23 @@ func (c Client) GetContainer(ctx context.Context, id *container.ID, opts ...Call
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVerifiedContainerStructure is a wrapper over Client.GetContainer method
|
||||||
|
// which checks if the structure of the resulting container matches its identifier.
|
||||||
|
//
|
||||||
|
// Returns container.ErrIDMismatch if container does not match the identifier.
|
||||||
|
func GetVerifiedContainerStructure(ctx context.Context, c *Client, id *container.ID, opts ...CallOption) (*container.Container, error) {
|
||||||
|
cnr, err := c.GetContainer(ctx, id, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !container.CalculateID(cnr).Equal(id) {
|
||||||
|
return nil, container.ErrIDMismatch
|
||||||
|
}
|
||||||
|
|
||||||
|
return cnr, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c Client) ListContainers(ctx context.Context, owner *owner.ID, opts ...CallOption) ([]*container.ID, error) {
|
func (c Client) ListContainers(ctx context.Context, owner *owner.ID, opts ...CallOption) ([]*container.ID, error) {
|
||||||
switch c.remoteNode.Version.Major() {
|
switch c.remoteNode.Version.Major() {
|
||||||
case 2:
|
case 2:
|
||||||
|
|
Loading…
Reference in a new issue