lifecycle

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugSpec = "@every 5s"
	// DebugTime for test: 1 day == 1 second
	DebugTime = time.Second
)
View Source
const (
	// Lifecycle config can't have more than 100 rules
	RulesNumber = 100
)

Variables

This section is empty.

Functions

func Lcp

func Lcp(l []string) string

lcp finds the longest common prefix of the input strings. It compares by bytes instead of runes (Unicode code points). It's up to the caller to do Unicode normalization if desired (e.g. see golang.org/x/text/unicode/norm).

func String

func String(s string) *string

String returns a pointer to the string value passed in.

Types

type AbortIncompleteMultipartUpload

type AbortIncompleteMultipartUpload struct {
	XMLName             xml.Name            `xml:"AbortIncompleteMultipartUpload,omitempty"`
	DaysAfterInitiation DaysAfterInitiation `xml:"DaysAfterInitiation,omitempty"`
}

AbortIncompleteMultipartUpload - an action for lifecycle configuration rule.

func (AbortIncompleteMultipartUpload) IsDaysNull

func (n AbortIncompleteMultipartUpload) IsDaysNull() bool

IsDaysNull returns true if days field is null

func (AbortIncompleteMultipartUpload) Validate

Validate - validates the "AbortIncompleteMultipartUpload" element

type Action

type Action int

Action represents a delete action or other transition actions that will be implemented later.

const (
	// NoneAction means no action required after evaluating lifecycle rules
	NoneAction Action = iota
	// DeleteAction means the object needs to be removed after evaluating lifecycle rules
	// For versioned buckets, this could be an added delete marker
	DeleteAction
	// DeleteVersionAction means the specific object version needs to be removed after evaluating lifecycle rules
	DeleteVersionAction
	//TransitionAction means the object storage class needs to be transitioned after evaluating lifecycle rules
	TransitionAction
	// AbortMultipartUploadAction means that abort incomplete multipart upload and delete all parts
	AbortMultipartUploadAction
)

type And

type And struct {
	XMLName xml.Name `xml:"And"`
	Prefix  *string  `xml:"Prefix,omitempty"`
	Tags    []Tag    `xml:"Tag,omitempty"`
}

And - a tag to combine a prefix and multiple tags for lifecycle configuration rule.

func (And) ContainsDuplicateTag

func (a And) ContainsDuplicateTag() bool

ContainsDuplicateTag - returns true if duplicate keys are present in And

func (And) Validate

func (a And) Validate() error

Validate - validates the And field

type DaysAfterInitiation

type DaysAfterInitiation int

DaysAfterInitiation is a type alias to unmarshal Days in AbortIncompleteMultipartUpload

func (*DaysAfterInitiation) MarshalXML

func (aDays *DaysAfterInitiation) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

MarshalXML encodes number of days to expire if it is non-zero and encodes empty string otherwise

func (*DaysAfterInitiation) UnmarshalXML

func (aDays *DaysAfterInitiation) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses number of days and validates if greater than zero

type Expiration

type Expiration struct {
	XMLName                   xml.Name       `xml:"Expiration"`
	Days                      ExpirationDays `xml:"Days,omitempty"`
	Date                      ExpirationDate `xml:"Date,omitempty"`
	ExpiredObjectDeleteMarker *bool          `xml:"ExpiredObjectDeleteMarker,omitempty"`
}

Expiration - expiration actions for a rule in lifecycle configuration.

func (Expiration) IsDateNull

func (e Expiration) IsDateNull() bool

IsDateNull returns true if date field is null

func (Expiration) IsDaysNull

func (e Expiration) IsDaysNull() bool

IsDaysNull returns true if days field is null

func (Expiration) IsNull

func (e Expiration) IsNull() bool

IsNull returns true if both date and days fields are null

func (Expiration) IsSetExpiredObjectDeleteMarker

func (e Expiration) IsSetExpiredObjectDeleteMarker() bool

func (Expiration) Validate

func (e Expiration) Validate() error

Validate - validates the "Expiration" element

type ExpirationDate

type ExpirationDate struct {
	time.Time
}

ExpirationDate is a embedded type containing time.Time to unmarshal Date in Expiration

func (*ExpirationDate) MarshalXML

func (eDate *ExpirationDate) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

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

func (*ExpirationDate) UnmarshalXML

func (eDate *ExpirationDate) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses date from Expiration and validates date format

type ExpirationDays

type ExpirationDays int

ExpirationDays is a type alias to unmarshal Days in Expiration

