forked from TrueCloudLab/frostfs-node
[#907] morph/container: Add native name and zone to PutArgs
Add `PutArgs.SetNativeNameWithZone` method which sets native name and zone for container. Call `putNamed` method of Container contract if name is set, otherwise call `put` method. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
36c5e4c527
commit
7db47c88bf
2 changed files with 57 additions and 9 deletions
|
@ -29,6 +29,7 @@ type Option func(*cfg)
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
putMethod, // put container method name for invocation
|
putMethod, // put container method name for invocation
|
||||||
|
putNamedMethod, // put named container method name for invocation
|
||||||
putSizeMethod, // put container size method name for invocation
|
putSizeMethod, // put container size method name for invocation
|
||||||
listSizesMethod, // list container sizes method name for invocation
|
listSizesMethod, // list container sizes method name for invocation
|
||||||
getSizeMethod, // get container size method name for invocation
|
getSizeMethod, // get container size method name for invocation
|
||||||
|
@ -55,6 +56,8 @@ const (
|
||||||
defaultPutSizeMethod = "putContainerSize" // default "put container size" method name
|
defaultPutSizeMethod = "putContainerSize" // default "put container size" method name
|
||||||
defaultListSizesMethod = "listContainerSizes" // default "list container sizes" method name
|
defaultListSizesMethod = "listContainerSizes" // default "list container sizes" method name
|
||||||
defaultGetSizeMethod = "getContainerSize" // default "get container size" method name
|
defaultGetSizeMethod = "getContainerSize" // default "get container size" method name
|
||||||
|
|
||||||
|
defaultPutNamedMethod = "putNamed" // default put named container method name
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultConfig() *cfg {
|
func defaultConfig() *cfg {
|
||||||
|
@ -71,6 +74,8 @@ func defaultConfig() *cfg {
|
||||||
putSizeMethod: defaultPutSizeMethod,
|
putSizeMethod: defaultPutSizeMethod,
|
||||||
listSizesMethod: defaultListSizesMethod,
|
listSizesMethod: defaultListSizesMethod,
|
||||||
getSizeMethod: defaultGetSizeMethod,
|
getSizeMethod: defaultGetSizeMethod,
|
||||||
|
|
||||||
|
putNamedMethod: defaultPutNamedMethod,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,3 +275,17 @@ func WithGetSizeMethod(n string) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPutNamedMethod returns a client constructor option that
|
||||||
|
// specifies the method name of "put named container" operation.
|
||||||
|
//
|
||||||
|
// Ignores empty value.
|
||||||
|
//
|
||||||
|
// If option not provided, "putNamed" is used.
|
||||||
|
func WithPutNamedMethod(n string) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
if n != "" {
|
||||||
|
c.putNamedMethod = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ type PutArgs struct {
|
||||||
publicKey []byte // public key of container owner
|
publicKey []byte // public key of container owner
|
||||||
|
|
||||||
token []byte // binary session token
|
token []byte // binary session token
|
||||||
|
|
||||||
|
name, zone string // native name and zone
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPublicKey sets the public key of container owner
|
// SetPublicKey sets the public key of container owner
|
||||||
|
@ -41,10 +43,33 @@ func (p *PutArgs) SetSessionToken(v []byte) {
|
||||||
p.token = v
|
p.token = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put invokes the call of put container method
|
// 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.
|
// of NeoFS Container contract.
|
||||||
func (c *Client) Put(args PutArgs) error {
|
func (c *Client) Put(args PutArgs) error {
|
||||||
err := c.client.Invoke(
|
var (
|
||||||
|
err error
|
||||||
|
method string
|
||||||
|
)
|
||||||
|
|
||||||
|
if args.name != "" {
|
||||||
|
err = c.client.Invoke(
|
||||||
|
c.putNamedMethod,
|
||||||
|
args.cnr,
|
||||||
|
args.sig,
|
||||||
|
args.publicKey,
|
||||||
|
args.token,
|
||||||
|
args.name,
|
||||||
|
args.zone,
|
||||||
|
)
|
||||||
|
|
||||||
|
method = c.putNamedMethod
|
||||||
|
} else {
|
||||||
|
err = c.client.Invoke(
|
||||||
c.putMethod,
|
c.putMethod,
|
||||||
args.cnr,
|
args.cnr,
|
||||||
args.sig,
|
args.sig,
|
||||||
|
@ -52,8 +77,12 @@ func (c *Client) Put(args PutArgs) error {
|
||||||
args.token,
|
args.token,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
method = c.putMethod
|
||||||
return fmt.Errorf("could not invoke method (%s): %w", c.putMethod, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not invoke method (%s): %w", method, err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue