Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #270 from nspcc-dev/upgrade/sdk
Browse files Browse the repository at this point in the history
Upgrade NeoFS SDK to RC-11
  • Loading branch information
roman-khimov authored Sep 8, 2023
2 parents 507790b + c6601ff commit 237f0a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
10 changes: 2 additions & 8 deletions downloader/head.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package downloader

import (
"errors"
"io"
"net/http"
"strconv"
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ 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.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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 4 additions & 4 deletions uploader/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -121,7 +121,7 @@ func prepareExpirationHeader(headers map[string]string, epochDurations *epochDur
}

if expirationInEpoch != "" {
headers[object.SysAttributeExpEpoch] = expirationInEpoch
headers[object.AttributeExpirationEpoch] = expirationInEpoch
}

return nil
Expand All @@ -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)
}
44 changes: 22 additions & 22 deletions uploader/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 237f0a9

Please sign in to comment.