func (*ExpirationDays) MarshalXML

func (eDays *ExpirationDays) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

MarshalXML encodes number of days to expire if it is non-zero and encodes empty string otherwise

func (*ExpirationDays) UnmarshalXML

func (eDays *ExpirationDays) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses number of days from Expiration and validates if greater than zero

type Filter

type Filter struct {
	XMLName xml.Name `xml:"Filter"`
	Prefix  *string  `xml:"Prefix,omitempty"`
	And     *And     `xml:"And,omitempty"`
	Tag     *Tag     `xml:"Tag,omitempty"`
}

Filter - a filter for a lifecycle configuration Rule.

func (Filter) IsTagEmpty

func (f Filter) IsTagEmpty() bool

IsTagEmpty - return true if Filter tag is empty

func (Filter) Validate

func (f Filter) Validate() error

Validate - validates the filter element

type Lifecycle

type Lifecycle struct {
	XMLName xml.Name `xml:"LifecycleConfiguration"`
	Rules   []Rule   `xml:"Rule"`
}

Lifecycle - Configuration for bucket lifecycle.

func ParseLifecycleConfig

func ParseLifecycleConfig(reader io.Reader) (*Lifecycle, error)

ParseLifecycleConfig - parses data in given reader to Lifecycle.

func (Lifecycle) ComputeAction

func (lc Lifecycle) ComputeAction(objName string, objTags map[string]string, objStorageClass string, modTime time.Time,
	expiredObjectDeleteMarker bool, rules []Rule) (Action, string)

ComputeAction returns the action to perform by evaluating all lifecycle rules against the object name and its modification time.

The day LC run
                    match                  match                     No

----> rule ----------->prefix X objectName -------->Tags X objTags -------> IS Expiration ? -------->Select Transition from Transitions

        ^                   | not match	 	                | not match	            | Yes                   | save/replace storageClass
        |<-------------------                                |                       |                       | GLACIER replace STANDARD_IA
        |<---------------------------------------------------                        |                       |
        |                                                                       Delete object               |
        |<---------------------------------------------------------------------------------------------------
	FOR MANY LOOP RULES, IF NOT EXPIRATION, SHOULD BE TRANSITION(RETURN THE CHEAPEST CLASS)

func (Lifecycle) ComputeActionForAbortIncompleteMultipartUpload

func (lc Lifecycle) ComputeActionForAbortIncompleteMultipartUpload(objName string, objTags map[string]string,
	modTime time.Time, rules []Rule) Action

ComputeAction for AbortIncompleteMultipartUpload

func (Lifecycle) ComputeActionForNonCurrentVersion

func (lc Lifecycle) ComputeActionForNonCurrentVersion(objName string, objTags map[string]string, objStorageClass string,
	modTime time.Time, rules []Rule) (Action, string)

Just like ComputeAction

func (Lifecycle) FilterRules

func (lc Lifecycle) FilterRules() (ncvRules, cvRules, abortMultipartRules []Rule)

func (Lifecycle) IsEmpty

func (lc Lifecycle) IsEmpty() bool

IsEmpty - returns whether policy is empty or not.

func (Lifecycle) Validate

func (lc Lifecycle) Validate() error

Validate - validates the lifecycle configuration

type NoncurrentDays

type NoncurrentDays int

NoncurrentDays is a type alias to unmarshal Days in NoncurrentVersionExpiration or NoncurrentVersionTransition

func (*NoncurrentDays) MarshalXML

func (nDays *NoncurrentDays) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

MarshalXML encodes number of days to expire if it is non-zero and encodes empty string otherwise

func (*NoncurrentDays) UnmarshalXML

func (nDays *NoncurrentDays) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses number of days and validates if greater than zero

type NoncurrentVersionExpiration

type NoncurrentVersionExpiration struct {
	XMLName        xml.Name       `xml:"NoncurrentVersionExpiration,omitempty"`
	NoncurrentDays NoncurrentDays `xml:"NoncurrentDays,omitempty"`
}

NoncurrentVersionExpiration - an action for lifecycle configuration rule.

func (NoncurrentVersionExpiration) IsDaysNull

func (n NoncurrentVersionExpiration) IsDaysNull() bool

IsDaysNull returns true if days field is null

func (NoncurrentVersionExpiration) Validate

func (n NoncurrentVersionExpiration) Validate() error

Validate - validates the "NoncurrentVersionExpiration" element

type NoncurrentVersionTransition

