Pass user.ID by value #821

Merged
dstepanov-yadro merged 1 commit from dstepanov-yadro/frostfs-node:feat/sdk-go-user-id into master 2024-09-04 19:51:04 +00:00
12 changed files with 27 additions and 27 deletions

View file

@ -39,7 +39,7 @@ var accountingBalanceCmd = &cobra.Command{
var prm internalclient.BalanceOfPrm var prm internalclient.BalanceOfPrm
prm.SetClient(cli) prm.SetClient(cli)
prm.Account = &idUser prm.Account = idUser
res, err := internalclient.BalanceOf(cmd.Context(), prm) res, err := internalclient.BalanceOf(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err) commonCmd.ExitOnErr(cmd, "rpc error: %w", err)

View file

@ -47,7 +47,7 @@ var listContainersCmd = &cobra.Command{
var prm internalclient.ListContainersPrm var prm internalclient.ListContainersPrm
prm.SetClient(cli) prm.SetClient(cli)
prm.Account = &idUser prm.Account = idUser
res, err := internalclient.ListContainers(cmd.Context(), prm) res, err := internalclient.ListContainers(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err) commonCmd.ExitOnErr(cmd, "rpc error: %w", err)

View file

@ -94,7 +94,7 @@ var objectLockCmd = &cobra.Command{
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cnr) obj.SetContainerID(cnr)
obj.SetOwnerID(&idOwner) obj.SetOwnerID(idOwner)
obj.SetType(objectSDK.TypeLock) obj.SetType(objectSDK.TypeLock)
obj.SetAttributes(expirationAttr) obj.SetAttributes(expirationAttr)
obj.SetPayload(lock.Marshal()) obj.SetPayload(lock.Marshal())

View file

@ -93,7 +93,7 @@ func putObject(cmd *cobra.Command, _ []string) {
attrs := getAllObjectAttributes(cmd) attrs := getAllObjectAttributes(cmd)
obj.SetContainerID(cnr) obj.SetContainerID(cnr)
obj.SetOwnerID(&ownerID) obj.SetOwnerID(ownerID)
obj.SetAttributes(attrs...) obj.SetAttributes(attrs...)
notificationInfo, err := parseObjectNotifications(cmd) notificationInfo, err := parseObjectNotifications(cmd)
@ -160,7 +160,7 @@ func readFilePayload(filename string, cmd *cobra.Command) (io.Reader, cid.ID, us
commonCmd.ExitOnErr(cmd, "can't unmarshal object from given file: %w", objTemp.Unmarshal(buf)) commonCmd.ExitOnErr(cmd, "can't unmarshal object from given file: %w", objTemp.Unmarshal(buf))
payloadReader := bytes.NewReader(objTemp.Payload()) payloadReader := bytes.NewReader(objTemp.Payload())
cnr, _ := objTemp.ContainerID() cnr, _ := objTemp.ContainerID()
ownerID := *objTemp.OwnerID() ownerID := objTemp.OwnerID()
return payloadReader, cnr, ownerID return payloadReader, cnr, ownerID
} }

View file

@ -165,7 +165,7 @@ func (v *FormatValidator) validateSignatureKey(obj *objectSDK.Object) error {
} }
token := obj.SessionToken() token := obj.SessionToken()
ownerID := *obj.OwnerID() ownerID := obj.OwnerID()
if token == nil || !token.AssertAuthKey(&key) { if token == nil || !token.AssertAuthKey(&key) {
return v.checkOwnerKey(ownerID, key) return v.checkOwnerKey(ownerID, key)
@ -412,7 +412,7 @@ func (v *FormatValidator) checkAttributes(obj *objectSDK.Object) error {
var errIncorrectOwner = errors.New("incorrect object owner") var errIncorrectOwner = errors.New("incorrect object owner")
func (v *FormatValidator) checkOwner(obj *objectSDK.Object) error { func (v *FormatValidator) checkOwner(obj *objectSDK.Object) error {
if idOwner := obj.OwnerID(); idOwner == nil || len(idOwner.WalletBytes()) == 0 { if idOwner := obj.OwnerID(); idOwner.IsEmpty() {
return errIncorrectOwner return errIncorrectOwner
} }

View file

@ -32,7 +32,7 @@ func blankValidObject(key *ecdsa.PrivateKey) *objectSDK.Object {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cidtest.ID()) obj.SetContainerID(cidtest.ID())
obj.SetOwnerID(&idOwner) obj.SetOwnerID(idOwner)
return obj return obj
} }
@ -107,7 +107,7 @@ func TestFormatValidator_Validate(t *testing.T) {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cidtest.ID()) obj.SetContainerID(cidtest.ID())
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
obj.SetOwnerID(&idOwner) obj.SetOwnerID(idOwner)
require.NoError(t, objectSDK.SetIDWithSignature(ownerKey.PrivateKey, obj)) require.NoError(t, objectSDK.SetIDWithSignature(ownerKey.PrivateKey, obj))
@ -303,7 +303,7 @@ func TestFormatValidator_ValidateTokenIssuer(t *testing.T) {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cidtest.ID()) obj.SetContainerID(cidtest.ID())
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
obj.SetOwnerID(&owner) obj.SetOwnerID(owner)
require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj)) require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj))
require.NoError(t, v.Validate(context.Background(), obj, false)) require.NoError(t, v.Validate(context.Background(), obj, false))
@ -352,7 +352,7 @@ func TestFormatValidator_ValidateTokenIssuer(t *testing.T) {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cnrID) obj.SetContainerID(cnrID)
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
obj.SetOwnerID(&owner) obj.SetOwnerID(owner)
require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj)) require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj))
require.NoError(t, v.Validate(context.Background(), obj, false)) require.NoError(t, v.Validate(context.Background(), obj, false))
@ -386,7 +386,7 @@ func TestFormatValidator_ValidateTokenIssuer(t *testing.T) {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cnrID) obj.SetContainerID(cnrID)
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
obj.SetOwnerID(&owner) obj.SetOwnerID(owner)
require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj)) require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj))
v := NewFormatValidator( v := NewFormatValidator(
@ -459,7 +459,7 @@ func TestFormatValidator_ValidateTokenIssuer(t *testing.T) {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cnrID) obj.SetContainerID(cnrID)
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
obj.SetOwnerID(&owner) obj.SetOwnerID(owner)
require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj)) require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj))
v := NewFormatValidator( v := NewFormatValidator(
@ -535,7 +535,7 @@ func TestFormatValidator_ValidateTokenIssuer(t *testing.T) {
obj := objectSDK.New() obj := objectSDK.New()
obj.SetContainerID(cnrID) obj.SetContainerID(cnrID)
obj.SetSessionToken(tok) obj.SetSessionToken(tok)
obj.SetOwnerID(&owner) obj.SetOwnerID(owner)
require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj)) require.NoError(t, objectSDK.SetIDWithSignature(signer.PrivateKey, obj))
v := NewFormatValidator( v := NewFormatValidator(

View file

@ -39,14 +39,14 @@ func TestStickyCheck(t *testing.T) {
info.SetSenderKey(make([]byte, 33)) // any non-empty key info.SetSenderKey(make([]byte, 33)) // any non-empty key
info.SetRequestRole(acl.RoleContainer) info.SetRequestRole(acl.RoleContainer)
require.True(t, checker.StickyBitCheck(info, *usertest.ID())) require.True(t, checker.StickyBitCheck(info, usertest.ID()))
var basicACL acl.Basic var basicACL acl.Basic
basicACL.MakeSticky() basicACL.MakeSticky()
info.SetBasicACL(basicACL) info.SetBasicACL(basicACL)
require.True(t, checker.StickyBitCheck(info, *usertest.ID())) require.True(t, checker.StickyBitCheck(info, usertest.ID()))
}) })
t.Run("owner ID and/or public key emptiness", func(t *testing.T) { t.Run("owner ID and/or public key emptiness", func(t *testing.T) {
@ -72,7 +72,7 @@ func TestStickyCheck(t *testing.T) {
var ownerID user.ID var ownerID user.ID
if withOwner { if withOwner {
ownerID = *usertest.ID() ownerID = usertest.ID()
} }
require.Equal(t, expected, checker.StickyBitCheck(info, ownerID)) require.Equal(t, expected, checker.StickyBitCheck(info, ownerID))

View file

@ -62,8 +62,8 @@ func headersFromObject(obj *objectSDK.Object, cnr cid.ID, oid *oid.ID) []eaclSDK
res = append(res, oidHeader(*oid)) res = append(res, oidHeader(*oid))
} }
if idOwner := obj.OwnerID(); idOwner != nil { if idOwner := obj.OwnerID(); !idOwner.IsEmpty() {
res = append(res, ownerIDHeader(*idOwner)) res = append(res, ownerIDHeader(idOwner))
} }
cs, ok := obj.PayloadChecksum() cs, ok := obj.PayloadChecksum()

View file

@ -176,11 +176,11 @@ func (exec *execCtx) initTombstoneObject() error {
tokenSession := exec.commonParameters().SessionToken() tokenSession := exec.commonParameters().SessionToken()
if tokenSession != nil { if tokenSession != nil {
issuer := tokenSession.Issuer() issuer := tokenSession.Issuer()
exec.tombstoneObj.SetOwnerID(&issuer) exec.tombstoneObj.SetOwnerID(issuer)
} else { } else {
// make local node a tombstone object owner // make local node a tombstone object owner
localUser := exec.svc.netInfo.LocalNodeID() localUser := exec.svc.netInfo.LocalNodeID()
exec.tombstoneObj.SetOwnerID(&localUser) exec.tombstoneObj.SetOwnerID(localUser)
} }
var a objectSDK.Attribute var a objectSDK.Attribute

View file

@ -112,7 +112,7 @@ func (p *Streamer) initTrustedTarget(prm *PutInitPrm) error {
// If it isn't owner key, replication attempts will fail, thus this check. // If it isn't owner key, replication attempts will fail, thus this check.
if sToken == nil { if sToken == nil {
ownerObj := prm.hdr.OwnerID() ownerObj := prm.hdr.OwnerID()
if ownerObj == nil { if ownerObj.IsEmpty() {
return errors.New("missing object owner") return errors.New("missing object owner")
} }

View file

@ -25,7 +25,7 @@ func TestNewKeyStorage(t *testing.T) {
tokenStor := tokenStorage.NewTokenStore() tokenStor := tokenStorage.NewTokenStore()
stor := util.NewKeyStorage(&nodeKey.PrivateKey, tokenStor, mockedNetworkState{42}) stor := util.NewKeyStorage(&nodeKey.PrivateKey, tokenStor, mockedNetworkState{42})
owner := *usertest.ID() owner := usertest.ID()
t.Run("node key", func(t *testing.T) { t.Run("node key", func(t *testing.T) {
key, err := stor.GetKey(nil) key, err := stor.GetKey(nil)
@ -36,7 +36,7 @@ func TestNewKeyStorage(t *testing.T) {
t.Run("unknown token", func(t *testing.T) { t.Run("unknown token", func(t *testing.T) {
_, err = stor.GetKey(&util.SessionInfo{ _, err = stor.GetKey(&util.SessionInfo{
ID: uuid.New(), ID: uuid.New(),
Owner: *usertest.ID(), Owner: usertest.ID(),
}) })
require.Error(t, err) require.Error(t, err)
}) })

View file

@ -22,7 +22,7 @@ func TestTokenStore(t *testing.T) {
defer ts.Close() defer ts.Close()
owner := *usertest.ID() owner := usertest.ID()
var ownerV2 refs.OwnerID var ownerV2 refs.OwnerID
owner.WriteToV2(&ownerV2) owner.WriteToV2(&ownerV2)
@ -66,7 +66,7 @@ func TestTokenStore_Persistent(t *testing.T) {
ts, err := NewTokenStore(path) ts, err := NewTokenStore(path)
require.NoError(t, err) require.NoError(t, err)
idOwner := *usertest.ID() idOwner := usertest.ID()
var idOwnerV2 refs.OwnerID var idOwnerV2 refs.OwnerID
idOwner.WriteToV2(&idOwnerV2) idOwner.WriteToV2(&idOwnerV2)
@ -127,7 +127,7 @@ func TestTokenStore_RemoveOld(t *testing.T) {
defer ts.Close() defer ts.Close()
owner := *usertest.ID() owner := usertest.ID()
var ownerV2 refs.OwnerID var ownerV2 refs.OwnerID
owner.WriteToV2(&ownerV2) owner.WriteToV2(&ownerV2)