print 'Add to your ssh config' message on stdout
This commit is contained in:
		
							parent
							
								
									5f3cfe044f
								
							
						
					
					
						commit
						244a44fa2b
					
				|  | @ -26,19 +26,17 @@ import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	sshHostnameFlag    = "hostname" | 	sshHostnameFlag         = "hostname" | ||||||
| 	sshDestinationFlag = "destination" | 	sshDestinationFlag      = "destination" | ||||||
| 	sshURLFlag         = "url" | 	sshURLFlag              = "url" | ||||||
| 	sshHeaderFlag      = "header" | 	sshHeaderFlag           = "header" | ||||||
| 	sshTokenIDFlag     = "service-token-id" | 	sshTokenIDFlag          = "service-token-id" | ||||||
| 	sshTokenSecretFlag = "service-token-secret" | 	sshTokenSecretFlag      = "service-token-secret" | ||||||
| 	sshGenCertFlag     = "short-lived-cert" | 	sshGenCertFlag          = "short-lived-cert" | ||||||
| 	sshConnectTo       = "connect-to" | 	sshConnectTo            = "connect-to" | ||||||
| 	sshDebugStream     = "debug-stream" | 	sshDebugStream          = "debug-stream" | ||||||
| 	sshConfigTemplate  = ` | 	sshConfigTemplateStdout = ` | ||||||
| Add to your {{.Home}}/.ssh/config: | {{- if .ShortLivedCerts -}} | ||||||
| 
 |  | ||||||
| {{- if .ShortLivedCerts}} |  | ||||||
| Match host {{.Hostname}} exec "{{.Cloudflared}} access ssh-gen --hostname %h" | Match host {{.Hostname}} exec "{{.Cloudflared}} access ssh-gen --hostname %h" | ||||||
|   ProxyCommand {{.Cloudflared}} access ssh --hostname %h |   ProxyCommand {{.Cloudflared}} access ssh --hostname %h | ||||||
|   IdentityFile ~/.cloudflared/%h-cf_key |   IdentityFile ~/.cloudflared/%h-cf_key | ||||||
|  | @ -47,6 +45,9 @@ Match host {{.Hostname}} exec "{{.Cloudflared}} access ssh-gen --hostname %h" | ||||||
| Host {{.Hostname}} | Host {{.Hostname}} | ||||||
|   ProxyCommand {{.Cloudflared}} access ssh --hostname %h |   ProxyCommand {{.Cloudflared}} access ssh --hostname %h | ||||||
| {{end}} | {{end}} | ||||||
|  | ` | ||||||
|  | 	sshConfigTemplateStderr = `Add to your {{.Home}}/.ssh/config: | ||||||
|  | 
 | ||||||
| ` | ` | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -372,8 +373,14 @@ func sshConfig(c *cli.Context) error { | ||||||
| 		Cloudflared     string | 		Cloudflared     string | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	t := template.Must(template.New("sshConfig").Parse(sshConfigTemplate)) | 	tc := config{Home: os.Getenv("HOME"), ShortLivedCerts: genCertBool, Hostname: hostname, Cloudflared: cloudflaredPath()} | ||||||
| 	return t.Execute(os.Stdout, config{Home: os.Getenv("HOME"), ShortLivedCerts: genCertBool, Hostname: hostname, Cloudflared: cloudflaredPath()}) | 	t := template.Must(template.New("sshConfig").Parse(sshConfigTemplateStderr)) | ||||||
|  | 	err := t.Execute(os.Stderr, tc) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 	t = template.Must(template.New("sshConfig").Parse(sshConfigTemplateStdout)) | ||||||
|  | 	return t.Execute(os.Stdout, tc) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // sshGen generates a short lived certificate for provided hostname
 | // sshGen generates a short lived certificate for provided hostname
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue