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

Method templateVersionByOrganizationTemplateAndName

coderd/templateversions.go:1005–1077  ·  view source on GitHub ↗

@Summary Get template version by organization, template, and name @ID get-template-version-by-organization-template-and-name @Security CoderSessionToken @Produce json @Tags Templates @Param organization path string true "Organization ID" format(uuid) @Param templatename path string true "Template na

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

1003// @Success 200 {object} codersdk.TemplateVersion
1004// @Router /api/v2/organizations/{organization}/templates/{templatename}/versions/{templateversionname} [get]
1005func (api *API) templateVersionByOrganizationTemplateAndName(rw http.ResponseWriter, r *http.Request) {
1006 ctx := r.Context()
1007 organization := httpmw.OrganizationParam(r)
1008 templateName := chi.URLParam(r, "templatename")
1009
1010 template, err := api.Database.GetTemplateByOrganizationAndName(ctx, database.GetTemplateByOrganizationAndNameParams{
1011 OrganizationID: organization.ID,
1012 Name: templateName,
1013 })
1014 if err != nil {
1015 if httpapi.Is404Error(err) {
1016 httpapi.ResourceNotFound(rw)
1017 return
1018 }
1019
1020 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1021 Message: "Internal error fetching template.",
1022 Detail: err.Error(),
1023 })
1024 return
1025 }
1026
1027 templateVersionName := chi.URLParam(r, "templateversionname")
1028 templateVersion, err := api.Database.GetTemplateVersionByTemplateIDAndName(ctx, database.GetTemplateVersionByTemplateIDAndNameParams{
1029 TemplateID: uuid.NullUUID{
1030 UUID: template.ID,
1031 Valid: true,
1032 },
1033 Name: templateVersionName,
1034 })
1035 if httpapi.Is404Error(err) {
1036 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
1037 Message: fmt.Sprintf("No template version found by name %q.", templateVersionName),
1038 })
1039 return
1040 }
1041 if err != nil {
1042 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1043 Message: "Internal error fetching template version.",
1044 Detail: err.Error(),
1045 })
1046 return
1047 }
1048 jobs, err := api.Database.GetProvisionerJobsByIDsWithQueuePosition(ctx, database.GetProvisionerJobsByIDsWithQueuePositionParams{
1049 IDs: []uuid.UUID{templateVersion.JobID},
1050 StaleIntervalMS: provisionerdserver.StaleInterval.Milliseconds(),
1051 })
1052 if err != nil || len(jobs) == 0 {
1053 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1054 Message: "Internal error fetching provisioner job.",
1055 Detail: err.Error(),
1056 })
1057 return
1058 }
1059
1060 var matchedProvisioners *codersdk.MatchedProvisioners
1061 if jobs[0].ProvisionerJob.JobStatus == database.ProvisionerJobStatusPending {
1062 // nolint: gocritic // The user hitting this endpoint may not have

Callers

nothing calls this directly

Calls 15

OrganizationParamFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
RefFunction · 0.92
MatchedProvisionersFunction · 0.92
NowFunction · 0.92
convertTemplateVersionFunction · 0.85
convertProvisionerJobFunction · 0.85
ContextMethod · 0.65

Tested by

no test coverage detected