Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/sdkutil/awsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ import (
var defaultRegion string
var defaultProfile string

// GetNewSessionWithEndpoint creates aws sdk session with given profile, region and endpoint
func GetNewSessionWithEndpoint(endpoint string) (sess *session.Session, err error) {
// GetDefaultSession creates aws sdk session with given profile and region
func GetDefaultSession() (sess *session.Session, err error) {
if sess, err = session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Retryer: newRetryer(),
SleepDelay: sleepDelay,
Region: aws.String(defaultRegion),
Endpoint: aws.String(endpoint),
},
SharedConfigState: session.SharedConfigEnable,
Profile: defaultProfile,
Expand All @@ -43,11 +42,6 @@ func GetNewSessionWithEndpoint(endpoint string) (sess *session.Session, err erro
return sess, nil
}

// GetDefaultSession creates aws sdk session with given profile and region
func GetDefaultSession() (sess *session.Session, err error) {
return GetNewSessionWithEndpoint("")
}

// Sets the region and profile for default aws sessions
func SetRegionAndProfile(region string, profile string) {
defaultRegion = region
Expand Down
14 changes: 7 additions & 7 deletions src/sessionmanagerplugin/session/sessionhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"math/rand"
"os"

"github.com/aws/aws-sdk-go/aws"
sdkSession "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/session-manager-plugin/src/config"
Expand Down Expand Up @@ -99,10 +100,10 @@ func (s *Session) GetResumeSessionParams(log log.T) (string, error) {
sdkSession *sdkSession.Session
)

if sdkSession, err = sdkutil.GetNewSessionWithEndpoint(s.Endpoint); err != nil {
if sdkSession, err = sdkutil.GetDefaultSession(); err != nil {
return "", err
}
s.sdk = ssm.New(sdkSession)
s.sdk = ssm.New(sdkSession, aws.NewConfig().WithEndpoint(s.Endpoint))

resumeSessionInput := ssm.ResumeSessionInput{
SessionId: &s.SessionId,
Expand Down Expand Up @@ -140,15 +141,14 @@ func (s *Session) ResumeSessionHandler(log log.T) (err error) {
// TerminateSession calls TerminateSession API
func (s *Session) TerminateSession(log log.T) error {
var (
err error
newSession *sdkSession.Session
err error
)

if newSession, err = sdkutil.GetNewSessionWithEndpoint(s.Endpoint); err != nil {
log.Errorf("Terminate Session failed: %v", err)
if sdkSession, err := sdkutil.GetDefaultSession(); err != nil {
return err
} else {
s.sdk = ssm.New(sdkSession, aws.NewConfig().WithEndpoint(s.Endpoint))
}
s.sdk = ssm.New(newSession)

terminateSessionInput := ssm.TerminateSessionInput{
SessionId: &s.SessionId,
Expand Down
10 changes: 4 additions & 6 deletions src/ssmclicommands/startsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"html/template"
"strings"

sdkSession "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/session-manager-plugin/src/datachannel"
"github.com/aws/session-manager-plugin/src/jsonutil"
Expand Down Expand Up @@ -92,13 +92,11 @@ type StartSessionCommand struct {
var getSSMClient = func(log log.T, region string, profile string, endpoint string) (*ssm.SSM, error) {
sdkutil.SetRegionAndProfile(region, profile)

var sdkSession *sdkSession.Session
sdkSession, err := sdkutil.GetNewSessionWithEndpoint(endpoint)
if err != nil {
log.Errorf("Get session with endpoint Failed: %v", err)
if sdkSession, err := sdkutil.GetDefaultSession(); err != nil {
return nil, err
} else {
return ssm.New(sdkSession, aws.NewConfig().WithEndpoint(endpoint)), nil
}
return ssm.New(sdkSession), nil
}

// executeSession to open datachannel
Expand Down