Skip to content

Commit

Permalink
feat: support multiple ISO formats for RetainUntilDate in object-locking
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiLorencato committed Jan 8, 2025
1 parent 425f5e7 commit d0fa752
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mgc/sdk/static/object_storage/objects/object-lock/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ func setObjectLocking(ctx context.Context, params setObjectLockParams, cfg commo
return
}

func parseISODate(dateStr string) (time.Time, error) {
formats := []string{
time.RFC3339, // "2006-01-02T15:04:05Z07:00"
"2006-01-02T15:04:05", // "2006-01-02T15:04:05"
"2006-01-02", // "2006-01-02"
"2006-01-02 15:04:05", // "2006-01-02 15:04:05"
"2006-01-02T15:04:05.000000Z07:00", // "2006-01-02T15:04:05.000000Z07:00"
"2006-01-02T15:04:05Z", // "2006-01-02T15:04:05Z"
}

for _, format := range formats {
date, err := time.Parse(format, dateStr)
if err == nil {
return date, nil
}
}

return time.Time{}, fmt.Errorf("invalid date format: %s", dateStr)
}

func newSetObjectLockingRequest(ctx context.Context, p setObjectLockParams, cfg common.Config) (*http.Request, error) {
url, err := common.BuildBucketHostWithPath(cfg, common.NewBucketNameFromURI(p.Object), p.Object.Path())
if err != nil {
Expand All @@ -74,7 +94,7 @@ func newSetObjectLockingRequest(ctx context.Context, p setObjectLockParams, cfg
getBody := func() (io.ReadCloser, error) {
var parsedTime time.Time

parsedTime, err = time.Parse("2006-01-02T15:04:05", p.RetainUntilDate)
parsedTime, err = parseISODate(p.RetainUntilDate)
if err != nil {
return nil, core.UsageError{Err: err}
}
Expand Down

0 comments on commit d0fa752

Please sign in to comment.