Skip to content

Commit

Permalink
managerd: Adding a way to retrieve user from stored key
Browse files Browse the repository at this point in the history
  • Loading branch information
fihuer committed Aug 22, 2017
1 parent 60d78c3 commit 86e36b6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sshproxy-managerd/sshproxy-managerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"io/ioutil"
"net"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -203,6 +204,17 @@ func genKey(user, host string) string {
return fmt.Sprintf("%s@%s", user, host)
}

// getUserFromKey returns the user from the key used in the proxiedConnections global variable.
func getUserFromKey(key string) (string, error) {
re := regexp.MustCompile(`^(\w*)@`)
match := re.FindStringSubmatch(key)
if len(match) < 2 {
return "", errors.New("Unable to extract user from given key (" + key + ")")
} else {
return match[1], nil
}
}

// getAlgorithmAndRoutes returns the selection algorithm and a slice with the
// possible destinations from the global configuration for a user connected to
// an hostport and belonging to groups.
Expand Down

0 comments on commit 86e36b6

Please sign in to comment.