Skip to content

Commit

Permalink
Merge branch 'feature/port-forward-only'
Browse files Browse the repository at this point in the history
  • Loading branch information
youyo committed Feb 8, 2022
2 parents c4d24ff + 2a465e9 commit 8254f0a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions _awssh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ _awssh() {
'(-i --identity-file)'{-i,--identity-file}'[identity file path.]' \
'--profile[use a specific profile from your credential file.]' \
'(-P --publickey)'{-P,--publickey}'[public key file path.]' \
'(-f --port-forward-only)'{-f,--port-forward-only}'[Only port-forwarding.]' \
'--select-profile[select a specific profile from your credential file.]'
}
1 change: 1 addition & 0 deletions awssh/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
rootCmd.Flags().Bool("cache", false, "enable cache a credentials.")
rootCmd.Flags().String("duration", "1 hour", "cache duration.")
rootCmd.Flags().Bool("enable-snapshot", false, "enable snapshot.")
rootCmd.Flags().BoolP("port-forward-only", "f", false, "Only port-forwarding")

viper.BindPFlags(rootCmd.Flags())
}
Expand Down
16 changes: 12 additions & 4 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Run(cmd *cobra.Command, args []string) (err error) {
profile := viper.GetString("profile")
cache := viper.GetBool("cache")
enableSnapshot := viper.GetBool("enable-snapshot")
portForwardOnly := viper.GetBool("port-forward-only")
duration, err := duration.Parse(viper.GetString("duration"))
if err != nil {
return err
Expand Down Expand Up @@ -74,18 +75,25 @@ func Run(cmd *cobra.Command, args []string) (err error) {
if err != nil {
return err
}
defer cmdPortForwarding.Process.Kill()
if !portForwardOnly {
defer cmdPortForwarding.Process.Kill()
}

if err = sendSSHPublicKey(ctx, awsSession, instanceID, viper.GetString("username"), viper.GetString("publicKey")); err != nil {
return err
}

time.Sleep(1 * time.Second)

cmdSsh, err := execSshCommand(ctx, viper.GetString("username"), ConnectHost, localPort, viper.GetString("identity-file"))
cmdSsh.Wait()
if portForwardOnly {
fmt.Printf("Host: %v\nPort: %v\nIdentityFile: %v\n", ConnectHost, localPort, viper.GetString("identity-file"))
} else {
cmdSsh, err := execSshCommand(ctx, viper.GetString("username"), ConnectHost, localPort, viper.GetString("identity-file"))
cmdSsh.Wait()
return err
}

return err
return nil
}

func Validate(cmd *cobra.Command, args []string) (err error) {
Expand Down

0 comments on commit 8254f0a

Please sign in to comment.