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"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2022-03-04 13:07:27 +00:00
|
|
|
)
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// PrmContainerCreate groups parameters of FrostFS.CreateContainer operation.
|
2022-03-04 13:07:27 +00:00
|
|
|
type PrmContainerCreate struct {
|
2022-12-20 08:38:58 +00:00
|
|
|
// FrostFS 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
|
|
|
|
|
2023-11-23 07:44:50 +00:00
|
|
|
// Zone for container registration.
|
|
|
|
Zone string
|
|
|
|
|
2022-11-08 09:12:55 +00:00
|
|
|
// CreationTime value for Timestamp attribute
|
|
|
|
CreationTime time.Time
|
|
|
|
|
2022-03-04 13:07:27 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-03-01 14:11:07 +00:00
|
|
|
// PrmContainer groups parameters of FrostFS.Container operation.
|
|
|
|
type PrmContainer struct {
|
|
|
|
// Container identifier.
|
|
|
|
ContainerID cid.ID
|
|
|
|
|
|
|
|
// Token of the container's creation session. Nil means session absence.
|
|
|
|
SessionToken *session.Container
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrmUserContainers groups parameters of FrostFS.UserContainers operation.
|
|
|
|
type PrmUserContainers struct {
|
|
|
|
// User identifier.
|
|
|
|
UserID user.ID
|
|
|
|
|
|
|
|
// Token of the container's creation session. Nil means session absence.
|
|
|
|
SessionToken *session.Container
|
|
|
|
}
|
|
|
|
|
2023-08-25 10:06:43 +00:00
|
|
|
// ContainerCreateResult is a result parameter of FrostFS.CreateContainer operation.
|
|
|
|
type ContainerCreateResult struct {
|
|
|
|
ContainerID cid.ID
|
|
|
|
HomomorphicHashDisabled bool
|
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// PrmAuth groups authentication parameters for the FrostFS operation.
|
2022-03-04 13:07:27 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
// PrmObjectHead groups parameters of FrostFS.HeadObject operation.
|
|
|
|
type PrmObjectHead struct {
|
2022-03-04 13:07:27 +00:00
|
|
|
// 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
|
2024-07-15 12:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PrmObjectGet groups parameters of FrostFS.GetObject operation.
|
|
|
|
type PrmObjectGet 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
|
|
|
|
}
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
// PrmObjectRange groups parameters of FrostFS.RangeObject operation.
|
|
|
|
type PrmObjectRange struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
// Container to read the object header from.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// ID of the object for which to read the header.
|
|
|
|
Object oid.ID
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Offset-length range of the object payload to be read.
|
|
|
|
PayloadRange [2]uint64
|
|
|
|
}
|
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
// Object represents full read FrostFS object.
|
|
|
|
type Object struct {
|
|
|
|
// Object header (doesn't contain payload).
|
|
|
|
Header object.Object
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Object payload part encapsulated in io.Reader primitive.
|
|
|
|
// Returns ErrAccessDenied on read access violation.
|
|
|
|
Payload io.ReadCloser
|
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// PrmObjectCreate groups parameters of FrostFS.CreateObject operation.
|
2022-03-04 13:07:27 +00:00
|
|
|
type PrmObjectCreate struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to store the object.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// Key-value object attributes.
|
|
|
|
Attributes [][2]string
|
|
|
|
|
2022-11-08 09:12:55 +00:00
|
|
|
// Value for Timestamp attribute (optional).
|
|
|
|
CreationTime time.Time
|
|
|
|
|
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
|
|
|
|
|
2022-09-07 06:59:24 +00:00
|
|
|
// Associated filepath (optional).
|
|
|
|
Filepath string
|
2022-03-04 13:07:27 +00:00
|
|
|
|
|
|
|
// Object payload encapsulated in io.Reader primitive.
|
|
|
|
Payload io.Reader
|
2022-08-11 22:48:56 +00:00
|
|
|
|
|
|
|
// Number of object copies that is enough to consider put successful.
|
2023-04-24 23:49:12 +00:00
|
|
|
CopiesNumber []uint32
|
2023-07-14 12:30:47 +00:00
|
|
|
|
|
|
|
// Enables client side object preparing.
|
|
|
|
ClientCut bool
|
2023-08-25 10:06:43 +00:00
|
|
|
|
|
|
|
// Disables using Tillich-Zémor hash for payload.
|
|
|
|
WithoutHomomorphicHash bool
|
2023-08-25 10:07:59 +00:00
|
|
|
|
|
|
|
// Sets max buffer size to read payload.
|
|
|
|
BufferMaxSize uint64
|
2022-03-04 13:07:27 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// PrmObjectDelete groups parameters of FrostFS.DeleteObject operation.
|
2022-03-04 13:07:27 +00:00
|
|
|
type PrmObjectDelete struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to delete the object from.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// Identifier of the removed object.
|
|
|
|
Object oid.ID
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:34:19 +00:00
|
|
|
// PrmObjectSearch groups parameters of FrostFS.sear SearchObjects operation.
|
|
|
|
type PrmObjectSearch struct {
|
|
|
|
// Authentication parameters.
|
|
|
|
PrmAuth
|
|
|
|
|
|
|
|
// Container to select the objects from.
|
|
|
|
Container cid.ID
|
|
|
|
|
|
|
|
// Key-value object attribute which should be
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2023-06-13 14:47:31 +00:00
|
|
|
var (
|
|
|
|
// ErrAccessDenied is returned from FrostFS in case of access violation.
|
|
|
|
ErrAccessDenied = errors.New("access denied")
|
|
|
|
|
|
|
|
// ErrGatewayTimeout is returned from FrostFS in case of timeout, deadline exceeded etc.
|
|
|
|
ErrGatewayTimeout = errors.New("gateway timeout")
|
|
|
|
)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// FrostFS represents virtual connection to FrostFS network.
|
|
|
|
type FrostFS interface {
|
|
|
|
// CreateContainer creates and saves parameterized container in FrostFS.
|
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-27 09:33:36 +00:00
|
|
|
// It returns exactly one non-zero value. It returns any error encountered which
|
2022-04-13 16:56:58 +00:00
|
|
|
// prevented the container from being created.
|
2023-08-25 10:06:43 +00:00
|
|
|
CreateContainer(context.Context, PrmContainerCreate) (*ContainerCreateResult, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// Container reads a container from FrostFS 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.
|
2024-03-01 14:11:07 +00:00
|
|
|
Container(context.Context, PrmContainer) (*container.Container, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
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.
|
2024-03-01 14:11:07 +00:00
|
|
|
UserContainers(context.Context, PrmUserContainers) ([]cid.ID, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// DeleteContainer marks the container to be removed from FrostFS by ID.
|
2022-03-04 13:07:27 +00:00
|
|
|
// 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
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
// HeadObject reads an info of the object from the FrostFS container by identifier.
|
|
|
|
//
|
|
|
|
// It returns ErrAccessDenied on read access violation.
|
|
|
|
//
|
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the object header from being read.
|
|
|
|
HeadObject(ctx context.Context, prm PrmObjectHead) (*object.Object, error)
|
|
|
|
|
|
|
|
// GetObject reads an object from the FrostFS container by identifier.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
2024-07-15 12:47:19 +00:00
|
|
|
// Payload reader should be closed if it is no longer needed.
|
|
|
|
//
|
|
|
|
// It returns ErrAccessDenied on read access violation.
|
|
|
|
//
|
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the object header from being read.
|
|
|
|
GetObject(ctx context.Context, prm PrmObjectGet) (*Object, error)
|
|
|
|
|
|
|
|
// RangeObject reads a part of object from the FrostFS container by identifier.
|
2022-03-04 13:07:27 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2024-07-15 12:47:19 +00:00
|
|
|
RangeObject(ctx context.Context, prm PrmObjectRange) (io.ReadCloser, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// CreateObject creates and saves a parameterized object in the FrostFS container.
|
2022-04-13 16:56:58 +00:00
|
|
|
// 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-06-27 09:33:36 +00:00
|
|
|
// It returns exactly one non-zero value. It returns any error encountered which
|
2022-04-13 16:56:58 +00:00
|
|
|
// prevented the container from being created.
|
2022-06-27 09:33:36 +00:00
|
|
|
CreateObject(context.Context, PrmObjectCreate) (oid.ID, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
|
2022-12-20 08:38:58 +00:00
|
|
|
// DeleteObject marks the object to be removed from the FrostFS 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
|
|
|
|
2023-06-13 09:34:19 +00:00
|
|
|
// SearchObjects performs object search from the NeoFS container according
|
|
|
|
// to the specified parameters. It searches user's objects only.
|
|
|
|
//
|
|
|
|
// It returns ErrAccessDenied on selection access violation.
|
|
|
|
//
|
|
|
|
// It returns exactly one non-nil value. It returns any error encountered which
|
|
|
|
// prevented the objects from being selected.
|
|
|
|
SearchObjects(context.Context, PrmObjectSearch) ([]oid.ID, error)
|
|
|
|
|
2022-11-08 09:12:55 +00:00
|
|
|
// TimeToEpoch computes current epoch and the epoch that corresponds to the provided now and future time.
|
2022-03-05 08:53:01 +00:00
|
|
|
// Note:
|
2022-11-08 09:12:55 +00:00
|
|
|
// * future time must be after the now
|
|
|
|
// * future time will be ceil rounded to match epoch
|
2022-03-05 08:53:01 +00:00
|
|
|
//
|
2022-04-13 16:56:58 +00:00
|
|
|
// It returns any error encountered which prevented computing epochs.
|
2022-11-08 09:12:55 +00:00
|
|
|
TimeToEpoch(ctx context.Context, now time.Time, future time.Time) (uint64, uint64, error)
|
2022-03-04 13:07:27 +00:00
|
|
|
}
|