Skip to content

Commit ee535a0

Browse files
committed
Merge branch 'main' into addproxy
2 parents c9ec3ce + 75da087 commit ee535a0

File tree

21 files changed

+223
-99
lines changed

21 files changed

+223
-99
lines changed

agent/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
592592
// proxying a port dynamically.
593593
cmd.Env = append(cmd.Env, fmt.Sprintf("VSCODE_PROXY_URI=%s", metadata.VSCodePortProxyURI))
594594

595+
// Hide Coder message on code-server's "Getting Started" page
596+
cmd.Env = append(cmd.Env, "CS_DISABLE_GETTING_STARTED_OVERRIDE=true")
597+
595598
// Load environment variables passed via the agent.
596599
// These should override all variables we manually specify.
597600
for envKey, value := range metadata.EnvironmentVariables {

cli/server.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,16 +468,17 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
468468
}
469469
}
470470

471-
// Parse the raw telemetry URL!
472-
telemetryURL, err := parseURL(cfg.Telemetry.URL.Value)
473-
if err != nil {
474-
return xerrors.Errorf("parse telemetry url: %w", err)
475-
}
476471
// Disable telemetry if the in-memory database is used unless explicitly defined!
477472
if cfg.InMemoryDatabase.Value && !cmd.Flags().Changed(cfg.Telemetry.Enable.Flag) {
478473
cfg.Telemetry.Enable.Value = false
479474
}
480475
if cfg.Telemetry.Enable.Value {
476+
// Parse the raw telemetry URL!
477+
telemetryURL, err := parseURL(cfg.Telemetry.URL.Value)
478+
if err != nil {
479+
return xerrors.Errorf("parse telemetry url: %w", err)
480+
}
481+
481482
options.Telemetry, err = telemetry.New(telemetry.Options{
482483
BuiltinPostgres: builtinPostgres,
483484
DeploymentID: deploymentID,

coderd/audit.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
5050
Action: filter.Action,
5151
Username: filter.Username,
5252
Email: filter.Email,
53+
DateFrom: filter.DateFrom,
54+
DateTo: filter.DateTo,
5355
})
5456
if err != nil {
5557
httpapi.InternalServerError(rw, err)
@@ -84,6 +86,8 @@ func (api *API) auditLogCount(rw http.ResponseWriter, r *http.Request) {
8486
Action: filter.Action,
8587
Username: filter.Username,
8688
Email: filter.Email,
89+
DateFrom: filter.DateFrom,
90+
DateTo: filter.DateTo,
8791
})
8892
if err != nil {
8993
httpapi.InternalServerError(rw, err)
@@ -142,10 +146,13 @@ func (api *API) generateFakeAuditLog(rw http.ResponseWriter, r *http.Request) {
142146
if params.ResourceID == uuid.Nil {
143147
params.ResourceID = uuid.New()
144148
}
149+
if params.Time.IsZero() {
150+
params.Time = time.Now()
151+
}
145152

146153
_, err = api.Database.InsertAuditLog(ctx, database.InsertAuditLogParams{
147154
ID: uuid.New(),
148-
Time: time.Now(),
155+
Time: params.Time,
149156
UserID: user.ID,
150157
Ip: ipNet,
151158
UserAgent: r.UserAgent(),
@@ -273,12 +280,33 @@ func auditSearchQuery(query string) (database.GetAuditLogsOffsetParams, []coders
273280
// Using the query param parser here just returns consistent errors with
274281
// other parsing.
275282
parser := httpapi.NewQueryParamParser()
283+
const layout = "2006-01-02"
284+
285+
var (
286+
dateFromString = parser.String(searchParams, "", "date_from")
287+
dateToString = parser.String(searchParams, "", "date_to")
288+
parsedDateFrom, _ = time.Parse(layout, dateFromString)
289+
parsedDateTo, _ = time.Parse(layout, dateToString)
290+
)
291+
292+
if dateToString != "" {
293+
parsedDateTo = parsedDateTo.Add(23*time.Hour + 59*time.Minute + 59*time.Second) // parsedDateTo goes to 23:59
294+
}
295+
296+
if dateToString != "" && parsedDateTo.Before(parsedDateFrom) {
297+
return database.GetAuditLogsOffsetParams{}, []codersdk.ValidationError{
298+
{Field: "q", Detail: fmt.Sprintf("DateTo value %q cannot be before than DateFrom", parsedDateTo)},
299+
}
300+
}
301+
276302
filter := database.GetAuditLogsOffsetParams{
277303
ResourceType: resourceTypeFromString(parser.String(searchParams, "", "resource_type")),
278304
ResourceID: parser.UUID(searchParams, uuid.Nil, "resource_id"),
279305
Action: actionFromString(parser.String(searchParams, "", "action")),
280306
Username: parser.String(searchParams, "", "username"),
281307
Email: parser.String(searchParams, "", "email"),
308+
DateFrom: parsedDateFrom,
309+
DateTo: parsedDateTo,
282310
}
283311

284312
return filter, parser.Errors

coderd/audit_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coderd_test
33
import (
44
"context"
55
"testing"
6+
"time"
67

78
"github.com/google/uuid"
89
"github.com/stretchr/testify/require"
@@ -54,12 +55,14 @@ func TestAuditLogsFilter(t *testing.T) {
5455
err := client.CreateTestAuditLog(ctx, codersdk.CreateTestAuditLogRequest{
5556
Action: codersdk.AuditActionCreate,
5657
ResourceType: codersdk.ResourceTypeTemplate,
58+
Time: time.Date(2022, 8, 15, 14, 30, 45, 100, time.UTC), // 2022-8-15 14:30:45
5759
})
5860
require.NoError(t, err)
5961
err = client.CreateTestAuditLog(ctx, codersdk.CreateTestAuditLogRequest{
6062
Action: codersdk.AuditActionCreate,
6163
ResourceType: codersdk.ResourceTypeUser,
6264
ResourceID: userResourceID,
65+
Time: time.Date(2022, 8, 16, 14, 30, 45, 100, time.UTC), // 2022-8-16 14:30:45
6366
})
6467
require.NoError(t, err)
6568

@@ -68,6 +71,7 @@ func TestAuditLogsFilter(t *testing.T) {
6871
Action: codersdk.AuditActionDelete,
6972
ResourceType: codersdk.ResourceTypeUser,
7073
ResourceID: userResourceID,
74+
Time: time.Date(2022, 8, 15, 14, 30, 45, 100, time.UTC), // 2022-8-15 14:30:45
7175
})
7276
require.NoError(t, err)
7377

@@ -127,6 +131,21 @@ func TestAuditLogsFilter(t *testing.T) {
127131
SearchQuery: "action:invalid",
128132
ExpectedResult: 3,
129133
},
134+
{
135+
Name: "FilterOnCreateSingleDay",
136+
SearchQuery: "action:create date_from:2022-08-15 date_to:2022-08-15",
137+
ExpectedResult: 1,
138+
},
139+
{
140+
Name: "FilterOnCreateDateFrom",
141+
SearchQuery: "action:create date_from:2022-08-15",
142+
ExpectedResult: 2,
143+
},
144+
{
145+
Name: "FilterOnCreateDateTo",
146+
SearchQuery: "action:create date_to:2022-08-15",
147+
ExpectedResult: 1,
148+
},
130149
}
131150

132151
for _, testCase := range testCases {

coderd/database/databasefake/databasefake.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,16 @@ func (q *fakeQuerier) GetAuditLogsOffset(ctx context.Context, arg database.GetAu
29952995
continue
29962996
}
29972997
}
2998+
if !arg.DateFrom.IsZero() {
2999+
if alog.Time.Before(arg.DateFrom) {
3000+
continue
3001+
}
3002+
}
3003+
if !arg.DateTo.IsZero() {
3004+
if alog.Time.After(arg.DateTo) {
3005+
continue
3006+
}
3007+
}
29983008

29993009
user, err := q.GetUserByID(ctx, alog.UserID)
30003010
userValid := err == nil
@@ -3057,6 +3067,16 @@ func (q *fakeQuerier) GetAuditLogCount(_ context.Context, arg database.GetAuditL
30573067
continue
30583068
}
30593069
}
3070+
if !arg.DateFrom.IsZero() {
3071+
if alog.Time.Before(arg.DateFrom) {
3072+
continue
3073+
}
3074+
}
3075+
if !arg.DateTo.IsZero() {
3076+
if alog.Time.After(arg.DateTo) {
3077+
continue
3078+
}
3079+
}
30603080

30613081
logs = append(logs, alog)
30623082
}

coderd/database/queries.sql.go

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

coderd/database/queries/auditlogs.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ WHERE
5050
users.email = @email
5151
ELSE true
5252
END
53+
-- Filter by date_from
54+
AND CASE
55+
WHEN @date_from :: timestamp with time zone != '0001-01-01 00:00:00' THEN
56+
"time" >= @date_from
57+
ELSE true
58+
END
59+
-- Filter by date_to
60+
AND CASE
61+
WHEN @date_to :: timestamp with time zone != '0001-01-01 00:00:00' THEN
62+
"time" <= @date_to
63+
ELSE true
64+
END
5365
ORDER BY
5466
"time" DESC
5567
LIMIT
@@ -98,6 +110,18 @@ WHERE
98110
WHEN @email :: text != '' THEN
99111
user_id = (SELECT id from users WHERE users.email = @email )
100112
ELSE true
113+
END
114+
-- Filter by date_from
115+
AND CASE
116+
WHEN @date_from :: timestamp with time zone != '0001-01-01 00:00:00' THEN
117+
"time" >= @date_from
118+
ELSE true
119+
END
120+
-- Filter by date_to
121+
AND CASE
122+
WHEN @date_to :: timestamp with time zone != '0001-01-01 00:00:00' THEN
123+
"time" <= @date_to
124+
ELSE true
101125
END;
102126

103127
-- name: InsertAuditLog :one

codersdk/audit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ type CreateTestAuditLogRequest struct {
127127
Action AuditAction `json:"action,omitempty"`
128128
ResourceType ResourceType `json:"resource_type,omitempty"`
129129
ResourceID uuid.UUID `json:"resource_id,omitempty"`
130+
Time time.Time `json:"time,omitempty"`
130131
}
131132

132133
// AuditLogs retrieves audit logs from the given page.

docs/admin/audit-logs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ The supported filters are:
3030
- `action`- The action applied to a resource. You can [find here](https://pkg.go.dev/github.com/coder/coder@main/codersdk#AuditAction) all the actions that are supported.
3131
- `username` - The username of the user who triggered the action.
3232
- `email` - The email of the user who triggered the action.
33+
- `date_from` - The inclusive start date with format `YYYY-MM-DD`.
34+
- `date_to ` - the inclusive end date with format `YYYY-MM-DD`.
3335

3436
## Enabling this feature
3537

docs/admin/configure.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ downloaded from Maven (https://repo1.maven.org/maven2) and store all data in the
3737

3838
> Postgres 13 is the minimum supported version.
3939
40+
If you are using the built-in PostgreSQL deployment and need to use `psql` (aka
41+
the PostgreSQL interactive terminal), output the connection URL with the following command:
42+
43+
```sh
44+
$ coder server postgres-builtin-url
45+
$ psql "postgres://coder@localhost:49627/coder?sslmode=disable&password=feU...yI1"
46+
```
47+
4048
## System packages
4149

4250
If you've installed Coder via a [system package](../install/packages.md) Coder, you can

docs/images/coderapp-port-forward.png

159 KB
Loading

docs/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@
7676
},
7777
{
7878
"title": "Google Cloud Platform",
79-
"description": "Setup Coder with Google Cloud Platform",
79+
"description": "Setup Coder on a GCP Compute Engine VM",
8080
"icon_path": "./images/google-cloud.svg",
8181
"path": "./quickstart/google-cloud-platform.md"
8282
},
8383
{
8484
"title": "AWS",
85-
"description": "Setup Coder with AWS",
85+
"description": "Setup Coder on an AWS EC2 VM",
8686
"icon_path": "./images/aws.svg",
8787
"path": "./quickstart/aws.md"
8888
},
8989
{
9090
"title": "Azure",
91-
"description": "Setup Coder with Azure",
91+
"description": "Setup Coder on an Azure VM",
9292
"icon_path": "./images/azure.svg",
9393
"path": "./quickstart/azure.md"
9494
}

docs/networking/port-forwarding.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,39 @@ For more examples, see `coder port-forward --help`.
4747
> To enable port forwarding via the dashboard, Coder must be configured with a
4848
> [wildcard access URL](../admin/configure.md#wildcard-access-url).
4949
50-
Use the "Port forward" button in the dashboard to access ports
51-
running on your workspace.
50+
### From an arbitrary port
51+
52+
One way to port forward in the dashboard is to use the "Port forward" button to specify an arbitrary port. Coder will also detect if processes are running, and will list them below the port picklist to click an open the running processes in the browser.
5253

5354
![Port forwarding in the UI](../images/port-forward-dashboard.png)
5455

56+
### From an coder_app resource
57+
58+
Another way to port forward is to configure a `coder_app` resource in the workspace's template. This approach shows a visual application icon in the dashboard. See the following `coder_app` example for a Node React app and note the `subdomain` and `share` settings:
59+
60+
```sh
61+
# node app
62+
resource "coder_app" "node-react-app" {
63+
agent_id = coder_agent.dev.id
64+
name = "node-react-app"
65+
icon = "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/2300px-React-icon.svg.png"
66+
url = "http://localhost:3000"
67+
subdomain = true
68+
share = "authenticated"
69+
70+
healthcheck {
71+
url = "http://localhost:3000/healthz"
72+
interval = 10
73+
threshold = 30
74+
}
75+
76+
}
77+
```
78+
79+
Valid `share` values include `owner` - private to the user, `authenticated` - accessible by any user authenticated to the Coder deployment, and `public` - accessible by users outside of the Coder deployment.
80+
81+
![Port forwarding from an app in the UI](../images/coderapp-port-forward.png)
82+
5583
## SSH
5684

5785
First, [configure SSH](../ides.md#ssh-configuration) on your

0 commit comments

Comments
 (0)