Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joremysh committed Oct 25, 2024
1 parent 20cdb1a commit 25daf77
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 32 deletions.
84 changes: 52 additions & 32 deletions minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (g ExpiryGroup) String() string {
return string(g)
}

type ExpiryRule struct {
Tag string
ExpirationDays int
}

const (
Location = "us-east-1"

Expand All @@ -55,7 +60,7 @@ type minio struct {
bucket string
}

func NewMinioClientAndInitBucket(ctx context.Context, cfg *Config, logger *zap.Logger) (MinioI, error) {
func NewMinioClientAndInitBucket(ctx context.Context, cfg *Config, logger *zap.Logger, expiryRules ...ExpiryRule) (MinioI, error) {
logger.Info("Initializing Minio client and bucket...")

endpoint := net.JoinHostPort(cfg.Host, cfg.Port)
Expand Down Expand Up @@ -98,45 +103,60 @@ func NewMinioClientAndInitBucket(ctx context.Context, cfg *Config, logger *zap.L
Days: lifecycle.ExpirationDays(30),
},
},
{
ID: "free-plan-rule",
Status: StatusEnabled,
Expiration: lifecycle.Expiration{
Days: lifecycle.ExpirationDays(expiryTimeConfig[FreePlanExpiry]),
},
RuleFilter: lifecycle.Filter{
Tag: lifecycle.Tag{
Key: ExpiryTag,
Value: FreePlanExpiry.String(),
},
},
},
{
ID: "pro-plan-rule",
Status: StatusEnabled,
Expiration: lifecycle.Expiration{
Days: lifecycle.ExpirationDays(expiryTimeConfig[ProPlanExpiry]),
},
RuleFilter: lifecycle.Filter{
Tag: lifecycle.Tag{
Key: ExpiryTag,
Value: ProPlanExpiry.String(),
},
},
},
{
ID: "team-plan-rule",
// {
// ID: "free-plan-rule",
// Status: StatusEnabled,
// Expiration: lifecycle.Expiration{
// Days: lifecycle.ExpirationDays(expiryTimeConfig[FreePlanExpiry]),
// },
// RuleFilter: lifecycle.Filter{
// Tag: lifecycle.Tag{
// Key: ExpiryTag,
// Value: FreePlanExpiry.String(),
// },
// },
// },
// {
// ID: "pro-plan-rule",
// Status: StatusEnabled,
// Expiration: lifecycle.Expiration{
// Days: lifecycle.ExpirationDays(expiryTimeConfig[ProPlanExpiry]),
// },
// RuleFilter: lifecycle.Filter{
// Tag: lifecycle.Tag{
// Key: ExpiryTag,
// Value: ProPlanExpiry.String(),
// },
// },
// },
// {
// ID: "team-plan-rule",
// Status: StatusEnabled,
// Expiration: lifecycle.Expiration{
// Days: lifecycle.ExpirationDays(expiryTimeConfig[TeamPlanExpiry]),
// },
// RuleFilter: lifecycle.Filter{
// Tag: lifecycle.Tag{
// Key: ExpiryTag,
// Value: TeamPlanExpiry.String(),
// },
// },
// },
}
for _, expiryRule := range expiryRules {
lccfg.Rules = append(lccfg.Rules, lifecycle.Rule{
ID: expiryRule.Tag,
Status: StatusEnabled,
Expiration: lifecycle.Expiration{
Days: lifecycle.ExpirationDays(expiryTimeConfig[TeamPlanExpiry]),
Days: lifecycle.ExpirationDays(expiryRule.ExpirationDays),
},
RuleFilter: lifecycle.Filter{
Tag: lifecycle.Tag{
Key: ExpiryTag,
Value: TeamPlanExpiry.String(),
Value: expiryRule.Tag,
},
},
},
})
}

err = client.SetBucketLifecycle(ctx, cfg.BucketName, lccfg)
Expand Down
7 changes: 7 additions & 0 deletions minio/minio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ func TestMinio(t *testing.T) {
fileBytes, err := mc.GetFile(ctx, log, fileName.String())
require.NoError(t, err)
require.Equal(t, jsonBytes, fileBytes)

err = mc.DeleteFile(ctx, log, fileName.String())
require.NoError(t, err)

fileBytes, err = mc.GetFile(ctx, log, fileName.String())

Check failure on line 57 in minio/minio_test.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to fileBytes (ineffassign)

Check failure on line 57 in minio/minio_test.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to fileBytes (ineffassign)
require.Error(t, err)

}

0 comments on commit 25daf77

Please sign in to comment.