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.
This commit is contained in:
db123-test
2026-05-05 17:54:07 +03:30
parent 31fc204ef2
commit 3ce20314db
2 changed files with 18 additions and 18 deletions

View File

@@ -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)
}