Content-Length: 883033 | pFad | http://github.com/coder/coder/commit/ee535a02a94d7d0b21958822efa32d85bcad6dbe

92 Merge branch 'main' into addproxy · coder/coder@ee535a0 · GitHub
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

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/coder/coder/commit/ee535a02a94d7d0b21958822efa32d85bcad6dbe

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy