forked from TrueCloudLab/frostfs-node
[#248] morph: Remove audit client
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
b2bc1fccbc
commit
f368ccbdf0
5 changed files with 0 additions and 265 deletions
|
@ -1,40 +0,0 @@
|
|||
package audit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// Client is a wrapper over StaticClient
|
||||
// which makes calls with the names and arguments
|
||||
// of the FrostFS Audit contract.
|
||||
//
|
||||
// Working client must be created via constructor New.
|
||||
// Using the Client that has been created with new(Client)
|
||||
// expression (or just declaring a Client variable) is unsafe
|
||||
// and can lead to panic.
|
||||
type Client struct {
|
||||
client *client.StaticClient // static Audit contract client
|
||||
}
|
||||
|
||||
const (
|
||||
putResultMethod = "put"
|
||||
getResultMethod = "get"
|
||||
listResultsMethod = "list"
|
||||
listByEpochResultsMethod = "listByEpoch"
|
||||
listByCIDResultsMethod = "listByCID"
|
||||
listByNodeResultsMethod = "listByNode"
|
||||
)
|
||||
|
||||
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...client.StaticClientOption) (*Client, error) {
|
||||
sc, err := client.NewStatic(cli, contract, fee, opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create static client of audit contract: %w", err)
|
||||
}
|
||||
|
||||
return &Client{client: sc}, nil
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package audit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
auditAPI "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/audit"
|
||||
)
|
||||
|
||||
// GetAuditResult returns audit result structure stored in audit contract.
|
||||
func (c *Client) GetAuditResult(id ResultID) (*auditAPI.Result, error) {
|
||||
prm := client.TestInvokePrm{}
|
||||
prm.SetMethod(getResultMethod)
|
||||
prm.SetArgs([]byte(id))
|
||||
|
||||
prms, err := c.client.TestInvoke(prm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform test invocation (%s): %w", getResultMethod, err)
|
||||
} else if ln := len(prms); ln != 1 {
|
||||
return nil, fmt.Errorf("unexpected stack item count (%s): %d", getResultMethod, ln)
|
||||
}
|
||||
|
||||
value, err := client.BytesFromStackItem(prms[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", getResultMethod, err)
|
||||
}
|
||||
|
||||
var auditRes auditAPI.Result
|
||||
if err := auditRes.Unmarshal(value); err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal audit result structure: %w", err)
|
||||
}
|
||||
|
||||
return &auditRes, nil
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package audit
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
)
|
||||
|
||||
// ListAllAuditResultID returns a list of all audit result IDs inside audit contract.
|
||||
func (c *Client) ListAllAuditResultID() ([]ResultID, error) {
|
||||
invokePrm := client.TestInvokePrm{}
|
||||
invokePrm.SetMethod(listResultsMethod)
|
||||
|
||||
items, err := c.client.TestInvoke(invokePrm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listResultsMethod, err)
|
||||
}
|
||||
return parseAuditResults(items, listResultsMethod)
|
||||
}
|
||||
|
||||
// ListAuditResultIDByEpoch returns a list of audit result IDs inside audit
|
||||
// contract for specific epoch number.
|
||||
func (c *Client) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, error) {
|
||||
prm := client.TestInvokePrm{}
|
||||
prm.SetMethod(listByEpochResultsMethod)
|
||||
prm.SetArgs(epoch)
|
||||
|
||||
items, err := c.client.TestInvoke(prm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByEpochResultsMethod, err)
|
||||
}
|
||||
return parseAuditResults(items, listByEpochResultsMethod)
|
||||
}
|
||||
|
||||
// ListAuditResultIDByCID returns a list of audit result IDs inside audit
|
||||
// contract for specific epoch number and container ID.
|
||||
func (c *Client) ListAuditResultIDByCID(epoch uint64, cnr cid.ID) ([]ResultID, error) {
|
||||
binCnr := make([]byte, sha256.Size)
|
||||
cnr.Encode(binCnr)
|
||||
|
||||
prm := client.TestInvokePrm{}
|
||||
prm.SetMethod(listByCIDResultsMethod)
|
||||
prm.SetArgs(epoch, binCnr)
|
||||
|
||||
items, err := c.client.TestInvoke(prm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByCIDResultsMethod, err)
|
||||
}
|
||||
return parseAuditResults(items, listByCIDResultsMethod)
|
||||
}
|
||||
|
||||
// ListAuditResultIDByNode returns a list of audit result IDs inside audit
|
||||
// contract for specific epoch number, container ID and inner ring public key.
|
||||
func (c *Client) ListAuditResultIDByNode(epoch uint64, cnr cid.ID, nodeKey []byte) ([]ResultID, error) {
|
||||
binCnr := make([]byte, sha256.Size)
|
||||
cnr.Encode(binCnr)
|
||||
|
||||
prm := client.TestInvokePrm{}
|
||||
prm.SetMethod(listByNodeResultsMethod)
|
||||
prm.SetArgs(epoch, binCnr, nodeKey)
|
||||
|
||||
items, err := c.client.TestInvoke(prm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not perform test invocation (%s): %w", listByNodeResultsMethod, err)
|
||||
}
|
||||
return parseAuditResults(items, listByNodeResultsMethod)
|
||||
}
|
||||
|
||||
func parseAuditResults(items []stackitem.Item, method string) ([]ResultID, error) {
|
||||
if ln := len(items); ln != 1 {
|
||||
return nil, fmt.Errorf("unexpected stack item count (%s): %d", method, ln)
|
||||
}
|
||||
|
||||
items, err := client.ArrayFromStackItem(items[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get stack item array from stack item (%s): %w", method, err)
|
||||
}
|
||||
|
||||
res := make([]ResultID, 0, len(items))
|
||||
for i := range items {
|
||||
rawRes, err := client.BytesFromStackItem(items[i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get byte array from stack item (%s): %w", method, err)
|
||||
}
|
||||
|
||||
res = append(res, rawRes)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package audit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
auditAPI "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/audit"
|
||||
)
|
||||
|
||||
// ResultID is an identity of audit result inside audit contract.
|
||||
type ResultID []byte
|
||||
|
||||
// PutPrm groups parameters of PutAuditResult operation.
|
||||
type PutPrm struct {
|
||||
result *auditAPI.Result
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetResult sets audit result.
|
||||
func (p *PutPrm) SetResult(result *auditAPI.Result) {
|
||||
p.result = result
|
||||
}
|
||||
|
||||
// PutAuditResult saves passed audit result structure in FrostFS system
|
||||
// through Audit contract call.
|
||||
//
|
||||
// Returns encountered error that caused the saving to interrupt.
|
||||
func (c *Client) PutAuditResult(p PutPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
prm.SetMethod(putResultMethod)
|
||||
prm.SetArgs(p.result.Marshal())
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
err := c.client.Invoke(prm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", putResultMethod, err)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
auditAPI "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/audit"
|
||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuditResults(t *testing.T) {
|
||||
t.Skip()
|
||||
const epoch = 11
|
||||
|
||||
endpoint := "http://morph_chain.frostfs.devenv:30333"
|
||||
sAuditHash := "cdfb3dab86e6d60e8a143d9e2ecb0b188f3dc2eb"
|
||||
irKeyWIF := "L3o221BojgcCPYgdbXsm6jn7ayTZ72xwREvBHXKknR8VJ3G4WmjB"
|
||||
|
||||
key, err := keys.NewPrivateKeyFromWIF(irKeyWIF)
|
||||
require.NoError(t, err)
|
||||
|
||||
auditHash, err := util.Uint160DecodeStringLE(sAuditHash)
|
||||
require.NoError(t, err)
|
||||
|
||||
morphClient, err := client.New(context.Background(), key, client.WithEndpoints(client.Endpoint{Address: endpoint}))
|
||||
require.NoError(t, err)
|
||||
|
||||
auditClientWrapper, err := NewFromMorph(morphClient, auditHash, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
id := cidtest.ID()
|
||||
|
||||
var auditRes auditAPI.Result
|
||||
auditRes.ForEpoch(epoch)
|
||||
auditRes.SetAuditorKey(key.PublicKey().Bytes())
|
||||
auditRes.ForContainer(id)
|
||||
|
||||
prm := PutPrm{}
|
||||
prm.SetResult(&auditRes)
|
||||
|
||||
require.NoError(t, auditClientWrapper.PutAuditResult(prm))
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
list, err := auditClientWrapper.ListAuditResultIDByCID(epoch, id)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, list, 1)
|
||||
|
||||
savedAuditRes, err := auditClientWrapper.GetAuditResult(list[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, auditRes, savedAuditRes)
|
||||
}
|
Loading…
Reference in a new issue