s3lifecycle

package
v0.0.0-...-546e6a5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BucketTypeAdminManaged  = "admin_managed"
	BucketTypeUserSpecified = "user_specified"
)
View Source
const (
	AdminBucketCategoryLog              = "log"
	AdminBucketCategoryLogLongRetention = "log_long_retention"
	AdminBucketCategoryLogFailedTasks   = "log_failed_tasks"
)
View Source
const (
	Collection = "s3_lifecycle_rules"
)

Variables

View Source
var (
	IDKey                      = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "ID")
	BucketNameKey              = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "BucketName")
	FilterPrefixKey            = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "FilterPrefix")
	BucketTypeKey              = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "BucketType")
	RegionKey                  = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "Region")
	AWSAccountIDKey            = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "AWSAccountID")
	AdminBucketCategoryKey     = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "AdminBucketCategory")
	ProjectAssociationsKey     = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "ProjectAssociations")
	RuleIDKey                  = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "RuleID")
	RuleStatusKeyDoc           = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "RuleStatus")
	ExpirationDaysKey          = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "ExpirationDays")
	TransitionToIADaysKey      = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "TransitionToIADays")
	TransitionToGlacierDaysKey = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "TransitionToGlacierDays")
	TransitionsKey             = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "Transitions")
	LastSyncedAtKey            = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "LastSyncedAt")
	SyncErrorKey               = bsonutil.MustHaveTag(S3LifecycleRuleDoc{}, "SyncError")
)

Functions

func BuildPailRulesByBucket

func BuildPailRulesByBucket(rules []S3LifecycleRuleDoc) map[string][]pail.LifecycleRule

BuildPailRulesByBucket converts a slice of S3LifecycleRuleDocs into a map of bucket name to pail.LifecycleRule, converting the type once at setup rather than on every per-file lookup.

func DiscoverAdminManagedBuckets

func DiscoverAdminManagedBuckets(ctx context.Context, settings *evergreen.Settings) (map[string]BucketInfo, error)

DiscoverAdminManagedBuckets returns information about admin-managed buckets from BucketsConfig.

func DiscoverAndCacheProjectBucket

func DiscoverAndCacheProjectBucket(ctx context.Context, bucketName, region string, roleARN *string, externalID *string, fallbackAccountID, projectID string, storageCostConfig *evergreen.S3StorageCostConfig, client S3LifecycleClient) bool

DiscoverAndCacheProjectBucket checks if we have lifecycle rules cached for a bucket and fetches them if not. It returns true if rules were successfully cached (discovery succeeded), false if already cached, if the bucket's artifacts are never priced or its rules are unreadable, or if discovery failed. fallbackAccountID is used when the account cannot be derived from roleARN, which is the case for key+secret s3.put uploads. An upload with no account at all is skipped, since it is never priced. This is best-effort - errors are logged but not returned to avoid failing file uploads.

func FindDistinctBucketNames

func FindDistinctBucketNames(ctx context.Context, bucketType string) ([]string, error)

FindDistinctBucketNames returns all unique bucket names for the given bucket type.

func Remove

func Remove(ctx context.Context, bucketName, filterPrefix string) error

Remove deletes the lifecycle rule for the specified bucket and prefix.

func UpdateSyncError

func UpdateSyncError(ctx context.Context, bucketName, filterPrefix, syncError string) error

UpdateSyncError updates the sync error field. Pass an empty string to clear the error.

Types

type BucketInfo

type BucketInfo struct {
	Name       string
	Region     string
	RoleARN    *string
	ExternalID *string
}

BucketInfo contains information needed to fetch lifecycle rules for a bucket.

type S3LifecycleClient

type S3LifecycleClient interface {
	GetBucketLifecycleConfiguration(ctx context.Context, bucket, region string, roleARN *string, externalID *string) ([]pail.LifecycleRule, error)
}

S3LifecycleClient fetches lifecycle configurations for an S3 bucket.

type S3LifecycleRuleDoc

type S3LifecycleRuleDoc struct {
	ID string `bson:"_id" json:"id"`

	BucketName   string `bson:"bucket_name" json:"bucket_name"`
	FilterPrefix string `bson:"filter_prefix" json:"filter_prefix"` // Empty string applies to all objects (default rule)
	BucketType   string `bson:"bucket_type" json:"bucket_type"`
	Region       string `bson:"region" json:"region"`
	// AWSAccountID is the 12-digit AWS account ID that owns this bucket, derived from the IAM role ARN used
	// during discovery. Empty for buckets that use key+secret authentication.
	AWSAccountID string `bson:"aws_account_id,omitempty" json:"aws_account_id,omitempty"`

	AdminBucketCategory string   `bson:"admin_bucket_category,omitempty" json:"admin_bucket_category,omitempty"`
	ProjectAssociations []string `bson:"project_associations" json:"project_associations"`

	RuleID     string `bson:"rule_id" json:"rule_id"`
	RuleStatus string `bson:"rule_status" json:"rule_status"`

	// Lifecycle configuration fields for cost calculation.
	// Note: These use *int (not *int32) for consistency with existing Evergreen DB schemas.
	// Pail provides these as *int32, so conversion is needed during sync.
	ExpirationDays          *int         `bson:"expiration_days,omitempty" json:"expiration_days,omitempty"`
	TransitionToIADays      *int         `bson:"transition_to_ia_days,omitempty" json:"transition_to_ia_days,omitempty"`
	TransitionToGlacierDays *int         `bson:"transition_to_glacier_days,omitempty" json:"transition_to_glacier_days,omitempty"`
	Transitions             []Transition `bson:"transitions,omitempty" json:"transitions,omitempty"`

	LastSyncedAt time.Time `bson:"last_synced_at" json:"last_synced_at"`
	SyncError    string    `bson:"sync_error,omitempty" json:"sync_error,omitempty"`
}

S3LifecycleRuleDoc represents a single S3 lifecycle rule for a bucket+prefix combination. Each rule is stored as a separate document with a composite ID "bucketName#filterPrefix".

func FindAllRules

func FindAllRules(ctx context.Context) ([]S3LifecycleRuleDoc, error)

FindAllRules retrieves all S3 lifecycle rules across all buckets.

func FindAllRulesForBucket

func FindAllRulesForBucket(ctx context.Context, bucketName string) ([]S3LifecycleRuleDoc, error)

FindAllRulesForBucket retrieves all lifecycle rules for the specified bucket.

func FindByBucketAndPrefix

func FindByBucketAndPrefix(ctx context.Context, bucketName, filterPrefix string) (*S3LifecycleRuleDoc, error)

FindByBucketAndPrefix retrieves a single lifecycle rule document by bucket name and prefix.

func (*S3LifecycleRuleDoc) Upsert

func (s *S3LifecycleRuleDoc) Upsert(ctx context.Context) error

Upsert inserts or updates the lifecycle rule document in the database.

type Transition

type Transition struct {
	Days         *int32 `bson:"days,omitempty" json:"days,omitempty"`
	StorageClass string `bson:"storage_class" json:"storage_class"`
}

Transition specifies when objects transition to a different storage class.

Jump to

Keyboard shortcuts

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