type NoncurrentVersionTransition struct {
	XMLName        xml.Name       `xml:"NoncurrentVersionTransition,omitempty"`
	NoncurrentDays NoncurrentDays `xml:"NoncurrentDays,omitempty"`
	StorageClass   string         `xml:"StorageClass,omitempty"`
}

NoncurrentVersionTransition - an action for lifecycle configuration rule.

func (NoncurrentVersionTransition) IsDaysNull

func (n NoncurrentVersionTransition) IsDaysNull() bool

IsDaysNull returns true if days field is null

func (NoncurrentVersionTransition) IsStorageClassNull

func (n NoncurrentVersionTransition) IsStorageClassNull() bool

IsDaysNull returns true if days field is null

func (NoncurrentVersionTransition) Validate

func (n NoncurrentVersionTransition) Validate() error

Validate - validates the "NoncurrentVersionTransition" element

type Rule

type Rule struct {
	XMLName                        xml.Name                        `xml:"Rule"`
	ID                             string                          `xml:"ID,omitempty"`
	Status                         Status                          `xml:"Status"`
	Filter                         *Filter                         `xml:"Filter,omitempty"`
	Expiration                     *Expiration                     `xml:"Expiration,omitempty"`
	Transitions                    []Transition                    `xml:"Transition,omitempty"`
	NoncurrentVersionExpiration    *NoncurrentVersionExpiration    `xml:"NoncurrentVersionExpiration,omitempty"`
	NoncurrentVersionTransitions   []NoncurrentVersionTransition   `xml:"NoncurrentVersionTransition,omitempty"`
	AbortIncompleteMultipartUpload *AbortIncompleteMultipartUpload `xml:"AbortIncompleteMultipartUpload,omitempty"`
}

Rule - a rule for lifecycle configuration.

func (Rule) Prefix

func (r Rule) Prefix() string

Prefix - a rule can either have prefix under <filter></filter> or under <filter><and></and></filter>. This method returns the prefix from the location where it is available

func (Rule) Validate

func (r Rule) Validate() error

Validate - validates the rule element

type Status

type Status string

Status represents lifecycle configuration status

const (
	Enabled  Status = "Enabled"
	Disabled Status = "Disabled"
)

Supported status types

type Tag

type Tag struct {
	XMLName xml.Name `xml:"Tag"`
	Key     string   `xml:"Key,omitempty"`
	Value   string   `xml:"Value,omitempty"`
}

Tag - single tag

func (Tag) IsEmpty

func (t Tag) IsEmpty() bool

IsEmpty - checks if tag is empty or not

func (Tag) String

func (t Tag) String() string

String - returns a string in format "tag1=value1" for the current Tag

func (Tag) Validate

func (t Tag) Validate() error

Validate - validates the tag element

type Transition

type Transition struct {
	XMLName      xml.Name       `xml:"Transition"`
	Days         TransitionDays `xml:"Days,omitempty"`
	Date         TransitionDate `xml:"Date,omitempty"`
	StorageClass string         `xml:"StorageClass"`
}

Transition - transition actions for a rule in lifecycle configuration.

func (Transition) IsDateNull

func (t Transition) IsDateNull() bool

IsDateNull returns true if date field is null

func (Transition) IsDaysNull

func (t Transition) IsDaysNull() bool

IsDaysNull returns true if days field is null

func (Transition) IsNull

func (t Transition) IsNull() bool

IsNull returns true if both date and days fields are null

func (Transition) IsStorageClassNull

func (t Transition) IsStorageClassNull() bool

IsStorageClassNull returns true if Storage field is null

func (Transition) Validate

func (t Transition) Validate() error

Validate - validates the "Expiration" element

type TransitionDate

type TransitionDate struct {
	time.Time
}

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

func (*TransitionDate) MarshalXML

func (tDate *TransitionDate) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

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

func (*TransitionDate) UnmarshalXML

func (tDate *TransitionDate) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses date from Transition and validates date format

type TransitionDays

type TransitionDays int

TransitionDays is a type alias to unmarshal Days in Expiration

func (*TransitionDays) MarshalXML

func (tDays *TransitionDays) MarshalXML(e *xml.Encoder, startElement xml.StartElement) error

MarshalXML encodes number of days to expire if it is non-zero and encodes empty string otherwise

func (*TransitionDays) UnmarshalXML

func (tDays *TransitionDays) UnmarshalXML(d *xml.Decoder, startElement xml.StartElement) error

UnmarshalXML parses number of days from Transition and validates if greater than zero

Jump to

Keyboard shortcuts

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