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"
|
|
|
|
|
2021-11-15 12:56:16 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-02-08 16:54:04 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object/address"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-11-15 12:56:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
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"
|
2021-10-04 14:32:35 +00:00
|
|
|
)
|
2021-08-27 21:33:50 +00:00
|
|
|
|
|
|
|
type (
|
|
|
|
// BucketInfo stores basic bucket data.
|
|
|
|
BucketInfo struct {
|
2022-01-11 12:33:09 +00:00
|
|
|
Name string
|
|
|
|
CID *cid.ID
|
|
|
|
Owner *owner.ID
|
|
|
|
Created time.Time
|
|
|
|
BasicACL uint32
|
|
|
|
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-02-08 16:54:04 +00:00
|
|
|
ID *oid.ID
|
2021-08-27 21:33:50 +00:00
|
|
|
CID *cid.ID
|
|
|
|
IsDir bool
|
|
|
|
|
|
|
|
Bucket string
|
|
|
|
Name string
|
|
|
|
Size int64
|
|
|
|
ContentType string
|
|
|
|
Created time.Time
|
|
|
|
CreationEpoch uint64
|
|
|
|
HashSum string
|
|
|
|
Owner *owner.ID
|
|
|
|
Headers map[string]string
|
|
|
|
}
|
2021-10-13 18:50:02 +00:00
|
|
|
|
2022-02-28 08:02:05 +00:00
|
|
|
// BucketSettings stores settings such as versioning.
|
|
|
|
BucketSettings struct {
|
2022-02-28 08:29:03 +00:00
|
|
|
VersioningEnabled bool `json:"versioning_enabled"`
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// SettingsObjectName is system name for 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
|
|
|
|
2021-10-04 14:32:35 +00:00
|
|
|
// CORSObjectName returns system name for bucket CORS configuration file.
|
|
|
|
func (b *BucketInfo) CORSObjectName() string { return bktCORSConfigurationObject }
|
|
|
|
|
2022-02-17 18:58:51 +00:00
|
|
|
func (b *BucketInfo) NotificationConfigurationObjectName() string {
|
|
|
|
return bktNotificationConfigurationObject
|
|
|
|
}
|
|
|
|
|
2021-08-27 21:33:50 +00:00
|
|
|
// Version returns object version from ObjectInfo.
|
|
|
|
func (o *ObjectInfo) Version() string { return o.ID.String() }
|
|
|
|
|
2022-01-18 15:28:46 +00:00
|
|
|
// NullableVersion returns object version from ObjectInfo.
|
|
|
|
// Return "null" if "S3-Versions-unversioned" header present.
|
|
|
|
func (o *ObjectInfo) NullableVersion() string {
|
|
|
|
if _, ok := o.Headers["S3-Versions-unversioned"]; ok {
|
|
|
|
return "null"
|
|
|
|
}
|
|
|
|
return o.Version()
|
|
|
|
}
|
|
|
|
|
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-02-08 16:54:04 +00:00
|
|
|
func (o *ObjectInfo) Address() *address.Address {
|
|
|
|
addr := address.NewAddress()
|
|
|
|
addr.SetContainerID(o.CID)
|
|
|
|
addr.SetObjectID(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
|
|
|
}
|
|
|
|
|
|
|
|
// TagsObject returns name of system object for tags.
|
|
|
|
func (o *ObjectInfo) TagsObject() string { return ".tagset." + o.Name + "." + o.Version() }
|