mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-07 19:03:17 +03:00
Added comments and better variable names in getGithubPubKeys.
This commit is contained in:
parent
3d7ff07587
commit
932410d057
@ -267,7 +267,7 @@ func (s *Server) Whitelist(fingerprint string) error {
|
|||||||
if strings.HasPrefix(fingerprint, "github.com/") {
|
if strings.HasPrefix(fingerprint, "github.com/") {
|
||||||
logger.Infof("Adding github account %s to whitelist", fingerprint)
|
logger.Infof("Adding github account %s to whitelist", fingerprint)
|
||||||
|
|
||||||
keys, err := getGithubKey(fingerprint)
|
keys, err := getGithubPubKeys(fingerprint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -290,8 +290,9 @@ func (s *Server) Whitelist(fingerprint string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var r = regexp.MustCompile(`ssh-rsa ([A-Za-z0-9\+=\/]+)\s*`)
|
var pubKeyRegex = regexp.MustCompile(`ssh-rsa ([A-Za-z0-9\+=\/]+)\s*`)
|
||||||
func getGithubKey(url string) ([]ssh.PublicKey, error) {
|
// Returns an array of public keys for the given github user URL
|
||||||
|
func getGithubPubKeys(url string) ([]ssh.PublicKey, error) {
|
||||||
resp, err := http.Get("http://" + url + ".keys")
|
resp, err := http.Get("http://" + url + ".keys")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -302,7 +303,7 @@ func getGithubKey(url string) ([]ssh.PublicKey, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
bodyStr := string(body)
|
bodyStr := string(body)
|
||||||
keys := r.FindAllStringSubmatch(bodyStr, -1)
|
keys := pubKeyRegex.FindAllStringSubmatch(bodyStr, -1)
|
||||||
pubs := make([]ssh.PublicKey, 0, 3)
|
pubs := make([]ssh.PublicKey, 0, 3)
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
if(len(key) < 2) {
|
if(len(key) < 2) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user