Get implements agpl.TemplateScheduleStore.
(ctx context.Context, db database.Store, templateID uuid.UUID)
| 58 | |
| 59 | // Get implements agpl.TemplateScheduleStore. |
| 60 | func (*EnterpriseTemplateScheduleStore) Get(ctx context.Context, db database.Store, templateID uuid.UUID) (agpl.TemplateScheduleOptions, error) { |
| 61 | ctx, span := tracing.StartSpan(ctx) |
| 62 | defer span.End() |
| 63 | |
| 64 | tpl, err := db.GetTemplateByID(ctx, templateID) |
| 65 | if err != nil { |
| 66 | return agpl.TemplateScheduleOptions{}, err |
| 67 | } |
| 68 | |
| 69 | // These extra checks have to be done before the conversion because we lose |
| 70 | // precision and signs when converting to the agpl types from the database. |
| 71 | if tpl.AutostopRequirementDaysOfWeek < 0 { |
| 72 | return agpl.TemplateScheduleOptions{}, xerrors.New("invalid autostop requirement days, negative") |
| 73 | } |
| 74 | if tpl.AutostopRequirementDaysOfWeek > 0b11111111 { |
| 75 | return agpl.TemplateScheduleOptions{}, xerrors.New("invalid autostop requirement days, too large") |
| 76 | } |
| 77 | if tpl.AutostopRequirementWeeks == 0 { |
| 78 | tpl.AutostopRequirementWeeks = 1 |
| 79 | } |
| 80 | // #nosec G115 - Safe conversion as we've verified tpl.AutostopRequirementDaysOfWeek is <= 255 |
| 81 | err = agpl.VerifyTemplateAutostopRequirement(uint8(tpl.AutostopRequirementDaysOfWeek), tpl.AutostopRequirementWeeks) |
| 82 | if err != nil { |
| 83 | return agpl.TemplateScheduleOptions{}, err |
| 84 | } |
| 85 | |
| 86 | return agpl.TemplateScheduleOptions{ |
| 87 | UserAutostartEnabled: tpl.AllowUserAutostart, |
| 88 | UserAutostopEnabled: tpl.AllowUserAutostop, |
| 89 | DefaultTTL: time.Duration(tpl.DefaultTTL), |
| 90 | ActivityBump: time.Duration(tpl.ActivityBump), |
| 91 | AutostopRequirement: agpl.TemplateAutostopRequirement{ |
| 92 | // #nosec G115 - Safe conversion as we've verified tpl.AutostopRequirementDaysOfWeek is <= 255 |
| 93 | DaysOfWeek: uint8(tpl.AutostopRequirementDaysOfWeek), |
| 94 | Weeks: tpl.AutostopRequirementWeeks, |
| 95 | }, |
| 96 | AutostartRequirement: agpl.TemplateAutostartRequirement{ |
| 97 | DaysOfWeek: tpl.AutostartAllowedDays(), |
| 98 | }, |
| 99 | FailureTTL: time.Duration(tpl.FailureTTL), |
| 100 | TimeTilDormant: time.Duration(tpl.TimeTilDormant), |
| 101 | TimeTilDormantAutoDelete: time.Duration(tpl.TimeTilDormantAutoDelete), |
| 102 | }, nil |
| 103 | } |
| 104 | |
| 105 | // Set implements agpl.TemplateScheduleStore. |
| 106 | func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.Store, tpl database.Template, opts agpl.TemplateScheduleOptions) (database.Template, error) { |
no test coverage detected