MCPcopy Index your code
hub / github.com/coder/coder / Get

Method Get

enterprise/coderd/schedule/template.go:60–103  ·  view source on GitHub ↗

Get implements agpl.TemplateScheduleStore.

(ctx context.Context, db database.Store, templateID uuid.UUID)

Source from the content-addressed store, hash-verified

58
59// Get implements agpl.TemplateScheduleStore.
60func (*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.
106func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.Store, tpl database.Template, opts agpl.TemplateScheduleOptions) (database.Template, error) {

Callers 2

SetMethod · 0.95
updateWorkspaceBuildMethod · 0.95

Calls 5

StartSpanFunction · 0.92
DurationMethod · 0.80
AutostartAllowedDaysMethod · 0.80
GetTemplateByIDMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected