repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
d247cbd
parent
bd8d606
author
Eric Bower
date
2025-12-17 19:31:56 -0500 EST
feat: find access logs by pubkey
3 files changed,  +31, -0
M pkg/db/db.go
+1, -0
1@@ -466,6 +466,7 @@ type DB interface {
2 	InsertAccessLog(log *AccessLog) error
3 	FindAccessLogs(userID string, fromDate *time.Time) ([]*AccessLog, error)
4 	FindPubkeysInAccessLogs(userID string) ([]string, error)
5+	FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*AccessLog, error)
6 
7 	Close() error
8 }
M pkg/db/postgres/storage.go
+26, -0
 1@@ -1967,6 +1967,32 @@ func (me *PsqlDB) FindAccessLogs(userID string, fromDate *time.Time) ([]*db.Acce
 2 	return logs, nil
 3 }
 4 
 5+func (me *PsqlDB) FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*db.AccessLog, error) {
 6+	logs := []*db.AccessLog{}
 7+	rs, err := me.Db.Query(
 8+		`SELECT id, user_id, service, pubkey, identity, created_at FROM access_logs WHERE pubkey=$1 AND created_at >= $2 ORDER BY created_at DESC`, pubkey, fromDate)
 9+	if err != nil {
10+		return nil, err
11+	}
12+
13+	for rs.Next() {
14+		log := db.AccessLog{}
15+		err := rs.Scan(
16+			&log.ID, &log.UserID, &log.Service, &log.Pubkey, &log.Identity, &log.CreatedAt,
17+		)
18+		if err != nil {
19+			return nil, err
20+		}
21+		logs = append(logs, &log)
22+	}
23+
24+	if rs.Err() != nil {
25+		return nil, rs.Err()
26+	}
27+
28+	return logs, nil
29+}
30+
31 func (me *PsqlDB) FindPubkeysInAccessLogs(userID string) ([]string, error) {
32 	pubkeys := []string{}
33 	rs, err := me.Db.Query(
M pkg/db/stub/stub.go
+4, -0
 1@@ -293,6 +293,10 @@ func (me *StubDB) FindAccessLogs(userID string, fromDate *time.Time) ([]*db.Acce
 2 	return nil, errNotImpl
 3 }
 4 
 5+func (me *StubDB) FindAccessLogsByPubkey(pubkey string, fromDate *time.Time) ([]*db.AccessLog, error) {
 6+	return nil, errNotImpl
 7+}
 8+
 9 func (me *StubDB) FindPubkeysInAccessLogs(userID string) ([]string, error) {
10 	return []string{}, errNotImpl
11 }