Skip to content

Commit

Permalink
Merge pull request #1 from cea-hpc/feature_user_from_key
Browse files Browse the repository at this point in the history
managerd: adding a way to retrieve user from stored key
  • Loading branch information
arno authored Jul 4, 2018
2 parents fb8f8f7 + d77fb67 commit 0f02832
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sshproxy-managerd/sshproxy-managerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -222,6 +223,15 @@ 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) {
match := regexp.MustCompile(`^(\w*)@`).FindStringSubmatch(key)
if len(match) < 2 {
return "", fmt.Errorf("Unable to extract user from given key (%s)", key)
}
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 0f02832

Please sign in to comment.