Skip to content

Commit

Permalink
Work around some issues when profiles are set
Browse files Browse the repository at this point in the history
Fixes #32
  • Loading branch information
Eugene Dementyev committed Mar 25, 2022
1 parent f891dbc commit 3139cad
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"aws-ssh/lib/cache"
"aws-ssh/lib/ec2connect"
"path"
"strings"

"github.com/apex/log"
homedir "github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -39,11 +40,8 @@ These placeholders are useful when you need to override the ssh command.`,
var instanceUser = viper.GetString("user")

profiles := viper.GetStringSlice("profiles")
if len(profiles) > 0 {
if len(profiles) > 0 && strings.HasPrefix(instanceID, "i-") {
profile = profiles[0]
if instanceID == "" {
log.Fatalf("--instanceid is required but not set")
}
ec2connect.ConnectEC2(
lib.SSHEntries{
&lib.SSHEntry{
Expand All @@ -58,7 +56,7 @@ These placeholders are useful when you need to override the ssh command.`,
)
} else {
// ok, profile is not set, switch to mode 2
log.Info("no profile has been provided, switching to the cache mode")
log.Info("switching to the cache mode")
cache := cache.NewYAMLCache(viper.GetString("cache-dir"))

sshEntry, err := cache.Lookup(instanceID)
Expand Down Expand Up @@ -95,6 +93,7 @@ func init() {
defaultSSHConfigFile := path.Join(homeDir, ".ssh", "ec2_connect_config")

connectCmd.Flags().StringP("instanceid", "i", "", "Instance ID to connect to")
connectCmd.Flags().StringP("security-group-id", "s", "", "Security group IP to add your IP address to before connecting. If not set, then checks aws-ssh-security-group-id tag on the ec2 instance.")

connectCmd.Flags().StringP("user", "u", "", "Existing user on the instance")
connectCmd.Flags().StringP("ssh-config-path", "c", defaultSSHConfigFile, "Path to the ssh config to generate")
Expand Down

0 comments on commit 3139cad

Please sign in to comment.