Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1ae295

Browse files
committed
fix ip nullability
1 parent 9003ae0 commit c1ae295

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

coderd/database/dbauthz/dbauthz_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -4075,6 +4075,7 @@ func (s *MethodTestSuite) TestSystemFunctions() {
40754075
AgentID: agent.ID,
40764076
AppID: app.ID,
40774077
UserID: u.ID,
4078+
Ip: "127.0.0.1",
40784079
}).Asserts(rbac.ResourceSystem, policy.ActionUpdate)
40794080
}))
40804081
s.Run("InsertWorkspaceAgentScriptTimings", s.Subtest(func(db database.Store, check *expects) {

coderd/database/dbmem/dbmem.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12284,7 +12284,7 @@ func (q *FakeQuerier) UpsertWorkspaceAppAuditSession(ctx context.Context, arg da
1228412284
if s.UserID != arg.UserID {
1228512285
continue
1228612286
}
12287-
if s.Ip.IPNet.String() != arg.Ip.IPNet.String() {
12287+
if s.Ip != arg.Ip {
1228812288
continue
1228912289
}
1229012290
if s.UserAgent != arg.UserAgent {

coderd/database/dump.sql

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000301_add_workspace_app_audit_sessions.up.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CREATE UNLOGGED TABLE workspace_app_audit_sessions (
44
agent_id UUID NOT NULL,
55
app_id UUID NOT NULL, -- Can be NULL, but must be uuid.Nil.
66
user_id UUID NOT NULL, -- Can be NULL, but must be uuid.Nil.
7-
ip inet NOT NULL,
7+
ip TEXT NOT NULL,
88
user_agent TEXT NOT NULL,
99
slug_or_port TEXT NOT NULL,
1010
status_code int4 NOT NULL,

coderd/database/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspaceapps/db.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/go-jose/go-jose/v4/jwt"
1717
"github.com/google/uuid"
18-
"github.com/sqlc-dev/pqtype"
1918
"golang.org/x/xerrors"
2019

2120
"cdr.dev/slog"
@@ -367,7 +366,6 @@ func (p *DBTokenProvider) authorizeRequest(ctx context.Context, roles *rbac.Subj
367366

368367
type auditRequest struct {
369368
time time.Time
370-
ip pqtype.Inet
371369
apiKey *database.APIKey
372370
dbReq *databaseRequest
373371
}
@@ -389,7 +387,6 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
389387

390388
aReq = &auditRequest{
391389
time: dbtime.Now(),
392-
ip: audit.ParseIP(r.RemoteAddr),
393390
}
394391

395392
// Set the commit function on the status writer to create an audit
@@ -412,6 +409,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
412409
userID = aReq.apiKey.UserID
413410
}
414411
userAgent := r.UserAgent()
412+
ip := r.RemoteAddr
415413

416414
// Approximation of the status code.
417415
statusCode := sw.Status
@@ -462,7 +460,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
462460
AgentID: aReq.dbReq.Agent.ID,
463461
AppID: aReq.dbReq.App.ID, // Can be unset, in which case uuid.Nil is fine.
464462
UserID: userID, // Can be unset, in which case uuid.Nil is fine.
465-
Ip: aReq.ip,
463+
Ip: ip,
466464
UserAgent: userAgent,
467465
SlugOrPort: appInfo.SlugOrPort,
468466
StatusCode: int32(statusCode),
@@ -512,7 +510,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
512510
RequestID: requestID,
513511
Time: aReq.time,
514512
Status: statusCode,
515-
IP: aReq.ip.IPNet.IP.String(),
513+
IP: ip,
516514
UserAgent: userAgent,
517515
New: aReq.dbReq.App,
518516
AdditionalFields: appInfoBytes,
@@ -529,7 +527,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
529527
RequestID: requestID,
530528
Time: aReq.time,
531529
Status: statusCode,
532-
IP: aReq.ip.IPNet.IP.String(),
530+
IP: ip,
533531
UserAgent: userAgent,
534532
New: aReq.dbReq.Agent,
535533
AdditionalFields: appInfoBytes,

0 commit comments

Comments
 (0)