Skip to content

Commit 56bf7b7

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_picker
2 parents 3d8063e + 0e63613 commit 56bf7b7

24 files changed

+374
-47
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"codersdk",
2121
"cronstrue",
2222
"databasefake",
23+
"dbfake",
24+
"dbgen",
2325
"dbtype",
2426
"DERP",
2527
"derphttp",

cli/testdata/coder_list_--output_json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"name": "test-workspace",
4949
"autostart_schedule": "CRON_TZ=US/Central 30 9 * * 1-5",
5050
"ttl_ms": 28800000,
51-
"last_used_at": "[timestamp]"
51+
"last_used_at": "[timestamp]",
52+
"deleting_at": null
5253
}
5354
]

coderd/apidoc/docs.go

Lines changed: 35 additions & 2 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: 31 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspaces.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,10 @@ func convertWorkspace(
11691169
autostartSchedule = &workspace.AutostartSchedule.String
11701170
}
11711171

1172-
ttlMillis := convertWorkspaceTTLMillis(workspace.Ttl)
1172+
var (
1173+
ttlMillis = convertWorkspaceTTLMillis(workspace.Ttl)
1174+
deletingAt = calculateDeletingAt(workspace, template)
1175+
)
11731176
return codersdk.Workspace{
11741177
ID: workspace.ID,
11751178
CreatedAt: workspace.CreatedAt,
@@ -1188,6 +1191,7 @@ func convertWorkspace(
11881191
AutostartSchedule: autostartSchedule,
11891192
TTLMillis: ttlMillis,
11901193
LastUsedAt: workspace.LastUsedAt,
1194+
DeletingAt: deletingAt,
11911195
}
11921196
}
11931197

@@ -1200,6 +1204,22 @@ func convertWorkspaceTTLMillis(i sql.NullInt64) *int64 {
12001204
return &millis
12011205
}
12021206

