-
Notifications
You must be signed in to change notification settings - Fork 782
Add shared software update schedule validation logic #38016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,36 @@ type SoftwareAutoUpdateSchedule struct { | |
| SoftwareAutoUpdateConfig | ||
| } | ||
|
|
||
| func (s SoftwareAutoUpdateSchedule) WindowIsValid() error { | ||
| if s.AutoUpdateEnabled == nil || !*s.AutoUpdateEnabled { | ||
| return nil | ||
| } | ||
|
Comment on lines
274
to
276
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A e.g. 30m window can end up on the database by setting In which case we can drop the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to update just the start and end time without flipping enabled? OR are all the three values always sent?
Thoughts?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The more relevant point is that it's not possible to flip The lowest-touch solution here is to ignore start and end time values when |
||
| if s.AutoUpdateStartTime == nil || s.AutoUpdateEndTime == nil || *s.AutoUpdateStartTime == "" || *s.AutoUpdateEndTime == "" { | ||
| return errors.New("Start and end time must both be set") | ||
| } | ||
| // Validate that the times are in HH:MM format. | ||
| // Note that durations can be arbitrarily long, but parsing in this way | ||
| // automatically validates that the hours are between 0 and 23 and the minutes are between 0 and 59. | ||
| startDuration, err := time.Parse("15:04", *s.AutoUpdateStartTime) | ||
| if err != nil { | ||
| return fmt.Errorf("Error parsing start time: %w", err) | ||
| } | ||
| endDuration, err := time.Parse("15:04", *s.AutoUpdateEndTime) | ||
| if err != nil { | ||
| return fmt.Errorf("Error parsing end time: %w", err) | ||
| } | ||
| // Validate that the window is at least one hour long. | ||
| // If the end time is less than the start time, the window wraps to the next day, so we need to add 24 hours to the end time in that case. | ||
| if endDuration.Before(startDuration) { | ||
| endDuration = endDuration.Add(24 * time.Hour) | ||
| } | ||
sgress454 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if endDuration.Sub(startDuration) < time.Hour { | ||
| return errors.New("The update window must be at least one hour long") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| type SoftwareAutoUpdateScheduleFilter struct { | ||
| Enabled *bool | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is slightly tortured. I deliberately kept the auto-update config out of
svc.UpdateAppStoreApp()because it has nothing to do with app store apps per se. But the endpoint runs this method first, so if we waited to do the validation inside ofsvc.UpdateSoftwareTitleAutoUpdateConfig()then we could end up in a situation where we update the app and then fail the API call because the schedule is invalid.The simplest thing would be to do the validation in the endpoint handler, but our pattern is to do everything in service methods and in fact doing validations at the endpoint is not well supported; if you try to return a validation error you'll just end up with a 500 error because it'll fail authz (which is done in the service methods).
Tempted to just give up and refactor so that the auto-update schedule is handled at the end of
UpdateAppStoreApp()after all, but to keep this low-touch I'm going with this for now.