lock

package
v0.0.0-...-d1e1776 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMalformedBucketObjectConfig -indicates that the bucket object lock config is malformed
	ErrMalformedBucketObjectConfig = errors.New("invalid bucket object lock config")
	// ErrInvalidRetentionDate - indicates that retention date needs to be in ISO 8601 format
	ErrInvalidRetentionDate = errors.New("date must be provided in ISO 8601 format")
	// ErrPastObjectLockRetainDate - indicates that retention date must be in the future
	ErrPastObjectLockRetainDate = errors.New("the retain until date must be in the future")
	// ErrUnknownWORMModeDirective - indicates that the retention mode is invalid
	ErrUnknownWORMModeDirective = errors.New("unknown WORM mode directive")
	// ErrObjectLockMissingContentMD5 - indicates missing Content-MD5 header for put object requests with locking
	ErrObjectLockMissingContentMD5 = errors.New("content-MD5 HTTP header is required for Put Object requests with Object Lock parameters")
	// ErrObjectLockInvalidHeaders indicates that object lock headers are missing
	ErrObjectLockInvalidHeaders = errors.New("x-amz-object-lock-retain-until-date and x-amz-object-lock-mode must both be supplied")
	// ErrMalformedXML - generic error indicating malformed XML
	ErrMalformedXML = errors.New("the XML you provided was not well-formed or did not validate against our published schema")
)

Functions

func FilterObjectLockMetadata

func FilterObjectLockMetadata(metadata map[string]string, filterRetention, filterLegalHold bool) map[string]string

FilterObjectLockMetadata filters object lock metadata if s3:GetObjectRetention permission is denied or if isCopy flag set.

func IsObjectLockGovernanceBypassSet

func IsObjectLockGovernanceBypassSet(h http.Header) bool

IsObjectLockGovernanceBypassSet returns true if object lock governance bypass header is set.

func IsObjectLockLegalHoldRequested

func IsObjectLockLegalHoldRequested(h http.Header) bool

IsObjectLockLegalHoldRequested returns true if object lock legal hold header is set.

func IsObjectLockRequested

func IsObjectLockRequested(h http.Header) bool

IsObjectLockRequested returns true if legal hold or object lock retention headers are requested.

func IsObjectLockRetentionRequested

func IsObjectLockRetentionRequested(h http.Header) bool

IsObjectLockRetentionRequested returns true if object lock retention headers are set.

func ParseObjectLockRetentionHeaders

func ParseObjectLockRetentionHeaders(h http.Header) (rmode Mode, r RetentionDate, err error)

ParseObjectLockRetentionHeaders parses http headers to extract retention mode and retention date

func UTCNowNTP

func UTCNowNTP() (time.Time, error)

UTCNowNTP - is similar in functionality to UTCNow() but only used when we do not wish to rely on system time.

Types

type BucketObjectLockConfig

type BucketObjectLockConfig struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

BucketObjectLockConfig - map of bucket and retention configuration.

func NewBucketObjectLockConfig

func NewBucketObjectLockConfig() *BucketObjectLockConfig

NewBucketObjectLockConfig returns initialized BucketObjectLockConfig

func (*BucketObjectLockConfig) Get

func (config *BucketObjectLockConfig) Get(bucketName string) (r Retention, ok bool)

Get - Get retention configuration.

func (*BucketObjectLockConfig) Remove

func (config *BucketObjectLockConfig) Remove(bucketName string)

Remove - removes retention configuration.

func (*BucketObjectLockConfig) Set

func (config *BucketObjectLockConfig) Set(bucketName string, retention Retention)

Set - set retention configuration.

type Config

type Config struct {
	XMLNS             string   `xml:"xmlns,attr,omitempty"`
	XMLName           xml.Name `xml:"ObjectLockConfiguration"`
	ObjectLockEnabled string   `xml:"ObjectLockEnabled"`
	Rule              *struct {
		DefaultRetention DefaultRetention `xml:"DefaultRetention"`
	} `xml:"Rule,omitempty"`
}

Config - object lock configuration specified in https://docs.aws.amazon.com/AmazonS3/latest/API/Type_API_ObjectLockConfiguration.html

func NewObjectLockConfig

