frostfs-s3-gw/neofs/layer/gateway-neofs.go

65 lines
1.9 KiB
Go
Raw Normal View History

package layer
import (
"context"
"crypto/ecdsa"
"math"
"time"
2020-07-16 15:33:47 +00:00
s3auth "github.com/minio/minio/auth"
2020-07-09 09:23:09 +00:00
minio "github.com/minio/minio/legacy"
"github.com/minio/minio/neofs/pool"
"github.com/nspcc-dev/neofs-api-go/refs"
"github.com/nspcc-dev/neofs-api-go/service"
2020-07-07 11:31:55 +00:00
"github.com/pkg/errors"
2020-07-13 11:23:23 +00:00
"go.uber.org/zap"
)
type (
// neofsObjects implements gateway for MinIO and S3
// compatible object storage server.
neofsObject struct {
minio.GatewayUnsupported // placeholder for unimplemented functions
log *zap.Logger
cli pool.Client
key *ecdsa.PrivateKey
owner refs.OwnerID
token *service.Token
bearerToken *service.BearerTokenMsg
// Concurrency must be resolved by creating one lock per object, but
// it may be unnecessary in neofs, because objects are immutable. So
// there are no any mutexes and locks right now but it might be
// useful during parallel execution from one client (different clients
// have different `neofsObject` instances).
// todo: add fast expired cache to store list of containers or
// even short objects during sequential reading
}
)
// NewGatewayLayer creates instance of neofsObject. It checks credentials
// and establishes gRPC connection with node.
func NewLayer(log *zap.Logger, cli pool.Client, center *s3auth.Center) (minio.ObjectLayer, error) {
// setup gRPC connection
// todo: think about getting timeout parameters from cli args
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
token, err := generateToken(ctx, tokenParams{
cli: cli,
2020-07-16 15:33:47 +00:00
key: center.GetNeoFSKeyPrivateKey(),
until: math.MaxInt64,
})
if err != nil {
2020-07-07 11:31:55 +00:00
return nil, errors.Wrap(err, "can't establish neofs session with remote host")
}
return &neofsObject{
cli: cli,
2020-07-16 15:33:47 +00:00
key: center.GetNeoFSKeyPrivateKey(),
2020-07-13 11:23:23 +00:00
log: log,
2020-07-16 15:33:47 +00:00
owner: center.GetOwnerID(),
token: token,
}, nil
}