From fda51836daeeb1ce14e32dcd72b50411481fbe90 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 7 Sep 2023 19:59:20 +0400 Subject: [PATCH 1/2] go.mod: Upgrade to NeoFS SDK module to RC-11 Client pool's `ObjectHead` method returns object header directly now. Signed-off-by: Leonard Lyubich --- downloader/head.go | 10 ++-------- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/downloader/head.go b/downloader/head.go index 8a93930..8e70545 100644 --- a/downloader/head.go +++ b/downloader/head.go @@ -1,7 +1,6 @@ package downloader import ( - "errors" "io" "net/http" "strconv" @@ -44,17 +43,12 @@ func (r request) headObject(clnt *pool.Pool, objectAddress oid.Address, signer u prm.WithBearerToken(*btoken) } - headResult, err := clnt.ObjectHead(r.appCtx, objectAddress.Container(), objectAddress.Object(), signer, prm) + obj, err := clnt.ObjectHead(r.appCtx, objectAddress.Container(), objectAddress.Object(), signer, prm) if err != nil { r.handleNeoFSErr(err, start) return } - var obj object.Object - if !headResult.ReadHeader(&obj) { - r.handleNeoFSErr(errors.New("header failed"), start) - } - r.Response.Header.Set(fasthttp.HeaderContentLength, strconv.FormatUint(obj.PayloadSize(), 10)) var contentType string for _, attr := range obj.Attributes() { @@ -83,7 +77,7 @@ func (r request) headObject(clnt *pool.Pool, objectAddress oid.Address, signer u } } - idsToResponse(&r.Response, &obj) + idsToResponse(&r.Response, obj) if len(contentType) == 0 { contentType, _, err = readContentType(obj.PayloadSize(), func(sz uint64) (io.Reader, error) { diff --git a/go.mod b/go.mod index 82b6f25..bc9b3e8 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/nspcc-dev/neo-go v0.101.0 github.com/nspcc-dev/neofs-api-go/v2 v2.14.0 github.com/nspcc-dev/neofs-contract v0.17.1-0.20230804121740-84ff5d244f69 - github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.10.0.20230808103753-5988a0b0c25d + github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11 github.com/prometheus/client_golang v1.14.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.8.1 diff --git a/go.sum b/go.sum index 7366faa..a4d481f 100644 --- a/go.sum +++ b/go.sum @@ -312,8 +312,8 @@ github.com/nspcc-dev/neofs-contract v0.17.1-0.20230804121740-84ff5d244f69 h1:Vw7 github.com/nspcc-dev/neofs-contract v0.17.1-0.20230804121740-84ff5d244f69/go.mod h1:SRedxMO37yDLu+5pvlbGKo3ZTMMUgVFkk8N2YVMC91g= github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4= github.com/nspcc-dev/neofs-crypto v0.4.0/go.mod h1:6XJ8kbXgOfevbI2WMruOtI+qUJXNwSGM/E9eClXxPHs= -github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.10.0.20230808103753-5988a0b0c25d h1:P0IwMErW4iNQkBpOLY1V99Z5haZ1HMrGeWTMBHURnoM= -github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.10.0.20230808103753-5988a0b0c25d/go.mod h1:W+ImTNRnSNMH8w43H1knCcIqwu7dLHePXtlJNZ7EFIs= +github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11 h1:QOc8ZRN5DXlAeRPh5QG9u8rMLgoeRNiZF5/vL7QupWg= +github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11/go.mod h1:W+ImTNRnSNMH8w43H1knCcIqwu7dLHePXtlJNZ7EFIs= github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/tzhash v1.7.0 h1:/+aL33NC7y5OIGnY2kYgjZt8mg7LVGFMdj/KAJLndnk= From c6601ff295084ab53cebe26c3cb91f0a54a582b2 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 7 Sep 2023 20:08:10 +0400 Subject: [PATCH 2/2] object: Use new constant key to the expiration attribute The constant is now declared in the NeoFS SDK and has same value, so NeoFS API Go usage is not needed anymore for this. After this change `github.com/nspcc-dev/neofs-api-go/v2` module is no longer used by the repository. Signed-off-by: Leonard Lyubich --- go.mod | 2 +- uploader/filter.go | 8 ++++---- uploader/filter_test.go | 44 ++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index bc9b3e8..dcd93e5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/docker/docker v24.0.5+incompatible github.com/fasthttp/router v1.4.1 github.com/nspcc-dev/neo-go v0.101.0 - github.com/nspcc-dev/neofs-api-go/v2 v2.14.0 github.com/nspcc-dev/neofs-contract v0.17.1-0.20230804121740-84ff5d244f69 github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11 github.com/prometheus/client_golang v1.14.0 @@ -54,6 +53,7 @@ require ( github.com/mr-tron/base58 v1.2.0 // indirect github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 // indirect github.com/nspcc-dev/hrw v1.0.9 // indirect + github.com/nspcc-dev/neofs-api-go/v2 v2.14.0 // indirect github.com/nspcc-dev/neofs-crypto v0.4.0 // indirect github.com/nspcc-dev/rfc6979 v0.2.0 // indirect github.com/nspcc-dev/tzhash v1.7.0 // indirect diff --git a/uploader/filter.go b/uploader/filter.go index c7349c7..529f595 100644 --- a/uploader/filter.go +++ b/uploader/filter.go @@ -7,8 +7,8 @@ import ( "strconv" "time" - "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-http-gw/utils" + "github.com/nspcc-dev/neofs-sdk-go/object" "github.com/valyala/fasthttp" "go.uber.org/zap" ) @@ -79,7 +79,7 @@ func filterHeaders(l *zap.Logger, header *fasthttp.RequestHeader) (map[string]st } func prepareExpirationHeader(headers map[string]string, epochDurations *epochDurations, now time.Time) error { - expirationInEpoch := headers[object.SysAttributeExpEpoch] + expirationInEpoch := headers[object.AttributeExpirationEpoch] if timeRFC3339, ok := headers[utils.ExpirationRFC3339Attr]; ok { expTime, err := time.Parse(time.RFC3339, timeRFC3339) @@ -121,7 +121,7 @@ func prepareExpirationHeader(headers map[string]string, epochDurations *epochDur } if expirationInEpoch != "" { - headers[object.SysAttributeExpEpoch] = expirationInEpoch + headers[object.AttributeExpirationEpoch] = expirationInEpoch } return nil @@ -141,5 +141,5 @@ func updateExpirationHeader(headers map[string]string, durations *epochDurations expirationEpoch = currentEpoch + numEpoch } - headers[object.SysAttributeExpEpoch] = strconv.FormatUint(expirationEpoch, 10) + headers[object.AttributeExpirationEpoch] = strconv.FormatUint(expirationEpoch, 10) } diff --git a/uploader/filter_test.go b/uploader/filter_test.go index de4c541..d8cd0cf 100644 --- a/uploader/filter_test.go +++ b/uploader/filter_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-http-gw/utils" + "github.com/nspcc-dev/neofs-sdk-go/object" "github.com/stretchr/testify/require" "github.com/valyala/fasthttp" "go.uber.org/zap" @@ -90,71 +90,71 @@ func TestPrepareExpirationHeader(t *testing.T) { }{ { name: "valid epoch", - headers: map[string]string{object.SysAttributeExpEpoch: epoch}, - expected: map[string]string{object.SysAttributeExpEpoch: epoch}, + headers: map[string]string{object.AttributeExpirationEpoch: epoch}, + expected: map[string]string{object.AttributeExpirationEpoch: epoch}, }, { name: "valid epoch, valid duration", headers: map[string]string{ - object.SysAttributeExpEpoch: epoch, - utils.ExpirationDurationAttr: duration, + object.AttributeExpirationEpoch: epoch, + utils.ExpirationDurationAttr: duration, }, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: epoch}, + expected: map[string]string{object.AttributeExpirationEpoch: epoch}, }, { name: "valid epoch, valid rfc3339", headers: map[string]string{ - object.SysAttributeExpEpoch: epoch, - utils.ExpirationRFC3339Attr: tomorrow.Format(time.RFC3339), + object.AttributeExpirationEpoch: epoch, + utils.ExpirationRFC3339Attr: tomorrow.Format(time.RFC3339), }, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: epoch}, + expected: map[string]string{object.AttributeExpirationEpoch: epoch}, }, { name: "valid epoch, valid timestamp sec", headers: map[string]string{ - object.SysAttributeExpEpoch: epoch, - utils.ExpirationTimestampAttr: timestampSec, + object.AttributeExpirationEpoch: epoch, + utils.ExpirationTimestampAttr: timestampSec, }, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: epoch}, + expected: map[string]string{object.AttributeExpirationEpoch: epoch}, }, { name: "valid epoch, valid timestamp milli", headers: map[string]string{ - object.SysAttributeExpEpoch: epoch, - utils.ExpirationTimestampAttr: timestampMilli, + object.AttributeExpirationEpoch: epoch, + utils.ExpirationTimestampAttr: timestampMilli, }, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: epoch}, + expected: map[string]string{object.AttributeExpirationEpoch: epoch}, }, { name: "valid epoch, valid timestamp nano", headers: map[string]string{ - object.SysAttributeExpEpoch: epoch, - utils.ExpirationTimestampAttr: timestampNano, + object.AttributeExpirationEpoch: epoch, + utils.ExpirationTimestampAttr: timestampNano, }, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: epoch}, + expected: map[string]string{object.AttributeExpirationEpoch: epoch}, }, { name: "valid timestamp sec", headers: map[string]string{utils.ExpirationTimestampAttr: timestampSec}, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: defaultExpEpoch}, + expected: map[string]string{object.AttributeExpirationEpoch: defaultExpEpoch}, }, { name: "valid duration", headers: map[string]string{utils.ExpirationDurationAttr: duration}, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: defaultExpEpoch}, + expected: map[string]string{object.AttributeExpirationEpoch: defaultExpEpoch}, }, { name: "valid rfc3339", headers: map[string]string{utils.ExpirationRFC3339Attr: tomorrow.Format(time.RFC3339)}, durations: defaultDurations, - expected: map[string]string{object.SysAttributeExpEpoch: defaultExpEpoch}, + expected: map[string]string{object.AttributeExpirationEpoch: defaultExpEpoch}, }, { name: "valid max uint 64", @@ -164,7 +164,7 @@ func TestPrepareExpirationHeader(t *testing.T) { msPerBlock: defaultDurations.msPerBlock, blockPerEpoch: defaultDurations.blockPerEpoch, }, - expected: map[string]string{object.SysAttributeExpEpoch: strconv.FormatUint(uint64(math.MaxUint64), 10)}, + expected: map[string]string{object.AttributeExpirationEpoch: strconv.FormatUint(uint64(math.MaxUint64), 10)}, }, { name: "invalid timestamp sec",