2021-09-10 06:56:56 +00:00
|
|
|
package data
|
2021-08-27 21:33:50 +00:00
|
|
|
|
|
|
|
import (
|
2021-10-13 18:50:02 +00:00
|
|
|
"encoding/xml"
|
2021-08-27 21:33:50 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2021-08-27 21:33:50 +00:00
|
|
|
)
|
|
|
|
|
2021-10-04 14:32:35 +00:00
|
|
|
const (
|
2022-02-28 08:02:05 +00:00
|
|
|
bktSettingsObject = ".s3-settings"
|
2022-02-17 18:58:51 +00:00
|
|
|
bktCORSConfigurationObject = ".s3-cors"
|
|
|
|
bktNotificationConfigurationObject = ".s3-notifications"
|
2022-07-19 14:58:18 +00:00
|
|
|
|
2022-07-20 10:30:19 +00:00
|
|
|
VersioningUnversioned = "Unversioned"
|
|
|
|
VersioningEnabled = "Enabled"
|
|
|
|
VersioningSuspended = "Suspended"
|
2021-10-04 14:32:35 +00:00
|
|
|
)
|
2021-08-27 21:33:50 +00:00
|
|
|
|
|
|
|
type (
|
|
|
|
// BucketInfo stores basic bucket data.
|
|
|
|
BucketInfo struct {
|
2023-02-10 12:09:32 +00:00
|
|
|
Name string // container name from system attribute
|
|
|
|
Zone string // container zone from system attribute
|
2022-05-25 17:25:43 +00:00
|
|
|
CID cid.ID
|
|
|
|
Owner user.ID
|
2022-01-11 12:33:09 +00:00
|
|
|
Created time.Time
|
|
|
|
LocationConstraint string
|
2022-02-25 09:06:40 +00:00
|
|
|
ObjectLockEnabled bool
|
2021-08-27 21:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectInfo holds S3 object data.
|
|
|
|
ObjectInfo struct {
|
2022-05-20 15:02:00 +00:00
|
|
|
ID oid.ID
|
|
|
|
CID cid.ID
|
|
|
|
IsDir bool
|
|
|
|
IsDeleteMarker bool
|
2021-08-27 21:33:50 +00:00
|
|
|
|
2023-06-13 09:34:19 +00:00
|
|
|
Bucket string
|
|
|
|
Name string
|
|
|
|
Size uint64
|
|
|
|
ContentType string
|
|
|
|
Created time.Time
|
|
|
|
CreationEpoch uint64
|
|
|
|
HashSum string
|
2023-10-02 08:52:07 +00:00
|
|
|
MD5Sum string
|
2023-06-13 09:34:19 +00:00
|
|
|
Owner user.ID
|
|
|
|
Headers map[string]string
|
2021-08-27 21:33:50 +00:00
|
|
|
}
|
2021-10-13 18:50:02 +00:00
|
|
|
|
2022-07-18 14:51:34 +00:00
|
|
|
// NotificationInfo store info to send s3 notification.
|
|
|
|
NotificationInfo struct {
|
|
|
|
Name string
|
|
|
|
Version string
|
2023-06-01 13:45:28 +00:00
|
|
|
Size uint64
|
2022-07-18 14:51:34 +00:00
|
|
|
HashSum string
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:02:05 +00:00
|
|
|
// BucketSettings stores settings such as versioning.
|
|
|
|
BucketSettings struct {
|
2022-07-19 14:58:18 +00:00
|
|
|
Versioning string `json:"versioning"`
|
2022-02-28 08:29:03 +00:00
|
|
|
LockConfiguration *ObjectLockConfiguration `json:"lock_configuration"`
|
2022-02-28 08:02:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 18:50:02 +00:00
|
|
|
// CORSConfiguration stores CORS configuration of a request.
|
|
|
|
CORSConfiguration struct {
|
|
|
|
XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ CORSConfiguration" json:"-"`
|
|
|
|
CORSRules []CORSRule `xml:"CORSRule" json:"CORSRules"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CORSRule stores rules for CORS in a bucket.
|
|
|
|
CORSRule struct {
|
|
|
|
ID string `xml:"ID,omitempty" json:"ID,omitempty"`
|
|
|
|
AllowedHeaders []string `xml:"AllowedHeader" json:"AllowedHeaders"`
|
|
|
|
AllowedMethods []string `xml:"AllowedMethod" json:"AllowedMethods"`
|
|
|
|
AllowedOrigins []string `xml:"AllowedOrigin" json:"AllowedOrigins"`
|
|
|
|
ExposeHeaders []string `xml:"ExposeHeader" json:"ExposeHeaders"`
|
|
|
|
MaxAgeSeconds int `xml:"MaxAgeSeconds,omitempty" json:"MaxAgeSeconds,omitempty"`
|
|
|
|
}
|
2021-08-27 21:33:50 +00:00
|
|
|
)
|
|
|
|
|
2022-07-18 14:51:34 +00:00
|
|
|
// NotificationInfoFromObject creates new NotificationInfo from ObjectInfo.
|
2023-10-02 08:52:07 +00:00
|
|
|
func NotificationInfoFromObject(objInfo *ObjectInfo, md5Enabled bool) *NotificationInfo {
|
2022-07-18 14:51:34 +00:00
|
|
|
return &NotificationInfo{
|
|
|
|
Name: objInfo.Name,
|
2022-08-04 17:31:33 +00:00
|
|
|
Version: objInfo.VersionID(),
|
2022-07-18 14:51:34 +00:00
|
|
|
Size: objInfo.Size,
|
2023-10-02 08:52:07 +00:00
|
|
|
HashSum: objInfo.ETag(md5Enabled),
|
2022-07-18 14:51:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// SettingsObjectName is a system name for a bucket settings file.
|
2022-02-28 08:02:05 +00:00
|
|
|
func (b *BucketInfo) SettingsObjectName() string { return bktSettingsObject }
|
2021-08-27 21:33:50 +00:00
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// CORSObjectName returns a system name for a bucket CORS configuration file.
|
2021-10-04 14:32:35 +00:00
|
|
|
func (b *BucketInfo) CORSObjectName() string { return bktCORSConfigurationObject }
|
|
|
|
|
2022-02-17 18:58:51 +00:00
|
|
|
func (b *BucketInfo) NotificationConfigurationObjectName() string {
|
|
|
|
return bktNotificationConfigurationObject
|
|
|
|
}
|
|
|
|
|
2022-08-04 17:31:33 +00:00
|
|
|
// VersionID returns object version from ObjectInfo.
|
|
|
|
func (o *ObjectInfo) VersionID() string { return o.ID.EncodeToString() }
|
2021-08-27 21:33:50 +00:00
|
|
|
|
|
|
|
// NiceName returns object name for cache.
|
|
|
|
func (o *ObjectInfo) NiceName() string { return o.Bucket + "/" + o.Name }
|
|
|
|
|
|
|
|
// Address returns object address.
|
2022-05-25 17:25:43 +00:00
|
|
|
func (o *ObjectInfo) Address() oid.Address {
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(o.CID)
|
|
|
|
addr.SetObject(o.ID)
|
2021-08-27 21:33:50 +00:00
|
|
|
|
2022-02-08 16:54:04 +00:00
|
|
|
return addr
|
2021-08-27 21:33:50 +00:00
|
|
|
}
|
2022-07-19 14:58:18 +00:00
|
|
|
|
2023-10-02 08:52:07 +00:00
|
|
|
func (o *ObjectInfo) ETag(md5Enabled bool) string {
|
|
|
|
if md5Enabled && len(o.MD5Sum) > 0 {
|
|
|
|
return o.MD5Sum
|
|
|
|
}
|
|
|
|
return o.HashSum
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:58:18 +00:00
|
|
|
func (b BucketSettings) Unversioned() bool {
|
2022-07-20 10:30:19 +00:00
|
|
|
return b.Versioning == VersioningUnversioned
|
2022-07-19 14:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b BucketSettings) VersioningEnabled() bool {
|
2022-07-20 10:30:19 +00:00
|
|
|
return b.Versioning == VersioningEnabled
|
2022-07-19 14:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (b BucketSettings) VersioningSuspended() bool {
|
2022-07-20 10:30:19 +00:00
|
|
|
return b.Versioning == VersioningSuspended
|
2022-07-19 14:58:18 +00:00
|
|
|
}
|