in plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/core/credentials/ConnectionSettingsMenuBuilder.kt [62:146]
fun build(): DefaultActionGroup {
val topLevelGroup = DefaultActionGroup()
identitySelectionSettings?.let { settings ->
val connections = ToolkitAuthManager.getInstance().listConnections().filterIsInstance<AwsBearerTokenConnection>()
if (connections.isEmpty()) {
return@let
}
topLevelGroup.add(Separator.create(message("settings.credentials.individual_identity_sub_menu")))
val actions = when (settings) {
is SelectableIdentitySelectionSettings -> {
connections.map {
object : DumbAwareToggleAction<AwsBearerTokenConnection>(
title = it.label,
value = it,
selected = it == settings.currentSelection,
onSelect = settings.onChange
) {
override fun update(e: AnActionEvent) {
super.update(e)
if (value.lazyIsUnauthedBearerConnection()) {
e.presentation.icon = AllIcons.General.Warning
}
}
}
}
}
is ActionsIdentitySelectionSettings -> {
connections.map {
IndividualIdentityActionGroup(it)
}
}
}
topLevelGroup.addAll(actions)
topLevelGroup.add(Separator.create())
}
val profileActions = createProfileActions()
val regionActions = createRegionActions()
// no header if only regions
if (profileActions.isNotEmpty() && regionActions.isNotEmpty()) {
// both profiles & regions
topLevelGroup.add(Separator.create(message("settings.credentials.iam_and_regions")))
} else if (profileActions.isNotEmpty() && regionActions.isEmpty()) {
// only profiles
topLevelGroup.add(Separator.create(message("settings.credentials.iam")))
}
val regionSettings = regionSelectionSettings
val recentRegions = accountSettingsManager?.recentlyUsedRegions()
if (recentRegions?.isNotEmpty() == true && regionSettings != null) {
recentRegions.forEach {
topLevelGroup.add(SwitchRegionAction(it, it == regionSettings.currentSelection, regionSettings.onChange))
}
val allRegionsGroup = DefaultActionGroup.createPopupGroup { message("settings.regions.region_sub_menu") }
allRegionsGroup.addAll(regionActions)
topLevelGroup.add(allRegionsGroup)
} else {
topLevelGroup.addAll(regionActions)
}
topLevelGroup.add(Separator.create())
val credentialsSettings = profileSelectionSettings
val recentCredentials = accountSettingsManager?.recentlyUsedCredentials()
if (recentCredentials?.isNotEmpty() == true && credentialsSettings != null) {
recentCredentials.forEach {
topLevelGroup.add(SwitchCredentialsAction(it, it == credentialsSettings.currentSelection, credentialsSettings.onChange))
}
val allCredentialsGroup = DefaultActionGroup.createPopupGroup { message("settings.credentials.profile_sub_menu") }
allCredentialsGroup.addAll(profileActions)
topLevelGroup.add(allCredentialsGroup)
} else {
topLevelGroup.addAll(profileActions)
}
return topLevelGroup
}