1207+
// Calculate the time of the upcoming workspace deletion, if applicable; otherwise, return nil.
1208+
// Workspaces may have impending deletions if InactivityTTL feature is turned on and the workspace is inactive.
1209+
func calculateDeletingAt(workspace database.Workspace, template database.Template) *time.Time {
1210+
var (
1211+
year, month, day = time.Now().Date()
1212+
beginningOfToday = time.Date(year, month, day, 0, 0, 0, 0, time.Now().Location())
1213+
)
1214+
// If InactivityTTL is turned off (set to 0), if the workspace has already been deleted,
1215+
// or if the workspace was used sometime within the last day, there is no impending deletion
1216+
if template.InactivityTTL == 0 || workspace.Deleted || workspace.LastUsedAt.After(beginningOfToday) {
1217+
return nil
1218+
}
1219+
1220+
return ptr.Ref(workspace.LastUsedAt.Add(time.Duration(template.InactivityTTL) * time.Nanosecond))
1221+
}
1222+
12031223
func validWorkspaceTTLMillis(millis *int64, templateDefault, templateMax time.Duration) (sql.NullInt64, error) {
12041224
if templateDefault == 0 && templateMax != 0 || (templateMax > 0 && templateDefault > templateMax) {
12051225
templateDefault = templateMax

coderd/workspaces_internal_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package coderd
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/coderd/database"
10+
"github.com/coder/coder/coderd/util/ptr"
11+
)
12+
13+
func Test_calculateDeletingAt(t *testing.T) {
14+
t.Parallel()
15+
16+
testCases := []struct {
17+
name string
18+
workspace database.Workspace
19+
template database.Template
20+
expected *time.Time
21+
}{
22+
{
23+
name: "DeletingAt",
24+
workspace: database.Workspace{
25+
Deleted: false,
26+
LastUsedAt: time.Now().Add(time.Duration(-10) * time.Hour * 24), // 10 days ago
27+
},
28+
template: database.Template{
29+
InactivityTTL: int64(9 * 24 * time.Hour), // 9 days
30+
},
31+
expected: ptr.Ref(time.Now().Add(time.Duration(-1) * time.Hour * 24)), // yesterday
32+
},
33+
{
34+
name: "InactivityTTLUnset",
35+
workspace: database.Workspace{
36+
Deleted: false,
37+
LastUsedAt: time.Now().Add(time.Duration(-10) * time.Hour * 24),
38+
},
39+
template: database.Template{
40+
InactivityTTL: 0,
41+
},
42+
expected: nil,
43+
},
44+
{
45+
name: "DeletedWorkspace",
46+
workspace: database.Workspace{
47+
Deleted: true,
48+
LastUsedAt: time.Now().Add(time.Duration(-10) * time.Hour * 24),
49+
},
50+
template: database.Template{
51+
InactivityTTL: int64(9 * 24 * time.Hour),
52+
},
53+
expected: nil,
54+
},
55+
{
56+
name: "ActiveWorkspace",
57+
workspace: database.Workspace{
58+
Deleted: true,
59+
LastUsedAt: time.Now().Add(time.Duration(-5) * time.Hour), // 5 hours ago
60+
},
61+
template: database.Template{
62+
InactivityTTL: int64(1 * 24 * time.Hour), // 1 day
63+
},
64+
expected: nil,
65+
},
66+
}
67+
68+
for _, tc := range testCases {
69+
tc := tc
70+
t.Run(tc.name, func(t *testing.T) {
71+
t.Parallel()
72+
73+
found := calculateDeletingAt(tc.workspace, tc.template)
74+
if tc.expected == nil {
75+
require.Nil(t, found, "impending deletion should be nil")
76+
} else {
77+
require.NotNil(t, found)
78+
require.WithinDuration(t, *tc.expected, *found, time.Second, "incorrect impending deletion")
79+
}
80+
})
81+
}
82+
}

codersdk/workspaceproxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515
type ProxyHealthStatus string
1616

1717
const (
18-
// ProxyReachable means the proxy access url is reachable and returns a healthy
18+
// ProxyHealthy means the proxy access url is reachable and returns a healthy
1919
// status code.
20-
ProxyReachable ProxyHealthStatus = "reachable"
20+
ProxyHealthy ProxyHealthStatus = "ok"
2121
// ProxyUnreachable means the proxy access url is not responding.
2222
ProxyUnreachable ProxyHealthStatus = "unreachable"
2323
// ProxyUnhealthy means the proxy access url is responding, but there is some

codersdk/workspaces.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type Workspace struct {
3434
AutostartSchedule *string `json:"autostart_schedule,omitempty"`
3535
TTLMillis *int64 `json:"ttl_ms,omitempty"`
3636
LastUsedAt time.Time `json:"last_used_at" format:"date-time"`
37+
38+
// DeletingAt indicates the time of the upcoming workspace deletion, if applicable; otherwise it is nil.
39+
// Workspaces may have impending deletions if Template.InactivityTTL feature is turned on and the workspace is inactive.
40+
DeletingAt *time.Time `json:"deleting_at" format:"date-time"`
3741
}
3842

3943
type WorkspacesRequest struct {

docs/admin/auth.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ CODER_OIDC_SIGN_IN_TEXT="Sign in with Gitea"
197197
CODER_OIDC_ICON_URL=https://gitea.io/images/gitea.png
198198
```
199199

200+
## Disable Built-in Authentication
201+
202+
To remove email and password login, set the following environment variable on your
203+
Coder deployment:
204+
205+
```console
206+
CODER_DISABLE_PASSWORD_AUTH=true
207+
```
208+
200209
## SCIM (enterprise)
201210

202211
Coder supports user provisioning and deprovisioning via SCIM 2.0 with header

docs/api/enterprise.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceproxies \
11921192
"errors": ["string"],
11931193
"warnings": ["string"]
11941194
},
1195-
"status": "reachable"
1195+
"status": "ok"
11961196
},
11971197
"updated_at": "2019-08-24T14:15:22Z",
11981198
"url": "string",
@@ -1234,7 +1234,7 @@ Status Code **200**
12341234

12351235
| Property | Value |
12361236
| -------- | -------------- |
1237-
| `status` | `reachable` |
1237+
| `status` | `ok` |
12381238
| `status` | `unreachable` |
12391239
| `status` | `unhealthy` |
12401240
| `status` | `unregistered` |
@@ -1289,7 +1289,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaceproxies \
12891289
"errors": ["string"],
12901290
"warnings": ["string"]
12911291
},
1292-
"status": "reachable"
1292+
"status": "ok"
12931293
},
12941294
"updated_at": "2019-08-24T14:15:22Z",
12951295
"url": "string",
@@ -1342,7 +1342,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaceproxies/{workspaceproxy} \
13421342
"errors": ["string"],
13431343
"warnings": ["string"]
13441344
},
1345-
"status": "reachable"
1345+
"status": "ok"
13461346
},
13471347
"updated_at": "2019-08-24T14:15:22Z",
13481348
"url": "string",
@@ -1453,7 +1453,7 @@ curl -X PATCH http://coder-server:8080/api/v2/workspaceproxies/{workspaceproxy}
14531453
"errors": ["string"],
14541454
"warnings": ["string"]
14551455
},
1456-
"status": "reachable"
1456+
"status": "ok"
14571457
},
14581458
"updated_at": "2019-08-24T14:15:22Z",
14591459
"url": "string",

0 commit comments

Comments
 (0)