Skip to content

Commit 2bfa57d

Browse files
committed
lint
1 parent bdf9131 commit 2bfa57d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/QRegionProfileManagerTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import org.junit.Rule
1515
import org.junit.Test
1616
import org.mockito.kotlin.any
1717
import org.mockito.kotlin.doReturn
18-
import org.mockito.kotlin.doThrow
1918
import org.mockito.kotlin.mock
2019
import org.mockito.kotlin.spy
2120
import org.mockito.kotlin.stub
@@ -201,10 +200,14 @@ class QRegionProfileManagerTest {
201200
this.connectionIdToActiveProfile[activeConn.id] = fooProfile
202201
this.connectionIdToActiveProfile[anotherConn.id] = barProfile
203202
}
204-
resourceCache.addEntry(activeConn.getConnectionSettings(), QProfileResources.LIST_REGION_PROFILES, listOf(
205-
QRegionProfile("foo", "foo-arn-v2"),
206-
QRegionProfile("bar", "bar-arn"),
207-
))
203+
resourceCache.addEntry(
204+
activeConn.getConnectionSettings(),
205+
QProfileResources.LIST_REGION_PROFILES,
206+
listOf(
207+
QRegionProfile("foo", "foo-arn-v2"),
208+
QRegionProfile("bar", "bar-arn"),
209+
)
210+
)
208211

209212
sut.loadState(state)
210213
assertThat(sut.activeProfile(project)).isEqualTo(fooProfile)

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/profile/QRegionProfileManager.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
1616
import com.intellij.util.xmlb.annotations.MapAnnotation
1717
import com.intellij.util.xmlb.annotations.Property
1818
import software.amazon.awssdk.core.SdkClient
19+
import software.amazon.awssdk.services.codewhispererruntime.model.AccessDeniedException
1920
import software.aws.toolkits.core.TokenConnectionSettings
2021
import software.aws.toolkits.core.utils.debug
2122
import software.aws.toolkits.core.utils.getLogger
@@ -68,14 +69,19 @@ class QRegionProfileManager : PersistentStateComponent<QProfileState>, Disposabl
6869
val selected = activeProfile(project) ?: return
6970
val profiles = try {
7071
listRegionProfiles(project)
71-
} catch (_: Exception) {
72-
// if we can't list profiles assume it is valid
73-
LOG.warn { "Continuing with $selected since listAvailableProfiles failed" }
74-
return
72+
} catch (e: Exception) {
73+
if (e is AccessDeniedException) {
74+
null
75+
} else {
76+
// if we can't list profiles assume it is valid
77+
LOG.warn { "Continuing with $selected since listAvailableProfiles failed" }
78+
return
79+
}
7580
}
7681

7782
// succeeded in listing profiles, but none match selected
78-
if (profiles?.none { it.arn == selected.arn } == true) {
83+
// profiles should be null if access denied or connection is not IdC
84+
if (profiles == null || profiles.none { it.arn == selected.arn }) {
7985
invalidateProfile(selected.arn)
8086
switchProfile(project, null, intent = QProfileSwitchIntent.Reload)
8187
Telemetry.amazonq.profileState.use { span ->

0 commit comments

Comments
 (0)