Skip to content

Commit 8b78f0d

Browse files
committed
Check if SSO authentication is still valid
1 parent eeb696f commit 8b78f0d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pkg/profile/profile.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,21 @@ func setProfile(selectedProfile string, awsProfiles models.AwsProfile) {
115115
fmt.Println("Profile set successfully")
116116

117117
if ssoEnabled {
118+
checkSSOSession()
119+
}
120+
}
121+
122+
func checkSSOSession() {
123+
// Check if the SSO session is valid
124+
err := exec.Command("aws", "sts", "get-caller-identity").Run()
125+
if err != nil {
126+
fmt.Println("SSO session is invalid, starting a new session...")
118127
err = exec.Command("aws", "sso", "login").Run()
119128
if err != nil {
120-
fmt.Println(fmt.Errorf("error logging in with SSO: %v", err))
129+
log.Fatalf("Failed to start a new SSO session: %v", err)
121130
}
122131
}
132+
123133
}
124134

125135
func PromptProfileName() string {

0 commit comments

Comments
 (0)