Skip to content

Commit 537ced7

Browse files
committed
removing new route; repurposing old
1 parent c049e9e commit 537ced7

File tree

12 files changed

+50
-280
lines changed

12 files changed

+50
-280
lines changed

coderd/apidoc/docs.go

Lines changed: 0 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ SET
104104
name = $4,
105105
icon = $5,
106106
display_name = $6,
107-
allow_user_cancel_workspace_jobs = $7,
108-
failure_ttl = $8,
109-
inactivity_ttl = $9
107+
allow_user_cancel_workspace_jobs = $7
110108
WHERE
111109
id = $1
112110
RETURNING
@@ -120,7 +118,9 @@ SET
120118
allow_user_autostart = $3,
121119
allow_user_autostop = $4,
122120
default_ttl = $5,
123-
max_ttl = $6
121+
max_ttl = $6,
122+
failure_ttl = $7,
123+
inactivity_ttl = $8
124124
WHERE
125125
id = $1
126126
RETURNING

coderd/schedule/template.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ type TemplateScheduleOptions struct {
1818
//
1919
// If set, users cannot disable automatic workspace shutdown.
2020
MaxTTL time.Duration `json:"max_ttl"`
21+
// If FailureTTL is set, all failed workspaces will be stopped automatically after this time has elapsed.
22+
FailureTTL time.Duration `json:"failure_ttl"`
23+
// If InactivityTTL is set, all inactive workspaces will be deleted automatically after this time has elapsed.
24+
InactivityTTL time.Duration `json:"inactivity_ttl"`
2125
}
2226

2327
// TemplateScheduleStore provides an interface for retrieving template
@@ -47,9 +51,11 @@ func (*agplTemplateScheduleStore) GetTemplateScheduleOptions(ctx context.Context
4751
UserAutostartEnabled: true,
4852
UserAutostopEnabled: true,
4953
DefaultTTL: time.Duration(tpl.DefaultTTL),
50-
// Disregard the value in the database, since MaxTTL is an enterprise
51-
// feature.
52-
MaxTTL: 0,
54+
// Disregard the values in the database, since MaxTTL, FailureTTL, and InactivityTTL are enterprise
55+
// features.
56+
MaxTTL: 0,
57+
FailureTTL: 0,
58+
InactivityTTL: 0,
5359
}, nil
5460
}
5561

@@ -68,5 +74,7 @@ func (*agplTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.Context
6874
AllowUserAutostart: tpl.AllowUserAutostart,
6975
AllowUserAutostop: tpl.AllowUserAutostop,
7076
MaxTTL: tpl.MaxTTL,
77+
FailureTTL: tpl.FailureTTL,
78+
InactivityTTL: tpl.InactivityTTL,
7179
})
7280
}

coderd/templates.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
476476
if req.MaxTTLMillis != 0 && req.DefaultTTLMillis > req.MaxTTLMillis {
477477
validErrs = append(validErrs, codersdk.ValidationError{Field: "default_ttl_ms", Detail: "Must be less than or equal to max_ttl_ms if max_ttl_ms is set."})
478478
}
479+
if req.FailureTTLMillis < 0 {
480+
validErrs = append(validErrs, codersdk.ValidationError{Field: "failure_ttl_ms", Detail: "Must be a positive integer."})
481+
}
482+
if req.InactivityTTLMillis < 0 {
483+
validErrs = append(validErrs, codersdk.ValidationError{Field: "inactivity_ttl_ms", Detail: "Must be a positive integer."})
484+
}
479485

