AUTH-1403: Print the paths in the ssh-config instructions

This commit is contained in:
Austin Cherry 2019-02-01 16:56:33 -06:00
parent 200f9a3786
commit 27c6977746
1 changed files with 24 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"os" "os"
"strings"
"github.com/cloudflare/cloudflared/cmd/cloudflared/shell" "github.com/cloudflare/cloudflared/cmd/cloudflared/shell"
"github.com/cloudflare/cloudflared/cmd/cloudflared/token" "github.com/cloudflare/cloudflared/cmd/cloudflared/token"
@ -191,10 +192,9 @@ func generateToken(c *cli.Context) error {
// sshConfig prints an example SSH config to stdout // sshConfig prints an example SSH config to stdout
func sshConfig(c *cli.Context) error { func sshConfig(c *cli.Context) error {
_, err := os.Stdout.Write([]byte(`Add this configuration block to your $HOME/.ssh/config outputMessage := "Add this configuration block to your %s/.ssh/config:\n\nHost [your hostname]\n\tProxyCommand %s access ssh --hostname %%h\n"
Host <your hostname> logger.Printf(outputMessage, os.Getenv("HOME"), cloudflaredPath())
ProxyCommand cloudflared access ssh --hostname %h` + "\n")) return nil
return err
} }
// getAppURL will pull the appURL needed for fetching a user's Access token // getAppURL will pull the appURL needed for fetching a user's Access token
@ -248,3 +248,23 @@ func processURL(s string) (*url.URL, error) {
return u, nil return u, nil
} }
// cloudflaredPath pulls the full path of cloudflared on disk
func cloudflaredPath() string {
for _, p := range strings.Split(os.Getenv("PATH"), ":") {
path := fmt.Sprintf("%s/%s", p, "cloudflared")
if isFileThere(path) {
return path
}
}
return "cloudflared"
}
// isFileThere will check for the presence of candidate path
func isFileThere(candidate string) bool {
fi, err := os.Stat(candidate)
if err != nil || fi.IsDir() || !fi.Mode().IsRegular() {
return false
}
return true
}