forked from FiloSottile/whoami.filippo.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.go
45 lines (37 loc) · 811 Bytes
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"crypto/rsa"
"database/sql"
"reflect"
"unsafe"
"golang.org/x/crypto/ssh"
)
func (s *Server) getUserName(user string) (string, error) {
u, _, err := s.githubClient.Users.Get(user)
if err != nil {
return "", err
}
if u.Name == nil {
return "@" + user, nil
}
return *u.Name, nil
}
func (s *Server) findUser(keys []ssh.PublicKey) (string, error) {
for _, pk := range keys {
if pk.Type() != "ssh-rsa" {
continue
}
// Don't judge me, judge the ssh.PublicKey interface. And me. A bit.
k := (*rsa.PublicKey)(unsafe.Pointer(reflect.ValueOf(pk).Elem().UnsafeAddr()))
var user string
err := s.sqlQuery.QueryRow(k.N.String()).Scan(&user)
if err == sql.ErrNoRows {
continue
}
if err != nil {
return "", err
}
return user, nil
}
return "", nil
}