@Summary Get template version by template ID and name @ID get-template-version-by-template-id-and-name @Security CoderSessionToken @Produce json @Tags Templates @Param template path string true "Template ID" format(uuid) @Param templateversionname path string true "Template version name" @Success 20
(rw http.ResponseWriter, r *http.Request)
| 938 | // @Success 200 {array} codersdk.TemplateVersion |
| 939 | // @Router /api/v2/templates/{template}/versions/{templateversionname} [get] |
| 940 | func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) { |
| 941 | ctx := r.Context() |
| 942 | template := httpmw.TemplateParam(r) |
| 943 | |
| 944 | templateVersionName := chi.URLParam(r, "templateversionname") |
| 945 | templateVersion, err := api.Database.GetTemplateVersionByTemplateIDAndName(ctx, database.GetTemplateVersionByTemplateIDAndNameParams{ |
| 946 | TemplateID: uuid.NullUUID{ |
| 947 | UUID: template.ID, |
| 948 | Valid: true, |
| 949 | }, |
| 950 | Name: templateVersionName, |
| 951 | }) |
| 952 | if httpapi.Is404Error(err) { |
| 953 | httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{ |
| 954 | Message: fmt.Sprintf("No template version found by name %q.", templateVersionName), |
| 955 | }) |
| 956 | return |
| 957 | } |
| 958 | if err != nil { |
| 959 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 960 | Message: "Internal error fetching template version.", |
| 961 | Detail: err.Error(), |
| 962 | }) |
| 963 | return |
| 964 | } |
| 965 | jobs, err := api.Database.GetProvisionerJobsByIDsWithQueuePosition(ctx, database.GetProvisionerJobsByIDsWithQueuePositionParams{ |
| 966 | IDs: []uuid.UUID{templateVersion.JobID}, |
| 967 | StaleIntervalMS: provisionerdserver.StaleInterval.Milliseconds(), |
| 968 | }) |
| 969 | if err != nil || len(jobs) == 0 { |
| 970 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 971 | Message: "Internal error fetching provisioner job.", |
| 972 | Detail: err.Error(), |
| 973 | }) |
| 974 | return |
| 975 | } |
| 976 | var matchedProvisioners *codersdk.MatchedProvisioners |
| 977 | if jobs[0].ProvisionerJob.JobStatus == database.ProvisionerJobStatusPending { |
| 978 | // nolint: gocritic // The user hitting this endpoint may not have |
| 979 | // permission to read provisioner daemons, but we want to show them |
| 980 | // information about the provisioner daemons that are available. |
| 981 | provisioners, err := api.Database.GetProvisionerDaemonsByOrganization(dbauthz.AsSystemReadProvisionerDaemons(ctx), database.GetProvisionerDaemonsByOrganizationParams{ |
| 982 | OrganizationID: jobs[0].ProvisionerJob.OrganizationID, |
| 983 | WantTags: jobs[0].ProvisionerJob.Tags, |
| 984 | }) |
| 985 | if err != nil { |
| 986 | api.Logger.Error(ctx, "failed to fetch provisioners for job id", slog.F("job_id", jobs[0].ProvisionerJob.ID), slog.Error(err)) |
| 987 | } else { |
| 988 | matchedProvisioners = ptr.Ref(db2sdk.MatchedProvisioners(provisioners, dbtime.Now(), provisionerdserver.StaleInterval)) |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(jobs[0]), matchedProvisioners, nil)) |
| 993 | } |
| 994 | |
| 995 | // @Summary Get template version by organization, template, and name |
| 996 | // @ID get-template-version-by-organization-template-and-name |
nothing calls this directly
no test coverage detected