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

Method postArchiveTemplateVersions

coderd/templateversions.go:1193–1248  ·  view source on GitHub ↗

@Summary Archive template unused versions by template id @ID archive-template-unused-versions-by-template-id @Security CoderSessionToken @Accept json @Produce json @Tags Templates @Param template path string true "Template ID" format(uuid) @Param request body codersdk.ArchiveTemplateVersionsRequest

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

Source from the content-addressed store, hash-verified

1191// @Success 200 {object} codersdk.Response
1192// @Router /api/v2/templates/{template}/versions/archive [post]
1193func (api *API) postArchiveTemplateVersions(rw http.ResponseWriter, r *http.Request) {
1194 var (
1195 ctx = r.Context()
1196 template = httpmw.TemplateParam(r)
1197 auditor = *api.Auditor.Load()
1198 aReq, commitAudit = audit.InitRequest[database.Template](rw, &audit.RequestParams{
1199 Audit: auditor,
1200 Log: api.Logger,
1201 Request: r,
1202 Action: database.AuditActionWrite,
1203 OrganizationID: template.OrganizationID,
1204 })
1205 )
1206 defer commitAudit()
1207 aReq.Old = template
1208
1209 var req codersdk.ArchiveTemplateVersionsRequest
1210 if !httpapi.Read(ctx, rw, r, &req) {
1211 return
1212 }
1213
1214 status := database.NullProvisionerJobStatus{
1215 ProvisionerJobStatus: database.ProvisionerJobStatusFailed,
1216 Valid: true,
1217 }
1218 if req.All {
1219 status = database.NullProvisionerJobStatus{}
1220 }
1221
1222 archived, err := api.Database.ArchiveUnusedTemplateVersions(ctx, database.ArchiveUnusedTemplateVersionsParams{
1223 UpdatedAt: dbtime.Now(),
1224 TemplateID: template.ID,
1225 JobStatus: status,
1226 // Archive all versions that match
1227 TemplateVersionID: uuid.Nil,
1228 })
1229
1230 if httpapi.Is404Error(err) {
1231 httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
1232 Message: "Template or template versions not found.",
1233 })
1234 return
1235 }
1236 if err != nil {
1237 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1238 Message: "Internal error fetching template version.",
1239 Detail: err.Error(),
1240 })
1241 return
1242 }
1243
1244 httpapi.Write(ctx, rw, http.StatusOK, codersdk.ArchiveTemplateVersionsResponse{
1245 TemplateID: template.ID,
1246 ArchivedIDs: archived,
1247 })
1248}
1249
1250// @Summary Archive template version

Callers

nothing calls this directly

Calls 10

TemplateParamFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
NowFunction · 0.92
Is404ErrorFunction · 0.92
WriteFunction · 0.92
ContextMethod · 0.65
LoadMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected