[#197] sdk/object: Rename getters of Attribute and Object types

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-16 11:48:38 +03:00 committed by Alex Vanin
parent 67bcf6eb4d
commit 5f5e5ac5dd
7 changed files with 82 additions and 82 deletions

View file

@ -180,8 +180,8 @@ func (c *Client) putObjectV2(ctx context.Context, p *PutObjectParams, opts ...Ca
req.SetBody(body) req.SetBody(body)
v2Addr := new(v2refs.Address) v2Addr := new(v2refs.Address)
v2Addr.SetObjectID(p.obj.GetID().ToV2()) v2Addr.SetObjectID(p.obj.ID().ToV2())
v2Addr.SetContainerID(p.obj.GetContainerID().ToV2()) v2Addr.SetContainerID(p.obj.ContainerID().ToV2())
// set meta header // set meta header
meta := v2MetaHeaderFromOpts(callOpts) meta := v2MetaHeaderFromOpts(callOpts)

View file

@ -19,8 +19,8 @@ func NewAttribute() *Attribute {
return NewAttributeFromV2(new(object.Attribute)) return NewAttributeFromV2(new(object.Attribute))
} }
// GetKey returns key to the object attribute. // Key returns key to the object attribute.
func (a *Attribute) GetKey() string { func (a *Attribute) Key() string {
return (*object.Attribute)(a).GetKey() return (*object.Attribute)(a).GetKey()
} }
@ -29,8 +29,8 @@ func (a *Attribute) SetKey(v string) {
(*object.Attribute)(a).SetKey(v) (*object.Attribute)(a).SetKey(v)
} }
// GetValue return value of the object attribute. // Value return value of the object attribute.
func (a *Attribute) GetValue() string { func (a *Attribute) Value() string {
return (*object.Attribute)(a).GetValue() return (*object.Attribute)(a).GetValue()
} }

View file

