Store IPv6 addresses correctly

This commit is contained in:
Roman Vynar 2024-08-15 14:56:51 +03:00
parent 6dc1408576
commit 920e4132f0

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -26,7 +27,7 @@ const (
action CHAR(5) NULL, action CHAR(5) NULL,
repository VARCHAR(100) NULL, repository VARCHAR(100) NULL,
tag VARCHAR(100) NULL, tag VARCHAR(100) NULL,
ip VARCHAR(15) NULL, ip VARCHAR(45) NULL,
user VARCHAR(50) NULL, user VARCHAR(50) NULL,
created DATETIME NULL created DATETIME NULL
); );
@ -112,7 +113,10 @@ func (e *EventListener) ProcessEvents(request *http.Request) {
if tag == "" { if tag == "" {
tag = i.Get("target.digest").String() tag = i.Get("target.digest").String()
} }
ip := strings.Split(i.Get("request.addr").String(), ":")[0] ip := i.Get("request.addr").String()
if x, _, _ := net.SplitHostPort(ip); x != "" {
ip = x
}
user := i.Get("actor.name").String() user := i.Get("actor.name").String()
e.logger.Debugf("Parsed event data: %s %s:%s %s %s ", action, repository, tag, ip, user) e.logger.Debugf("Parsed event data: %s %s:%s %s %s ", action, repository, tag, ip, user)