From 3ce20314db9a02d73028c06e4d5ea52d4169d689 Mon Sep 17 00:00:00 2001 From: db123-test Date: Tue, 5 May 2026 17:54:07 +0330 Subject: [PATCH] refactor: rename 'entry' to 'ip' in audit log schema Rename the 'entry' column to 'ip' throughout the database schema and function signatures for clarity. This affects both the CREATE TABLE statement and all INSERT queries in the audit_log table. The parameter naming in AddPermanentEntry, DeletePermanentEntry, and AddTempEntry functions has also been updated to reflect the more specific 'ip' terminology. Corresponding log messages have been adjusted to use 'temp ip' instead of 'temp entry' for consistency. --- src/auth.go | 6 +++--- src/db.go | 30 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/auth.go b/src/auth.go index 97efe56..1216f8d 100644 --- a/src/auth.go +++ b/src/auth.go @@ -89,7 +89,7 @@ func whitelistTempHandler(cfg Config, db *sql.DB) http.HandlerFunc { } clientIP := getClientIP(r) if err := AddTempEntry(db, req.IP, req.TTLSeconds, req.Reason, clientIP); err != nil { - slog.Error("failed to add temp entry", "error", err) + slog.Error("failed to add temp ip", "error", err) http.Error(w, "internal error", http.StatusInternalServerError) return } @@ -153,7 +153,7 @@ func whitelistDeleteHandler(cfg Config, db *sql.DB) http.HandlerFunc { } clientIP := getClientIP(r) if err := DeleteTempEntry(db, ip, clientIP); err != nil { - slog.Error("failed to delete temp entry", "error", err) + slog.Error("failed to delete temp ip", "error", err) http.Error(w, "internal error", http.StatusInternalServerError) return } @@ -169,7 +169,7 @@ func logsHandler(cfg Config, db *sql.DB) http.HandlerFunc { return } - query := `SELECT timestamp, action, entry, ttl_seconds, reason, api_client_ip FROM audit_log` + query := `SELECT timestamp, action, ip, ttl_seconds, reason, api_client_ip FROM audit_log` var args []any filterAction := r.URL.Query().Get("action") diff --git a/src/db.go b/src/db.go index 8457113..0b40360 100644 --- a/src/db.go +++ b/src/db.go @@ -41,7 +41,7 @@ func InitDB(dbPath string) (*sql.DB, error) { id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, action TEXT NOT NULL, - entry TEXT, + ip TEXT, ttl_seconds INTEGER, reason TEXT, api_client_ip TEXT @@ -55,14 +55,14 @@ func InitDB(dbPath string) (*sql.DB, error) { return db, nil } -func AddPermanentEntry(db *sql.DB, entry, apiClientIP string) (bool, error) { - _, err := db.Exec(`INSERT INTO perm_whitelist(ip) VALUES(?)`, entry) +func AddPermanentEntry(db *sql.DB, ip, apiClientIP string) (bool, error) { + _, err := db.Exec(`INSERT INTO perm_whitelist(ip) VALUES(?)`, ip) if err != nil { if isUniqueConstraintError(err) { _, err = db.Exec(` - INSERT INTO audit_log(action, entry, api_client_ip) + INSERT INTO audit_log(action, ip, api_client_ip) VALUES('add_perm_duplicate', ?, ?) - `, entry, apiClientIP) + `, ip, apiClientIP) if err != nil { return false, err } @@ -71,27 +71,27 @@ func AddPermanentEntry(db *sql.DB, entry, apiClientIP string) (bool, error) { return false, err } _, err = db.Exec(` - INSERT INTO audit_log(action, entry, api_client_ip) + INSERT INTO audit_log(action, ip, api_client_ip) VALUES('add_perm', ?, ?) - `, entry, apiClientIP) + `, ip, apiClientIP) if err != nil { return true, err } return true, nil } -func DeletePermanentEntry(db *sql.DB, entry, apiClientIP string) error { +func DeletePermanentEntry(db *sql.DB, ip, apiClientIP string) error { _, err := db.Exec(` DELETE FROM perm_whitelist WHERE ip = ? - `, entry) + `, ip) if err != nil { return err } _, err = db.Exec(` - INSERT INTO audit_log(action, entry, api_client_ip) + INSERT INTO audit_log(action, ip, api_client_ip) VALUES('delete_perm', ?, ?) - `, entry, apiClientIP) + `, ip, apiClientIP) if err != nil { return err } @@ -135,7 +135,7 @@ func AddTempEntry(db *sql.DB, ip string, ttlSeconds int, reason, apiClientIP str return err } _, err = db.Exec(` - INSERT INTO audit_log(action, entry, ttl_seconds, reason, api_client_ip) + INSERT INTO audit_log(action, ip, ttl_seconds, reason, api_client_ip) VALUES('add_temp', ?, ?, ?, ?) `, ip, ttlSeconds, reason, apiClientIP) if err != nil { @@ -153,7 +153,7 @@ func DeleteTempEntry(db *sql.DB, ip, apiClientIP string) error { return err } _, err = db.Exec(` - INSERT INTO audit_log(action, entry, api_client_ip) + INSERT INTO audit_log(action, ip, api_client_ip) VALUES('delete_temp', ?, ?) `, ip, apiClientIP) if err != nil { @@ -209,11 +209,11 @@ func CleanupExpiredTemp(db *sql.DB) error { for _, ip := range expiredIPs { _, err = db.Exec(` - INSERT INTO audit_log(action, entry, reason) + INSERT INTO audit_log(action, ip, reason) VALUES('expire_temp', ?, ?) `, ip, reason) if err != nil { - slog.Warn("failed to log expired temp entry", "ip", ip, "error", err) + slog.Warn("failed to log expired temp ip", "ip", ip, "error", err) } slog.Info("expired temporary whitelist", "ip", ip) }