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"
|
2023-10-27 15:15:33 +00:00
|
|
|
"strings"
|
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"
|
2024-02-12 12:28:55 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2021-08-27 21:33:50 +00:00
|
|
|
)
|
|
|
|
|
2021-10-04 14:32:35 +00:00
|
|
|
const (
|
2024-08-12 11:22:56 +00:00
|
|
|
bktSettingsObject = ".s3-settings"
|
|
|
|
bktCORSConfigurationObject = ".s3-cors"
|
|
|
|
bktLifecycleConfigurationObject = ".s3-lifecycle"
|
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-08-25 10:06:43 +00:00
|
|
|
Name string // container name from system attribute
|
|
|
|
Zone string // container zone from system attribute
|
|
|
|
CID cid.ID
|
|
|
|
Owner user.ID
|
|
|
|
Created time.Time
|
|
|
|
LocationConstraint string
|
|
|
|
ObjectLockEnabled bool
|
|
|
|
HomomorphicHashDisabled bool
|
2021-08-27 21:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectInfo holds S3 object data.
|
|
|
|
ObjectInfo struct {
|
2024-01-17 14:26:02 +00:00
|
|
|
ID oid.ID
|
|
|
|
CID cid.ID
|
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-02-28 08:02:05 +00:00
|
|
|
// BucketSettings stores settings such as versioning.
|
|
|
|
BucketSettings struct {
|
2024-02-12 12:28:55 +00:00
|
|
|
Versioning string
|
|
|
|
LockConfiguration *ObjectLockConfiguration
|
|
|
|
CannedACL string
|
|
|
|
OwnerKey *keys.PublicKey
|
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"`
|
|
|
|
}
|
2024-04-10 06:41:07 +00:00
|
|
|
|
|
|
|
// ObjectVersion stores object version info.
|
|
|
|
ObjectVersion struct {
|
|
|
|
BktInfo *BucketInfo
|
|
|
|
ObjectName string
|
|
|
|
VersionID string
|
|
|
|
NoErrorOnDeleteMarker bool
|
|
|
|
}
|
2021-08-27 21:33:50 +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.
|
2024-07-15 15:35:54 +00:00
|
|
|
func (b *BucketInfo) CORSObjectName() string {
|
|
|
|
return b.CID.EncodeToString() + bktCORSConfigurationObject
|
|
|
|
}
|
2021-10-04 14:32:35 +00:00
|
|
|
|
2024-08-12 11:22:56 +00:00
|
|
|
func (b *BucketInfo) LifecycleConfigurationObjectName() string {
|
|
|
|
return b.CID.EncodeToString() + bktLifecycleConfigurationObject
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-10-27 15:15:33 +00:00
|
|
|
|
|
|
|
func Quote(val string) string {
|
|
|
|
return "\"" + val + "\""
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnQuote(val string) string {
|
|
|
|
return strings.Trim(val, "\"")
|
|
|
|
}
|