@ -13,8 +13,8 @@ func TestAttribute(t *testing.T) {
a.SetKey(key) a.SetKey(key)
a.SetValue(val) a.SetValue(val)
require.Equal(t, key, a.GetKey()) require.Equal(t, key, a.Key())
require.Equal(t, val, a.GetValue()) require.Equal(t, val, a.Value())
aV2 := a.ToV2() aV2 := a.ToV2()

View file

@ -23,7 +23,7 @@ func CalculatePayloadChecksum(payload []byte) *pkg.Checksum {
// object payload and writes it to the object. // object payload and writes it to the object.
func CalculateAndSetPayloadChecksum(obj *RawObject) { func CalculateAndSetPayloadChecksum(obj *RawObject) {
obj.SetPayloadChecksum( obj.SetPayloadChecksum(
CalculatePayloadChecksum(obj.GetPayload()), CalculatePayloadChecksum(obj.Payload()),
) )
} }
@ -31,8 +31,8 @@ func CalculateAndSetPayloadChecksum(obj *RawObject) {
// corresponds to its payload. // corresponds to its payload.
func VerifyPayloadChecksum(obj *Object) error { func VerifyPayloadChecksum(obj *Object) error {
if !pkg.EqualChecksums( if !pkg.EqualChecksums(
obj.GetPayloadChecksum(), obj.PayloadChecksum(),
CalculatePayloadChecksum(obj.GetPayload()), CalculatePayloadChecksum(obj.Payload()),
) { ) {
return errors.New("payload checksum mismatch") return errors.New("payload checksum mismatch")
} }
@ -74,7 +74,7 @@ func VerifyID(obj *Object) error {
return err return err
} }
if !id.Equal(obj.GetID()) { if !id.Equal(obj.ID()) {
return errors.New("incorrect object identifier") return errors.New("incorrect object identifier")
} }
@ -101,7 +101,7 @@ func CalculateIDSignature(key *ecdsa.PrivateKey, id *ID) (*pkg.Signature, error)
} }
func CalculateAndSetSignature(key *ecdsa.PrivateKey, obj *RawObject) error { func CalculateAndSetSignature(key *ecdsa.PrivateKey, obj *RawObject) error {
sig, err := CalculateIDSignature(key, obj.GetID()) sig, err := CalculateIDSignature(key, obj.ID())
if err != nil { if err != nil {
return err return err
} }
@ -114,10 +114,10 @@ func CalculateAndSetSignature(key *ecdsa.PrivateKey, obj *RawObject) error {
func VerifyIDSignature(obj *Object) error { func VerifyIDSignature(obj *Object) error {
return signature.VerifyDataWithSource( return signature.VerifyDataWithSource(
signatureV2.StableMarshalerWrapper{ signatureV2.StableMarshalerWrapper{
SM: obj.GetID().ToV2(), SM: obj.ID().ToV2(),
}, },
func() ([]byte, []byte) { func() ([]byte, []byte) {
sig := obj.GetSignature() sig := obj.Signature()
return sig.Key(), sig.Sign() return sig.Key(), sig.Sign()
}, },

View file

@ -35,34 +35,34 @@ func TestVerificationFields(t *testing.T) {
}, },
{ {
corrupt: func() { corrupt: func() {
obj.SetPayloadSize(obj.GetPayloadSize() + 1) obj.SetPayloadSize(obj.PayloadSize() + 1)
}, },
restore: func() { restore: func() {
obj.SetPayloadSize(obj.GetPayloadSize() - 1) obj.SetPayloadSize(obj.PayloadSize() - 1)
}, },
}, },
{ {
corrupt: func() { corrupt: func() {
obj.GetID().ToV2().GetValue()[0]++ obj.ID().ToV2().GetValue()[0]++
}, },
restore: func() { restore: func() {
obj.GetID().ToV2().GetValue()[0]-- obj.ID().ToV2().GetValue()[0]--
}, },
}, },
{ {
corrupt: func() { corrupt: func() {
obj.GetSignature().Key()[0]++ obj.Signature().Key()[0]++
}, },
restore: func() { restore: func() {
obj.GetSignature().Key()[0]-- obj.Signature().Key()[0]--
}, },
}, },
{ {
corrupt: func() { corrupt: func() {
obj.GetSignature().Sign()[0]++ obj.Signature().Sign()[0]++
}, },
restore: func() { restore: func() {
obj.GetSignature().Sign()[0]-- obj.Signature().Sign()[0]--
}, },
}, },
} }

View file

@ -48,7 +48,7 @@ func TestRawObject_SetID(t *testing.T) {
obj.SetID(id) obj.SetID(id)
require.Equal(t, id, obj.GetID()) require.Equal(t, id, obj.ID())
} }
func TestRawObject_SetSignature(t *testing.T) { func TestRawObject_SetSignature(t *testing.T) {
@ -60,7 +60,7 @@ func TestRawObject_SetSignature(t *testing.T) {
obj.SetSignature(sig) obj.SetSignature(sig)
require.Equal(t, sig, obj.GetSignature()) require.Equal(t, sig, obj.Signature())
} }
func TestRawObject_SetPayload(t *testing.T) { func TestRawObject_SetPayload(t *testing.T) {
@ -71,7 +71,7 @@ func TestRawObject_SetPayload(t *testing.T) {
obj.SetPayload(payload) obj.SetPayload(payload)
require.Equal(t, payload, obj.GetPayload()) require.Equal(t, payload, obj.Payload())
} }
func TestRawObject_SetVersion(t *testing.T) { func TestRawObject_SetVersion(t *testing.T) {
@ -83,7 +83,7 @@ func TestRawObject_SetVersion(t *testing.T) {
obj.SetVersion(ver) obj.SetVersion(ver)
require.Equal(t, ver, obj.GetVersion()) require.Equal(t, ver, obj.Version())
} }
func TestRawObject_SetPayloadSize(t *testing.T) { func TestRawObject_SetPayloadSize(t *testing.T) {
@ -92,7 +92,7 @@ func TestRawObject_SetPayloadSize(t *testing.T) {
sz := uint64(133) sz := uint64(133)
obj.SetPayloadSize(sz) obj.SetPayloadSize(sz)
require.Equal(t, sz, obj.GetPayloadSize()) require.Equal(t, sz, obj.PayloadSize())
} }
func TestRawObject_SetContainerID(t *testing.T) { func TestRawObject_SetContainerID(t *testing.T) {
@ -105,7 +105,7 @@ func TestRawObject_SetContainerID(t *testing.T) {
obj.SetContainerID(cid) obj.SetContainerID(cid)
require.Equal(t, cid, obj.GetContainerID()) require.Equal(t, cid, obj.ContainerID())
} }
func TestRawObject_SetOwnerID(t *testing.T) { func TestRawObject_SetOwnerID(t *testing.T) {
@ -119,7 +119,7 @@ func TestRawObject_SetOwnerID(t *testing.T) {
obj.SetOwnerID(ownerID) obj.SetOwnerID(ownerID)
require.Equal(t, ownerID, obj.GetOwnerID()) require.Equal(t, ownerID, obj.OwnerID())
} }
func TestRawObject_SetCreationEpoch(t *testing.T) { func TestRawObject_SetCreationEpoch(t *testing.T) {
@ -128,7 +128,7 @@ func TestRawObject_SetCreationEpoch(t *testing.T) {
creat := uint64(228) creat := uint64(228)
obj.setCreationEpoch(creat) obj.setCreationEpoch(creat)
require.Equal(t, creat, obj.GetCreationEpoch()) require.Equal(t, creat, obj.CreationEpoch())
} }
func TestRawObject_SetPayloadChecksum(t *testing.T) { func TestRawObject_SetPayloadChecksum(t *testing.T) {
@ -139,7 +139,7 @@ func TestRawObject_SetPayloadChecksum(t *testing.T) {
obj.SetPayloadChecksum(cs) obj.SetPayloadChecksum(cs)
require.Equal(t, cs, obj.GetPayloadChecksum()) require.Equal(t, cs, obj.PayloadChecksum())
} }
func TestRawObject_SetPayloadHomomorphicHash(t *testing.T) { func TestRawObject_SetPayloadHomomorphicHash(t *testing.T) {
@ -150,7 +150,7 @@ func TestRawObject_SetPayloadHomomorphicHash(t *testing.T) {
obj.SetPayloadHomomorphicHash(cs) obj.SetPayloadHomomorphicHash(cs)
require.Equal(t, cs, obj.GetPayloadHomomorphicHash()) require.Equal(t, cs, obj.PayloadHomomorphicHash())
} }
func TestRawObject_SetAttributes(t *testing.T) { func TestRawObject_SetAttributes(t *testing.T) {
@ -166,7 +166,7 @@ func TestRawObject_SetAttributes(t *testing.T) {
obj.SetAttributes(a1, a2) obj.SetAttributes(a1, a2)
require.Equal(t, []*Attribute{a1, a2}, obj.GetAttributes()) require.Equal(t, []*Attribute{a1, a2}, obj.Attributes())
} }
func TestRawObject_SetPreviousID(t *testing.T) { func TestRawObject_SetPreviousID(t *testing.T) {
@ -176,7 +176,7 @@ func TestRawObject_SetPreviousID(t *testing.T) {
obj.SetPreviousID(prev) obj.SetPreviousID(prev)
require.Equal(t, prev, obj.GetPreviousID()) require.Equal(t, prev, obj.PreviousID())
} }
func TestRawObject_SetChildren(t *testing.T) { func TestRawObject_SetChildren(t *testing.T) {
@ -187,13 +187,13 @@ func TestRawObject_SetChildren(t *testing.T) {
obj.SetChildren(id1, id2) obj.SetChildren(id1, id2)
require.Equal(t, []*ID{id1, id2}, obj.GetChildren()) require.Equal(t, []*ID{id1, id2}, obj.Children())
} }
func TestRawObject_SetParent(t *testing.T) { func TestRawObject_SetParent(t *testing.T) {
obj := NewRaw() obj := NewRaw()
require.Nil(t, obj.GetParent()) require.Nil(t, obj.Parent())
par := NewRaw() par := NewRaw()
par.SetID(randID(t)) par.SetID(randID(t))
@ -204,7 +204,7 @@ func TestRawObject_SetParent(t *testing.T) {
obj.SetParent(parObj) obj.SetParent(parObj)
require.Equal(t, parObj, obj.GetParent()) require.Equal(t, parObj, obj.Parent())
} }
func TestRawObject_ToV2(t *testing.T) { func TestRawObject_ToV2(t *testing.T) {
@ -224,7 +224,7 @@ func TestRawObject_SetSessionToken(t *testing.T) {
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
require.Equal(t, tok, obj.GetSessionToken()) require.Equal(t, tok, obj.SessionToken())
} }
func TestRawObject_SetType(t *testing.T) { func TestRawObject_SetType(t *testing.T) {
@ -234,7 +234,7 @@ func TestRawObject_SetType(t *testing.T) {
obj.SetType(typ) obj.SetType(typ)
require.Equal(t, typ, obj.GetType()) require.Equal(t, typ, obj.Type())
} }
func TestRawObject_CutPayload(t *testing.T) { func TestRawObject_CutPayload(t *testing.T) {
@ -248,20 +248,20 @@ func TestRawObject_CutPayload(t *testing.T) {
o2 := o1.CutPayload() o2 := o1.CutPayload()
require.Equal(t, sz, o2.GetPayloadSize()) require.Equal(t, sz, o2.PayloadSize())
require.Empty(t, o2.GetPayload()) require.Empty(t, o2.Payload())
sz++ sz++
o1.SetPayloadSize(sz) o1.SetPayloadSize(sz)
require.Equal(t, sz, o1.GetPayloadSize()) require.Equal(t, sz, o1.PayloadSize())
require.Equal(t, sz, o2.GetPayloadSize()) require.Equal(t, sz, o2.PayloadSize())
p2 := []byte{4, 5, 6} p2 := []byte{4, 5, 6}
o2.SetPayload(p2) o2.SetPayload(p2)
require.Equal(t, p2, o2.GetPayload()) require.Equal(t, p2, o2.Payload())
require.Equal(t, p1, o1.GetPayload()) require.Equal(t, p1, o1.Payload())
} }
func TestRawObject_SetParentID(t *testing.T) { func TestRawObject_SetParentID(t *testing.T) {
@ -270,7 +270,7 @@ func TestRawObject_SetParentID(t *testing.T) {
id := randID(t) id := randID(t)
obj.setParentID(id) obj.setParentID(id)
require.Equal(t, id, obj.GetParentID()) require.Equal(t, id, obj.ParentID())
} }
func TestRawObject_ResetRelations(t *testing.T) { func TestRawObject_ResetRelations(t *testing.T) {
@ -280,7 +280,7 @@ func TestRawObject_ResetRelations(t *testing.T) {
obj.ResetRelations() obj.ResetRelations()
require.Nil(t, obj.GetPreviousID()) require.Nil(t, obj.PreviousID())
} }
func TestRwObject_HasParent(t *testing.T) { func TestRwObject_HasParent(t *testing.T) {

View file

@ -42,8 +42,8 @@ func (o *rwObject) setSplitFields(setter func(*object.SplitHeader)) {
}) })
} }
// GetID returns object identifier. // ID returns object identifier.
func (o *rwObject) GetID() *ID { func (o *rwObject) ID() *ID {
return NewIDFromV2( return NewIDFromV2(
(*object.Object)(o). (*object.Object)(o).
GetObjectID(), GetObjectID(),
@ -55,8 +55,8 @@ func (o *rwObject) setID(v *ID) {
SetObjectID(v.ToV2()) SetObjectID(v.ToV2())
} }
// GetSignature returns signature of the object identifier. // Signature returns signature of the object identifier.
func (o *rwObject) GetSignature() *pkg.Signature { func (o *rwObject) Signature() *pkg.Signature {
return pkg.NewSignatureFromV2( return pkg.NewSignatureFromV2(
(*object.Object)(o). (*object.Object)(o).
GetSignature(), GetSignature(),
@ -68,8 +68,8 @@ func (o *rwObject) setSignature(v *pkg.Signature) {
SetSignature(v.ToV2()) SetSignature(v.ToV2())
} }
// GetPayload returns payload bytes. // Payload returns payload bytes.
func (o *rwObject) GetPayload() []byte { func (o *rwObject) Payload() []byte {
return (*object.Object)(o). return (*object.Object)(o).
GetPayload() GetPayload()
} }
@ -79,8 +79,8 @@ func (o *rwObject) setPayload(v []byte) {
SetPayload(v) SetPayload(v)
} }
// GetVersion returns version of the object. // Version returns version of the object.
func (o *rwObject) GetVersion() *pkg.Version { func (o *rwObject) Version() *pkg.Version {
return pkg.NewVersionFromV2( return pkg.NewVersionFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -94,8 +94,8 @@ func (o *rwObject) setVersion(v *pkg.Version) {
}) })
} }
// GetPayloadSize returns payload length of the object. // PayloadSize returns payload length of the object.
func (o *rwObject) GetPayloadSize() uint64 { func (o *rwObject) PayloadSize() uint64 {
return (*object.Object)(o). return (*object.Object)(o).
GetHeader(). GetHeader().
GetPayloadLength() GetPayloadLength()
@ -107,8 +107,8 @@ func (o *rwObject) setPayloadSize(v uint64) {
}) })
} }
// GetContainerID returns identifier of the related container. // ContainerID returns identifier of the related container.
func (o *rwObject) GetContainerID() *container.ID { func (o *rwObject) ContainerID() *container.ID {
return container.NewIDFromV2( return container.NewIDFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -122,8 +122,8 @@ func (o *rwObject) setContainerID(v *container.ID) {
}) })
} }
// GetOwnerID returns identifier of the object owner. // OwnerID returns identifier of the object owner.
func (o *rwObject) GetOwnerID() *owner.ID { func (o *rwObject) OwnerID() *owner.ID {
return owner.NewIDFromV2( return owner.NewIDFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -137,8 +137,8 @@ func (o *rwObject) setOwnerID(v *owner.ID) {
}) })
} }
// GetCreationEpoch returns epoch number in which object was created. // CreationEpoch returns epoch number in which object was created.
func (o *rwObject) GetCreationEpoch() uint64 { func (o *rwObject) CreationEpoch() uint64 {
return (*object.Object)(o). return (*object.Object)(o).
GetHeader(). GetHeader().
GetCreationEpoch() GetCreationEpoch()
@ -150,8 +150,8 @@ func (o *rwObject) setCreationEpoch(v uint64) {
}) })
} }
// GetPayloadChecksum returns checksum of the object payload. // PayloadChecksum returns checksum of the object payload.
func (o *rwObject) GetPayloadChecksum() *pkg.Checksum { func (o *rwObject) PayloadChecksum() *pkg.Checksum {
return pkg.NewChecksumFromV2( return pkg.NewChecksumFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -165,8 +165,8 @@ func (o *rwObject) setPayloadChecksum(v *pkg.Checksum) {
}) })
} }
// GetPayloadHomomorphicHash returns homomorphic hash of the object payload. // PayloadHomomorphicHash returns homomorphic hash of the object payload.
func (o *rwObject) GetPayloadHomomorphicHash() *pkg.Checksum { func (o *rwObject) PayloadHomomorphicHash() *pkg.Checksum {
return pkg.NewChecksumFromV2( return pkg.NewChecksumFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -180,8 +180,8 @@ func (o *rwObject) setPayloadHomomorphicHash(v *pkg.Checksum) {
}) })
} }
// GetAttributes returns object attributes. // Attributes returns object attributes.
func (o *rwObject) GetAttributes() []*Attribute { func (o *rwObject) Attributes() []*Attribute {
attrs := (*object.Object)(o). attrs := (*object.Object)(o).
GetHeader(). GetHeader().
GetAttributes() GetAttributes()
@ -207,8 +207,8 @@ func (o *rwObject) setAttributes(v ...*Attribute) {
}) })
} }
// GetPreviousID returns identifier of the previous sibling object. // PreviousID returns identifier of the previous sibling object.
func (o *rwObject) GetPreviousID() *ID { func (o *rwObject) PreviousID() *ID {
return NewIDFromV2( return NewIDFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -223,8 +223,8 @@ func (o *rwObject) setPreviousID(v *ID) {
}) })
} }
// GetChildren return list of the identifiers of the child objects. // Children return list of the identifiers of the child objects.
func (o *rwObject) GetChildren() []*ID { func (o *rwObject) Children() []*ID {
ids := (*object.Object)(o). ids := (*object.Object)(o).
GetHeader(). GetHeader().
GetSplit(). GetSplit().
@ -251,8 +251,8 @@ func (o *rwObject) setChildren(v ...*ID) {
}) })
} }
// GetParentID returns identifier of the parent object. // ParentID returns identifier of the parent object.
func (o *rwObject) GetParentID() *ID { func (o *rwObject) ParentID() *ID {
return NewIDFromV2( return NewIDFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -267,8 +267,8 @@ func (o *rwObject) setParentID(v *ID) {
}) })
} }
// GetParent returns parent object w/o payload. // Parent returns parent object w/o payload.
func (o *rwObject) GetParent() *Object { func (o *rwObject) Parent() *Object {
h := (*object.Object)(o). h := (*object.Object)(o).
GetHeader(). GetHeader().
GetSplit() GetSplit()
@ -308,9 +308,9 @@ func (o *rwObject) resetRelations() {
}) })
} }
// GetSessionToken returns token of the session // SessionToken returns token of the session
// within which object was created. // within which object was created.
func (o *rwObject) GetSessionToken() *token.SessionToken { func (o *rwObject) SessionToken() *token.SessionToken {
return token.NewSessionTokenFromV2( return token.NewSessionTokenFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
@ -324,8 +324,8 @@ func (o *rwObject) setSessionToken(v *token.SessionToken) {
}) })
} }
// GetType returns type of the object. // Type returns type of the object.
func (o *rwObject) GetType() Type { func (o *rwObject) Type() Type {
return TypeFromV2( return TypeFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().