480486
if len(validErrs) > 0 {
481487
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
@@ -495,18 +501,14 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
495501
req.AllowUserAutostop == template.AllowUserAutostop &&
496502
req.AllowUserCancelWorkspaceJobs == template.AllowUserCancelWorkspaceJobs &&
497503
req.DefaultTTLMillis == time.Duration(template.DefaultTTL).Milliseconds() &&
498-
req.MaxTTLMillis == time.Duration(template.MaxTTL).Milliseconds() {
504+
req.MaxTTLMillis == time.Duration(template.MaxTTL).Milliseconds() &&
505+
req.FailureTTLMillis == time.Duration(template.FailureTTL).Milliseconds() &&
506+
req.InactivityTTLMillis == time.Duration(template.InactivityTTL).Milliseconds() {
499507
return nil
500508
}
501509

502-
// Update template metadata -- empty fields are not overwritten,
503-
// except for display_name, description, icon, and default_ttl.
504-
// These exceptions are required to clear content of these fields with UI.
510+
// Users should not be able to clear the template name in the UI
505511
name := req.Name
506-
displayName := req.DisplayName
507-
desc := req.Description
508-
icon := req.Icon
509-
510512
if name == "" {
511513
name = template.Name
512514
}
@@ -516,9 +518,9 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
516518
ID: template.ID,
517519
UpdatedAt: database.Now(),
518520
Name: name,
519-
DisplayName: displayName,
520-
Description: desc,
521-
Icon: icon,
521+
DisplayName: req.DisplayName,
522+
Description: req.Description,
523+
Icon: req.Icon,
522524
AllowUserCancelWorkspaceJobs: req.AllowUserCancelWorkspaceJobs,
523525
})
524526
if err != nil {
@@ -527,8 +529,13 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
527529

528530
defaultTTL := time.Duration(req.DefaultTTLMillis) * time.Millisecond
529531
maxTTL := time.Duration(req.MaxTTLMillis) * time.Millisecond
532+
failureTTL := time.Duration(req.FailureTTLMillis) * time.Millisecond
533+
inactivityTTL := time.Duration(req.InactivityTTLMillis) * time.Millisecond
534+
530535
if defaultTTL != time.Duration(template.DefaultTTL) ||
531536
maxTTL != time.Duration(template.MaxTTL) ||
537+
failureTTL != time.Duration(template.FailureTTL) ||
538+
inactivityTTL != time.Duration(template.InactivityTTL) ||
532539
req.AllowUserAutostart != template.AllowUserAutostart ||
533540
req.AllowUserAutostop != template.AllowUserAutostop {
534541
updated, err = (*api.TemplateScheduleStore.Load()).SetTemplateScheduleOptions(ctx, tx, updated, schedule.TemplateScheduleOptions{
@@ -539,6 +546,8 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
539546
UserAutostopEnabled: req.AllowUserAutostop,
540547
DefaultTTL: defaultTTL,
541548
MaxTTL: maxTTL,
549+
FailureTTL: failureTTL,
550+
InactivityTTL: inactivityTTL,
542551
})
543552
if err != nil {
544553
return xerrors.Errorf("set template schedule options: %w", err)

codersdk/templates.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,8 @@ type UpdateTemplateMeta struct {
9595
AllowUserAutostart bool `json:"allow_user_autostart,omitempty"`
9696
AllowUserAutostop bool `json:"allow_user_autostop,omitempty"`
9797
AllowUserCancelWorkspaceJobs bool `json:"allow_user_cancel_workspace_jobs,omitempty"`
98-
}
99-
100-
type UpdateTemplateEnterpriseMeta struct {
101-
FailureTTL int64 `json:"failure_ttl,omitempty"`
102-
InactivityTTL int64 `json:"inactivity_ttl,omitempty"`
98+
FailureTTLMillis int64 `json:"failure_ttl_ms,omitempty"`
99+
InactivityTTLMillis int64 `json:"inactivity_ttl_ms,omitempty"`
103100
}
104101

105102
type TemplateExample struct {

docs/api/enterprise.md

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,61 +1122,6 @@ curl -X PATCH http://coder-server:8080/api/v2/templates/{template}/acl \
11221122

11231123
To perform this operation, you must be authenticated. [Learn more](authentication.md).
11241124

1125-
## Update template enterprise meta
1126-
1127-
### Code samples
1128-
1129-
```shell
1130-
# Example request using curl
1131-
curl -X PATCH http://coder-server:8080/api/v2/templates/{template}/enterprisemeta \
1132-
-H 'Content-Type: application/json' \
1133-
-H 'Accept: application/json' \
1134-
-H 'Coder-Session-Token: API_KEY'
1135-
```
1136-
1137-
`PATCH /templates/{template}/enterprisemeta`
1138-
1139-
> Body parameter
1140-
1141-
```json
1142-
{
1143-
"failure_ttl": 0,
1144-
"inactivity_ttl": 0
1145-
}
1146-
```
1147-
1148-
### Parameters
1149-
1150-
| Name | In | Type | Required | Description |
1151-
| ---------- | ---- | ---------------------------------------------------------------------------------------- | -------- | ------------------------------- |
1152-
| `template` | path | string(uuid) | true | Template ID |
1153-
| `body` | body | [codersdk.UpdateTemplateEnterpriseMeta](schemas.md#codersdkupdatetemplateenterprisemeta) | true | Update template enterprise meta |
1154-
1155-
### Example responses
1156-
1157-
> 200 Response
1158-
1159-
```json
1160-
{
1161-
"detail": "string",
1162-
"message": "string",
1163-
"validations": [
1164-
{
1165-
"detail": "string",
1166-
"field": "string"
1167-
}
1168-
]
1169-
}
1170-
```
1171-
1172-
### Responses
1173-
1174-
| Status | Meaning | Description | Schema |
1175-
| ------ | ------------------------------------------------------- | ----------- | ------------------------------------------------ |
1176-
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.Response](schemas.md#codersdkresponse) |
1177-
1178-
To perform this operation, you must be authenticated. [Learn more](authentication.md).
1179-
11801125
## Get workspace quota by user
11811126

11821127
### Code samples

0 commit comments

Comments
 (0)