Skip to content

Commit 017a3a2

Browse files
committed
remove config file editing and stop Q window from switching views on unauthed connection selection.
1 parent 3755880 commit 017a3a2

File tree

3 files changed

+5
-37
lines changed

3 files changed

+5
-37
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQToolWindowFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class AmazonQToolWindowFactory : ToolWindowFactory, DumbAware {
144144
QWebviewPanel.getInstance(project).browser?.prepareBrowser(BrowserState(FeatureId.Q))
145145

146146
// isQConnected alone is not robust and there is race condition (read/update connection states)
147-
val component = if (isNewConnectionForQ || (isQConnected(project) && !isQExpired(project))) {
147+
val component = if ((isQConnected(project) && !isQExpired(project))) {
148148
LOG.debug { "returning Q-chat window; isQConnection=$isNewConnectionForQ; hasPinnedConnection=$isNewConnectionForQ" }
149149
AmazonQToolWindow.getInstance(project).component
150150
} else {

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ConfigFilesFacade.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ interface ConfigFilesFacade {
4141
fun updateSectionInConfig(sectionName: String, profile: Profile)
4242

4343
fun deleteSsoConnectionFromConfig(sessionName: String)
44-
fun deleteSsoProfileScopesFromConfig(sessionName: String)
4544
}
4645

4746
class DefaultConfigFilesFacade(
@@ -198,31 +197,6 @@ class DefaultConfigFilesFacade(
198197
}
199198
}
200199

201-
override fun deleteSsoProfileScopesFromConfig(sessionName: String) {
202-
val filePath = configPath
203-
val lines = filePath.inputStreamIfExists()?.reader()?.readLines().orEmpty().toMutableList()
204-
val ssoHeaderLine = lines.indexOfFirst { it.startsWith("[${SsoSessionConstants.SSO_SESSION_SECTION_NAME} $sessionName]") }
205-
if (ssoHeaderLine == -1) return
206-
val nextHeaderLine = lines.subList(ssoHeaderLine + 1, lines.size).indexOfFirst { it.startsWith("[") }
207-
val endIndex = if (nextHeaderLine == -1) lines.size else ssoHeaderLine + nextHeaderLine + 1
208-
209-
// Find and remove the sso_registration_scopes line
210-
for (i in ssoHeaderLine until endIndex) {
211-
if (lines[i].trim().startsWith("sso_registration_scopes=")) {
212-
lines.removeAt(i)
213-
break
214-
}
215-
}
216-
217-
filePath.writeText(lines.joinToString("\n"))
218-
219-
val applicationManager = ApplicationManager.getApplication()
220-
if (applicationManager != null && !applicationManager.isUnitTestMode) {
221-
FileDocumentManager.getInstance().saveAllDocuments()
222-
ProfileWatcher.getInstance().forceRefresh()
223-
}
224-
}
225-
226200
private fun getCorrespondingSsoSessionProfilePosition(updatedArray: List<String>, sessionName: String): List<String> {
227201
var content = updatedArray
228202
val finalContent = mutableListOf<String>()

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitAuthManager.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,9 @@ fun loginSso(
203203

204204
@Suppress("UnusedParameter")
205205
fun logoutFromSsoConnection(project: Project?, connection: AwsBearerTokenConnection, callback: () -> Unit = {}) {
206-
try {
207-
ToolkitAuthManager.getInstance().deleteConnection(connection.id)
208-
ProfileWatcher.getInstance().forceRefresh()
209-
if (connection is ProfileSsoManagedBearerSsoConnection) {
210-
deleteSsoConnection(connection)
211-
}
212-
} finally {
213-
callback()
214-
}
206+
ToolkitAuthManager.getInstance().deleteConnection(connection.id)
207+
ProfileWatcher.getInstance().forceRefresh()
208+
callback()
215209
}
216210

217211
fun lazyGetUnauthedBearerConnections() =
@@ -340,7 +334,7 @@ fun deleteSsoConnection(connection: ProfileSsoManagedBearerSsoConnection) =
340334
fun deleteSsoConnection(connection: CredentialIdentifier) =
341335
deleteSsoConnection(getSsoSessionProfileNameFromCredentials(connection))
342336

343-
fun deleteSsoConnection(sessionName: String) = DefaultConfigFilesFacade().deleteSsoProfileScopesFromConfig(sessionName)
337+
fun deleteSsoConnection(sessionName: String) = DefaultConfigFilesFacade().deleteSsoConnectionFromConfig(sessionName)
344338

345339
private fun getSsoSessionProfileNameFromCredentials(connection: CredentialIdentifier): String {
346340
connection as ProfileCredentialsIdentifierSso

0 commit comments

Comments
 (0)