Skip to content
Merged
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
2 changes: 1 addition & 1 deletion internal/common/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (s *Services) IsAWSConfigured() bool {
return false
}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

creds, err := s.Provider.AwsConfig.Credentials.Retrieve(ctx)
Expand Down
2 changes: 1 addition & 1 deletion internal/sso/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (c *RealSSOClient) SSOLogin(awsProfile string, refresh, noBrowser bool) err
}
args = append(args, "--profile", awsProfile)

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

err := c.Executor.RunInteractiveCommand(ctx, "aws", args...)
Expand Down
9 changes: 3 additions & 6 deletions internal/sso/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,12 @@ func (c *RealSSOClient) loadOrCreateSession() (string, *models.SSOSession, error
return "", nil, fmt.Errorf("failed to prompt for SSO start URL: %w", err)
}

region, err := c.Prompter.PromptForRegion("ap-south-1")
region, err := c.Prompter.PromptForRegion("us-east-1")
if err != nil {
return "", nil, fmt.Errorf("failed to prompt for SSO region: %w", err)
}

scopes, err := c.Prompter.PromptWithDefault("SSO registration scopes (comma separated)", "sso:account:access")
if err != nil {
return "", nil, fmt.Errorf("failed to prompt for SSO scopes: %w", err)
}
scopes := "sso:account:access"

ssoSession = &models.SSOSession{
Name: name,
Expand Down Expand Up @@ -235,7 +232,7 @@ func (c *RealSSOClient) runSSOLogin(sessionName string) error {

fmt.Println("\nInitiating AWS SSO login... (this may open a browser window)")

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()

if err := c.Executor.RunInteractiveCommand(ctx, "aws", "sso", "login", "--sso-session", sessionName); err != nil {
Expand Down
35 changes: 4 additions & 31 deletions internal/sso/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func TestLoadOrCreateSession(t *testing.T) {
mockPrompts: []mockPrompt{
{"PromptWithDefault", "SSO session name", "default-sso", "test-session", nil},
{"PromptRequired", "SSO start URL (e.g., https://my-sso-portal.awsapps.com/start)", "", "https://test.awsapps.com/start", nil},
{"PromptForRegion", "SSO region (Default: ap-south-1):", "ap-south-1", "us-west-2", nil},
{"PromptWithDefault", "SSO registration scopes (comma separated)", "sso:account:access", "sso:account:access", nil},
{"PromptForRegion", "us-east-1", "us-east-1", "us-west-2", nil},
},
wantSession: &models.SSOSession{
Name: "test-session",
Expand All @@ -54,30 +53,7 @@ func TestLoadOrCreateSession(t *testing.T) {
},
wantConfigPath: "",
},
{
name: "Use existing single session - exact name match",
initialConfig: &models.Config{
SSOSessions: []models.SSOSession{
{
Name: "existing-session",
StartURL: "https://existing.awsapps.com/start",
Region: "us-east-1",
},
},
},
mockPrompts: []mockPrompt{
{"PromptWithDefault", "SSO session name", "default-sso", "existing-session", nil},
{"PromptRequired", "SSO start URL (e.g., https://my-sso-portal.awsapps.com/start)", "", "https://existing.awsapps.com/start", nil},
{"PromptForRegion", "SSO region (Default: ap-south-1):", "ap-south-1", "us-east-1", nil},
{"PromptWithDefault", "SSO registration scopes (comma separated)", "sso:account:access", "sso:account:access", nil},
},
wantSession: &models.SSOSession{
Name: "existing-session",
StartURL: "https://existing.awsapps.com/start",
Region: "us-east-1",
Scopes: "sso:account:access",
},
},

{
name: "Region prompt error",
initialConfig: &models.Config{
Expand All @@ -86,7 +62,7 @@ func TestLoadOrCreateSession(t *testing.T) {
mockPrompts: []mockPrompt{
{"PromptWithDefault", "SSO session name", "default-sso", "test-session", nil},
{"PromptRequired", "SSO start URL (e.g., https://my-sso-portal.awsapps.com/start)", "", "https://test.awsapps.com/start", nil},
{"PromptForRegion", "SSO region (Default: ap-south-1):", "ap-south-1", "", errors.New("invalid region")},
{"PromptForRegion", "us-east-1", "us-east-1", "", errors.New("invalid region")},
},
wantErr: true,
errContains: "failed to prompt for SSO region",
Expand All @@ -100,6 +76,7 @@ func TestLoadOrCreateSession(t *testing.T) {

mockPrompter := mock_sso.NewMockPrompter(ctrl)

// Set up expected mock calls
for _, mp := range tt.mockPrompts {
switch mp.method {
case "PromptWithDefault":
Expand All @@ -114,10 +91,6 @@ func TestLoadOrCreateSession(t *testing.T) {
mockPrompter.EXPECT().
PromptForRegion(mp.defaultValue).
Return(mp.response, mp.err)
case "SelectFromList":
mockPrompter.EXPECT().
SelectFromList(mp.label, gomock.Any()).
Return(mp.response, mp.err)
}
}

Expand Down
28 changes: 8 additions & 20 deletions internal/sso/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,30 @@ func (c *RealSSOClient) SetupSSO() error {
return fmt.Errorf("failed to select role: %w", err)
}

profileName, region, err := c.promptProfileDetails(ssoSession.Region)
if err != nil {
if errors.Is(err, promptUtils.ErrInterrupted) {
return nil
}
return fmt.Errorf("failed to prompt profile details: %w", err)
}
profileName := ssoSession.Name + "-profile"

if err := c.configureAWSProfile(profileName, ssoSession.Name, ssoSession.Region, ssoSession.StartURL, accountID, role, region); err != nil {
if err := c.configureAWSProfile(profileName, ssoSession.Name, ssoSession.Region, ssoSession.StartURL, accountID, role, ssoSession.Region); err != nil {
return fmt.Errorf("failed to configure AWS profile: %w", err)
}

defaultConfigured := profileName == "default"

if !defaultConfigured {
setDefault, err := c.Prompter.PromptYesNo("Set this as the default profile? [Y/n]", true)
if err != nil {
if errors.Is(err, promptUtils.ErrInterrupted) {
return nil
}
return fmt.Errorf("failed to prompt for default profile: %w", err)
}
if setDefault {
if err := c.configureAWSProfile("default", ssoSession.Name, ssoSession.Region, ssoSession.StartURL, accountID, role, region); err != nil {
return fmt.Errorf("failed to configure AWS default profile: %w", err)
}
defaultConfigured = true
if err := c.configureAWSProfile("default", ssoSession.Name, ssoSession.Region, ssoSession.StartURL, accountID, role, ssoSession.Region); err != nil {
return fmt.Errorf("failed to configure AWS default profile: %w", err)
}
defaultConfigured = true
}

printSummary(profileName, ssoSession.Name, ssoSession.StartURL, ssoSession.Region, accountID, role, "", "", "")
fmt.Printf("\nSuccessfully configured AWS profile '%s'!\n", profileName)

if defaultConfigured {
fmt.Println("You can now use AWS CLI commands without specifying --profile")
} else {
fmt.Printf("You can now use this profile with AWS CLI commands using: --profile %s\n", profileName)
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion utils/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func terminateProcess(pid int) error {
}
}

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
for {
select {
Expand Down
Loading