frostfs-node/pkg/morph/client/container/put.go
Evgenii Stratonikov 3c5b62d839 [#625] morph/client: make method names constant
We don't use custom names and the only place where custom method option
is used it provides the default name and can be omitted.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-02-01 15:47:54 +03:00

82 lines
1.7 KiB
Go

package container
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
)
// PutArgs groups the arguments
// of put container invocation call.
type PutArgs struct {
cnr []byte // container in a binary format
sig []byte // binary container signature
publicKey []byte // public key of container owner
token []byte // binary session token
name, zone string // native name and zone
client.InvokePrmOptional
}
// SetPublicKey sets the public key of container owner
// in a binary format.
func (p *PutArgs) SetPublicKey(v []byte) {
p.publicKey = v
}
// SetContainer sets the container structure
// in a binary format.
func (p *PutArgs) SetContainer(v []byte) {
p.cnr = v
}
// SetSignature sets the container structure
// owner's signature.
func (p *PutArgs) SetSignature(v []byte) {
p.sig = v
}
// SetSessionToken sets token of the session
// within which the container was created
// in a binary format.
func (p *PutArgs) SetSessionToken(v []byte) {
p.token = v
}
// SetNativeNameWithZone sets container native name and its zone.
func (p *PutArgs) SetNativeNameWithZone(name, zone string) {
p.name, p.zone = name, zone
}
// Put invokes the call of put (named if name is set) container method
// of NeoFS Container contract.
func (c *Client) Put(args PutArgs) error {
var (
method string
prm client.InvokePrm
)
if args.name != "" {
method = PutNamedMethod
prm.SetArgs(args.cnr, args.sig, args.publicKey, args.token, args.name, args.zone)
} else {
method = putMethod
prm.SetArgs(args.cnr, args.sig, args.publicKey, args.token)
}
prm.SetMethod(method)
prm.InvokePrmOptional = args.InvokePrmOptional
err := c.client.Invoke(prm)
if err != nil {
return fmt.Errorf("could not invoke method (%s): %w", method, err)
}
return nil
}