mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
fix(coderd): ensure agent timings are non-zero on insert (#18065)
Relates to https://github.com/coder/coder/issues/15432 Ensures that no workspace build timings with zero values for started_at or ended_at are inserted into the DB or returned from the API.
This commit is contained in:
@ -18,11 +18,29 @@ type ScriptsAPI struct {
|
||||
func (s *ScriptsAPI) ScriptCompleted(ctx context.Context, req *agentproto.WorkspaceAgentScriptCompletedRequest) (*agentproto.WorkspaceAgentScriptCompletedResponse, error) {
|
||||
res := &agentproto.WorkspaceAgentScriptCompletedResponse{}
|
||||
|
||||
scriptID, err := uuid.FromBytes(req.Timing.ScriptId)
|
||||
if req.GetTiming() == nil {
|
||||
return nil, xerrors.New("script timing is required")
|
||||
}
|
||||
|
||||
scriptID, err := uuid.FromBytes(req.GetTiming().GetScriptId())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("script id from bytes: %w", err)
|
||||
}
|
||||
|
||||
scriptStart := req.GetTiming().GetStart()
|
||||
if !scriptStart.IsValid() || scriptStart.AsTime().IsZero() {
|
||||
return nil, xerrors.New("script start time is required and cannot be zero")
|
||||
}
|
||||
|
||||
scriptEnd := req.GetTiming().GetEnd()
|
||||
if !scriptEnd.IsValid() || scriptEnd.AsTime().IsZero() {
|
||||
return nil, xerrors.New("script end time is required and cannot be zero")
|
||||
}
|
||||
|
||||
if scriptStart.AsTime().After(scriptEnd.AsTime()) {
|
||||
return nil, xerrors.New("script start time cannot be after end time")
|
||||
}
|
||||
|
||||
var stage database.WorkspaceAgentScriptTimingStage
|
||||
switch req.Timing.Stage {
|
||||
case agentproto.Timing_START:
|
||||
|
Reference in New Issue
Block a user