2020-07-03 13:52:04 +00:00
|
|
|
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"
|
2020-07-03 13:52:04 +00:00
|
|
|
"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"
|
2020-07-03 13:52:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
// neofsObjects implements gateway for MinIO and S3
|
|
|
|
// compatible object storage server.
|
|
|
|
neofsObject struct {
|
|
|
|
minio.GatewayUnsupported // placeholder for unimplemented functions
|
|
|
|
|
2020-07-20 17:23:16 +00:00
|
|
|
log *zap.Logger
|
|
|
|
cli pool.Client
|
|
|
|
key *ecdsa.PrivateKey
|
|
|
|
owner refs.OwnerID
|
|
|
|
token *service.Token
|
|
|
|
bearerToken *service.BearerTokenMsg
|
2020-07-03 13:52:04 +00:00
|
|
|
|
|
|
|
// 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.
|
2020-07-20 17:23:16 +00:00
|
|
|
func NewLayer(log *zap.Logger, cli pool.Client, center *s3auth.Center) (minio.ObjectLayer, error) {
|
2020-07-03 13:52:04 +00:00
|
|
|
// 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-21 09:44:25 +00:00
|
|
|
key: center.GetNeoFSPrivateKey(),
|
2020-07-03 13:52:04 +00:00
|
|
|
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")
|
2020-07-03 13:52:04 +00:00
|
|
|
}
|
|
|
|
return &neofsObject{
|
|
|
|
cli: cli,
|
2020-07-21 09:44:25 +00:00
|
|
|
key: center.GetNeoFSPrivateKey(),
|
2020-07-13 11:23:23 +00:00
|
|
|
log: log,
|
2020-07-16 15:33:47 +00:00
|
|
|
owner: center.GetOwnerID(),
|
2020-07-03 13:52:04 +00:00
|
|
|
token: token,
|
|
|
|
}, nil
|
|
|
|
}
|