From 1c25c3904baa8383dc21f0bfd59fba61b50d2ae2 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 21 Dec 2020 17:35:03 +0300 Subject: [PATCH] [#234] Update audit result struct definition Signed-off-by: Alex Vanin --- pkg/audit/result.go | 31 ++++++++++++++++++++++++++++++- pkg/audit/result_test.go | 5 +++++ v2/audit/convert.go | 12 ++++++++++++ v2/audit/grpc/types.go | 14 ++++++++++++++ v2/audit/grpc/types.pb.go | Bin 10610 -> 11822 bytes v2/audit/marshal.go | 18 ++++++++++++++++++ v2/audit/marshal_test.go | 6 ++++++ v2/audit/types.go | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 121 insertions(+), 1 deletion(-) diff --git a/pkg/audit/result.go b/pkg/audit/result.go index c5af81a..6f5ea9f 100644 --- a/pkg/audit/result.go +++ b/pkg/audit/result.go @@ -1,6 +1,7 @@ package audit import ( + "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/v2/audit" @@ -17,7 +18,10 @@ func NewResultFromV2(aV2 *audit.DataAuditResult) *Result { // New creates and initializes blank Result. func NewResult() *Result { - return NewResultFromV2(new(audit.DataAuditResult)) + r := NewResultFromV2(new(audit.DataAuditResult)) + r.SetVersion(pkg.SDKVersion()) + + return r } // ToV2 converts Result to v2 DataAuditResult message. @@ -57,6 +61,19 @@ func (r *Result) UnmarshalJSON(data []byte) error { UnmarshalJSON(data) } +// Version returns Data Audit structure version. +func (r *Result) Version() *pkg.Version { + return pkg.NewVersionFromV2( + (*audit.DataAuditResult)(r).GetVersion(), + ) +} + +// SetVersion sets Data Audit structure version. +func (r *Result) SetVersion(v *pkg.Version) { + (*audit.DataAuditResult)(r). + SetVersion(v.ToV2()) +} + // AuditEpoch returns epoch number when the Data Audit was conducted. func (r *Result) AuditEpoch() uint64 { return (*audit.DataAuditResult)(r). @@ -95,6 +112,18 @@ func (r *Result) SetPublicKey(key []byte) { SetPublicKey(key) } +// Complete returns completion state of audit result. +func (r *Result) Complete() bool { + return (*audit.DataAuditResult)(r). + GetComplete() +} + +// SetComplete sets completion state of audit result. +func (r *Result) SetComplete(v bool) { + (*audit.DataAuditResult)(r). + SetComplete(v) +} + // PassSG returns list of Storage Groups that passed audit PoR stage. func (r *Result) PassSG() []*object.ID { mV2 := (*audit.DataAuditResult)(r). diff --git a/pkg/audit/result_test.go b/pkg/audit/result_test.go index 8f86037..57038a3 100644 --- a/pkg/audit/result_test.go +++ b/pkg/audit/result_test.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "testing" + "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/audit" "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -32,6 +33,7 @@ func testOID() *object.ID { func TestResult(t *testing.T) { r := audit.NewResult() + require.Equal(t, pkg.SDKVersion(), r.Version()) epoch := uint64(13) r.SetAuditEpoch(epoch) @@ -45,6 +47,9 @@ func TestResult(t *testing.T) { r.SetPublicKey(key) require.Equal(t, key, r.PublicKey()) + r.SetComplete(true) + require.True(t, r.Complete()) + passSG := []*object.ID{testOID(), testOID()} r.SetPassSG(passSG) require.Equal(t, passSG, r.PassSG()) diff --git a/v2/audit/convert.go b/v2/audit/convert.go index 40dcd3b..4384953 100644 --- a/v2/audit/convert.go +++ b/v2/audit/convert.go @@ -14,6 +14,10 @@ func DataAuditResultToGRPCMessage(a *DataAuditResult) *audit.DataAuditResult { m := new(audit.DataAuditResult) + m.SetVersion( + refs.VersionToGRPCMessage(a.GetVersion()), + ) + m.SetAuditEpoch(a.GetAuditEpoch()) m.SetContainerId( @@ -22,6 +26,8 @@ func DataAuditResultToGRPCMessage(a *DataAuditResult) *audit.DataAuditResult { m.SetPublicKey(a.GetPublicKey()) + m.SetComplete(a.GetComplete()) + m.SetPassSg( refs.ObjectIDListToGRPCMessage(a.GetPassSG()), ) @@ -49,6 +55,10 @@ func DataAuditResultFromGRPCMessage(m *audit.DataAuditResult) *DataAuditResult { a := new(DataAuditResult) + a.SetVersion( + refs.VersionFromGRPCMessage(m.GetVersion()), + ) + a.SetAuditEpoch(m.GetAuditEpoch()) a.SetContainerID( @@ -57,6 +67,8 @@ func DataAuditResultFromGRPCMessage(m *audit.DataAuditResult) *DataAuditResult { a.SetPublicKey(m.GetPublicKey()) + a.SetComplete(m.GetComplete()) + a.SetPassSG( refs.ObjectIDListFromGRPCMessage(m.GetPassSg()), ) diff --git a/v2/audit/grpc/types.go b/v2/audit/grpc/types.go index 7390d89..2c225ef 100644 --- a/v2/audit/grpc/types.go +++ b/v2/audit/grpc/types.go @@ -4,6 +4,13 @@ import ( refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" ) +// SetVersion is a Version field setter. +func (x *DataAuditResult) SetVersion(v *refs.Version) { + if x != nil { + x.Version = v + } +} + // SetAuditEpoch is an AuditEpoch field setter. func (x *DataAuditResult) SetAuditEpoch(v uint64) { if x != nil { @@ -25,6 +32,13 @@ func (x *DataAuditResult) SetPublicKey(v []byte) { } } +// SetComplete is a Complete field setter. +func (x *DataAuditResult) SetComplete(v bool) { + if x != nil { + x.Complete = v + } +} + // SetPassSg is a PassSg field setter. func (x *DataAuditResult) SetPassSg(v []*refs.ObjectID) { if x != nil { diff --git a/v2/audit/grpc/types.pb.go b/v2/audit/grpc/types.pb.go index 10158d4ec74fa86e0ad24ec4a531d5dff84a7afe..32daf3a10fdb5ad6dd5ab1b126dc639768317b0a 100644 GIT binary patch delta 1643 zcmb7E&2Jl35Z4CB&Mr}t;MiV!o%qEz)QLah^~bs~B@h}EDnLL%kpigd+J2^s>|J+v zof1Bj!ii(0p`1X7J1SIG|AlfT0wh!+AtaD`C>NwkTvB*%cC9E-4*2lAGxM9@{APCc z{c-O48((h)_BVA`CmX|#;gWOI8TMS#wd}s`l3i*$hGmw>Gu-L@`uC9`yLp#K^h)oBU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