Skip to content

Commit

Permalink
Handle throttle exceptions on public key send
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Burgess committed Dec 17, 2019
1 parent 4d48bd4 commit 5ddad4a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/aws/aws-sdk-go v1.25.48
github.com/blang/semver v3.5.1+incompatible
github.com/pkg/errors v0.8.1
github.com/rhysd/go-github-selfupdate v1.1.0
github.com/sirupsen/logrus v1.4.2
github.com/urfave/cli/v2 v2.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rhysd/go-github-selfupdate v1.1.0 h1:+aMomy69YCYxJ6kr13nYIgAJWSB1kHK5M5YpbmjQkWo=
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func main() {
Aliases: []string{"lp"},
DefaultText: "local port to map to, defaults to tunnel port",
},
&cli.BoolFlag{
Name: "debug",
DefaultText: "Print debug information",
},
},
Commands: []*cli.Command{
{
Expand Down Expand Up @@ -103,6 +107,10 @@ func SetupSignalHandlers() {
}

func run(c *cli.Context) error {
if c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}

var tagName string
var tagValue string

Expand Down
13 changes: 11 additions & 2 deletions pkg/sshutils/ec2endpoint.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package sshutils

import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
connect "github.com/aws/aws-sdk-go/service/ec2instanceconnect"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
)
Expand Down Expand Up @@ -94,8 +95,16 @@ func sendPublicKey(instance *ec2.Instance, user, publicKey string, client *conne
InstanceOSUser: aws.String(user),
SSHPublicKey: aws.String(publicKey),
})

if err != nil {
return err
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == connect.ErrCodeThrottlingException {
log.Debug("Got throttling exception, usually just means the key is already valid")
return nil
}
}

return errors.Wrap(err, "send public key error")
}

if !*out.Success {
Expand Down

0 comments on commit 5ddad4a

Please sign in to comment.