Skip to content

feat: add endpoint for resolving autostart status #10507

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

Merged
merged 9 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pr changes
  • Loading branch information
sreya committed Nov 8, 2023
commit 1e9fede5aa10f68ce0a6913eb4fc594b46202cd4
14 changes: 9 additions & 5 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,8 @@ func (api *API) resolveAutostart(rw http.ResponseWriter, r *http.Request) {
return
}

useActiveVersion := template.RequireActiveVersion || workspace.AutomaticUpdates == database.AutomaticUpdatesAlways
templateAccessControl := (*(api.AccessControlStore.Load())).GetTemplateAccessControl(template)
useActiveVersion := templateAccessControl.RequireActiveVersion || workspace.AutomaticUpdates == database.AutomaticUpdatesAlways
if !useActiveVersion {
httpapi.Write(ctx, rw, http.StatusOK, codersdk.ResolveAutostartResponse{})
return
Expand Down Expand Up @@ -1111,7 +1112,7 @@ func (api *API) resolveAutostart(rw http.ResponseWriter, r *http.Request) {

dbVersionParams, err := api.Database.GetTemplateVersionParameters(ctx, version.ID)
if err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching template version parameters.",
Detail: err.Error(),
})
Expand Down Expand Up @@ -1141,13 +1142,16 @@ func (api *API) resolveAutostart(rw http.ResponseWriter, r *http.Request) {
}

var response codersdk.ResolveAutostartResponse
for i := 0; i < len(versionParams) && !response.ParameterMismatch; i++ {
_, err := resolver.ValidateResolve(versionParams[i], nil)
for _, param := range versionParams {
_, err := resolver.ValidateResolve(param, nil)
// There's a parameter mismatch if we get an error back from the
// resolver.
response.ParameterMismatch = err != nil
}
if response.ParameterMismatch {
break
}

}
httpapi.Write(ctx, rw, http.StatusOK, response)
}

Expand Down