Skip to content

Commit

Permalink
*: fix deprecated code
Browse files Browse the repository at this point in the history
Use:
- `eacl.Target.RawSubjects` instead of `eacl.Target.BinaryKeys`.
- `eacl.NewTargetByRole` with `eacl.Target.SetRawSubjects` for targets with
public keys.
- `eacl.ConstructTable` instead of `eacl.NewTable`.
- `eacl.ConstructRecord` instead of `eacl.NewRecord`.
- `*.Get*ID` instead of `*.*ID`.
- comparing with == instead of `ID.Equals`.
- `cid.NewFromMarshalledContainer(cnr.Marshal())` instead of.
`cid.ID.CalculateID`.
- `user.NewFromECDSAPublicKey` instead of `user.ResolveFromECDSAPublicKey`.
- direct copy instead of `ID.Encode`.
- direct assign instead of `ID.SetSHA256`.
- use `rand.Read` from `crypto/rand`.
- get expiration epoch of storage group from attribute in header of
the object carrying this storage group.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Sep 25, 2024
1 parent b3d4f8f commit f34d244
Show file tree
Hide file tree
Showing 128 changed files with 452 additions and 472 deletions.
2 changes: 1 addition & 1 deletion cmd/neofs-adm/internal/modules/morph/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func restoreContainers(cmd *cobra.Command, _ []string) error {
var id cid.ID
b := smartcontract.NewBuilder()
for _, cnt := range containers {
id.FromBinary(cnt.Value)
id = cid.NewFromMarshalledContainer(cnt.Value)
if _, ok := requested[id]; !ok {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-adm/internal/modules/morph/estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func estimationsFunc(cmd *cobra.Command, _ []string) error {
}

cIDBytes := make([]byte, sha256.Size)
cID.Encode(cIDBytes)
copy(cIDBytes, cID[:])

sID, iter, err := unwrap.SessionIterator(inv.Call(cnrHash, "iterateContainerSizes", epoch, cIDBytes))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/accounting/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var accountingBalanceCmd = &cobra.Command{

balanceOwner, _ := cmd.Flags().GetString(ownerFlag)
if balanceOwner == "" {
idUser = user.ResolveFromECDSAPublicKey(pk.PublicKey)
idUser = user.NewFromECDSAPublicKey(pk.PublicKey)
} else {
return fmt.Errorf("can't decode owner ID wallet address: %w", idUser.DecodeString(balanceOwner))
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-cli/modules/acl/extended/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ func TestParseTable(t *testing.T) {
},
}

eaclTable := eacl.NewTable()
eaclTable := eacl.ConstructTable(nil)

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := util.ParseEACLRule(eaclTable, test.rule)
err := util.ParseEACLRule(&eaclTable, test.rule)
ok := len(test.jsonRecord) > 0
require.Equal(t, ok, err == nil, err)
if ok {
expectedRecord := eacl.NewRecord()
expectedRecord := eacl.ConstructRecord(eacl.ActionUnspecified, eacl.OperationUnspecified, nil, eacl.Filter{})
err = expectedRecord.UnmarshalJSON([]byte(test.jsonRecord))
require.NoError(t, err)

actualRecord := eaclTable.Records()[len(eaclTable.Records())-1]

equalRecords(t, expectedRecord, &actualRecord)
equalRecords(t, &expectedRecord, &actualRecord)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ It will be stored in sidechain when inner ring will accepts it.`,
issuer := tok.Issuer()
cnr.SetOwner(issuer)
} else {
cnr.SetOwner(user.ResolveFromECDSAPublicKey(key.PublicKey))
cnr.SetOwner(user.NewFromECDSAPublicKey(key.PublicKey))
}

cnr.SetPlacementPolicy(*placementPolicy)
Expand Down
6 changes: 3 additions & 3 deletions cmd/neofs-cli/modules/container/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ Only owner of the container has a permission to remove container.`,
if tok != nil {
common.PrintVerbose(cmd, "Checking session issuer...")

if !tok.Issuer().Equals(owner) {
if tok.Issuer() != owner {
return fmt.Errorf("session issuer differs with the container owner: expected %s, has %s", owner, tok.Issuer())
}
} else {
common.PrintVerbose(cmd, "Checking provided account...")

acc := user.ResolveFromECDSAPublicKey(pk.PublicKey)
acc := user.NewFromECDSAPublicKey(pk.PublicKey)

if !acc.Equals(owner) {
if acc != owner {
return fmt.Errorf("provided account differs with the container owner: expected %s, has %s", owner, acc)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/container/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func prettyPrintContainer(cmd *cobra.Command, cnr container.Container, jsonEncod
return nil
}

var id cid.ID
cnr.CalculateID(&id)
id := cid.NewFromMarshalledContainer(cnr.Marshal())
cmd.Println("container ID:", id)

cmd.Println("owner ID:", cnr.Owner())
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/container/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var listContainersCmd = &cobra.Command{
}

if flagVarListContainerOwner == "" {
idUser = user.ResolveFromECDSAPublicKey(key.PublicKey)
idUser = user.NewFromECDSAPublicKey(key.PublicKey)
} else {
err := idUser.DecodeString(flagVarListContainerOwner)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-cli/modules/container/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ var containerNodesCmd = &cobra.Command{
return fmt.Errorf("unable to get netmap snapshot: %w", err)
}

var id cid.ID
cnr.CalculateID(&id)
id := cid.NewFromMarshalledContainer(cnr.Marshal())

policy := cnr.PlacementPolicy()

Expand Down
6 changes: 3 additions & 3 deletions cmd/neofs-cli/modules/container/set_eacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
if tok != nil {
common.PrintVerbose(cmd, "Checking session issuer...")

if !tok.Issuer().Equals(owner) {
if tok.Issuer() != owner {
return fmt.Errorf("session issuer differs with the container owner: expected %s, has %s", owner, tok.Issuer())
}
} else {
common.PrintVerbose(cmd, "Checking provided account...")

acc := user.ResolveFromECDSAPublicKey(pk.PublicKey)
acc := user.NewFromECDSAPublicKey(pk.PublicKey)

if !acc.Equals(owner) {
if acc != owner {
return fmt.Errorf("provided account differs with the container owner: expected %s, has %s", owner, acc)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/control/synchronize_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func synchronizeTree(cmd *cobra.Command, _ []string) error {
height, _ := cmd.Flags().GetUint64("height")

rawCID := make([]byte, sha256.Size)
cnr.Encode(rawCID)
copy(rawCID, cnr[:])

req := &control.SynchronizeTreeRequest{
Body: &control.SynchronizeTreeRequest_Body{
Expand Down
22 changes: 11 additions & 11 deletions cmd/neofs-cli/modules/object/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ func marshalHeader(cmd *cobra.Command, hdr *object.Object) ([]byte, error) {
}
}

func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {
func printObjectID(cmd *cobra.Command, recv func() oid.ID) {
var strID string

id, ok := recv()
if ok {
id := recv()
if !id.IsZero() {
strID = id.String()
} else {
strID = "<empty>"
Expand All @@ -148,11 +148,11 @@ func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {
cmd.Printf("ID: %s\n", strID)
}

func printContainerID(cmd *cobra.Command, recv func() (cid.ID, bool)) {
func printContainerID(cmd *cobra.Command, recv func() cid.ID) {
var strID string

id, ok := recv()
if ok {
id := recv()
if !id.IsZero() {
strID = id.String()
} else {
strID = "<empty>"
Expand All @@ -162,8 +162,8 @@ func printContainerID(cmd *cobra.Command, recv func() (cid.ID, bool)) {
}

func printHeader(cmd *cobra.Command, obj *object.Object) error {
printObjectID(cmd, obj.ID)
printContainerID(cmd, obj.ContainerID)
printObjectID(cmd, obj.GetID)
printContainerID(cmd, obj.GetContainerID)
cmd.Printf("Owner: %s\n", obj.OwnerID())
cmd.Printf("CreatedAt: %d\n", obj.CreationEpoch())
cmd.Printf("Size: %d\n", obj.PayloadSize())
Expand Down Expand Up @@ -197,11 +197,11 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error {
cmd.Printf("Split ID: %s\n", splitID)
}

if oid, ok := obj.ParentID(); ok {
cmd.Printf("Split ParentID: %s\n", oid)
if oID := obj.GetParentID(); !oID.IsZero() {
cmd.Printf("Split ParentID: %s\n", oID)
}

if prev, ok := obj.PreviousID(); ok {
if prev := obj.GetPreviousID(); !prev.IsZero() {
cmd.Printf("Split PreviousID: %s\n", prev)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/object/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var objectLockCmd = &cobra.Command{
return err
}

idOwner := user.ResolveFromECDSAPublicKey(key.PublicKey)
idOwner := user.NewFromECDSAPublicKey(key.PublicKey)

var lock objectSDK.Lock
lock.WriteMembers(lockList)
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-cli/modules/object/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func putObject(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't unmarshal object from given file: %w", err)
}
payloadReader = bytes.NewReader(objTemp.Payload())
cnr, _ = objTemp.ContainerID()
cnr = objTemp.GetContainerID()
ownerID = *objTemp.OwnerID()
} else {
fi, err := f.Stat()
Expand All @@ -108,7 +108,7 @@ func putObject(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
ownerID = user.ResolveFromECDSAPublicKey(pk.PublicKey)
ownerID = user.NewFromECDSAPublicKey(pk.PublicKey)
}

attrs, err := parseObjectAttrs(cmd)
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-cli/modules/object/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func marshalSplitInfo(cmd *cobra.Command, info *object.SplitInfo) ([]byte, error
if splitID := info.SplitID(); splitID != nil {
b.WriteString("Split ID: " + splitID.String() + "\n")
}
if link, ok := info.Link(); ok {
if link := info.GetLink(); !link.IsZero() {
b.WriteString("Linking object: " + link.String() + "\n")
}
if last, ok := info.LastPart(); ok {
if last := info.GetLastPart(); !last.IsZero() {
b.WriteString("Last object: " + last.String() + "\n")
}
return b.Bytes(), nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/neofs-cli/modules/object/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func readObjectAddressBin(cnr *cid.ID, obj *oid.ID, filename string) (oid.Addres
}

var addr oid.Address
*cnr, _ = objTemp.ContainerID()
*obj, _ = objTemp.ID()
*cnr = objTemp.GetContainerID()
*obj = objTemp.GetID()
addr.SetContainer(*cnr)
addr.SetObject(*obj)
return addr, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/storagegroup/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func putSG(cmd *cobra.Command, _ []string) error {
return err
}

ownerID := user.ResolveFromECDSAPublicKey(pk.PublicKey)
ownerID := user.NewFromECDSAPublicKey(pk.PublicKey)

var cnr cid.ID
err = readCID(cmd, &cnr)
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func add(cmd *cobra.Command, _ []string) error {
}

rawCID := make([]byte, sha256.Size)
cnr.Encode(rawCID)
copy(rawCID, cnr[:])

req := new(tree.AddRequest)
req.Body = &tree.AddRequest_Body{
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/add_by_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func addByPath(cmd *cobra.Command, _ []string) error {
}

rawCID := make([]byte, sha256.Size)
cnr.Encode(rawCID)
copy(rawCID, cnr[:])

meta, err := parseMeta(cmd)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/get_by_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func getByPath(cmd *cobra.Command, _ []string) error {
}

rawCID := make([]byte, sha256.Size)
cnr.Encode(rawCID)
copy(rawCID, cnr[:])

latestOnly, _ := cmd.Flags().GetBool(latestOnlyFlagKey)
path, _ := cmd.Flags().GetString(pathFlagKey)
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/tree/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func list(cmd *cobra.Command, _ []string) error {
}

rawCID := make([]byte, sha256.Size)
cnr.Encode(rawCID)
copy(rawCID, cnr[:])

req := &tree.TreeListRequest{
Body: &tree.TreeListRequest_Body{
Expand Down
10 changes: 6 additions & 4 deletions cmd/neofs-cli/modules/util/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func PrettyPrintTableEACL(cmd *cobra.Command, table *eacl.Table) {
func eaclTargetsToString(ts []eacl.Target) string {
b := bytes.NewBuffer(nil)
for _, t := range ts {
keysExists := len(t.BinaryKeys()) > 0
keysExists := len(t.RawSubjects()) > 0
switch t.Role() {
case eacl.RoleUser:
b.WriteString("User")
Expand All @@ -107,7 +107,7 @@ func eaclTargetsToString(ts []eacl.Target) string {
}
}

for i, pub := range t.BinaryKeys() {
for i, pub := range t.RawSubjects() {
if i != 0 {
b.WriteString(" ")
}
Expand Down Expand Up @@ -286,8 +286,10 @@ func parseEACLRecord(args []string) (eacl.Record, error) {
continue
}

var target eacl.Target
eacl.SetTargetECDSAKeys(&target, pubs...)
target := eacl.NewTargetByRole(eacl.RoleUnspecified)
for _, pub := range pubs {
target.SetRawSubjects(append(target.RawSubjects(), (*keys.PublicKey)(pub).Bytes()))
}
targets = append(targets, target)
case "address": // targets
var (
Expand Down
18 changes: 9 additions & 9 deletions cmd/neofs-cli/modules/util/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ func anyValidEACL() eacl.Table {

func TestValidateEACL(t *testing.T) {
t.Run("absence matcher", func(t *testing.T) {
var r eacl.Record
r.AddObjectAttributeFilter(eacl.MatchNotPresent, "any_key", "any_value")
r := eacl.ConstructRecord(eacl.ActionUnspecified, eacl.OperationUnspecified, []eacl.Target{},
eacl.NewObjectPropertyFilter("any_key", eacl.MatchNotPresent, "any_value"))
tb := anyValidEACL()
tb.AddRecord(&r)
tb.SetRecords([]eacl.Record{r})

err := ValidateEACLTable(tb)
require.ErrorContains(t, err, "non-empty value in absence filter")

r = eacl.Record{}
r.AddObjectAttributeFilter(eacl.MatchNotPresent, "any_key", "")
r = eacl.ConstructRecord(eacl.ActionUnspecified, eacl.OperationUnspecified, []eacl.Target{},
eacl.NewObjectPropertyFilter("any_key", eacl.MatchNotPresent, ""))
tb = anyValidEACL()
tb.AddRecord(&r)
tb.SetRecords([]eacl.Record{r})

err = ValidateEACLTable(tb)
require.NoError(t, err)
Expand All @@ -119,10 +119,10 @@ func TestValidateEACL(t *testing.T) {
{true, "-1111111111111111111111111111111111111111111111"},
} {
for _, m := range allNumMatchers {
var r eacl.Record
r.AddObjectAttributeFilter(m, "any_key", tc.v)
r := eacl.ConstructRecord(eacl.ActionUnspecified, eacl.OperationUnspecified, []eacl.Target{},
eacl.NewObjectPropertyFilter("any_key", m, tc.v))
tb := anyValidEACL()
tb.AddRecord(&r)
tb.SetRecords([]eacl.Record{r})

err := ValidateEACLTable(tb)
if tc.ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-cli/modules/util/sign_bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func signBearerToken(cmd *cobra.Command, _ []string) error {

signer := user.NewAutoIDSignerRFC6979(*pk)
var zeroUsr user.ID
if issuer := btok.Issuer(); !issuer.Equals(zeroUsr) {
if issuer := btok.Issuer(); issuer != zeroUsr {
// issuer is already set, don't corrupt it
signer = user.NewSigner(signer, issuer)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/neofs-lens/internal/meta/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ func getFunc(cmd *cobra.Command, _ []string) error {

res, err := db.Get(prm)
if errors.As(err, &siErr) {
link, linkSet := siErr.SplitInfo().Link()
last, lastSet := siErr.SplitInfo().LastPart()
link := siErr.SplitInfo().GetLink()
last := siErr.SplitInfo().GetLastPart()

fmt.Println("Object is split")
cmd.Println("\tSplitID:", siErr.SplitInfo().SplitID().String())

if linkSet {
if !link.IsZero() {
cmd.Println("\tLink:", link)
}
if lastSet {
if !last.IsZero() {
cmd.Println("\tLast:", last)
}

Expand Down
Loading

0 comments on commit f34d244

Please sign in to comment.