func NewObjectLockConfig() *Config

NewObjectLockConfig returns a initialized lock.Config struct

func ParseObjectLockConfig

func ParseObjectLockConfig(reader io.Reader) (*Config, error)

ParseObjectLockConfig parses ObjectLockConfig from xml

func (*Config) ToRetention

func (config *Config) ToRetention() (r Retention)

ToRetention - convert to Retention type.

func (*Config) UnmarshalXML

func (config *Config) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML - decodes XML data.

type DefaultRetention

type DefaultRetention struct {
	XMLName xml.Name `xml:"DefaultRetention"`
	Mode    Mode     `xml:"Mode"`
	Days    *uint64  `xml:"Days"`
	Years   *uint64  `xml:"Years"`
}

DefaultRetention - default retention configuration.

func (*DefaultRetention) UnmarshalXML

func (dr *DefaultRetention) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML - decodes XML data.

type LegalHoldStatus

type LegalHoldStatus string

LegalHoldStatus - object legal hold status.

const (
	// ON -legal hold is on.
	ON LegalHoldStatus = "ON"

	// OFF -legal hold is off.
	OFF LegalHoldStatus = "OFF"
)

type Mode

type Mode string

Mode - object retention mode.

const (
	// Governance - governance mode.
	Governance Mode = "GOVERNANCE"

	// Compliance - compliance mode.
	Compliance Mode = "COMPLIANCE"

	// Invalid - invalid retention mode.
	Invalid Mode = ""
)

type ObjectLegalHold

type ObjectLegalHold struct {
	XMLNS   string          `xml:"xmlns,attr,omitempty"`
	XMLName xml.Name        `xml:"LegalHold"`
	Status  LegalHoldStatus `xml:"Status,omitempty"`
}

ObjectLegalHold specified in https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectLegalHold.html

func GetObjectLegalHoldMeta

func GetObjectLegalHoldMeta(meta map[string]string) ObjectLegalHold

GetObjectLegalHoldMeta constructs ObjectLegalHold from metadata

func ParseObjectLegalHold

func ParseObjectLegalHold(reader io.Reader) (hold *ObjectLegalHold, err error)

ParseObjectLegalHold decodes the XML into ObjectLegalHold

func ParseObjectLockLegalHoldHeaders

func ParseObjectLockLegalHoldHeaders(h http.Header) (lhold ObjectLegalHold, err error)

ParseObjectLockLegalHoldHeaders parses request headers to construct ObjectLegalHold

func (*ObjectLegalHold) IsEmpty

func (l *ObjectLegalHold) IsEmpty() bool

IsEmpty returns true if struct is empty

type ObjectRetention

type ObjectRetention struct {
	XMLNS           string        `xml:"xmlns,attr,omitempty"`
	XMLName         xml.Name      `xml:"Retention"`
	Mode            Mode          `xml:"Mode,omitempty"`
	RetainUntilDate RetentionDate `xml:"RetainUntilDate,omitempty"`
}

ObjectRetention specified in https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectRetention.html

func GetObjectRetentionMeta

func GetObjectRetentionMeta(meta map[string]string) ObjectRetention

GetObjectRetentionMeta constructs ObjectRetention from metadata

func ParseObjectRetention

func ParseObjectRetention(reader io.Reader) (*ObjectRetention, error)

ParseObjectRetention constructs ObjectRetention struct from xml input

type Retention

type Retention struct {
	Mode     Mode
	Validity time.Duration
}

Retention - bucket level retention configuration.

func (Retention) IsEmpty

func (r Retention) IsEmpty() bool

IsEmpty - returns whether retention is empty or not.

func (Retention) Retain

func (r Retention) Retain(created time.Time) bool

Retain - check whether given date is retainable by validity time.

type RetentionDate

type RetentionDate struct {
	time.Time
}

RetentionDate is a embedded type containing time.Time to unmarshal Date in Retention

func (*RetentionDate) MarshalXML

func (rDate *RetentionDate) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

MarshalXML encodes expiration date if it is non-zero and encodes empty string otherwise

func (*RetentionDate) UnmarshalXML

func (rDate *RetentionDate) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses date from Retention and validates date format

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL