2022-06-06 11:09:09 +00:00
|
|
|
package layer
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
2022-04-25 09:57:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/bearer"
|
2022-03-04 13:07:27 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
2022-06-17 14:43:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
|
2022-03-04 13:07:27 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/eacl"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
2022-04-25 09:57:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
2022-03-04 13:07:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PrmContainerCreate groups parameters of NeoFS.CreateContainer operation.
|
|
|
|
type PrmContainerCreate struct {
|
|
|
|
// NeoFS identifier of the container creator.
|
2022-04-25 09:57:58 +00:00
|
|
|
Creator user.ID
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Container placement policy.
|
|
|
|
Policy netmap.PlacementPolicy
|
|
|
|
|
|
|
|
// Name for the container.
|
|
|
|
Name string
|
|
|
|
|
|
|
|
// Token of the container's creation session. Nil means session absence.
|
2022-05-04 12:29:11 +00:00
|
|
|
SessionToken *session.Container
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Basic ACL of the container.
|
2022-06-17 14:43:40 +00:00
|
|
|
BasicACL acl.Basic
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Attributes for optional parameters.
|
|
|
|
AdditionalAttributes [][2]string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmAuth groups authentication parameters for the NeoFS operation.
|
|
|
|
type PrmAuth struct {
|
|
|
|
// Bearer token to be used for the operation. Overlaps PrivateKey. Optional.
|
2022-04-25 09:57:58 +00:00
|
|
|
BearerToken *bearer.Token
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Private key used for the operation if BearerToken is missing (in this case non-nil).
|
|
|
|
PrivateKey *ecdsa.PrivateKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectSelect groups parameters of NeoFS.SelectObjects operation.
|
|
|
|
type PrmObjectSelect struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to select the objects from.
|
|
|
|
Container cid.ID
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// Key-value object attribute which should be
|
2022-03-04 13:07:27 +00:00
|
|
|
// presented in selected objects. Optional, empty key means any.
|
|
|
|
ExactAttribute [2]string
|
|
|
|
|
|
|
|
// File prefix of the selected objects. Optional, empty value means any.
|
|
|
|
FilePrefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectRead groups parameters of NeoFS.ReadObject operation.
|
|
|
|
type PrmObjectRead struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to read the object header from.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// ID of the object for which to read the header.
|
|
|
|
Object oid.ID
|
|
|
|
|
|
|
|
// Flag to read object header.
|
|
|
|
WithHeader bool
|
|
|
|
|
|
|
|
// Flag to read object payload. False overlaps payload range.
|
|
|
|
WithPayload bool
|
|
|
|
|
|
|
|
// Offset-length range of the object payload to be read.
|
|
|
|
PayloadRange [2]uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectPart represents partially read NeoFS object.
|
|
|
|
type ObjectPart struct {
|
|
|
|
// Object header with optional in-memory payload part.
|
|
|
|
Head *object.Object
|
|
|
|
|
|
|
|
// Object payload part encapsulated in io.Reader primitive.
|
|
|
|
// Returns ErrAccessDenied on read access violation.
|
|
|
|
Payload io.ReadCloser
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectCreate groups parameters of NeoFS.CreateObject operation.
|
|
|
|
type PrmObjectCreate struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to store the object.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// NeoFS identifier of the object creator.
|
2022-04-25 09:57:58 +00:00
|
|
|
Creator user.ID
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Key-value object attributes.
|
|
|
|
Attributes [][2]string
|
|
|
|
|
2022-03-04 14:36:30 +00:00
|
|
|
// List of ids to lock (optional).
|
|
|
|
Locks []oid.ID
|
|
|
|
|
2022-03-04 13:07:27 +00:00
|
|
|
// Full payload size (optional).
|
|
|
|
PayloadSize uint64
|
|
|
|
|
|
|
|
// Associated filename (optional).
|
|
|
|
Filename string
|
|
|
|
|
|
|
|
// Object payload encapsulated in io.Reader primitive.
|
|
|
|
Payload io.Reader
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectDelete groups parameters of NeoFS.DeleteObject operation.
|
|
|
|
type PrmObjectDelete struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to delete the object from.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// Identifier of the removed object.
|
|
|
|
Object oid.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrAccessDenied is returned from NeoFS in case of access violation.
|
|
|
|
var ErrAccessDenied = errors.New("access denied")
|
|
|
|
|
|
|
|
// NeoFS represents virtual connection to NeoFS network.
|
|
|
|
type NeoFS interface {
|
|
|
|
// CreateContainer creates and saves parameterized container in NeoFS.
|
2022-04-13 16:56:58 +00:00
|
|
|
// It sets 'Timestamp' attribute to the current time.
|
|
|
|
// It returns the ID of the saved container.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-06-10 01:59:17 +00:00
|
|
|
// Created container is public with enabled ACL extension.
|
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the container from being created.
|
2022-03-04 13:07:27 +00:00
|
|
|
CreateContainer(context.Context, PrmContainerCreate) (*cid.ID, error)
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// Container reads a container from NeoFS by ID.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the container from being read.
|
2022-03-04 13:07:27 +00:00
|
|
|
Container(context.Context, cid.ID) (*container.Container, error)
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// UserContainers reads a list of the containers owned by the specified user.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the containers from being listed.
|
2022-04-25 09:57:58 +00:00
|
|
|
UserContainers(context.Context, user.ID) ([]cid.ID, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-06-21 15:21:20 +00:00
|
|
|
// SetContainerEACL saves the eACL table of the container in NeoFS. The
|
|
|
|
// extended ACL is modified within session if session token is not nil.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns any error encountered which prevented the eACL from being saved.
|
2022-06-21 15:21:20 +00:00
|
|
|
SetContainerEACL(context.Context, eacl.Table, *session.Container) error
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// ContainerEACL reads the container eACL from NeoFS by the container ID.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the eACL from being read.
|
2022-03-04 13:07:27 +00:00
|
|
|
ContainerEACL(context.Context, cid.ID) (*eacl.Table, error)
|
|
|
|
|
|
|
|
// DeleteContainer marks the container to be removed from NeoFS by ID.
|
|
|
|
// Request is sent within session if the session token is specified.
|
2022-04-13 16:56:58 +00:00
|
|
|
// Successful return does not guarantee actual removal.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns any error encountered which prevented the removal request from being sent.
|
2022-05-04 12:29:11 +00:00
|
|
|
DeleteContainer(context.Context, cid.ID, *session.Container) error
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// SelectObjects performs object selection from the NeoFS container according
|
|
|
|
// to the specified parameters. It selects user's objects only.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns ErrAccessDenied on selection access violation.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the objects from being selected.
|
2022-03-04 13:07:27 +00:00
|
|
|
SelectObjects(context.Context, PrmObjectSelect) ([]oid.ID, error)
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// ReadObject reads a part of the object from the NeoFS container by identifier.
|
2022-03-04 13:07:27 +00:00
|
|
|
// Exact part is returned according to the parameters:
|
|
|
|
// * with header only: empty payload (both in-mem and reader parts are nil);
|
|
|
|
// * with payload only: header is nil (zero range means full payload);
|
|
|
|
// * with header and payload: full in-mem object, payload reader is nil.
|
|
|
|
//
|
|
|
|
// WithHeader or WithPayload is true. Range length is positive if offset is positive.
|
|
|
|
//
|
|
|
|
// Payload reader should be closed if it is no longer needed.
|
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns ErrAccessDenied on read access violation.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the object header from being read.
|
2022-03-04 13:07:27 +00:00
|
|
|
ReadObject(context.Context, PrmObjectRead) (*ObjectPart, error)
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// CreateObject creates and saves a parameterized object in the NeoFS container.
|
|
|
|
// It sets 'Timestamp' attribute to the current time.
|
|
|
|
// It returns the ID of the saved object.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// Creation time should be written into the object (UTC).
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns ErrAccessDenied on write access violation.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the container from being created.
|
2022-03-04 13:07:27 +00:00
|
|
|
CreateObject(context.Context, PrmObjectCreate) (*oid.ID, error)
|
|
|
|
|
|
|
|
// DeleteObject marks the object to be removed from the NeoFS container by identifier.
|
2022-04-13 16:56:58 +00:00
|
|
|
// Successful return does not guarantee actual removal.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns ErrAccessDenied on remove access violation.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns any error encountered which prevented the removal request from being sent.
|
2022-03-04 13:07:27 +00:00
|
|
|
DeleteObject(context.Context, PrmObjectDelete) error
|
2022-03-05 08:53:01 +00:00
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// TimeToEpoch computes current epoch and the epoch that corresponds to the provided time.
|
2022-03-05 08:53:01 +00:00
|
|
|
// Note:
|
|
|
|
// * time must be in the future
|
|
|
|
// * time will be ceil rounded to match epoch
|
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns any error encountered which prevented computing epochs.
|
2022-03-05 08:53:01 +00:00
|
|
|
TimeToEpoch(context.Context, time.Time) (uint64, uint64, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
}
|