mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: update golang to 1.24.1 (#17035)
- Update go.mod to use Go 1.24.1 - Update GitHub Actions setup-go action to use Go 1.24.1 - Fix linting issues with golangci-lint by: - Updating to golangci-lint v1.57.1 (more compatible with Go 1.24.1) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <claude@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
type Auditor interface {
|
||||
Export(ctx context.Context, alog database.AuditLog) error
|
||||
diff(old, new any) Map
|
||||
diff(old, newVal any) Map
|
||||
}
|
||||
|
||||
type AdditionalFields struct {
|
||||
|
||||
@@ -60,10 +60,10 @@ func Diff[T Auditable](a Auditor, left, right T) Map { return a.diff(left, right
|
||||
// the Auditor feature interface. Only types in the same package as the
|
||||
// interface can implement unexported methods.
|
||||
type Differ struct {
|
||||
DiffFn func(old, new any) Map
|
||||
DiffFn func(old, newVal any) Map
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func (d Differ) diff(old, new any) Map {
|
||||
return d.DiffFn(old, new)
|
||||
func (d Differ) diff(old, newVal any) Map {
|
||||
return d.DiffFn(old, newVal)
|
||||
}
|
||||
|
||||
+35
-30
@@ -407,11 +407,12 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
|
||||
|
||||
var userID uuid.UUID
|
||||
key, ok := httpmw.APIKeyOptional(p.Request)
|
||||
if ok {
|
||||
switch {
|
||||
case ok:
|
||||
userID = key.UserID
|
||||
} else if req.UserID != uuid.Nil {
|
||||
case req.UserID != uuid.Nil:
|
||||
userID = req.UserID
|
||||
} else {
|
||||
default:
|
||||
// if we do not have a user associated with the audit action
|
||||
// we do not want to audit
|
||||
// (this pertains to logins; we don't want to capture non-user login attempts)
|
||||
@@ -425,16 +426,17 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
|
||||
|
||||
ip := ParseIP(p.Request.RemoteAddr)
|
||||
auditLog := database.AuditLog{
|
||||
ID: uuid.New(),
|
||||
Time: dbtime.Now(),
|
||||
UserID: userID,
|
||||
Ip: ip,
|
||||
UserAgent: sql.NullString{String: p.Request.UserAgent(), Valid: true},
|
||||
ResourceType: either(req.Old, req.New, ResourceType[T], req.params.Action),
|
||||
ResourceID: either(req.Old, req.New, ResourceID[T], req.params.Action),
|
||||
ResourceTarget: either(req.Old, req.New, ResourceTarget[T], req.params.Action),
|
||||
Action: action,
|
||||
Diff: diffRaw,
|
||||
ID: uuid.New(),
|
||||
Time: dbtime.Now(),
|
||||
UserID: userID,
|
||||
Ip: ip,
|
||||
UserAgent: sql.NullString{String: p.Request.UserAgent(), Valid: true},
|
||||
ResourceType: either(req.Old, req.New, ResourceType[T], req.params.Action),
|
||||
ResourceID: either(req.Old, req.New, ResourceID[T], req.params.Action),
|
||||
ResourceTarget: either(req.Old, req.New, ResourceTarget[T], req.params.Action),
|
||||
Action: action,
|
||||
Diff: diffRaw,
|
||||
// #nosec G115 - Safe conversion as HTTP status code is expected to be within int32 range (typically 100-599)
|
||||
StatusCode: int32(sw.Status),
|
||||
RequestID: httpmw.RequestID(p.Request),
|
||||
AdditionalFields: additionalFieldsRaw,
|
||||
@@ -475,17 +477,18 @@ func BackgroundAudit[T Auditable](ctx context.Context, p *BackgroundAuditParams[
|
||||
}
|
||||
|
||||
auditLog := database.AuditLog{
|
||||
ID: uuid.New(),
|
||||
Time: p.Time,
|
||||
UserID: p.UserID,
|
||||
OrganizationID: requireOrgID[T](ctx, p.OrganizationID, p.Log),
|
||||
Ip: ip,
|
||||
UserAgent: sql.NullString{Valid: p.UserAgent != "", String: p.UserAgent},
|
||||
ResourceType: either(p.Old, p.New, ResourceType[T], p.Action),
|
||||
ResourceID: either(p.Old, p.New, ResourceID[T], p.Action),
|
||||
ResourceTarget: either(p.Old, p.New, ResourceTarget[T], p.Action),
|
||||
Action: p.Action,
|
||||
Diff: diffRaw,
|
||||
ID: uuid.New(),
|
||||
Time: p.Time,
|
||||
UserID: p.UserID,
|
||||
OrganizationID: requireOrgID[T](ctx, p.OrganizationID, p.Log),
|
||||
Ip: ip,
|
||||
UserAgent: sql.NullString{Valid: p.UserAgent != "", String: p.UserAgent},
|
||||
ResourceType: either(p.Old, p.New, ResourceType[T], p.Action),
|
||||
ResourceID: either(p.Old, p.New, ResourceID[T], p.Action),
|
||||
ResourceTarget: either(p.Old, p.New, ResourceTarget[T], p.Action),
|
||||
Action: p.Action,
|
||||
Diff: diffRaw,
|
||||
// #nosec G115 - Safe conversion as HTTP status code is expected to be within int32 range (typically 100-599)
|
||||
StatusCode: int32(p.Status),
|
||||
RequestID: p.RequestID,
|
||||
AdditionalFields: p.AdditionalFields,
|
||||
@@ -554,17 +557,19 @@ func BaggageFromContext(ctx context.Context) WorkspaceBuildBaggage {
|
||||
return d
|
||||
}
|
||||
|
||||
func either[T Auditable, R any](old, new T, fn func(T) R, auditAction database.AuditAction) R {
|
||||
if ResourceID(new) != uuid.Nil {
|
||||
return fn(new)
|
||||
} else if ResourceID(old) != uuid.Nil {
|
||||
func either[T Auditable, R any](old, newVal T, fn func(T) R, auditAction database.AuditAction) R {
|
||||
switch {
|
||||
case ResourceID(newVal) != uuid.Nil:
|
||||
return fn(newVal)
|
||||
case ResourceID(old) != uuid.Nil:
|
||||
return fn(old)
|
||||
} else if auditAction == database.AuditActionLogin || auditAction == database.AuditActionLogout {
|
||||
case auditAction == database.AuditActionLogin || auditAction == database.AuditActionLogout:
|
||||
// If the request action is a login or logout, we always want to audit it even if
|
||||
// there is no diff. See the comment in audit.InitRequest for more detail.
|
||||
return fn(old)
|
||||
default:
|
||||
panic("both old and new are nil")
|
||||
}
|
||||
panic("both old and new are nil")
|
||||
}
|
||||
|
||||
func ParseIP(ipStr string) pqtype.Inet {
|
||||
|
||||
Reference in New Issue
Block a user